微弱提示音
This commit is contained in:
parent
ae224bd983
commit
4ea9a51740
16
src/chat.js
16
src/chat.js
@ -134,10 +134,23 @@ export default class Chat {
|
|||||||
Notification.requestPermission()
|
Notification.requestPermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async 播放提示音() {
|
||||||
|
// 如果页面可见或且浏览器不在前台运行
|
||||||
|
if (document.visibilityState === 'visible') return console.log('页面可见')
|
||||||
|
// 创建一个MIDI的清脆的"叮咚"
|
||||||
|
const context = new AudioContext()
|
||||||
|
const o = context.createOscillator()
|
||||||
|
const g = context.createGain()
|
||||||
|
o.connect(g)
|
||||||
|
o.type = 'sine'
|
||||||
|
o.frequency.value = 400
|
||||||
|
g.connect(context.destination)
|
||||||
|
o.start(0)
|
||||||
|
g.gain.exponentialRampToValueAtTime(0.00001, context.currentTime + 1)
|
||||||
|
}
|
||||||
async 通知栏消息(data) {
|
async 通知栏消息(data) {
|
||||||
console.log('通知栏消息', data)
|
console.log('通知栏消息', data)
|
||||||
const { name, text, avatar } = data
|
const { name, text, avatar } = data
|
||||||
const icon = 'https://webrtc.satori.love/favicon.ico'
|
|
||||||
// 如果页面可见或且浏览器不在前台运行, 则发送通知
|
// 如果页面可见或且浏览器不在前台运行, 则发送通知
|
||||||
if (document.visibilityState === 'visible') return console.log('页面可见')
|
if (document.visibilityState === 'visible') return console.log('页面可见')
|
||||||
// 如果用户不允许通知,则不发送通知
|
// 如果用户不允许通知,则不发送通知
|
||||||
@ -372,5 +385,6 @@ export default class Chat {
|
|||||||
this.添加元素(data)
|
this.添加元素(data)
|
||||||
this.存储消息(save)
|
this.存储消息(save)
|
||||||
this.通知栏消息(data)
|
this.通知栏消息(data)
|
||||||
|
this.播放提示音()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user