通知支持头像
This commit is contained in:
parent
175db8c90c
commit
ae224bd983
@ -136,7 +136,7 @@ export default class Chat {
|
||||
}
|
||||
async 通知栏消息(data) {
|
||||
console.log('通知栏消息', data)
|
||||
const { name, text, time, type } = data
|
||||
const { name, text, avatar } = data
|
||||
const icon = 'https://webrtc.satori.love/favicon.ico'
|
||||
// 如果页面可见或且浏览器不在前台运行, 则发送通知
|
||||
if (document.visibilityState === 'visible') return console.log('页面可见')
|
||||
@ -147,7 +147,7 @@ export default class Chat {
|
||||
await Notification.requestPermission()
|
||||
}
|
||||
if (Notification.permission === 'granted') {
|
||||
const notification = new Notification(name, { body: text, icon })
|
||||
const notification = new Notification(name, { body: text, icon:avatar })
|
||||
notification.onclick = () => {
|
||||
window.focus()
|
||||
notification.close()
|
||||
@ -368,9 +368,9 @@ export default class Chat {
|
||||
this.send(data)
|
||||
}
|
||||
收到消息(data) {
|
||||
console.log('收到消息', data)
|
||||
const { avatar, ...save } = data
|
||||
this.添加元素(data)
|
||||
this.存储消息(data)
|
||||
this.存储消息(save)
|
||||
this.通知栏消息(data)
|
||||
}
|
||||
}
|
@ -200,7 +200,7 @@ clientList.setChannel('chat', {
|
||||
const data = JSON.parse(event.data)
|
||||
if (data.type === 'message') {
|
||||
console.log(client.name, '发来消息:', data)
|
||||
chat.收到消息({ name: client.name, ...data.text })
|
||||
chat.收到消息({ name: client.name, ...data.text, avatar: client.avatar })
|
||||
return
|
||||
}
|
||||
if (data.type === 'answer') {
|
||||
|
Loading…
Reference in New Issue
Block a user