From 2c90f65535b5c3cc63a07ff10c1e00a4cda1d9f6 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Tue, 19 Jun 2018 09:52:04 +0200 Subject: [PATCH] openvidu-browser: Stream stores iceCandidate list (sent and received) --- openvidu-browser/src/OpenVidu/Session.ts | 16 ---------------- openvidu-browser/src/OpenVidu/Stream.ts | 14 ++++++++++++++ .../OpenViduInternal/WebRtcPeer/WebRtcPeer.ts | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index a517e279..04891b8f 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -698,22 +698,6 @@ export class Session implements EventDispatcher { return { candidate: msg.candidate }; } }; - - /*this.getConnection(msg.endpointName, 'Connection not found for endpoint ' + msg.endpointName + '. Ice candidate will be ignored: ' + candidate) - - .then(connection => { - const stream = connection.stream; - stream.getWebRtcPeer().addIceCandidate(candidate, (error) => { - if (error) { - console.error('Error adding candidate for ' + stream.streamId - + ' stream of endpoint ' + msg.endpointName + ': ' + error); - } - }); - }) - .catch(openViduError => { - console.error(openViduError); - });*/ - this.getConnection(msg.endpointName, 'Connection not found for endpoint ' + msg.endpointName + '. Ice candidate will be ignored: ' + candidate) .then(connection => { const stream = connection.stream; diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index d71549ea..fbbf45d0 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -374,6 +374,20 @@ export class Stream { }); } + /** + * @hidden + */ + getRemoteIceCandidateList(): RTCIceCandidate[] { + return this.webRtcPeer.remoteCandidatesQueue; + } + + /** + * @hidden + */ + getLocalIceCandidateList(): RTCIceCandidate[] { + return this.webRtcPeer.localCandidatesQueue; + } + /* Private methods */ private initWebRtcPeerSend(): Promise { diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts index 53afefb4..5bf14e4f 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts @@ -37,9 +37,10 @@ export class WebRtcPeer { pc: RTCPeerConnection; id: string; + remoteCandidatesQueue: RTCIceCandidate[] = []; + localCandidatesQueue: RTCIceCandidate[] = []; private candidategatheringdone = false; - private candidatesQueue: RTCIceCandidate[] = []; constructor(private configuration: WebRtcPeerConfiguration) { this.configuration.iceServers = (!!this.configuration.iceServers && this.configuration.iceServers.length > 0) ? this.configuration.iceServers : freeice(); @@ -48,8 +49,9 @@ export class WebRtcPeer { this.id = !!configuration.id ? configuration.id : uuid.v4(); this.pc.onicecandidate = event => { - const candidate = event.candidate; + const candidate: RTCIceCandidate = event.candidate; if (candidate) { + this.localCandidatesQueue.push({ candidate: candidate.candidate }); this.candidategatheringdone = false; this.configuration.onicecandidate(event.candidate); } else if (!this.candidategatheringdone) { @@ -59,9 +61,12 @@ export class WebRtcPeer { this.pc.onsignalingstatechange = () => { if (this.pc.signalingState === 'stable') { - while (this.candidatesQueue.length > 0) { - this.pc.addIceCandidate(this.candidatesQueue.shift()); + for (const candidate of this.remoteCandidatesQueue) { + this.pc.addIceCandidate(candidate); } + /*while (this.remoteCandidatesQueue.length > 0) { + this.pc.addIceCandidate(this.remoteCandidatesQueue.shift()); + }*/ } }; @@ -104,6 +109,8 @@ export class WebRtcPeer { if (this.pc.signalingState === 'closed') { return; } + this.remoteCandidatesQueue = []; + this.localCandidatesQueue = []; this.pc.getLocalStreams().forEach(str => { this.streamStop(str); @@ -231,7 +238,7 @@ export class WebRtcPeer { } break; default: - this.candidatesQueue.push(iceCandidate); + this.remoteCandidatesQueue.push(iceCandidate); resolve(); } });