onicecandidate 连接稳定
This commit is contained in:
parent
4f7741b341
commit
383f1bd70e
|
@ -18,12 +18,12 @@ export default class ClientList {
|
||||||
console.log('取得在线对端列表:', data)
|
console.log('取得在线对端列表:', data)
|
||||||
const webrtc = new RTCPeerConnection()
|
const webrtc = new RTCPeerConnection()
|
||||||
webrtc.createDataChannel('music')
|
webrtc.createDataChannel('music')
|
||||||
//webrtc.onicecandidate = event => {
|
webrtc.onicecandidate = event => {
|
||||||
// console.log('clientlist onicecandidate E', event)
|
console.log('clientlist onicecandidate E', event)
|
||||||
// if (event.candidate) {
|
if (event.candidate) {
|
||||||
// this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate }))
|
this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate }))
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
console.log('发送给对方 offer')
|
console.log('发送给对方 offer')
|
||||||
const offer = await webrtc.createOffer()
|
const offer = await webrtc.createOffer()
|
||||||
await webrtc.setLocalDescription(offer)
|
await webrtc.setLocalDescription(offer)
|
||||||
|
@ -43,12 +43,12 @@ export default class ClientList {
|
||||||
console.log('收到对方 offer', data)
|
console.log('收到对方 offer', data)
|
||||||
const webrtc = new RTCPeerConnection()
|
const webrtc = new RTCPeerConnection()
|
||||||
webrtc.createDataChannel('music')
|
webrtc.createDataChannel('music')
|
||||||
//webrtc.onicecandidate = event => {
|
webrtc.onicecandidate = event => {
|
||||||
// console.log('clientlist onicecandidate X', event)
|
console.log('clientlist onicecandidate X', event)
|
||||||
// if (event.candidate) {
|
if (event.candidate) {
|
||||||
// this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate }))
|
this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate }))
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
this.clientlist.push({ id: data.id, name: data.name, webrtc })
|
this.clientlist.push({ id: data.id, name: data.name, webrtc })
|
||||||
console.log('发送给对方 answer')
|
console.log('发送给对方 answer')
|
||||||
await webrtc.setRemoteDescription(data.offer)
|
await webrtc.setRemoteDescription(data.offer)
|
||||||
|
|
Loading…
Reference in New Issue