openvidu-browser: Stream stores iceCandidate list (sent and received)

pull/88/merge
pabloFuente 2018-06-19 09:52:04 +02:00
parent c8400a6d69
commit 2c90f65535
3 changed files with 26 additions and 21 deletions

View File

@ -698,22 +698,6 @@ export class Session implements EventDispatcher {
return { candidate: msg.candidate }; 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) this.getConnection(msg.endpointName, 'Connection not found for endpoint ' + msg.endpointName + '. Ice candidate will be ignored: ' + candidate)
.then(connection => { .then(connection => {
const stream = connection.stream; const stream = connection.stream;

View File

@ -374,6 +374,20 @@ export class Stream {
}); });
} }
/**
* @hidden
*/
getRemoteIceCandidateList(): RTCIceCandidate[] {
return this.webRtcPeer.remoteCandidatesQueue;
}
/**
* @hidden
*/
getLocalIceCandidateList(): RTCIceCandidate[] {
return this.webRtcPeer.localCandidatesQueue;
}
/* Private methods */ /* Private methods */
private initWebRtcPeerSend(): Promise<any> { private initWebRtcPeerSend(): Promise<any> {

View File

@ -37,9 +37,10 @@ export class WebRtcPeer {
pc: RTCPeerConnection; pc: RTCPeerConnection;
id: string; id: string;
remoteCandidatesQueue: RTCIceCandidate[] = [];
localCandidatesQueue: RTCIceCandidate[] = [];
private candidategatheringdone = false; private candidategatheringdone = false;
private candidatesQueue: RTCIceCandidate[] = [];
constructor(private configuration: WebRtcPeerConfiguration) { constructor(private configuration: WebRtcPeerConfiguration) {
this.configuration.iceServers = (!!this.configuration.iceServers && this.configuration.iceServers.length > 0) ? this.configuration.iceServers : freeice(); 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.id = !!configuration.id ? configuration.id : uuid.v4();
this.pc.onicecandidate = event => { this.pc.onicecandidate = event => {
const candidate = event.candidate; const candidate: RTCIceCandidate = event.candidate;
if (candidate) { if (candidate) {
this.localCandidatesQueue.push(<RTCIceCandidate>{ candidate: candidate.candidate });
this.candidategatheringdone = false; this.candidategatheringdone = false;
this.configuration.onicecandidate(event.candidate); this.configuration.onicecandidate(event.candidate);
} else if (!this.candidategatheringdone) { } else if (!this.candidategatheringdone) {
@ -59,9 +61,12 @@ export class WebRtcPeer {
this.pc.onsignalingstatechange = () => { this.pc.onsignalingstatechange = () => {
if (this.pc.signalingState === 'stable') { if (this.pc.signalingState === 'stable') {
while (this.candidatesQueue.length > 0) { for (const candidate of this.remoteCandidatesQueue) {
this.pc.addIceCandidate(<RTCIceCandidate>this.candidatesQueue.shift()); this.pc.addIceCandidate(<RTCIceCandidate>candidate);
} }
/*while (this.remoteCandidatesQueue.length > 0) {
this.pc.addIceCandidate(<RTCIceCandidate>this.remoteCandidatesQueue.shift());
}*/
} }
}; };
@ -104,6 +109,8 @@ export class WebRtcPeer {
if (this.pc.signalingState === 'closed') { if (this.pc.signalingState === 'closed') {
return; return;
} }
this.remoteCandidatesQueue = [];
this.localCandidatesQueue = [];
this.pc.getLocalStreams().forEach(str => { this.pc.getLocalStreams().forEach(str => {
this.streamStop(str); this.streamStop(str);
@ -231,7 +238,7 @@ export class WebRtcPeer {
} }
break; break;
default: default:
this.candidatesQueue.push(iceCandidate); this.remoteCandidatesQueue.push(iceCandidate);
resolve(); resolve();
} }
}); });