DEBUG: candidate 状态
This commit is contained in:
parent
f16e3f62cb
commit
688ba3a7f6
@ -119,7 +119,8 @@ export default class ClientList {
|
|||||||
}
|
}
|
||||||
webrtc.oniceconnectionstatechange = async event => {
|
webrtc.oniceconnectionstatechange = async event => {
|
||||||
if (webrtc.iceConnectionState === 'disconnected' || webrtc.iceConnectionState === 'failed') {
|
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
|
// 添加新的 candidate
|
||||||
} else if (webrtc.iceConnectionState === 'connected' || webrtc.iceConnectionState === 'completed') {
|
} else if (webrtc.iceConnectionState === 'connected' || webrtc.iceConnectionState === 'completed') {
|
||||||
//console.debug(data.name, 'WebRTC 连接已经建立成功')
|
//console.debug(data.name, 'WebRTC 连接已经建立成功')
|
||||||
@ -147,7 +148,7 @@ export default class ClientList {
|
|||||||
const { webrtc, channels } = await webrtc_init()
|
const { webrtc, channels } = await webrtc_init()
|
||||||
const offer = await webrtc.createOffer()
|
const offer = await webrtc.createOffer()
|
||||||
await webrtc.setLocalDescription(offer)
|
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 }))
|
websocket.send(JSON.stringify({ type: 'offer', id: data.id, offer }))
|
||||||
this.push(this.clientlist.find(client => client.id === data.id))
|
this.push(this.clientlist.find(client => client.id === data.id))
|
||||||
return
|
return
|
||||||
@ -158,11 +159,14 @@ export default class ClientList {
|
|||||||
}
|
}
|
||||||
if (data.type === 'pull') {
|
if (data.type === 'pull') {
|
||||||
//console.debug('移除客户端:', data)
|
//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)
|
return this.exit(data)
|
||||||
}
|
}
|
||||||
if (data.type === 'offer') {
|
if (data.type === 'offer') {
|
||||||
const { webrtc, channels } = await webrtc_init()
|
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))
|
this.push(this.clientlist.find(client => client.id === data.id))
|
||||||
await webrtc.setRemoteDescription(data.offer)
|
await webrtc.setRemoteDescription(data.offer)
|
||||||
const answer = await webrtc.createAnswer()
|
const answer = await webrtc.createAnswer()
|
||||||
@ -239,7 +243,7 @@ export default class ClientList {
|
|||||||
const avatar = localStorage.getItem('avatar')
|
const avatar = localStorage.getItem('avatar')
|
||||||
this.push({ id, name: username, avatar }, true)
|
this.push({ id, name: username, avatar }, true)
|
||||||
}
|
}
|
||||||
async 用户列表() {}
|
async 用户列表() { }
|
||||||
async 用户加入(data) {
|
async 用户加入(data) {
|
||||||
await set(data.id, data, this.store)
|
await set(data.id, data, this.store)
|
||||||
this.push(data)
|
this.push(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user