Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (signal.sdp) {
streamSource.implementation.peerConnection.setRemoteDescription(new webrtc.RTCSessionDescription(signal.sdp)).then(() => {
return streamSource.implementation.peerConnection.createAnswer();
}).then((desc) => {
return streamSource.implementation.peerConnection.setLocalDescription(desc);
}).then(() => {
streamSource.server_stream_description(JSON.stringify({"sdp": streamSource.implementation.peerConnection.localDescription}));
}).catch((error) => {
console.error(error);
streamSource.client.close();
});
} else if (signal.candidate) {
streamSource.implementation.peerConnection.addIceCandidate(new webrtc.RTCIceCandidate(signal.candidate)).catch((error) => {
console.error("Error: Failure during addIceCandidate()", error);
streamSource.client.close();
});
}
}
iceCandidates.forEach((iceCandidate: wrtc.IceCandidate) => {
logger.verbose(`${LOG_PREFIX} ${chalk.cyanBright(`${channelId} pc1: adding ice candidate from browser`)}`, iceCandidate);
if (channel == null) {
throw new Error("Channel is null.");
}
iceCandidate = this.mapPortsFromBrowser(req, channel, iceCandidate);
if (channel.localAddress == null || channel.remoteAddress == null) {
throw new Error("Channel localAddress or remoteAddress is null.");
}
this.udpProxy.setMap(channel.localAddress, channel.remoteAddress);
channel.pc.addIceCandidate(new wrtc.RTCIceCandidate(iceCandidate));
});
}