Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.stream = options.stream;
// Create an RTCPeerConnection via the polyfill
this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionContraints);
this.pc.on('ice', this.onIceCandidate.bind(this));
if (options.type === 'screen') {
if (this.parent.localScreen && this.sharemyscreen) {
log('adding local screen stream to peer connection');
this.pc.addStream(this.parent.localScreen);
this.broadcaster = this.parent.connection.socket.sessionid;
}
} else {
this.pc.addStream(this.parent.localStream);
}
this.pc.on('addStream', this.handleRemoteStreamAdded.bind(this));
this.pc.on('removeStream', this.handleStreamRemoved.bind(this));
WildEmitter.call(this);
// proxy events to parent
this.on('*', function(name, value) {
self.parent.emit(name, value, self);
});
}
// handle screensharing/broadcast mode
if (options.type === 'screen') {
if (this.parent.localScreen && this.sharemyscreen) {
this.logger.log('adding local screen stream to peer connection');
this.pc.addStream(this.parent.localScreen);
this.broadcaster = options.broadcaster;
}
} else {
this.parent.localStreams.forEach(function (stream) {
self.pc.addStream(stream);
});
}
// call emitter constructor
WildEmitter.call(this);
this.on('channelOpen', function (channel) {
if (channel.protocol === INBAND_FILETRANSFER_V1) {
channel.onmessage = function (event) {
var metadata = JSON.parse(event.data);
var receiver = new FileTransfer.Receiver();
receiver.receive(metadata, channel);
self.emit('fileTransfer', metadata, receiver);
receiver.on('receivedFile', function (file, metadata) {
receiver.channel.close();
});
};
}
});
// proxy events to parent
});
peer.handleMessage(message);
} else if (peers.length) {
peers.forEach(function(peer) {
peer.handleMessage(message);
});
}
});
connection.on('remove', function(room) {
if (room.id !== self.connection.socket.sessionid) {
self.removeForPeerSession(room.id, room.type);
}
});
WildEmitter.call(this);
// log events
if (this.config.log) {
this.on('*', function(event, val1, val2) {
log('event:', event, val1, val2);
});
}
// auto request if configured
if (this.config.autoRequestMedia) this.startLocalVideo();
}
function Peer(options) {
var self = this;
// call emitter constructor
WildEmitter.call(this);
this.id = options.id;
this.parent = options.parent;
this.type = options.type || 'video';
this.oneway = options.oneway || false;
this.sharemyscreen = options.sharemyscreen || false;
this.browserPrefix = options.prefix;
this.stream = options.stream;
this.enableDataChannels = options.enableDataChannels === undefined ? this.parent.config.enableDataChannels : options.enableDataChannels;
this.receiveMedia = options.receiveMedia || this.parent.config.receiveMedia;
this.channels = {};
this.sid = options.sid || Date.now().toString();
// Create an RTCPeerConnection via the polyfill
this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionConstraints);
this.pc.on('ice', this.onIceCandidate.bind(this));
this.pc.on('endOfCandidates', function (event) {
function Peer(options) {
var self = this;
// call emitter constructor
WildEmitter.call(this);
this.id = options.id;
this.parent = options.parent;
this.type = options.type || 'video';
this.oneway = options.oneway || false;
this.sharemyscreen = options.sharemyscreen || false;
this.browserPrefix = options.prefix;
this.stream = options.stream;
this.enableDataChannels = options.enableDataChannels === undefined ? this.parent.config.enableDataChannels : options.enableDataChannels;
this.receiveMedia = options.receiveMedia || this.parent.config.receiveMedia;
this.channels = {};
this.sid = options.sid || Date.now().toString();
// Create an RTCPeerConnection via the polyfill
this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionConstraints);
this.pc.on('ice', this.onIceCandidate.bind(this));
this.pc.on('offer', function (offer) {
function Sender(opts) {
WildEmitter.call(this);
var options = opts || {};
this.config = {
chunksize: 16384,
pacing: 0
};
// set our config from options
var item;
for (item in options) {
this.config[item] = options[item];
}
this.file = null;
this.channel = null;
}
util.inherits(Sender, WildEmitter);
function Sender(opts) {
WildEmitter.call(this);
var self = this;
this.base = new base.Sender(opts);
var options = opts || {};
if (!options.hash) {
options.hash = 'sha-1';
}
this.hash = hashes.createHash(options.hash);
this.base.on('progress', function (start, size, data) {
self.emit('progress', start, size, data);
if (data) {
self.hash.update(new Uint8Array(data));
}
});
this.base.on('sentFile', function () {
function Receiver(opts) {
WildEmitter.call(this);
var self = this;
this.base = new base.Receiver(opts);
var options = opts || {};
if (!options.hash) {
options.hash = 'sha-1';
}
this.hash = hashes.createHash(options.hash);
this.base.on('progress', function (start, size, data) {
self.emit('progress', start, size, data);
if (data) {
self.hash.update(new Uint8Array(data));
}
});
this.base.on('receivedFile', function (file, metadata) {
function Receiver() {
WildEmitter.call(this);
this.receiveBuffer = [];
this.received = 0;
this.metadata = {};
this.channel = null;
}
util.inherits(Receiver, WildEmitter);
function SessionManager(conf) {
WildEmitter.call(this);
conf = conf || {};
this.jid = conf.jid;
this.selfID = conf.selfID || (this.jid && this.jid.full) || this.jid || '';
this.sessions = {};
this.peers = {};
this.prepareSession = conf.prepareSession || function (opts) {
if (opts.applicationTypes.indexOf('rtp') >= 0) {
return new MediaSession(opts);
}
if (opts.applicationTypes.indexOf('filetransfer') >= 0) {
return new FileSession(opts);
}