Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
break
}
// Route session descriptions to peers.
case "OFFER":
case "ANSWER": {
const {
src,
payload: { sdp },
} = message
const peer = this.peers[src] || this.addPeer(src)
let description: RTCSessionDescription
try {
description = new RTCSessionDescription(sdp)
} catch (e) {
throw new Error("Invalid SDP")
}
peer.setRemoteDescription(description)
if (message.type === "OFFER") {
const sdp = await peer.answer()
this.onPeerSDP(sdp, src)
}
break
}
case "KEEP_ALIVE": {
this.transport.send({
peer.addIceCandidate(ice);
break;
}
// Route session descriptions to peers.
case "OFFER":
case "ANSWER": {
var _src = message.src,
sdp = message.payload.sdp;
var _peer = _this._peers[_src] || _this._addPeer(_src);
var description = void 0;
try {
description = new wrtc.RTCSessionDescription(sdp);
} catch (e) {
throw new Error("Invalid SDP");
}
_peer.setRemoteDescription(description);
if (message.type === "OFFER") {
_peer.answer();
}
break;
}
default:
break;
}
};
function clientStreamDescription(streamSource, description) {
const signal = JSON.parse(description);
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();
});
}
function setRemoteDescription1(desc: RTCSessionDescriptionInit): void {
if (channel == null) {
throw new Error("Channel is null.");
}
logger.verbose(`${LOG_PREFIX} ${chalk.magentaBright(`${channel.id} pc1: set remote description`)}`, desc.sdp);
channel.pc.setRemoteDescription(
new wrtc.RTCSessionDescription(desc),
() => {
res.status(200).json({
success: true
});
if (channel == null) {
throw new Error("Channel is destroyed!");
}
logger.verbose(`${LOG_PREFIX} ${chalk.cyanBright("channel.pc.localDescription.sdp")}`, channel.pc.localDescription.sdp);
logger.verbose(
`${LOG_PREFIX} ${chalk.magentaBright("channel.pc.remoteDescription.sdp")}`,
channel.pc.remoteDescription.sdp
);
},
handleError
);
channel.status = Statuses.Answered;
function setLocalDescription1(desc: RTCSessionDescriptionInit): void {
logger.verbose(`${LOG_PREFIX} ${chalk.cyanBright(`${channel.id} pc1: set local description:`)}`, desc.sdp);
pc1.setLocalDescription(new wrtc.RTCSessionDescription(desc), setRemoteDescription2.bind(null, desc), handleError);
}