DEBUG: candidate 状态

This commit is contained in:
2023-10-22 15:42:42 +08:00
parent f16e3f62cb
commit 688ba3a7f6
1 changed files with 8 additions and 4 deletions

View File

@ -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()