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
|
||||
*/
|
||||
recvIceCandidate(event: { senderConnectionId: string, endpointName: string, sdpMLineIndex: number, sdpMid: string, candidate: string }): void {
|
||||
const candidate: RTCIceCandidate = {
|
||||
address: null,
|
||||
// The event contains fields 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 = {
|
||||
candidate: event.candidate,
|
||||
sdpMid: event.sdpMid,
|
||||
sdpMLineIndex: event.sdpMLineIndex,
|
||||
component: null,
|
||||
foundation: null,
|
||||
port: null,
|
||||
priority: null,
|
||||
protocol: null,
|
||||
relatedAddress: null,
|
||||
relatedPort: null,
|
||||
tcpType: null,
|
||||
usernameFragment: null,
|
||||
type: null,
|
||||
toJSON: () => {
|
||||
return { candidate: event.candidate };
|
||||
}
|
||||
sdpMid: event.sdpMid,
|
||||
};
|
||||
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 => {
|
||||
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
|
||||
+ ' stream of endpoint ' + event.endpointName + ': ' + error);
|
||||
});
|
||||
|
|
|
@ -80,12 +80,20 @@ export class WebRtcPeer {
|
|||
|
||||
this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });
|
||||
|
||||
this.pc.addEventListener('icecandidate', (event: RTCPeerConnectionIceEvent) => {
|
||||
if (event.candidate != null) {
|
||||
const candidate: RTCIceCandidate = event.candidate;
|
||||
this.configuration.onIceCandidate(candidate);
|
||||
if (candidate.candidate !== '') {
|
||||
this.localCandidatesQueue.push(<RTCIceCandidate>{ candidate: candidate.candidate });
|
||||
this.pc.addEventListener("icecandidate", (event: RTCPeerConnectionIceEvent) => {
|
||||
if (event.candidate !== null) {
|
||||
// `RTCPeerConnectionIceEvent.candidate` is supposed to be an RTCIceCandidate:
|
||||
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnectioniceevent-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