diff --git a/src/client.js b/src/client.js index 35db8fd..ee09054 100644 --- a/src/client.js +++ b/src/client.js @@ -119,7 +119,8 @@ export default class ClientList { } webrtc.oniceconnectionstatechange = async event => { if (webrtc.iceConnectionState === 'disconnected' || webrtc.iceConnectionState === 'failed') { - console.error(data.name, '需要添加新的 candidate') + const client = this.clientlist.find(x => x.id === data.id) + console.error(data.name, '需要添加新的 candidate', client.online) // 添加新的 candidate } else if (webrtc.iceConnectionState === 'connected' || webrtc.iceConnectionState === 'completed') { //console.debug(data.name, 'WebRTC 连接已经建立成功') @@ -147,7 +148,7 @@ export default class ClientList { const { webrtc, channels } = await webrtc_init() const offer = await webrtc.createOffer() await webrtc.setLocalDescription(offer) - this.clientlist.push({ id: data.id, name: data.name, webrtc, channels }) + this.clientlist.push({ id: data.id, name: data.name, webrtc, channels, online: true }) websocket.send(JSON.stringify({ type: 'offer', id: data.id, offer })) this.push(this.clientlist.find(client => client.id === data.id)) return @@ -158,11 +159,14 @@ export default class ClientList { } if (data.type === 'pull') { //console.debug('移除客户端:', data) + const client = this.clientlist.find(client => client.id === data.id) + if (!client) return console.error('目标用户本不存在') + client.online = false // 离开时改变状态 return this.exit(data) } if (data.type === 'offer') { const { webrtc, channels } = await webrtc_init() - this.clientlist.push({ id: data.id, name: data.name, webrtc, channels }) + this.clientlist.push({ id: data.id, name: data.name, webrtc, channels, online: true }) this.push(this.clientlist.find(client => client.id === data.id)) await webrtc.setRemoteDescription(data.offer) const answer = await webrtc.createAnswer() @@ -239,7 +243,7 @@ export default class ClientList { const avatar = localStorage.getItem('avatar') this.push({ id, name: username, avatar }, true) } - async 用户列表() {} + async 用户列表() { } async 用户加入(data) { await set(data.id, data, this.store) this.push(data)