From 383f1bd70e2cabb36161f8653bf222c7c90758b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Thu, 28 Sep 2023 23:54:58 +0800 Subject: [PATCH] =?UTF-8?q?onicecandidate=20=E8=BF=9E=E6=8E=A5=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/client.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/public/client.js b/public/client.js index f49727f..3565e58 100644 --- a/public/client.js +++ b/public/client.js @@ -18,12 +18,12 @@ export default class ClientList { console.log('取得在线对端列表:', data) const webrtc = new RTCPeerConnection() webrtc.createDataChannel('music') - //webrtc.onicecandidate = event => { - // console.log('clientlist onicecandidate E', event) - // if (event.candidate) { - // this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate })) - // } - //} + webrtc.onicecandidate = event => { + console.log('clientlist onicecandidate E', event) + if (event.candidate) { + this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate })) + } + } console.log('发送给对方 offer') const offer = await webrtc.createOffer() await webrtc.setLocalDescription(offer) @@ -43,12 +43,12 @@ export default class ClientList { console.log('收到对方 offer', data) const webrtc = new RTCPeerConnection() webrtc.createDataChannel('music') - //webrtc.onicecandidate = event => { - // console.log('clientlist onicecandidate X', event) - // if (event.candidate) { - // this.websocket.send(JSON.stringify({ type: 'candidate', id: data.id, candidate: event.candidate })) - // } - //} + webrtc.onicecandidate = event => { + console.log('clientlist onicecandidate X', event) + if (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 }) console.log('发送给对方 answer') await webrtc.setRemoteDescription(data.offer)