mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: Use the RTCIceCandidate constructor on new candidates
The ice candidate event provides an "RTCIceCandidateInit" object, which should be passed to the RTCIceCandidate() constructor, to build a proper instance of RTCIceCandidate.pull/699/head
parent
e426d223af
commit
97656aa9d6
|
@ -995,29 +995,20 @@ export class Session extends EventDispatcher {
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
recvIceCandidate(event: { senderConnectionId: string, endpointName: string, sdpMLineIndex: number, sdpMid: string, candidate: string }): void {
|
recvIceCandidate(event: { senderConnectionId: string, endpointName: string, sdpMLineIndex: number, sdpMid: string, candidate: string }): void {
|
||||||
const candidate: RTCIceCandidate = {
|
// The event contains fields that can be used to obtain a proper candidate,
|
||||||
address: null,
|
// using the RTCIceCandidate constructor:
|
||||||
|
// https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-constructor
|
||||||
|
const candidateInit: RTCIceCandidateInit = {
|
||||||
candidate: event.candidate,
|
candidate: event.candidate,
|
||||||
sdpMid: event.sdpMid,
|
|
||||||
sdpMLineIndex: event.sdpMLineIndex,
|
sdpMLineIndex: event.sdpMLineIndex,
|
||||||
component: null,
|
sdpMid: event.sdpMid,
|
||||||
foundation: null,
|
|
||||||
port: null,
|
|
||||||
priority: null,
|
|
||||||
protocol: null,
|
|
||||||
relatedAddress: null,
|
|
||||||
relatedPort: null,
|
|
||||||
tcpType: null,
|
|
||||||
usernameFragment: null,
|
|
||||||
type: null,
|
|
||||||
toJSON: () => {
|
|
||||||
return { candidate: event.candidate };
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
this.getConnection(event.senderConnectionId, 'Connection not found for connectionId ' + event.senderConnectionId + ' owning endpoint ' + event.endpointName + '. Ice candidate will be ignored: ' + candidate)
|
const iceCandidate = new RTCIceCandidate(candidateInit);
|
||||||
|
|
||||||
|
this.getConnection(event.senderConnectionId, 'Connection not found for connectionId ' + event.senderConnectionId + ' owning endpoint ' + event.endpointName + '. Ice candidate will be ignored: ' + iceCandidate)
|
||||||
.then(connection => {
|
.then(connection => {
|
||||||
const stream: Stream = connection.stream!;
|
const stream: Stream = connection.stream!;
|
||||||
stream.getWebRtcPeer().addIceCandidate(candidate).catch(error => {
|
stream.getWebRtcPeer().addIceCandidate(iceCandidate).catch(error => {
|
||||||
logger.error('Error adding candidate for ' + stream!.streamId
|
logger.error('Error adding candidate for ' + stream!.streamId
|
||||||
+ ' stream of endpoint ' + event.endpointName + ': ' + error);
|
+ ' stream of endpoint ' + event.endpointName + ': ' + error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -80,12 +80,20 @@ export class WebRtcPeer {
|
||||||
|
|
||||||
this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });
|
this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });
|
||||||
|
|
||||||
this.pc.addEventListener('icecandidate', (event: RTCPeerConnectionIceEvent) => {
|
this.pc.addEventListener("icecandidate", (event: RTCPeerConnectionIceEvent) => {
|
||||||
if (event.candidate != null) {
|
if (event.candidate !== null) {
|
||||||
const candidate: RTCIceCandidate = event.candidate;
|
// `RTCPeerConnectionIceEvent.candidate` is supposed to be an RTCIceCandidate:
|
||||||
this.configuration.onIceCandidate(candidate);
|
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnectioniceevent-candidate
|
||||||
if (candidate.candidate !== '') {
|
//
|
||||||
this.localCandidatesQueue.push(<RTCIceCandidate>{ candidate: candidate.candidate });
|
// But in practice, it is actually an RTCIceCandidateInit that can be used to
|
||||||
|
// obtain a proper candidate, using the RTCIceCandidate constructor:
|
||||||
|
// https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-constructor
|
||||||
|
const candidateInit: RTCIceCandidateInit = event.candidate as RTCIceCandidateInit;
|
||||||
|
const iceCandidate = new RTCIceCandidate(candidateInit);
|
||||||
|
|
||||||
|
this.configuration.onIceCandidate(iceCandidate);
|
||||||
|
if (iceCandidate.candidate !== '') {
|
||||||
|
this.localCandidatesQueue.push(iceCandidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue