Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
import * as node_server from '../node/server';
import * as node_socket from '../node/socket';
import * as session from '../session';
import * as wrtc from 'wrtc';
const SERVER_ADDRESS = '0.0.0.0';
const SERVER_PORT = 9999;
const getter = new wrtc.RTCPeerConnection();
const giver = new wrtc.RTCPeerConnection();
getter.onicecandidate = (event: any) => {
if (event.candidate) {
console.info('getter candidate', event.candidate.candidate);
giver.addIceCandidate(event.candidate);
}
}
giver.onicecandidate = (event: any) => {
if (event.candidate) {
console.info('giver candidate', event.candidate.candidate);
getter.addIceCandidate(event.candidate);
}
}
// Create a SocksSession in response to each new datachannel.
// NOTE: because onopen datachannel events don't fire for the
function createPeerConnection(sessionID, callbackType, callback)
{
var pc = new RTCPeerConnection
(
{iceServers: [{url: 'stun:'+stun_server}]},
{optional: [{DtlsSrtpKeyAgreement: true}]}
);
pc.addEventListener('icecandidate', function(event)
{
// There's a candidate, ignore it
if(event.candidate)
return;
// There's no candidate, send the full SDP
var type = this.localDescription.type;
var sdp = this.localDescription.sdp;
if(type == callbackType)
function createPeerConnection(sessionID, callbackType, callback)
{
var pc = new RTCPeerConnection
(
{iceServers: [{url: 'stun:'+stun_server}]},
{optional: [{DtlsSrtpKeyAgreement: true}]}
);
pc.addEventListener('icecandidate', function(event)
{
// There's a candidate, ignore it
if(event.candidate)
return;
// There's no candidate, send the full SDP
var type = this.localDescription.type;
var sdp = this.localDescription.sdp;
if(type == callbackType)
value: function _addPeer(id) {
var _this2 = this;
if (this._peers[id]) {
throw new Error(
"RTCPeer with id " + id + " already exists."
);
}
var peer = new RTCPeer({
pc: new wrtc.RTCPeerConnection(RTC_PEER_CONNECTION_OPTIONS),
onChannel: this._onPeerChannel,
onClose: function onClose() {
return _this2._onPeerClose(id);
},
onSDP: function onSDP(sdp) {
return _this2._onPeerSDP(sdp, id);
},
onICE: function onICE(ice) {
return _this2._onPeerICE(ice, id);
}
});
this._peers[id] = peer;
return peer;
}
private postChannels(req: express.Request, res: express.Response): void {
const isUDP = (candidate: wrtc.IceCandidate): boolean => {
if (typeof candidate.candidate !== "string") {
throw new Error("Invalid candidate.");
}
return candidate.candidate.includes("udp");
};
const pc1 = new wrtc.RTCPeerConnection();
pc1.onerror = (error: ErrorEvent) => {
logger.error(`${LOG_PREFIX} ${chalk.red("error")}`, error);
};
pc1.onnegotationneeded = (event: Event) => {
logger.verbose(`${LOG_PREFIX} ${chalk.yellow("negotation-needed")}`, event);
};
pc1.onicecandidateerror = (event: Event) => {
logger.error(`${LOG_PREFIX} ${chalk.yellow("ice-candidate-error")}`, event);
};
pc1.onsignalingstatechange = (event: Event) => {
logger.verbose(`${LOG_PREFIX} ${chalk.yellow("signaling-state")}: ${chalk.yellowBright(pc1.signalingState.toString())}`);
};
pc1.oniceconnectionstatechange = (event: Event) => {
logger.verbose(
`${LOG_PREFIX} ${chalk.yellow("ice-connection-state")}: ${chalk.yellowBright(pc1.iceConnectionState.toString())}`
private addPeer(pid: string) {
if (this.peers[pid]) {
throw new Error(`RTCPeer with id ${pid} already exists.`)
}
const peerOptions = {
onChannel: this.onPeerChannel,
onClose: () => this.onPeerClose(pid),
onICE: (ice: RTCIceCandidate) => this.onPeerICE(ice, pid),
peerConnection: new RTCPeerConnection({
iceServers: this.iceServers,
portRange: this.portRange,
}),
}
const peer = new RTCPeer(peerOptions)
this.peers[pid] = peer
return peer
}