webrtc断开时重连
This commit is contained in:
parent
c461a69cd9
commit
c7c3ff2b24
@ -62,8 +62,18 @@ export default class ClientList {
|
||||
}
|
||||
}
|
||||
}
|
||||
webrtc.oniceconnectionstatechange = event => {
|
||||
console.log('WebRTC ICE 连接状态更改:', webrtc.iceConnectionState)
|
||||
webrtc.oniceconnectionstatechange = async event => {
|
||||
console.log('WebRTC ICE 连接状态更改:', webrtc.iceConnectionState, event)
|
||||
if (webrtc.iceConnectionState === 'disconnected') {
|
||||
console.log('WebRTC ICE connection disconnected')
|
||||
// 如果用户没有离线, 则尝试重连
|
||||
if (this.clientlist.find(x => x.id === data.id)) {
|
||||
console.log('用户仍在线, 尝试重连...')
|
||||
const offer = await webrtc.createOffer()
|
||||
await webrtc.setLocalDescription(offer)
|
||||
websocket.send(JSON.stringify({ type: 'offer', id: data.id, offer }))
|
||||
}
|
||||
}
|
||||
}
|
||||
const channels = Object.entries(this.channels).map(([name, callback]) => {
|
||||
const channel = webrtc.createDataChannel(name, { reliable: true })
|
||||
|
Loading…
Reference in New Issue
Block a user