通知支持头像

This commit is contained in:
2023-10-25 22:37:28 +08:00
parent 175db8c90c
commit ae224bd983
2 changed files with 5 additions and 5 deletions

View File

@ -136,7 +136,7 @@ export default class Chat {
} }
async 通知栏消息(data) { async 通知栏消息(data) {
console.log('通知栏消息', data) console.log('通知栏消息', data)
const { name, text, time, type } = data const { name, text, avatar } = data
const icon = 'https://webrtc.satori.love/favicon.ico' const icon = 'https://webrtc.satori.love/favicon.ico'
// 如果页面可见或且浏览器不在前台运行, 则发送通知 // 如果页面可见或且浏览器不在前台运行, 则发送通知
if (document.visibilityState === 'visible') return console.log('页面可见') if (document.visibilityState === 'visible') return console.log('页面可见')
@ -147,7 +147,7 @@ export default class Chat {
await Notification.requestPermission() await Notification.requestPermission()
} }
if (Notification.permission === 'granted') { if (Notification.permission === 'granted') {
const notification = new Notification(name, { body: text, icon }) const notification = new Notification(name, { body: text, icon:avatar })
notification.onclick = () => { notification.onclick = () => {
window.focus() window.focus()
notification.close() notification.close()
@ -368,9 +368,9 @@ export default class Chat {
this.send(data) this.send(data)
} }
收到消息(data) { 收到消息(data) {
console.log('收到消息', data) const { avatar, ...save } = data
this.添加元素(data) this.添加元素(data)
this.存储消息(data) this.存储消息(save)
this.通知栏消息(data) this.通知栏消息(data)
} }
} }

View File

@ -200,7 +200,7 @@ clientList.setChannel('chat', {
const data = JSON.parse(event.data) const data = JSON.parse(event.data)
if (data.type === 'message') { if (data.type === 'message') {
console.log(client.name, '发来消息:', data) console.log(client.name, '发来消息:', data)
chat.收到消息({ name: client.name, ...data.text }) chat.收到消息({ name: client.name, ...data.text, avatar: client.avatar })
return return
} }
if (data.type === 'answer') { if (data.type === 'answer') {