函数存在判断

This commit is contained in:
2023-10-01 00:06:03 +08:00
parent 3a2d7f40c8
commit f82c1538f5
1 changed files with 2 additions and 2 deletions

View File

@ -40,13 +40,13 @@ export default class ClientList {
console.log('收到对方 datachannel', channel) console.log('收到对方 datachannel', channel)
channel.onopen = event => { channel.onopen = event => {
console.log('收到对方 datachannel open', event) console.log('收到对方 datachannel open', event)
if (this.channels[event.target.label]) { if (this.channels[event.target.label] && this.channels[event.target.label].onopen) {
this.channels[event.target.label].onopen(event, this.clientlist.find(x => x.id === data.id)) this.channels[event.target.label].onopen(event, this.clientlist.find(x => x.id === data.id))
} }
} }
channel.onmessage = event => { channel.onmessage = event => {
console.log('收到对方 datachannel message', event) console.log('收到对方 datachannel message', event)
if (this.channels[event.target.label]) { if (this.channels[event.target.label] && this.channels[event.target.label].onmessage) {
this.channels[event.target.label].onmessage(event, this.clientlist.find(x => x.id === data.id)) this.channels[event.target.label].onmessage(event, this.clientlist.find(x => x.id === data.id))
} }
} }