|
|
|
(function(e){if("function"==typeof bootstrap)bootstrap("simplewebrtc",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeSimpleWebRTC=e}else"undefined"!=typeof window?window.SimpleWebRTC=e():global.SimpleWebRTC=e()})(function(){var define,ses,bootstrap,module,exports;
|
|
|
|
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
|
|
|
|
var WebRTC = require('./webrtc');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var webrtcSupport = require('webrtcsupport');
|
|
|
|
var attachMediaStream = require('attachmediastream');
|
|
|
|
var mockconsole = require('mockconsole');
|
|
|
|
var SocketIoConnection = require('./socketioconnection');
|
|
|
|
|
|
|
|
function SimpleWebRTC(opts) {
|
|
|
|
var self = this;
|
|
|
|
var options = opts || {};
|
|
|
|
var config = this.config = {
|
|
|
|
url: 'https://signaling.simplewebrtc.com:443/',
|
|
|
|
socketio: {/* 'force new connection':true*/},
|
|
|
|
connection: null,
|
|
|
|
debug: false,
|
|
|
|
localVideoEl: '',
|
|
|
|
remoteVideosEl: '',
|
|
|
|
enableDataChannels: true,
|
|
|
|
autoRequestMedia: false,
|
|
|
|
autoRemoveVideos: true,
|
|
|
|
adjustPeerVolume: true,
|
|
|
|
peerVolumeWhenSpeaking: 0.25,
|
|
|
|
media: {
|
|
|
|
video: true,
|
|
|
|
audio: true
|
|
|
|
},
|
|
|
|
receiveMedia: { // FIXME: remove old chrome <= 37 constraints format
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: true,
|
|
|
|
OfferToReceiveVideo: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
localVideo: {
|
|
|
|
autoplay: true,
|
|
|
|
mirror: true,
|
|
|
|
muted: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var item, connection;
|
|
|
|
|
|
|
|
// We also allow a 'logger' option. It can be any object that implements
|
|
|
|
// log, warn, and error methods.
|
|
|
|
// We log nothing by default, following "the rule of silence":
|
|
|
|
// http://www.linfo.org/rule_of_silence.html
|
|
|
|
this.logger = function () {
|
|
|
|
// we assume that if you're in debug mode and you didn't
|
|
|
|
// pass in a logger, you actually want to log as much as
|
|
|
|
// possible.
|
|
|
|
if (opts.debug) {
|
|
|
|
return opts.logger || console;
|
|
|
|
} else {
|
|
|
|
// or we'll use your logger which should have its own logic
|
|
|
|
// for output. Or we'll return the no-op.
|
|
|
|
return opts.logger || mockconsole;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
// set our config from options
|
|
|
|
for (item in options) {
|
|
|
|
this.config[item] = options[item];
|
|
|
|
}
|
|
|
|
|
|
|
|
// attach detected support for convenience
|
|
|
|
this.capabilities = webrtcSupport;
|
|
|
|
|
|
|
|
// call WildEmitter constructor
|
|
|
|
WildEmitter.call(this);
|
|
|
|
|
|
|
|
// create default SocketIoConnection if it's not passed in
|
|
|
|
if (this.config.connection === null) {
|
|
|
|
connection = this.connection = new SocketIoConnection(this.config);
|
|
|
|
} else {
|
|
|
|
connection = this.connection = this.config.connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.on('connect', function () {
|
|
|
|
self.emit('connectionReady', connection.getSessionid());
|
|
|
|
self.sessionReady = true;
|
|
|
|
self.testReadiness();
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.on('message', function (message) {
|
|
|
|
var peers = self.webrtc.getPeers(message.from, message.roomType);
|
|
|
|
var peer;
|
|
|
|
|
|
|
|
if (message.type === 'offer') {
|
|
|
|
if (peers.length) {
|
|
|
|
peers.forEach(function (p) {
|
|
|
|
if (p.sid == message.sid) peer = p;
|
|
|
|
});
|
|
|
|
//if (!peer) peer = peers[0]; // fallback for old protocol versions
|
|
|
|
}
|
|
|
|
if (!peer) {
|
|
|
|
peer = self.webrtc.createPeer({
|
|
|
|
id: message.from,
|
|
|
|
sid: message.sid,
|
|
|
|
type: message.roomType,
|
|
|
|
enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen',
|
|
|
|
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
|
|
|
|
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null
|
|
|
|
});
|
|
|
|
self.emit('createdPeer', peer);
|
|
|
|
}
|
|
|
|
peer.handleMessage(message);
|
|
|
|
} else if (peers.length) {
|
|
|
|
peers.forEach(function (peer) {
|
|
|
|
if (message.sid) {
|
|
|
|
if (peer.sid === message.sid) {
|
|
|
|
peer.handleMessage(message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
peer.handleMessage(message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.on('remove', function (room) {
|
|
|
|
if (room.id !== self.connection.getSessionid()) {
|
|
|
|
self.webrtc.removePeers(room.id, room.type);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// instantiate our main WebRTC helper
|
|
|
|
// using same logger from logic here
|
|
|
|
opts.logger = this.logger;
|
|
|
|
opts.debug = false;
|
|
|
|
this.webrtc = new WebRTC(opts);
|
|
|
|
|
|
|
|
// attach a few methods from underlying lib to simple.
|
|
|
|
['mute', 'unmute', 'pauseVideo', 'resumeVideo', 'pause', 'resume', 'sendToAll', 'sendDirectlyToAll', 'getPeers'].forEach(function (method) {
|
|
|
|
self[method] = self.webrtc[method].bind(self.webrtc);
|
|
|
|
});
|
|
|
|
|
|
|
|
// proxy events from WebRTC
|
|
|
|
this.webrtc.on('*', function () {
|
|
|
|
self.emit.apply(self, arguments);
|
|
|
|
});
|
|
|
|
|
|
|
|
// log all events in debug mode
|
|
|
|
if (config.debug) {
|
|
|
|
this.on('*', this.logger.log.bind(this.logger, 'SimpleWebRTC event:'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for readiness
|
|
|
|
this.webrtc.on('localStream', function () {
|
|
|
|
self.testReadiness();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.webrtc.on('message', function (payload) {
|
|
|
|
self.connection.emit('message', payload);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.webrtc.on('peerStreamAdded', this.handlePeerStreamAdded.bind(this));
|
|
|
|
this.webrtc.on('peerStreamRemoved', this.handlePeerStreamRemoved.bind(this));
|
|
|
|
|
|
|
|
// echo cancellation attempts
|
|
|
|
if (this.config.adjustPeerVolume) {
|
|
|
|
this.webrtc.on('speaking', this.setVolumeForAll.bind(this, this.config.peerVolumeWhenSpeaking));
|
|
|
|
this.webrtc.on('stoppedSpeaking', this.setVolumeForAll.bind(this, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.on('stunservers', function (args) {
|
|
|
|
// resets/overrides the config
|
|
|
|
self.webrtc.config.peerConnectionConfig.iceServers = args;
|
|
|
|
self.emit('stunservers', args);
|
|
|
|
});
|
|
|
|
connection.on('turnservers', function (args) {
|
|
|
|
// appends to the config
|
|
|
|
self.webrtc.config.peerConnectionConfig.iceServers = self.webrtc.config.peerConnectionConfig.iceServers.concat(args);
|
|
|
|
self.emit('turnservers', args);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.webrtc.on('iceFailed', function (peer) {
|
|
|
|
// local ice failure
|
|
|
|
});
|
|
|
|
this.webrtc.on('connectivityError', function (peer) {
|
|
|
|
// remote ice failure
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// sending mute/unmute to all peers
|
|
|
|
this.webrtc.on('audioOn', function () {
|
|
|
|
self.webrtc.sendToAll('unmute', {name: 'audio'});
|
|
|
|
});
|
|
|
|
this.webrtc.on('audioOff', function () {
|
|
|
|
self.webrtc.sendToAll('mute', {name: 'audio'});
|
|
|
|
});
|
|
|
|
this.webrtc.on('videoOn', function () {
|
|
|
|
self.webrtc.sendToAll('unmute', {name: 'video'});
|
|
|
|
});
|
|
|
|
this.webrtc.on('videoOff', function () {
|
|
|
|
self.webrtc.sendToAll('mute', {name: 'video'});
|
|
|
|
});
|
|
|
|
|
|
|
|
// screensharing events
|
|
|
|
this.webrtc.on('localScreen', function (stream) {
|
|
|
|
var item,
|
|
|
|
el = document.createElement('video'),
|
|
|
|
container = self.getRemoteVideoContainer();
|
|
|
|
|
|
|
|
el.oncontextmenu = function () { return false; };
|
|
|
|
el.id = 'localScreen';
|
|
|
|
attachMediaStream(stream, el);
|
|
|
|
if (container) {
|
|
|
|
container.appendChild(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.emit('localScreenAdded', el);
|
|
|
|
self.connection.emit('shareScreen');
|
|
|
|
|
|
|
|
self.webrtc.peers.forEach(function (existingPeer) {
|
|
|
|
var peer;
|
|
|
|
if (existingPeer.type === 'video') {
|
|
|
|
peer = self.webrtc.createPeer({
|
|
|
|
id: existingPeer.id,
|
|
|
|
type: 'screen',
|
|
|
|
sharemyscreen: true,
|
|
|
|
enableDataChannels: false,
|
|
|
|
receiveMedia: {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: false,
|
|
|
|
OfferToReceiveVideo: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
broadcaster: self.connection.getSessionid(),
|
|
|
|
});
|
|
|
|
self.emit('createdPeer', peer);
|
|
|
|
peer.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.webrtc.on('localScreenStopped', function (stream) {
|
|
|
|
self.stopScreenShare();
|
|
|
|
/*
|
|
|
|
self.connection.emit('unshareScreen');
|
|
|
|
self.webrtc.peers.forEach(function (peer) {
|
|
|
|
if (peer.sharemyscreen) {
|
|
|
|
peer.end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
|
|
|
|
this.webrtc.on('channelMessage', function (peer, label, data) {
|
|
|
|
if (data.type == 'volume') {
|
|
|
|
self.emit('remoteVolumeChange', peer, data.volume);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.config.autoRequestMedia) this.startLocalVideo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype = Object.create(WildEmitter.prototype, {
|
|
|
|
constructor: {
|
|
|
|
value: SimpleWebRTC
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.leaveRoom = function () {
|
|
|
|
if (this.roomName) {
|
|
|
|
this.connection.emit('leave');
|
|
|
|
this.webrtc.peers.forEach(function (peer) {
|
|
|
|
peer.end();
|
|
|
|
});
|
|
|
|
if (this.getLocalScreen()) {
|
|
|
|
this.stopScreenShare();
|
|
|
|
}
|
|
|
|
this.emit('leftRoom', this.roomName);
|
|
|
|
this.roomName = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.disconnect = function () {
|
|
|
|
this.connection.disconnect();
|
|
|
|
delete this.connection;
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.handlePeerStreamAdded = function (peer) {
|
|
|
|
var self = this;
|
|
|
|
var container = this.getRemoteVideoContainer();
|
|
|
|
var video = attachMediaStream(peer.stream);
|
|
|
|
|
|
|
|
// store video element as part of peer for easy removal
|
|
|
|
peer.videoEl = video;
|
|
|
|
video.id = this.getDomId(peer);
|
|
|
|
|
|
|
|
if (container) container.appendChild(video);
|
|
|
|
|
|
|
|
this.emit('videoAdded', video, peer);
|
|
|
|
|
|
|
|
// send our mute status to new peer if we're muted
|
|
|
|
// currently called with a small delay because it arrives before
|
|
|
|
// the video element is created otherwise (which happens after
|
|
|
|
// the async setRemoteDescription-createAnswer)
|
|
|
|
window.setTimeout(function () {
|
|
|
|
if (!self.webrtc.isAudioEnabled()) {
|
|
|
|
peer.send('mute', {name: 'audio'});
|
|
|
|
}
|
|
|
|
if (!self.webrtc.isVideoEnabled()) {
|
|
|
|
peer.send('mute', {name: 'video'});
|
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.handlePeerStreamRemoved = function (peer) {
|
|
|
|
var container = this.getRemoteVideoContainer();
|
|
|
|
var videoEl = peer.videoEl;
|
|
|
|
if (this.config.autoRemoveVideos && container && videoEl) {
|
|
|
|
container.removeChild(videoEl);
|
|
|
|
}
|
|
|
|
if (videoEl) this.emit('videoRemoved', videoEl, peer);
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.getDomId = function (peer) {
|
|
|
|
return [peer.id, peer.type, peer.broadcaster ? 'broadcasting' : 'incoming'].join('_');
|
|
|
|
};
|
|
|
|
|
|
|
|
// set volume on video tag for all peers takse a value between 0 and 1
|
|
|
|
SimpleWebRTC.prototype.setVolumeForAll = function (volume) {
|
|
|
|
this.webrtc.peers.forEach(function (peer) {
|
|
|
|
if (peer.videoEl) peer.videoEl.volume = volume;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.joinRoom = function (name, cb) {
|
|
|
|
var self = this;
|
|
|
|
this.roomName = name;
|
|
|
|
this.connection.emit('join', name, function (err, roomDescription) {
|
|
|
|
if (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
} else {
|
|
|
|
var id,
|
|
|
|
client,
|
|
|
|
type,
|
|
|
|
peer;
|
|
|
|
for (id in roomDescription.clients) {
|
|
|
|
client = roomDescription.clients[id];
|
|
|
|
for (type in client) {
|
|
|
|
if (client[type]) {
|
|
|
|
peer = self.webrtc.createPeer({
|
|
|
|
id: id,
|
|
|
|
type: type,
|
|
|
|
enableDataChannels: self.config.enableDataChannels && type !== 'screen',
|
|
|
|
receiveMedia: {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: type !== 'screen' && self.config.receiveMedia.mandatory.OfferToReceiveAudio,
|
|
|
|
OfferToReceiveVideo: self.config.receiveMedia.mandatory.OfferToReceiveVideo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.emit('createdPeer', peer);
|
|
|
|
peer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb) cb(err, roomDescription);
|
|
|
|
self.emit('joinedRoom', name);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.getEl = function (idOrEl) {
|
|
|
|
if (typeof idOrEl === 'string') {
|
|
|
|
return document.getElementById(idOrEl);
|
|
|
|
} else {
|
|
|
|
return idOrEl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.startLocalVideo = function () {
|
|
|
|
var self = this;
|
|
|
|
this.webrtc.startLocalMedia(this.config.media, function (err, stream) {
|
|
|
|
if (err) {
|
|
|
|
self.emit('localMediaError', err);
|
|
|
|
} else {
|
|
|
|
attachMediaStream(stream, self.getLocalVideoContainer(), self.config.localVideo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.stopLocalVideo = function () {
|
|
|
|
this.webrtc.stopLocalMedia();
|
|
|
|
};
|
|
|
|
|
|
|
|
// this accepts either element ID or element
|
|
|
|
// and either the video tag itself or a container
|
|
|
|
// that will be used to put the video tag into.
|
|
|
|
SimpleWebRTC.prototype.getLocalVideoContainer = function () {
|
|
|
|
var el = this.getEl(this.config.localVideoEl);
|
|
|
|
if (el && el.tagName === 'VIDEO') {
|
|
|
|
el.oncontextmenu = function () { return false; };
|
|
|
|
return el;
|
|
|
|
} else if (el) {
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.oncontextmenu = function () { return false; };
|
|
|
|
el.appendChild(video);
|
|
|
|
return video;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.getRemoteVideoContainer = function () {
|
|
|
|
return this.getEl(this.config.remoteVideosEl);
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.shareScreen = function (cb) {
|
|
|
|
this.webrtc.startScreenShare(cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.getLocalScreen = function () {
|
|
|
|
return this.webrtc.localScreen;
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.stopScreenShare = function () {
|
|
|
|
this.connection.emit('unshareScreen');
|
|
|
|
var videoEl = document.getElementById('localScreen');
|
|
|
|
var container = this.getRemoteVideoContainer();
|
|
|
|
var stream = this.getLocalScreen();
|
|
|
|
|
|
|
|
if (this.config.autoRemoveVideos && container && videoEl) {
|
|
|
|
container.removeChild(videoEl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// a hack to emit the event the removes the video
|
|
|
|
// element that we want
|
|
|
|
if (videoEl) this.emit('videoRemoved', videoEl);
|
|
|
|
if (stream) {
|
|
|
|
stream.getTracks().forEach(function (track) { track.stop(); });
|
|
|
|
}
|
|
|
|
this.webrtc.peers.forEach(function (peer) {
|
|
|
|
if (peer.broadcaster) {
|
|
|
|
peer.end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//delete this.webrtc.localScreen;
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.testReadiness = function () {
|
|
|
|
var self = this;
|
|
|
|
if (this.webrtc.localStream && this.sessionReady) {
|
|
|
|
self.emit('readyToCall', self.connection.getSessionid());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.createRoom = function (name, cb) {
|
|
|
|
if (arguments.length === 2) {
|
|
|
|
this.connection.emit('create', name, cb);
|
|
|
|
} else {
|
|
|
|
this.connection.emit('create', name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleWebRTC.prototype.sendFile = function () {
|
|
|
|
if (!webrtcSupport.dataChannel) {
|
|
|
|
return this.emit('error', new Error('DataChannelNotSupported'));
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SimpleWebRTC;
|
|
|
|
|
|
|
|
},{"./socketioconnection":3,"./webrtc":2,"attachmediastream":7,"mockconsole":6,"webrtcsupport":5,"wildemitter":4}],4:[function(require,module,exports){
|
|
|
|
/*
|
|
|
|
WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based
|
|
|
|
on @visionmedia's Emitter from UI Kit.
|
|
|
|
|
|
|
|
Why? I wanted it standalone.
|
|
|
|
|
|
|
|
I also wanted support for wildcard emitters like this:
|
|
|
|
|
|
|
|
emitter.on('*', function (eventName, other, event, payloads) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
emitter.on('somenamespace*', function (eventName, payloads) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Please note that callbacks triggered by wildcard registered events also get
|
|
|
|
the event name as the first argument.
|
|
|
|
*/
|
|
|
|
module.exports = WildEmitter;
|
|
|
|
|
|
|
|
function WildEmitter() {
|
|
|
|
this.isWildEmitter = true;
|
|
|
|
this.callbacks = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listen on the given `event` with `fn`. Store a group name if present.
|
|
|
|
WildEmitter.prototype.on = function (event, groupName, fn) {
|
|
|
|
var hasGroup = (arguments.length === 3),
|
|
|
|
group = hasGroup ? arguments[1] : undefined,
|
|
|
|
func = hasGroup ? arguments[2] : arguments[1];
|
|
|
|
func._groupName = group;
|
|
|
|
(this.callbacks[event] = this.callbacks[event] || []).push(func);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adds an `event` listener that will be invoked a single
|
|
|
|
// time then automatically removed.
|
|
|
|
WildEmitter.prototype.once = function (event, groupName, fn) {
|
|
|
|
var self = this,
|
|
|
|
hasGroup = (arguments.length === 3),
|
|
|
|
group = hasGroup ? arguments[1] : undefined,
|
|
|
|
func = hasGroup ? arguments[2] : arguments[1];
|
|
|
|
function on() {
|
|
|
|
self.off(event, on);
|
|
|
|
func.apply(this, arguments);
|
|
|
|
}
|
|
|
|
this.on(event, group, on);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unbinds an entire group
|
|
|
|
WildEmitter.prototype.releaseGroup = function (groupName) {
|
|
|
|
var item, i, len, handlers;
|
|
|
|
for (item in this.callbacks) {
|
|
|
|
handlers = this.callbacks[item];
|
|
|
|
for (i = 0, len = handlers.length; i < len; i++) {
|
|
|
|
if (handlers[i]._groupName === groupName) {
|
|
|
|
//console.log('removing');
|
|
|
|
// remove it and shorten the array we're looping through
|
|
|
|
handlers.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Remove the given callback for `event` or all
|
|
|
|
// registered callbacks.
|
|
|
|
WildEmitter.prototype.off = function (event, fn) {
|
|
|
|
var callbacks = this.callbacks[event],
|
|
|
|
i;
|
|
|
|
|
|
|
|
if (!callbacks) return this;
|
|
|
|
|
|
|
|
// remove all handlers
|
|
|
|
if (arguments.length === 1) {
|
|
|
|
delete this.callbacks[event];
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove specific handler
|
|
|
|
i = callbacks.indexOf(fn);
|
|
|
|
callbacks.splice(i, 1);
|
|
|
|
if (callbacks.length === 0) {
|
|
|
|
delete this.callbacks[event];
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Emit `event` with the given args.
|
|
|
|
// also calls any `*` handlers
|
|
|
|
WildEmitter.prototype.emit = function (event) {
|
|
|
|
var args = [].slice.call(arguments, 1),
|
|
|
|
callbacks = this.callbacks[event],
|
|
|
|
specialCallbacks = this.getWildcardCallbacks(event),
|
|
|
|
i,
|
|
|
|
len,
|
|
|
|
item,
|
|
|
|
listeners;
|
|
|
|
|
|
|
|
if (callbacks) {
|
|
|
|
listeners = callbacks.slice();
|
|
|
|
for (i = 0, len = listeners.length; i < len; ++i) {
|
|
|
|
if (listeners[i]) {
|
|
|
|
listeners[i].apply(this, args);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specialCallbacks) {
|
|
|
|
len = specialCallbacks.length;
|
|
|
|
listeners = specialCallbacks.slice();
|
|
|
|
for (i = 0, len = listeners.length; i < len; ++i) {
|
|
|
|
if (listeners[i]) {
|
|
|
|
listeners[i].apply(this, [event].concat(args));
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper for for finding special wildcard event handlers that match the event
|
|
|
|
WildEmitter.prototype.getWildcardCallbacks = function (eventName) {
|
|
|
|
var item,
|
|
|
|
split,
|
|
|
|
result = [];
|
|
|
|
|
|
|
|
for (item in this.callbacks) {
|
|
|
|
split = item.split('*');
|
|
|
|
if (item === '*' || (split.length === 2 && eventName.slice(0, split[0].length) === split[0])) {
|
|
|
|
result = result.concat(this.callbacks[item]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],5:[function(require,module,exports){
|
|
|
|
// created by @HenrikJoreteg
|
|
|
|
var prefix;
|
|
|
|
var version;
|
|
|
|
|
|
|
|
if (window.mozRTCPeerConnection || navigator.mozGetUserMedia) {
|
|
|
|
prefix = 'moz';
|
|
|
|
version = parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
|
|
|
|
} else if (window.webkitRTCPeerConnection || navigator.webkitGetUserMedia) {
|
|
|
|
prefix = 'webkit';
|
|
|
|
version = navigator.userAgent.match(/Chrom(e|ium)/) && parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
|
|
|
var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;
|
|
|
|
var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
|
|
|
|
var MediaStream = window.webkitMediaStream || window.MediaStream;
|
|
|
|
var screenSharing = window.location.protocol === 'https:' &&
|
|
|
|
((prefix === 'webkit' && version >= 26) ||
|
|
|
|
(prefix === 'moz' && version >= 33))
|
|
|
|
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
|
|
|
var videoEl = document.createElement('video');
|
|
|
|
var supportVp8 = videoEl && videoEl.canPlayType && videoEl.canPlayType('video/webm; codecs="vp8", vorbis') === "probably";
|
|
|
|
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia;
|
|
|
|
|
|
|
|
// export support flags and constructors.prototype && PC
|
|
|
|
module.exports = {
|
|
|
|
prefix: prefix,
|
|
|
|
browserVersion: version,
|
|
|
|
support: !!PC && supportVp8 && !!getUserMedia,
|
|
|
|
// new support style
|
|
|
|
supportRTCPeerConnection: !!PC,
|
|
|
|
supportVp8: supportVp8,
|
|
|
|
supportGetUserMedia: !!getUserMedia,
|
|
|
|
supportDataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel),
|
|
|
|
supportWebAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource),
|
|
|
|
supportMediaStream: !!(MediaStream && MediaStream.prototype.removeTrack),
|
|
|
|
supportScreenSharing: !!screenSharing,
|
|
|
|
// old deprecated style. Dont use this anymore
|
|
|
|
dataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel),
|
|
|
|
webAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource),
|
|
|
|
mediaStream: !!(MediaStream && MediaStream.prototype.removeTrack),
|
|
|
|
screenSharing: !!screenSharing,
|
|
|
|
// constructors
|
|
|
|
AudioContext: AudioContext,
|
|
|
|
PeerConnection: PC,
|
|
|
|
SessionDescription: SessionDescription,
|
|
|
|
IceCandidate: IceCandidate,
|
|
|
|
MediaStream: MediaStream,
|
|
|
|
getUserMedia: getUserMedia
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],6:[function(require,module,exports){
|
|
|
|
var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(",");
|
|
|
|
var l = methods.length;
|
|
|
|
var fn = function () {};
|
|
|
|
var mockconsole = {};
|
|
|
|
|
|
|
|
while (l--) {
|
|
|
|
mockconsole[methods[l]] = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mockconsole;
|
|
|
|
|
|
|
|
},{}],7:[function(require,module,exports){
|
|
|
|
module.exports = function (stream, el, options) {
|
|
|
|
var URL = window.URL;
|
|
|
|
var opts = {
|
|
|
|
autoplay: true,
|
|
|
|
mirror: false,
|
|
|
|
muted: false
|
|
|
|
};
|
|
|
|
var element = el || document.createElement('video');
|
|
|
|
var item;
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
for (item in options) {
|
|
|
|
opts[item] = options[item];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.autoplay) element.autoplay = 'autoplay';
|
|
|
|
if (opts.muted) element.muted = true;
|
|
|
|
if (opts.mirror) {
|
|
|
|
['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) {
|
|
|
|
var styleName = prefix ? prefix + 'Transform' : 'transform';
|
|
|
|
element.style[styleName] = 'scaleX(-1)';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// this first one should work most everywhere now
|
|
|
|
// but we have a few fallbacks just in case.
|
|
|
|
if (URL && URL.createObjectURL) {
|
|
|
|
element.src = URL.createObjectURL(stream);
|
|
|
|
} else if (element.srcObject) {
|
|
|
|
element.srcObject = stream;
|
|
|
|
} else if (element.mozSrcObject) {
|
|
|
|
element.mozSrcObject = stream;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],2:[function(require,module,exports){
|
|
|
|
var util = require('util');
|
|
|
|
var webrtc = require('webrtcsupport');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var mockconsole = require('mockconsole');
|
|
|
|
var localMedia = require('localmedia');
|
|
|
|
var Peer = require('./peer');
|
|
|
|
|
|
|
|
|
|
|
|
function WebRTC(opts) {
|
|
|
|
var self = this;
|
|
|
|
var options = opts || {};
|
|
|
|
var config = this.config = {
|
|
|
|
debug: false,
|
|
|
|
// makes the entire PC config overridable
|
|
|
|
peerConnectionConfig: {
|
|
|
|
iceServers: [{"url": "stun:stun.l.google.com:19302"}]
|
|
|
|
},
|
|
|
|
peerConnectionConstraints: {
|
|
|
|
optional: [
|
|
|
|
{DtlsSrtpKeyAgreement: true}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
receiveMedia: {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: true,
|
|
|
|
OfferToReceiveVideo: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
enableDataChannels: true
|
|
|
|
};
|
|
|
|
var item;
|
|
|
|
|
|
|
|
// expose screensharing check
|
|
|
|
this.screenSharingSupport = webrtc.screenSharing;
|
|
|
|
|
|
|
|
// We also allow a 'logger' option. It can be any object that implements
|
|
|
|
// log, warn, and error methods.
|
|
|
|
// We log nothing by default, following "the rule of silence":
|
|
|
|
// http://www.linfo.org/rule_of_silence.html
|
|
|
|
this.logger = function () {
|
|
|
|
// we assume that if you're in debug mode and you didn't
|
|
|
|
// pass in a logger, you actually want to log as much as
|
|
|
|
// possible.
|
|
|
|
if (opts.debug) {
|
|
|
|
return opts.logger || console;
|
|
|
|
} else {
|
|
|
|
// or we'll use your logger which should have its own logic
|
|
|
|
// for output. Or we'll return the no-op.
|
|
|
|
return opts.logger || mockconsole;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
// set options
|
|
|
|
for (item in options) {
|
|
|
|
this.config[item] = options[item];
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for support
|
|
|
|
if (!webrtc.support) {
|
|
|
|
this.logger.error('Your browser doesn\'t seem to support WebRTC');
|
|
|
|
}
|
|
|
|
|
|
|
|
// where we'll store our peer connections
|
|
|
|
this.peers = [];
|
|
|
|
|
|
|
|
// call localMedia constructor
|
|
|
|
localMedia.call(this, this.config);
|
|
|
|
|
|
|
|
this.on('speaking', function () {
|
|
|
|
if (!self.hardMuted) {
|
|
|
|
// FIXME: should use sendDirectlyToAll, but currently has different semantics wrt payload
|
|
|
|
self.peers.forEach(function (peer) {
|
|
|
|
if (peer.enableDataChannels) {
|
|
|
|
var dc = peer.getDataChannel('hark');
|
|
|
|
if (dc.readyState != 'open') return;
|
|
|
|
dc.send(JSON.stringify({type: 'speaking'}));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.on('stoppedSpeaking', function () {
|
|
|
|
if (!self.hardMuted) {
|
|
|
|
// FIXME: should use sendDirectlyToAll, but currently has different semantics wrt payload
|
|
|
|
self.peers.forEach(function (peer) {
|
|
|
|
if (peer.enableDataChannels) {
|
|
|
|
var dc = peer.getDataChannel('hark');
|
|
|
|
if (dc.readyState != 'open') return;
|
|
|
|
dc.send(JSON.stringify({type: 'stoppedSpeaking'}));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.on('volumeChange', function (volume, treshold) {
|
|
|
|
if (!self.hardMuted) {
|
|
|
|
// FIXME: should use sendDirectlyToAll, but currently has different semantics wrt payload
|
|
|
|
self.peers.forEach(function (peer) {
|
|
|
|
if (peer.enableDataChannels) {
|
|
|
|
var dc = peer.getDataChannel('hark');
|
|
|
|
if (dc.readyState != 'open') return;
|
|
|
|
dc.send(JSON.stringify({type: 'volume', volume: volume }));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// log events in debug mode
|
|
|
|
if (this.config.debug) {
|
|
|
|
this.on('*', function (event, val1, val2) {
|
|
|
|
var logger;
|
|
|
|
// if you didn't pass in a logger and you explicitly turning on debug
|
|
|
|
// we're just going to assume you're wanting log output with console
|
|
|
|
if (self.config.logger === mockconsole) {
|
|
|
|
logger = console;
|
|
|
|
} else {
|
|
|
|
logger = self.logger;
|
|
|
|
}
|
|
|
|
logger.log('event:', event, val1, val2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(WebRTC, localMedia);
|
|
|
|
|
|
|
|
WebRTC.prototype.createPeer = function (opts) {
|
|
|
|
var peer;
|
|
|
|
opts.parent = this;
|
|
|
|
peer = new Peer(opts);
|
|
|
|
this.peers.push(peer);
|
|
|
|
return peer;
|
|
|
|
};
|
|
|
|
|
|
|
|
// removes peers
|
|
|
|
WebRTC.prototype.removePeers = function (id, type) {
|
|
|
|
this.getPeers(id, type).forEach(function (peer) {
|
|
|
|
peer.end();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// fetches all Peer objects by session id and/or type
|
|
|
|
WebRTC.prototype.getPeers = function (sessionId, type) {
|
|
|
|
return this.peers.filter(function (peer) {
|
|
|
|
return (!sessionId || peer.id === sessionId) && (!type || peer.type === type);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// sends message to all
|
|
|
|
WebRTC.prototype.sendToAll = function (message, payload) {
|
|
|
|
this.peers.forEach(function (peer) {
|
|
|
|
peer.send(message, payload);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// sends message to all using a datachannel
|
|
|
|
// only sends to anyone who has an open datachannel
|
|
|
|
WebRTC.prototype.sendDirectlyToAll = function (channel, message, payload) {
|
|
|
|
this.peers.forEach(function (peer) {
|
|
|
|
if (peer.enableDataChannels) {
|
|
|
|
peer.sendDirectly(channel, message, payload);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = WebRTC;
|
|
|
|
|
|
|
|
},{"./peer":9,"localmedia":10,"mockconsole":6,"util":8,"webrtcsupport":5,"wildemitter":4}],3:[function(require,module,exports){
|
|
|
|
var io = require('socket.io-client');
|
|
|
|
|
|
|
|
function SocketIoConnection(config) {
|
|
|
|
this.connection = io.connect(config.url, config.socketio);
|
|
|
|
}
|
|
|
|
|
|
|
|
SocketIoConnection.prototype.on = function (ev, fn) {
|
|
|
|
this.connection.on(ev, fn);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketIoConnection.prototype.emit = function () {
|
|
|
|
this.connection.emit.apply(this.connection, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketIoConnection.prototype.getSessionid = function () {
|
|
|
|
return this.connection.socket.sessionid;
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketIoConnection.prototype.disconnect = function () {
|
|
|
|
return this.connection.disconnect();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SocketIoConnection;
|
|
|
|
|
|
|
|
},{"socket.io-client":11}],8:[function(require,module,exports){
|
|
|
|
var events = require('events');
|
|
|
|
|
|
|
|
exports.isArray = isArray;
|
|
|
|
exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
|
|
|
|
exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
|
|
|
|
|
|
|
|
|
|
|
|
exports.print = function () {};
|
|
|
|
exports.puts = function () {};
|
|
|
|
exports.debug = function() {};
|
|
|
|
|
|
|
|
exports.inspect = function(obj, showHidden, depth, colors) {
|
|
|
|
var seen = [];
|
|
|
|
|
|
|
|
var stylize = function(str, styleType) {
|
|
|
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
|
|
var styles =
|
|
|
|
{ 'bold' : [1, 22],
|
|
|
|
'italic' : [3, 23],
|
|
|
|
'underline' : [4, 24],
|
|
|
|
'inverse' : [7, 27],
|
|
|
|
'white' : [37, 39],
|
|
|
|
'grey' : [90, 39],
|
|
|
|
'black' : [30, 39],
|
|
|
|
'blue' : [34, 39],
|
|
|
|
'cyan' : [36, 39],
|
|
|
|
'green' : [32, 39],
|
|
|
|
'magenta' : [35, 39],
|
|
|
|
'red' : [31, 39],
|
|
|
|
'yellow' : [33, 39] };
|
|
|
|
|
|
|
|
var style =
|
|
|
|
{ 'special': 'cyan',
|
|
|
|
'number': 'blue',
|
|
|
|
'boolean': 'yellow',
|
|
|
|
'undefined': 'grey',
|
|
|
|
'null': 'bold',
|
|
|
|
'string': 'green',
|
|
|
|
'date': 'magenta',
|
|
|
|
// "name": intentionally not styling
|
|
|
|
'regexp': 'red' }[styleType];
|
|
|
|
|
|
|
|
if (style) {
|
|
|
|
return '\u001b[' + styles[style][0] + 'm' + str +
|
|
|
|
'\u001b[' + styles[style][1] + 'm';
|
|
|
|
} else {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (! colors) {
|
|
|
|
stylize = function(str, styleType) { return str; };
|
|
|
|
}
|
|
|
|
|
|
|
|
function format(value, recurseTimes) {
|
|
|
|
// Provide a hook for user-specified inspect functions.
|
|
|
|
// Check that value is an object with an inspect function on it
|
|
|
|
if (value && typeof value.inspect === 'function' &&
|
|
|
|
// Filter out the util module, it's inspect function is special
|
|
|
|
value !== exports &&
|
|
|
|
// Also filter out any prototype objects using the circular check.
|
|
|
|
!(value.constructor && value.constructor.prototype === value)) {
|
|
|
|
return value.inspect(recurseTimes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Primitive types cannot have properties
|
|
|
|
switch (typeof value) {
|
|
|
|
case 'undefined':
|
|
|
|
return stylize('undefined', 'undefined');
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
|
|
.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"') + '\'';
|
|
|
|
return stylize(simple, 'string');
|
|
|
|
|
|
|
|
case 'number':
|
|
|
|
return stylize('' + value, 'number');
|
|
|
|
|
|
|
|
case 'boolean':
|
|
|
|
return stylize('' + value, 'boolean');
|
|
|
|
}
|
|
|
|
// For some reason typeof null is "object", so special case here.
|
|
|
|
if (value === null) {
|
|
|
|
return stylize('null', 'null');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look up the keys of the object.
|
|
|
|
var visible_keys = Object_keys(value);
|
|
|
|
var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
|
|
|
|
|
|
|
|
// Functions without properties can be shortcutted.
|
|
|
|
if (typeof value === 'function' && keys.length === 0) {
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
return stylize('' + value, 'regexp');
|
|
|
|
} else {
|
|
|
|
var name = value.name ? ': ' + value.name : '';
|
|
|
|
return stylize('[Function' + name + ']', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dates without properties can be shortcutted
|
|
|
|
if (isDate(value) && keys.length === 0) {
|
|
|
|
return stylize(value.toUTCString(), 'date');
|
|
|
|
}
|
|
|
|
|
|
|
|
var base, type, braces;
|
|
|
|
// Determine the object type
|
|
|
|
if (isArray(value)) {
|
|
|
|
type = 'Array';
|
|
|
|
braces = ['[', ']'];
|
|
|
|
} else {
|
|
|
|
type = 'Object';
|
|
|
|
braces = ['{', '}'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make functions say that they are functions
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
var n = value.name ? ': ' + value.name : '';
|
|
|
|
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
|
|
|
|
} else {
|
|
|
|
base = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make dates with properties first say the date
|
|
|
|
if (isDate(value)) {
|
|
|
|
base = ' ' + value.toUTCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keys.length === 0) {
|
|
|
|
return braces[0] + base + braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recurseTimes < 0) {
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
return stylize('' + value, 'regexp');
|
|
|
|
} else {
|
|
|
|
return stylize('[Object]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
seen.push(value);
|
|
|
|
|
|
|
|
var output = keys.map(function(key) {
|
|
|
|
var name, str;
|
|
|
|
if (value.__lookupGetter__) {
|
|
|
|
if (value.__lookupGetter__(key)) {
|
|
|
|
if (value.__lookupSetter__(key)) {
|
|
|
|
str = stylize('[Getter/Setter]', 'special');
|
|
|
|
} else {
|
|
|
|
str = stylize('[Getter]', 'special');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (value.__lookupSetter__(key)) {
|
|
|
|
str = stylize('[Setter]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (visible_keys.indexOf(key) < 0) {
|
|
|
|
name = '[' + key + ']';
|
|
|
|
}
|
|
|
|
if (!str) {
|
|
|
|
if (seen.indexOf(value[key]) < 0) {
|
|
|
|
if (recurseTimes === null) {
|
|
|
|
str = format(value[key]);
|
|
|
|
} else {
|
|
|
|
str = format(value[key], recurseTimes - 1);
|
|
|
|
}
|
|
|
|
if (str.indexOf('\n') > -1) {
|
|
|
|
if (isArray(value)) {
|
|
|
|
str = str.split('\n').map(function(line) {
|
|
|
|
return ' ' + line;
|
|
|
|
}).join('\n').substr(2);
|
|
|
|
} else {
|
|
|
|
str = '\n' + str.split('\n').map(function(line) {
|
|
|
|
return ' ' + line;
|
|
|
|
}).join('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str = stylize('[Circular]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof name === 'undefined') {
|
|
|
|
if (type === 'Array' && key.match(/^\d+$/)) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
name = JSON.stringify('' + key);
|
|
|
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
|
|
name = name.substr(1, name.length - 2);
|
|
|
|
name = stylize(name, 'name');
|
|
|
|
} else {
|
|
|
|
name = name.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"')
|
|
|
|
.replace(/(^"|"$)/g, "'");
|
|
|
|
name = stylize(name, 'string');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return name + ': ' + str;
|
|
|
|
});
|
|
|
|
|
|
|
|
seen.pop();
|
|
|
|
|
|
|
|
var numLinesEst = 0;
|
|
|
|
var length = output.reduce(function(prev, cur) {
|
|
|
|
numLinesEst++;
|
|
|
|
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|
|
|
return prev + cur.length + 1;
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
if (length > 50) {
|
|
|
|
output = braces[0] +
|
|
|
|
(base === '' ? '' : base + '\n ') +
|
|
|
|
' ' +
|
|
|
|
output.join(',\n ') +
|
|
|
|
' ' +
|
|
|
|
braces[1];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
return format(obj, (typeof depth === 'undefined' ? 2 : depth));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function isArray(ar) {
|
|
|
|
return Array.isArray(ar) ||
|
|
|
|
(typeof ar === 'object' && Object.prototype.toString.call(ar) === '[object Array]');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isRegExp(re) {
|
|
|
|
typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isDate(d) {
|
|
|
|
return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function pad(n) {
|
|
|
|
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|
|
|
'Oct', 'Nov', 'Dec'];
|
|
|
|
|
|
|
|
// 26 Feb 16:19:34
|
|
|
|
function timestamp() {
|
|
|
|
var d = new Date();
|
|
|
|
var time = [pad(d.getHours()),
|
|
|
|
pad(d.getMinutes()),
|
|
|
|
pad(d.getSeconds())].join(':');
|
|
|
|
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.log = function (msg) {};
|
|
|
|
|
|
|
|
exports.pump = null;
|
|
|
|
|
|
|
|
var Object_keys = Object.keys || function (obj) {
|
|
|
|
var res = [];
|
|
|
|
for (var key in obj) res.push(key);
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
|
|
|
|
var res = [];
|
|
|
|
for (var key in obj) {
|
|
|
|
if (Object.hasOwnProperty.call(obj, key)) res.push(key);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
var Object_create = Object.create || function (prototype, properties) {
|
|
|
|
// from es5-shim
|
|
|
|
var object;
|
|
|
|
if (prototype === null) {
|
|
|
|
object = { '__proto__' : null };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (typeof prototype !== 'object') {
|
|
|
|
throw new TypeError(
|
|
|
|
'typeof prototype[' + (typeof prototype) + '] != \'object\''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
var Type = function () {};
|
|
|
|
Type.prototype = prototype;
|
|
|
|
object = new Type();
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
}
|
|
|
|
if (typeof properties !== 'undefined' && Object.defineProperties) {
|
|
|
|
Object.defineProperties(object, properties);
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.inherits = function(ctor, superCtor) {
|
|
|
|
ctor.super_ = superCtor;
|
|
|
|
ctor.prototype = Object_create(superCtor.prototype, {
|
|
|
|
constructor: {
|
|
|
|
value: ctor,
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var formatRegExp = /%[sdj%]/g;
|
|
|
|
exports.format = function(f) {
|
|
|
|
if (typeof f !== 'string') {
|
|
|
|
var objects = [];
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
objects.push(exports.inspect(arguments[i]));
|
|
|
|
}
|
|
|
|
return objects.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
var i = 1;
|
|
|
|
var args = arguments;
|
|
|
|
var len = args.length;
|
|
|
|
var str = String(f).replace(formatRegExp, function(x) {
|
|
|
|
if (x === '%%') return '%';
|
|
|
|
if (i >= len) return x;
|
|
|
|
switch (x) {
|
|
|
|
case '%s': return String(args[i++]);
|
|
|
|
case '%d': return Number(args[i++]);
|
|
|
|
case '%j': return JSON.stringify(args[i++]);
|
|
|
|
default:
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
for(var x = args[i]; i < len; x = args[++i]){
|
|
|
|
if (x === null || typeof x !== 'object') {
|
|
|
|
str += ' ' + x;
|
|
|
|
} else {
|
|
|
|
str += ' ' + exports.inspect(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"events":12}],11:[function(require,module,exports){
|
|
|
|
/*! Socket.IO.js build:0.9.16, development. Copyright(c) 2011 LearnBoost <dev@learnboost.com> MIT Licensed */
|
|
|
|
|
|
|
|
var io = ('undefined' === typeof module ? {} : module.exports);
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IO namespace.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
|
|
|
|
var io = exports;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Socket.IO version
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.version = '0.9.16';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Protocol implemented.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.protocol = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Available transports, these will be populated with the available transports
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep track of jsonp callbacks.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.j = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep track of our io.Sockets
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
io.sockets = {};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages connections to hosts.
|
|
|
|
*
|
|
|
|
* @param {String} uri
|
|
|
|
* @Param {Boolean} force creation of new socket (defaults to false)
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.connect = function (host, details) {
|
|
|
|
var uri = io.util.parseUri(host)
|
|
|
|
, uuri
|
|
|
|
, socket;
|
|
|
|
|
|
|
|
if (global && global.location) {
|
|
|
|
uri.protocol = uri.protocol || global.location.protocol.slice(0, -1);
|
|
|
|
uri.host = uri.host || (global.document
|
|
|
|
? global.document.domain : global.location.hostname);
|
|
|
|
uri.port = uri.port || global.location.port;
|
|
|
|
}
|
|
|
|
|
|
|
|
uuri = io.util.uniqueUri(uri);
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
host: uri.host
|
|
|
|
, secure: 'https' == uri.protocol
|
|
|
|
, port: uri.port || ('https' == uri.protocol ? 443 : 80)
|
|
|
|
, query: uri.query || ''
|
|
|
|
};
|
|
|
|
|
|
|
|
io.util.merge(options, details);
|
|
|
|
|
|
|
|
if (options['force new connection'] || !io.sockets[uuri]) {
|
|
|
|
socket = new io.Socket(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options['force new connection'] && socket) {
|
|
|
|
io.sockets[uuri] = socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
socket = socket || io.sockets[uuri];
|
|
|
|
|
|
|
|
// if path is different from '' or /
|
|
|
|
return socket.of(uri.path.length > 1 ? uri.path : '');
|
|
|
|
};
|
|
|
|
|
|
|
|
})('object' === typeof module ? module.exports : (this.io = {}), this);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utilities namespace.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
|
|
|
|
var util = exports.util = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses an URI
|
|
|
|
*
|
|
|
|
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
|
|
|
|
|
|
var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password',
|
|
|
|
'host', 'port', 'relative', 'path', 'directory', 'file', 'query',
|
|
|
|
'anchor'];
|
|
|
|
|
|
|
|
util.parseUri = function (str) {
|
|
|
|
var m = re.exec(str || '')
|
|
|
|
, uri = {}
|
|
|
|
, i = 14;
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
uri[parts[i]] = m[i] || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produces a unique url that identifies a Socket.IO connection.
|
|
|
|
*
|
|
|
|
* @param {Object} uri
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.uniqueUri = function (uri) {
|
|
|
|
var protocol = uri.protocol
|
|
|
|
, host = uri.host
|
|
|
|
, port = uri.port;
|
|
|
|
|
|
|
|
if ('document' in global) {
|
|
|
|
host = host || document.domain;
|
|
|
|
port = port || (protocol == 'https'
|
|
|
|
&& document.location.protocol !== 'https:' ? 443 : document.location.port);
|
|
|
|
} else {
|
|
|
|
host = host || 'localhost';
|
|
|
|
|
|
|
|
if (!port && protocol == 'https') {
|
|
|
|
port = 443;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (protocol || 'http') + '://' + host + ':' + (port || 80);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mergest 2 query strings in to once unique query string
|
|
|
|
*
|
|
|
|
* @param {String} base
|
|
|
|
* @param {String} addition
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.query = function (base, addition) {
|
|
|
|
var query = util.chunkQuery(base || '')
|
|
|
|
, components = [];
|
|
|
|
|
|
|
|
util.merge(query, util.chunkQuery(addition || ''));
|
|
|
|
for (var part in query) {
|
|
|
|
if (query.hasOwnProperty(part)) {
|
|
|
|
components.push(part + '=' + query[part]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return components.length ? '?' + components.join('&') : '';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms a querystring in to an object
|
|
|
|
*
|
|
|
|
* @param {String} qs
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.chunkQuery = function (qs) {
|
|
|
|
var query = {}
|
|
|
|
, params = qs.split('&')
|
|
|
|
, i = 0
|
|
|
|
, l = params.length
|
|
|
|
, kv;
|
|
|
|
|
|
|
|
for (; i < l; ++i) {
|
|
|
|
kv = params[i].split('=');
|
|
|
|
if (kv[0]) {
|
|
|
|
query[kv[0]] = kv[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the given function when the page is loaded.
|
|
|
|
*
|
|
|
|
* io.util.load(function () { console.log('page loaded'); });
|
|
|
|
*
|
|
|
|
* @param {Function} fn
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
var pageLoaded = false;
|
|
|
|
|
|
|
|
util.load = function (fn) {
|
|
|
|
if ('document' in global && document.readyState === 'complete' || pageLoaded) {
|
|
|
|
return fn();
|
|
|
|
}
|
|
|
|
|
|
|
|
util.on(global, 'load', fn, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an event.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.on = function (element, event, fn, capture) {
|
|
|
|
if (element.attachEvent) {
|
|
|
|
element.attachEvent('on' + event, fn);
|
|
|
|
} else if (element.addEventListener) {
|
|
|
|
element.addEventListener(event, fn, capture);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the correct `XMLHttpRequest` for regular and cross domain requests.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [xdomain] Create a request that can be used cross domain.
|
|
|
|
* @returns {XMLHttpRequest|false} If we can create a XMLHttpRequest.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.request = function (xdomain) {
|
|
|
|
|
|
|
|
if (xdomain && 'undefined' != typeof XDomainRequest && !util.ua.hasCORS) {
|
|
|
|
return new XDomainRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('undefined' != typeof XMLHttpRequest && (!xdomain || util.ua.hasCORS)) {
|
|
|
|
return new XMLHttpRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xdomain) {
|
|
|
|
try {
|
|
|
|
return new window[(['Active'].concat('Object').join('X'))]('Microsoft.XMLHTTP');
|
|
|
|
} catch(e) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XHR based transport constructor.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the internal pageLoaded value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ('undefined' != typeof window) {
|
|
|
|
util.load(function () {
|
|
|
|
pageLoaded = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defers a function to ensure a spinner is not displayed by the browser
|
|
|
|
*
|
|
|
|
* @param {Function} fn
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.defer = function (fn) {
|
|
|
|
if (!util.ua.webkit || 'undefined' != typeof importScripts) {
|
|
|
|
return fn();
|
|
|
|
}
|
|
|
|
|
|
|
|
util.load(function () {
|
|
|
|
setTimeout(fn, 100);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges two objects.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.merge = function merge (target, additional, deep, lastseen) {
|
|
|
|
var seen = lastseen || []
|
|
|
|
, depth = typeof deep == 'undefined' ? 2 : deep
|
|
|
|
, prop;
|
|
|
|
|
|
|
|
for (prop in additional) {
|
|
|
|
if (additional.hasOwnProperty(prop) && util.indexOf(seen, prop) < 0) {
|
|
|
|
if (typeof target[prop] !== 'object' || !depth) {
|
|
|
|
target[prop] = additional[prop];
|
|
|
|
seen.push(additional[prop]);
|
|
|
|
} else {
|
|
|
|
util.merge(target[prop], additional[prop], depth - 1, seen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges prototypes from objects
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.mixin = function (ctor, ctor2) {
|
|
|
|
util.merge(ctor.prototype, ctor2.prototype);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for prototypical and static inheritance.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.inherit = function (ctor, ctor2) {
|
|
|
|
function f() {};
|
|
|
|
f.prototype = ctor2.prototype;
|
|
|
|
ctor.prototype = new f;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given object is an Array.
|
|
|
|
*
|
|
|
|
* io.util.isArray([]); // true
|
|
|
|
* io.util.isArray({}); // false
|
|
|
|
*
|
|
|
|
* @param Object obj
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.isArray = Array.isArray || function (obj) {
|
|
|
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intersects values of two arrays into a third
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.intersect = function (arr, arr2) {
|
|
|
|
var ret = []
|
|
|
|
, longest = arr.length > arr2.length ? arr : arr2
|
|
|
|
, shortest = arr.length > arr2.length ? arr2 : arr;
|
|
|
|
|
|
|
|
for (var i = 0, l = shortest.length; i < l; i++) {
|
|
|
|
if (~util.indexOf(longest, shortest[i]))
|
|
|
|
ret.push(shortest[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array indexOf compatibility.
|
|
|
|
*
|
|
|
|
* @see bit.ly/a5Dxa2
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.indexOf = function (arr, o, i) {
|
|
|
|
|
|
|
|
for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0;
|
|
|
|
i < j && arr[i] !== o; i++) {}
|
|
|
|
|
|
|
|
return j <= i ? -1 : i;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts enumerables to array.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.toArray = function (enu) {
|
|
|
|
var arr = [];
|
|
|
|
|
|
|
|
for (var i = 0, l = enu.length; i < l; i++)
|
|
|
|
arr.push(enu[i]);
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UA / engines detection namespace.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.ua = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the UA supports CORS for XHR.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function () {
|
|
|
|
try {
|
|
|
|
var a = new XMLHttpRequest();
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.withCredentials != undefined;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect webkit.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.ua.webkit = 'undefined' != typeof navigator
|
|
|
|
&& /webkit/i.test(navigator.userAgent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect iPad/iPhone/iPod.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
util.ua.iDevice = 'undefined' != typeof navigator
|
|
|
|
&& /iPad|iPhone|iPod/i.test(navigator.userAgent);
|
|
|
|
|
|
|
|
})('undefined' != typeof io ? io : module.exports, this);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.EventEmitter = EventEmitter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event emitter constructor.
|
|
|
|
*
|
|
|
|
* @api public.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function EventEmitter () {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a listener
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.on = function (name, fn) {
|
|
|
|
if (!this.$events) {
|
|
|
|
this.$events = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.$events[name]) {
|
|
|
|
this.$events[name] = fn;
|
|
|
|
} else if (io.util.isArray(this.$events[name])) {
|
|
|
|
this.$events[name].push(fn);
|
|
|
|
} else {
|
|
|
|
this.$events[name] = [this.$events[name], fn];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a volatile listener.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.once = function (name, fn) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
function on () {
|
|
|
|
self.removeListener(name, on);
|
|
|
|
fn.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
on.listener = fn;
|
|
|
|
this.on(name, on);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a listener.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeListener = function (name, fn) {
|
|
|
|
if (this.$events && this.$events[name]) {
|
|
|
|
var list = this.$events[name];
|
|
|
|
|
|
|
|
if (io.util.isArray(list)) {
|
|
|
|
var pos = -1;
|
|
|
|
|
|
|
|
for (var i = 0, l = list.length; i < l; i++) {
|
|
|
|
if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
|
|
|
|
pos = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos < 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.splice(pos, 1);
|
|
|
|
|
|
|
|
if (!list.length) {
|
|
|
|
delete this.$events[name];
|
|
|
|
}
|
|
|
|
} else if (list === fn || (list.listener && list.listener === fn)) {
|
|
|
|
delete this.$events[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all listeners for an event.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeAllListeners = function (name) {
|
|
|
|
if (name === undefined) {
|
|
|
|
this.$events = {};
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$events && this.$events[name]) {
|
|
|
|
this.$events[name] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all listeners for a certain event.
|
|
|
|
*
|
|
|
|
* @api publci
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.listeners = function (name) {
|
|
|
|
if (!this.$events) {
|
|
|
|
this.$events = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.$events[name]) {
|
|
|
|
this.$events[name] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!io.util.isArray(this.$events[name])) {
|
|
|
|
this.$events[name] = [this.$events[name]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$events[name];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits an event.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
EventEmitter.prototype.emit = function (name) {
|
|
|
|
if (!this.$events) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var handler = this.$events[name];
|
|
|
|
|
|
|
|
if (!handler) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
|
|
|
|
if ('function' == typeof handler) {
|
|
|
|
handler.apply(this, args);
|
|
|
|
} else if (io.util.isArray(handler)) {
|
|
|
|
var listeners = handler.slice();
|
|
|
|
|
|
|
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
|
|
listeners[i].apply(this, args);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Based on JSON2 (http://www.JSON.org/js.html).
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, nativeJSON) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// use native JSON if it's available
|
|
|
|
if (nativeJSON && nativeJSON.parse){
|
|
|
|
return exports.JSON = {
|
|
|
|
parse: nativeJSON.parse
|
|
|
|
, stringify: nativeJSON.stringify
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var JSON = exports.JSON = {};
|
|
|
|
|
|
|
|
function f(n) {
|
|
|
|
// Format integers to have at least two digits.
|
|
|
|
return n < 10 ? '0' + n : n;
|
|
|
|
}
|
|
|
|
|
|
|
|
function date(d, key) {
|
|
|
|
return isFinite(d.valueOf()) ?
|
|
|
|
d.getUTCFullYear() + '-' +
|
|
|
|
f(d.getUTCMonth() + 1) + '-' +
|
|
|
|
f(d.getUTCDate()) + 'T' +
|
|
|
|
f(d.getUTCHours()) + ':' +
|
|
|
|
f(d.getUTCMinutes()) + ':' +
|
|
|
|
f(d.getUTCSeconds()) + 'Z' : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
|
|
|
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
|
|
|
gap,
|
|
|
|
indent,
|
|
|
|
meta = { // table of character substitutions
|
|
|
|
'\b': '\\b',
|
|
|
|
'\t': '\\t',
|
|
|
|
'\n': '\\n',
|
|
|
|
'\f': '\\f',
|
|
|
|
'\r': '\\r',
|
|
|
|
'"' : '\\"',
|
|
|
|
'\\': '\\\\'
|
|
|
|
},
|
|
|
|
rep;
|
|
|
|
|
|
|
|
|
|
|
|
function quote(string) {
|
|
|
|
|
|
|
|
// If the string contains no control characters, no quote characters, and no
|
|
|
|
// backslash characters, then we can safely slap some quotes around it.
|
|
|
|
// Otherwise we must also replace the offending characters with safe escape
|
|
|
|
// sequences.
|
|
|
|
|
|
|
|
escapable.lastIndex = 0;
|
|
|
|
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
|
|
|
var c = meta[a];
|
|
|
|
return typeof c === 'string' ? c :
|
|
|
|
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
|
|
|
}) + '"' : '"' + string + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function str(key, holder) {
|
|
|
|
|
|
|
|
// Produce a string from holder[key].
|
|
|
|
|
|
|
|
var i, // The loop counter.
|
|
|
|
k, // The member key.
|
|
|
|
v, // The member value.
|
|
|
|
length,
|
|
|
|
mind = gap,
|
|
|
|
partial,
|
|
|
|
value = holder[key];
|
|
|
|
|
|
|
|
// If the value has a toJSON method, call it to obtain a replacement value.
|
|
|
|
|
|
|
|
if (value instanceof Date) {
|
|
|
|
value = date(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were called with a replacer function, then call the replacer to
|
|
|
|
// obtain a replacement value.
|
|
|
|
|
|
|
|
if (typeof rep === 'function') {
|
|
|
|
value = rep.call(holder, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// What happens next depends on the value's type.
|
|
|
|
|
|
|
|
switch (typeof value) {
|
|
|
|
case 'string':
|
|
|
|
return quote(value);
|
|
|
|
|
|
|
|
case 'number':
|
|
|
|
|
|
|
|
// JSON numbers must be finite. Encode non-finite numbers as null.
|
|
|
|
|
|
|
|
return isFinite(value) ? String(value) : 'null';
|
|
|
|
|
|
|
|
case 'boolean':
|
|
|
|
case 'null':
|
|
|
|
|
|
|
|
// If the value is a boolean or null, convert it to a string. Note:
|
|
|
|
// typeof null does not produce 'null'. The case is included here in
|
|
|
|
// the remote chance that this gets fixed someday.
|
|
|
|
|
|
|
|
return String(value);
|
|
|
|
|
|
|
|
// If the type is 'object', we might be dealing with an object or an array or
|
|
|
|
// null.
|
|
|
|
|
|
|
|
case 'object':
|
|
|
|
|
|
|
|
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
|
|
|
// so watch out for that case.
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
return 'null';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make an array to hold the partial results of stringifying this object value.
|
|
|
|
|
|
|
|
gap += indent;
|
|
|
|
partial = [];
|
|
|
|
|
|
|
|
// Is the value an array?
|
|
|
|
|
|
|
|
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
|
|
|
|
|
|
|
// The value is an array. Stringify every element. Use null as a placeholder
|
|
|
|
// for non-JSON values.
|
|
|
|
|
|
|
|
length = value.length;
|
|
|
|
for (i = 0; i < length; i += 1) {
|
|
|
|
partial[i] = str(i, value) || 'null';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Join all of the elements together, separated with commas, and wrap them in
|
|
|
|
// brackets.
|
|
|
|
|
|
|
|
v = partial.length === 0 ? '[]' : gap ?
|
|
|
|
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
|
|
|
|
'[' + partial.join(',') + ']';
|
|
|
|
gap = mind;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the replacer is an array, use it to select the members to be stringified.
|
|
|
|
|
|
|
|
if (rep && typeof rep === 'object') {
|
|
|
|
length = rep.length;
|
|
|
|
for (i = 0; i < length; i += 1) {
|
|
|
|
if (typeof rep[i] === 'string') {
|
|
|
|
k = rep[i];
|
|
|
|
v = str(k, value);
|
|
|
|
if (v) {
|
|
|
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Otherwise, iterate through all of the keys in the object.
|
|
|
|
|
|
|
|
for (k in value) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
|
|
v = str(k, value);
|
|
|
|
if (v) {
|
|
|
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Join all of the member texts together, separated with commas,
|
|
|
|
// and wrap them in braces.
|
|
|
|
|
|
|
|
v = partial.length === 0 ? '{}' : gap ?
|
|
|
|
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
|
|
|
|
'{' + partial.join(',') + '}';
|
|
|
|
gap = mind;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the JSON object does not yet have a stringify method, give it one.
|
|
|
|
|
|
|
|
JSON.stringify = function (value, replacer, space) {
|
|
|
|
|
|
|
|
// The stringify method takes a value and an optional replacer, and an optional
|
|
|
|
// space parameter, and returns a JSON text. The replacer can be a function
|
|
|
|
// that can replace values, or an array of strings that will select the keys.
|
|
|
|
// A default replacer method can be provided. Use of the space parameter can
|
|
|
|
// produce text that is more easily readable.
|
|
|
|
|
|
|
|
var i;
|
|
|
|
gap = '';
|
|
|
|
indent = '';
|
|
|
|
|
|
|
|
// If the space parameter is a number, make an indent string containing that
|
|
|
|
// many spaces.
|
|
|
|
|
|
|
|
if (typeof space === 'number') {
|
|
|
|
for (i = 0; i < space; i += 1) {
|
|
|
|
indent += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the space parameter is a string, it will be used as the indent string.
|
|
|
|
|
|
|
|
} else if (typeof space === 'string') {
|
|
|
|
indent = space;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a replacer, it must be a function or an array.
|
|
|
|
// Otherwise, throw an error.
|
|
|
|
|
|
|
|
rep = replacer;
|
|
|
|
if (replacer && typeof replacer !== 'function' &&
|
|
|
|
(typeof replacer !== 'object' ||
|
|
|
|
typeof replacer.length !== 'number')) {
|
|
|
|
throw new Error('JSON.stringify');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a fake root object containing our value under the key of ''.
|
|
|
|
// Return the result of stringifying the value.
|
|
|
|
|
|
|
|
return str('', {'': value});
|
|
|
|
};
|
|
|
|
|
|
|
|
// If the JSON object does not yet have a parse method, give it one.
|
|
|
|
|
|
|
|
JSON.parse = function (text, reviver) {
|
|
|
|
// The parse method takes a text and an optional reviver function, and returns
|
|
|
|
// a JavaScript value if the text is a valid JSON text.
|
|
|
|
|
|
|
|
var j;
|
|
|
|
|
|
|
|
function walk(holder, key) {
|
|
|
|
|
|
|
|
// The walk method is used to recursively walk the resulting structure so
|
|
|
|
// that modifications can be made.
|
|
|
|
|
|
|
|
var k, v, value = holder[key];
|
|
|
|
if (value && typeof value === 'object') {
|
|
|
|
for (k in value) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
|
|
v = walk(value, k);
|
|
|
|
if (v !== undefined) {
|
|
|
|
value[k] = v;
|
|
|
|
} else {
|
|
|
|
delete value[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reviver.call(holder, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Parsing happens in four stages. In the first stage, we replace certain
|
|
|
|
// Unicode characters with escape sequences. JavaScript handles many characters
|
|
|
|
// incorrectly, either silently deleting them, or treating them as line endings.
|
|
|
|
|
|
|
|
text = String(text);
|
|
|
|
cx.lastIndex = 0;
|
|
|
|
if (cx.test(text)) {
|
|
|
|
text = text.replace(cx, function (a) {
|
|
|
|
return '\\u' +
|
|
|
|
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the second stage, we run the text against regular expressions that look
|
|
|
|
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
|
|
|
// because they can cause invocation, and '=' because it can cause mutation.
|
|
|
|
// But just to be safe, we want to reject all unexpected forms.
|
|
|
|
|
|
|
|
// We split the second stage into 4 regexp operations in order to work around
|
|
|
|
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
|
|
|
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
|
|
|
// replace all simple value tokens with ']' characters. Third, we delete all
|
|
|
|
// open brackets that follow a colon or comma or that begin the text. Finally,
|
|
|
|
// we look to see that the remaining characters are only whitespace or ']' or
|
|
|
|
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
|
|
|
|
|
|
|
if (/^[\],:{}\s]*$/
|
|
|
|
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
|
|
|
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
|
|
|
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
|
|
|
|
|
|
|
// In the third stage we use the eval function to compile the text into a
|
|
|
|
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
|
|
|
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
|
|
|
// in parens to eliminate the ambiguity.
|
|
|
|
|
|
|
|
j = eval('(' + text + ')');
|
|
|
|
|
|
|
|
// In the optional fourth stage, we recursively walk the new structure, passing
|
|
|
|
// each name/value pair to a reviver function for possible transformation.
|
|
|
|
|
|
|
|
return typeof reviver === 'function' ?
|
|
|
|
walk({'': j}, '') : j;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
|
|
|
|
|
|
|
throw new SyntaxError('JSON.parse');
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, typeof JSON !== 'undefined' ? JSON : undefined
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parser namespace.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
|
|
|
|
var parser = exports.parser = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Packet types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var packets = parser.packets = [
|
|
|
|
'disconnect'
|
|
|
|
, 'connect'
|
|
|
|
, 'heartbeat'
|
|
|
|
, 'message'
|
|
|
|
, 'json'
|
|
|
|
, 'event'
|
|
|
|
, 'ack'
|
|
|
|
, 'error'
|
|
|
|
, 'noop'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Errors reasons.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var reasons = parser.reasons = [
|
|
|
|
'transport not supported'
|
|
|
|
, 'client not handshaken'
|
|
|
|
, 'unauthorized'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Errors advice.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var advice = parser.advice = [
|
|
|
|
'reconnect'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcuts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var JSON = io.JSON
|
|
|
|
, indexOf = io.util.indexOf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes a packet.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
parser.encodePacket = function (packet) {
|
|
|
|
var type = indexOf(packets, packet.type)
|
|
|
|
, id = packet.id || ''
|
|
|
|
, endpoint = packet.endpoint || ''
|
|
|
|
, ack = packet.ack
|
|
|
|
, data = null;
|
|
|
|
|
|
|
|
switch (packet.type) {
|
|
|
|
case 'error':
|
|
|
|
var reason = packet.reason ? indexOf(reasons, packet.reason) : ''
|
|
|
|
, adv = packet.advice ? indexOf(advice, packet.advice) : '';
|
|
|
|
|
|
|
|
if (reason !== '' || adv !== '')
|
|
|
|
data = reason + (adv !== '' ? ('+' + adv) : '');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'message':
|
|
|
|
if (packet.data !== '')
|
|
|
|
data = packet.data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'event':
|
|
|
|
var ev = { name: packet.name };
|
|
|
|
|
|
|
|
if (packet.args && packet.args.length) {
|
|
|
|
ev.args = packet.args;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = JSON.stringify(ev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'json':
|
|
|
|
data = JSON.stringify(packet.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'connect':
|
|
|
|
if (packet.qs)
|
|
|
|
data = packet.qs;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ack':
|
|
|
|
data = packet.ackId
|
|
|
|
+ (packet.args && packet.args.length
|
|
|
|
? '+' + JSON.stringify(packet.args) : '');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct packet with required fragments
|
|
|
|
var encoded = [
|
|
|
|
type
|
|
|
|
, id + (ack == 'data' ? '+' : '')
|
|
|
|
, endpoint
|
|
|
|
];
|
|
|
|
|
|
|
|
// data fragment is optional
|
|
|
|
if (data !== null && data !== undefined)
|
|
|
|
encoded.push(data);
|
|
|
|
|
|
|
|
return encoded.join(':');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes multiple messages (payload).
|
|
|
|
*
|
|
|
|
* @param {Array} messages
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
parser.encodePayload = function (packets) {
|
|
|
|
var decoded = '';
|
|
|
|
|
|
|
|
if (packets.length == 1)
|
|
|
|
return packets[0];
|
|
|
|
|
|
|
|
for (var i = 0, l = packets.length; i < l; i++) {
|
|
|
|
var packet = packets[i];
|
|
|
|
decoded += '\ufffd' + packet.length + '\ufffd' + packets[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes a packet
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
var regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/;
|
|
|
|
|
|
|
|
parser.decodePacket = function (data) {
|
|
|
|
var pieces = data.match(regexp);
|
|
|
|
|
|
|
|
if (!pieces) return {};
|
|
|
|
|
|
|
|
var id = pieces[2] || ''
|
|
|
|
, data = pieces[5] || ''
|
|
|
|
, packet = {
|
|
|
|
type: packets[pieces[1]]
|
|
|
|
, endpoint: pieces[4] || ''
|
|
|
|
};
|
|
|
|
|
|
|
|
// whether we need to acknowledge the packet
|
|
|
|
if (id) {
|
|
|
|
packet.id = id;
|
|
|
|
if (pieces[3])
|
|
|
|
packet.ack = 'data';
|
|
|
|
else
|
|
|
|
packet.ack = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle different packet types
|
|
|
|
switch (packet.type) {
|
|
|
|
case 'error':
|
|
|
|
var pieces = data.split('+');
|
|
|
|
packet.reason = reasons[pieces[0]] || '';
|
|
|
|
packet.advice = advice[pieces[1]] || '';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'message':
|
|
|
|
packet.data = data || '';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'event':
|
|
|
|
try {
|
|
|
|
var opts = JSON.parse(data);
|
|
|
|
packet.name = opts.name;
|
|
|
|
packet.args = opts.args;
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
packet.args = packet.args || [];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'json':
|
|
|
|
try {
|
|
|
|
packet.data = JSON.parse(data);
|
|
|
|
} catch (e) { }
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'connect':
|
|
|
|
packet.qs = data || '';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ack':
|
|
|
|
var pieces = data.match(/^([0-9]+)(\+)?(.*)/);
|
|
|
|
if (pieces) {
|
|
|
|
packet.ackId = pieces[1];
|
|
|
|
packet.args = [];
|
|
|
|
|
|
|
|
if (pieces[3]) {
|
|
|
|
try {
|
|
|
|
packet.args = pieces[3] ? JSON.parse(pieces[3]) : [];
|
|
|
|
} catch (e) { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'disconnect':
|
|
|
|
case 'heartbeat':
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes data payload. Detects multiple messages
|
|
|
|
*
|
|
|
|
* @return {Array} messages
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
parser.decodePayload = function (data) {
|
|
|
|
// IE doesn't like data[i] for unicode chars, charAt works fine
|
|
|
|
if (data.charAt(0) == '\ufffd') {
|
|
|
|
var ret = [];
|
|
|
|
|
|
|
|
for (var i = 1, length = ''; i < data.length; i++) {
|
|
|
|
if (data.charAt(i) == '\ufffd') {
|
|
|
|
ret.push(parser.decodePacket(data.substr(i + 1).substr(0, length)));
|
|
|
|
i += Number(length) + 1;
|
|
|
|
length = '';
|
|
|
|
} else {
|
|
|
|
length += data.charAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return [parser.decodePacket(data)];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.Transport = Transport;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the transport template for all supported transport methods.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Transport (socket, sessid) {
|
|
|
|
this.socket = socket;
|
|
|
|
this.sessid = sessid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply EventEmitter mixin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.mixin(Transport, io.EventEmitter);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether heartbeats is enabled for this transport
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.heartbeats = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the response from the server. When a new response is received
|
|
|
|
* it will automatically update the timeout, decode the message and
|
|
|
|
* forwards the response to the onMessage function for further processing.
|
|
|
|
*
|
|
|
|
* @param {String} data Response from the server.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onData = function (data) {
|
|
|
|
this.clearCloseTimeout();
|
|
|
|
|
|
|
|
// If the connection in currently open (or in a reopening state) reset the close
|
|
|
|
// timeout since we have just received data. This check is necessary so
|
|
|
|
// that we don't reset the timeout on an explicitly disconnected connection.
|
|
|
|
if (this.socket.connected || this.socket.connecting || this.socket.reconnecting) {
|
|
|
|
this.setCloseTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data !== '') {
|
|
|
|
// todo: we should only do decodePayload for xhr transports
|
|
|
|
var msgs = io.parser.decodePayload(data);
|
|
|
|
|
|
|
|
if (msgs && msgs.length) {
|
|
|
|
for (var i = 0, l = msgs.length; i < l; i++) {
|
|
|
|
this.onPacket(msgs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles packets.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onPacket = function (packet) {
|
|
|
|
this.socket.setHeartbeatTimeout();
|
|
|
|
|
|
|
|
if (packet.type == 'heartbeat') {
|
|
|
|
return this.onHeartbeat();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.type == 'connect' && packet.endpoint == '') {
|
|
|
|
this.onConnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.type == 'error' && packet.advice == 'reconnect') {
|
|
|
|
this.isOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.socket.onPacket(packet);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets close timeout
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.setCloseTimeout = function () {
|
|
|
|
if (!this.closeTimeout) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.closeTimeout = setTimeout(function () {
|
|
|
|
self.onDisconnect();
|
|
|
|
}, this.socket.closeTimeout);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when transport disconnects.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onDisconnect = function () {
|
|
|
|
if (this.isOpen) this.close();
|
|
|
|
this.clearTimeouts();
|
|
|
|
this.socket.onDisconnect();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when transport connects
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onConnect = function () {
|
|
|
|
this.socket.onConnect();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears close timeout
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.clearCloseTimeout = function () {
|
|
|
|
if (this.closeTimeout) {
|
|
|
|
clearTimeout(this.closeTimeout);
|
|
|
|
this.closeTimeout = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear timeouts
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.clearTimeouts = function () {
|
|
|
|
this.clearCloseTimeout();
|
|
|
|
|
|
|
|
if (this.reopenTimeout) {
|
|
|
|
clearTimeout(this.reopenTimeout);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a packet
|
|
|
|
*
|
|
|
|
* @param {Object} packet object.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.packet = function (packet) {
|
|
|
|
this.send(io.parser.encodePacket(packet));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the received heartbeat message back to server. So the server
|
|
|
|
* knows we are still connected.
|
|
|
|
*
|
|
|
|
* @param {String} heartbeat Heartbeat response from the server.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onHeartbeat = function (heartbeat) {
|
|
|
|
this.packet({ type: 'heartbeat' });
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the transport opens.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onOpen = function () {
|
|
|
|
this.isOpen = true;
|
|
|
|
this.clearCloseTimeout();
|
|
|
|
this.socket.onOpen();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the base when the connection with the Socket.IO server
|
|
|
|
* has been disconnected.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.onClose = function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
/* FIXME: reopen delay causing a infinit loop
|
|
|
|
this.reopenTimeout = setTimeout(function () {
|
|
|
|
self.open();
|
|
|
|
}, this.socket.options['reopen delay']);*/
|
|
|
|
|
|
|
|
this.isOpen = false;
|
|
|
|
this.socket.onClose();
|
|
|
|
this.onDisconnect();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a connection url based on the Socket.IO URL Protocol.
|
|
|
|
* See <https://github.com/learnboost/socket.io-node/> for more details.
|
|
|
|
*
|
|
|
|
* @returns {String} Connection url
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.prepareUrl = function () {
|
|
|
|
var options = this.socket.options;
|
|
|
|
|
|
|
|
return this.scheme() + '://'
|
|
|
|
+ options.host + ':' + options.port + '/'
|
|
|
|
+ options.resource + '/' + io.protocol
|
|
|
|
+ '/' + this.name + '/' + this.sessid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the transport is ready to start a connection.
|
|
|
|
*
|
|
|
|
* @param {Socket} socket The socket instance that needs a transport
|
|
|
|
* @param {Function} fn The callback
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transport.prototype.ready = function (socket, fn) {
|
|
|
|
fn.call(this);
|
|
|
|
};
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.Socket = Socket;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new `Socket.IO client` which can establish a persistent
|
|
|
|
* connection with a Socket.IO enabled server.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Socket (options) {
|
|
|
|
this.options = {
|
|
|
|
port: 80
|
|
|
|
, secure: false
|
|
|
|
, document: 'document' in global ? document : false
|
|
|
|
, resource: 'socket.io'
|
|
|
|
, transports: io.transports
|
|
|
|
, 'connect timeout': 10000
|
|
|
|
, 'try multiple transports': true
|
|
|
|
, 'reconnect': true
|
|
|
|
, 'reconnection delay': 500
|
|
|
|
, 'reconnection limit': Infinity
|
|
|
|
, 'reopen delay': 3000
|
|
|
|
, 'max reconnection attempts': 10
|
|
|
|
, 'sync disconnect on unload': false
|
|
|
|
, 'auto connect': true
|
|
|
|
, 'flash policy port': 10843
|
|
|
|
, 'manualFlush': false
|
|
|
|
};
|
|
|
|
|
|
|
|
io.util.merge(this.options, options);
|
|
|
|
|
|
|
|
this.connected = false;
|
|
|
|
this.open = false;
|
|
|
|
this.connecting = false;
|
|
|
|
this.reconnecting = false;
|
|
|
|
this.namespaces = {};
|
|
|
|
this.buffer = [];
|
|
|
|
this.doBuffer = false;
|
|
|
|
|
|
|
|
if (this.options['sync disconnect on unload'] &&
|
|
|
|
(!this.isXDomain() || io.util.ua.hasCORS)) {
|
|
|
|
var self = this;
|
|
|
|
io.util.on(global, 'beforeunload', function () {
|
|
|
|
self.disconnectSync();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.options['auto connect']) {
|
|
|
|
this.connect();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply EventEmitter mixin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.mixin(Socket, io.EventEmitter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a namespace listener/emitter for this socket
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.of = function (name) {
|
|
|
|
if (!this.namespaces[name]) {
|
|
|
|
this.namespaces[name] = new io.SocketNamespace(this, name);
|
|
|
|
|
|
|
|
if (name !== '') {
|
|
|
|
this.namespaces[name].packet({ type: 'connect' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.namespaces[name];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits the given event to the Socket and all namespaces
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.publish = function () {
|
|
|
|
this.emit.apply(this, arguments);
|
|
|
|
|
|
|
|
var nsp;
|
|
|
|
|
|
|
|
for (var i in this.namespaces) {
|
|
|
|
if (this.namespaces.hasOwnProperty(i)) {
|
|
|
|
nsp = this.of(i);
|
|
|
|
nsp.$emit.apply(nsp, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs the handshake
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
function empty () { };
|
|
|
|
|
|
|
|
Socket.prototype.handshake = function (fn) {
|
|
|
|
var self = this
|
|
|
|
, options = this.options;
|
|
|
|
|
|
|
|
function complete (data) {
|
|
|
|
if (data instanceof Error) {
|
|
|
|
self.connecting = false;
|
|
|
|
self.onError(data.message);
|
|
|
|
} else {
|
|
|
|
fn.apply(null, data.split(':'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var url = [
|
|
|
|
'http' + (options.secure ? 's' : '') + ':/'
|
|
|
|
, options.host + ':' + options.port
|
|
|
|
, options.resource
|
|
|
|
, io.protocol
|
|
|
|
, io.util.query(this.options.query, 't=' + +new Date)
|
|
|
|
].join('/');
|
|
|
|
|
|
|
|
if (this.isXDomain() && !io.util.ua.hasCORS) {
|
|
|
|
var insertAt = document.getElementsByTagName('script')[0]
|
|
|
|
, script = document.createElement('script');
|
|
|
|
|
|
|
|
script.src = url + '&jsonp=' + io.j.length;
|
|
|
|
insertAt.parentNode.insertBefore(script, insertAt);
|
|
|
|
|
|
|
|
io.j.push(function (data) {
|
|
|
|
complete(data);
|
|
|
|
script.parentNode.removeChild(script);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var xhr = io.util.request();
|
|
|
|
|
|
|
|
xhr.open('GET', url, true);
|
|
|
|
if (this.isXDomain()) {
|
|
|
|
xhr.withCredentials = true;
|
|
|
|
}
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
if (xhr.readyState == 4) {
|
|
|
|
xhr.onreadystatechange = empty;
|
|
|
|
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
complete(xhr.responseText);
|
|
|
|
} else if (xhr.status == 403) {
|
|
|
|
self.onError(xhr.responseText);
|
|
|
|
} else {
|
|
|
|
self.connecting = false;
|
|
|
|
!self.reconnecting && self.onError(xhr.responseText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an available transport based on the options supplied in the constructor.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.getTransport = function (override) {
|
|
|
|
var transports = override || this.transports, match;
|
|
|
|
|
|
|
|
for (var i = 0, transport; transport = transports[i]; i++) {
|
|
|
|
if (io.Transport[transport]
|
|
|
|
&& io.Transport[transport].check(this)
|
|
|
|
&& (!this.isXDomain() || io.Transport[transport].xdomainCheck(this))) {
|
|
|
|
return new io.Transport[transport](this, this.sessionid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connects to the server.
|
|
|
|
*
|
|
|
|
* @param {Function} [fn] Callback.
|
|
|
|
* @returns {io.Socket}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.connect = function (fn) {
|
|
|
|
if (this.connecting) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
self.connecting = true;
|
|
|
|
|
|
|
|
this.handshake(function (sid, heartbeat, close, transports) {
|
|
|
|
self.sessionid = sid;
|
|
|
|
self.closeTimeout = close * 1000;
|
|
|
|
self.heartbeatTimeout = heartbeat * 1000;
|
|
|
|
if(!self.transports)
|
|
|
|
self.transports = self.origTransports = (transports ? io.util.intersect(
|
|
|
|
transports.split(',')
|
|
|
|
, self.options.transports
|
|
|
|
) : self.options.transports);
|
|
|
|
|
|
|
|
self.setHeartbeatTimeout();
|
|
|
|
|
|
|
|
function connect (transports){
|
|
|
|
if (self.transport) self.transport.clearTimeouts();
|
|
|
|
|
|
|
|
self.transport = self.getTransport(transports);
|
|
|
|
if (!self.transport) return self.publish('connect_failed');
|
|
|
|
|
|
|
|
// once the transport is ready
|
|
|
|
self.transport.ready(self, function () {
|
|
|
|
self.connecting = true;
|
|
|
|
self.publish('connecting', self.transport.name);
|
|
|
|
self.transport.open();
|
|
|
|
|
|
|
|
if (self.options['connect timeout']) {
|
|
|
|
self.connectTimeoutTimer = setTimeout(function () {
|
|
|
|
if (!self.connected) {
|
|
|
|
self.connecting = false;
|
|
|
|
|
|
|
|
if (self.options['try multiple transports']) {
|
|
|
|
var remaining = self.transports;
|
|
|
|
|
|
|
|
while (remaining.length > 0 && remaining.splice(0,1)[0] !=
|
|
|
|
self.transport.name) {}
|
|
|
|
|
|
|
|
if (remaining.length){
|
|
|
|
connect(remaining);
|
|
|
|
} else {
|
|
|
|
self.publish('connect_failed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, self.options['connect timeout']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(self.transports);
|
|
|
|
|
|
|
|
self.once('connect', function (){
|
|
|
|
clearTimeout(self.connectTimeoutTimer);
|
|
|
|
|
|
|
|
fn && typeof fn == 'function' && fn();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears and sets a new heartbeat timeout using the value given by the
|
|
|
|
* server during the handshake.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.setHeartbeatTimeout = function () {
|
|
|
|
clearTimeout(this.heartbeatTimeoutTimer);
|
|
|
|
if(this.transport && !this.transport.heartbeats()) return;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.heartbeatTimeoutTimer = setTimeout(function () {
|
|
|
|
self.transport.onClose();
|
|
|
|
}, this.heartbeatTimeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a message.
|
|
|
|
*
|
|
|
|
* @param {Object} data packet.
|
|
|
|
* @returns {io.Socket}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.packet = function (data) {
|
|
|
|
if (this.connected && !this.doBuffer) {
|
|
|
|
this.transport.packet(data);
|
|
|
|
} else {
|
|
|
|
this.buffer.push(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets buffer state
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.setBuffer = function (v) {
|
|
|
|
this.doBuffer = v;
|
|
|
|
|
|
|
|
if (!v && this.connected && this.buffer.length) {
|
|
|
|
if (!this.options['manualFlush']) {
|
|
|
|
this.flushBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flushes the buffer data over the wire.
|
|
|
|
* To be invoked manually when 'manualFlush' is set to true.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.flushBuffer = function() {
|
|
|
|
this.transport.payload(this.buffer);
|
|
|
|
this.buffer = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect the established connect.
|
|
|
|
*
|
|
|
|
* @returns {io.Socket}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.disconnect = function () {
|
|
|
|
if (this.connected || this.connecting) {
|
|
|
|
if (this.open) {
|
|
|
|
this.of('').packet({ type: 'disconnect' });
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle disconnection immediately
|
|
|
|
this.onDisconnect('booted');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects the socket with a sync XHR.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.disconnectSync = function () {
|
|
|
|
// ensure disconnection
|
|
|
|
var xhr = io.util.request();
|
|
|
|
var uri = [
|
|
|
|
'http' + (this.options.secure ? 's' : '') + ':/'
|
|
|
|
, this.options.host + ':' + this.options.port
|
|
|
|
, this.options.resource
|
|
|
|
, io.protocol
|
|
|
|
, ''
|
|
|
|
, this.sessionid
|
|
|
|
].join('/') + '/?disconnect=1';
|
|
|
|
|
|
|
|
xhr.open('GET', uri, false);
|
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
// handle disconnection immediately
|
|
|
|
this.onDisconnect('booted');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we need to use cross domain enabled transports. Cross domain would
|
|
|
|
* be a different port or different domain name.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.isXDomain = function () {
|
|
|
|
|
|
|
|
var port = global.location.port ||
|
|
|
|
('https:' == global.location.protocol ? 443 : 80);
|
|
|
|
|
|
|
|
return this.options.host !== global.location.hostname
|
|
|
|
|| this.options.port != port;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called upon handshake.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onConnect = function () {
|
|
|
|
if (!this.connected) {
|
|
|
|
this.connected = true;
|
|
|
|
this.connecting = false;
|
|
|
|
if (!this.doBuffer) {
|
|
|
|
// make sure to flush the buffer
|
|
|
|
this.setBuffer(false);
|
|
|
|
}
|
|
|
|
this.emit('connect');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the transport opens
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onOpen = function () {
|
|
|
|
this.open = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the transport closes.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onClose = function () {
|
|
|
|
this.open = false;
|
|
|
|
clearTimeout(this.heartbeatTimeoutTimer);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the transport first opens a connection
|
|
|
|
*
|
|
|
|
* @param text
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onPacket = function (packet) {
|
|
|
|
this.of(packet.endpoint).onPacket(packet);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles an error.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onError = function (err) {
|
|
|
|
if (err && err.advice) {
|
|
|
|
if (err.advice === 'reconnect' && (this.connected || this.connecting)) {
|
|
|
|
this.disconnect();
|
|
|
|
if (this.options.reconnect) {
|
|
|
|
this.reconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.publish('error', err && err.reason ? err.reason : err);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the transport disconnects.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.onDisconnect = function (reason) {
|
|
|
|
var wasConnected = this.connected
|
|
|
|
, wasConnecting = this.connecting;
|
|
|
|
|
|
|
|
this.connected = false;
|
|
|
|
this.connecting = false;
|
|
|
|
this.open = false;
|
|
|
|
|
|
|
|
if (wasConnected || wasConnecting) {
|
|
|
|
this.transport.close();
|
|
|
|
this.transport.clearTimeouts();
|
|
|
|
if (wasConnected) {
|
|
|
|
this.publish('disconnect', reason);
|
|
|
|
|
|
|
|
if ('booted' != reason && this.options.reconnect && !this.reconnecting) {
|
|
|
|
this.reconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called upon reconnection.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Socket.prototype.reconnect = function () {
|
|
|
|
this.reconnecting = true;
|
|
|
|
this.reconnectionAttempts = 0;
|
|
|
|
this.reconnectionDelay = this.options['reconnection delay'];
|
|
|
|
|
|
|
|
var self = this
|
|
|
|
, maxAttempts = this.options['max reconnection attempts']
|
|
|
|
, tryMultiple = this.options['try multiple transports']
|
|
|
|
, limit = this.options['reconnection limit'];
|
|
|
|
|
|
|
|
function reset () {
|
|
|
|
if (self.connected) {
|
|
|
|
for (var i in self.namespaces) {
|
|
|
|
if (self.namespaces.hasOwnProperty(i) && '' !== i) {
|
|
|
|
self.namespaces[i].packet({ type: 'connect' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.publish('reconnect', self.transport.name, self.reconnectionAttempts);
|
|
|
|
}
|
|
|
|
|
|
|
|
clearTimeout(self.reconnectionTimer);
|
|
|
|
|
|
|
|
self.removeListener('connect_failed', maybeReconnect);
|
|
|
|
self.removeListener('connect', maybeReconnect);
|
|
|
|
|
|
|
|
self.reconnecting = false;
|
|
|
|
|
|
|
|
delete self.reconnectionAttempts;
|
|
|
|
delete self.reconnectionDelay;
|
|
|
|
delete self.reconnectionTimer;
|
|
|
|
delete self.redoTransports;
|
|
|
|
|
|
|
|
self.options['try multiple transports'] = tryMultiple;
|
|
|
|
};
|
|
|
|
|
|
|
|
function maybeReconnect () {
|
|
|
|
if (!self.reconnecting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.connected) {
|
|
|
|
return reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (self.connecting && self.reconnecting) {
|
|
|
|
return self.reconnectionTimer = setTimeout(maybeReconnect, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.reconnectionAttempts++ >= maxAttempts) {
|
|
|
|
if (!self.redoTransports) {
|
|
|
|
self.on('connect_failed', maybeReconnect);
|
|
|
|
self.options['try multiple transports'] = true;
|
|
|
|
self.transports = self.origTransports;
|
|
|
|
self.transport = self.getTransport();
|
|
|
|
self.redoTransports = true;
|
|
|
|
self.connect();
|
|
|
|
} else {
|
|
|
|
self.publish('reconnect_failed');
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (self.reconnectionDelay < limit) {
|
|
|
|
self.reconnectionDelay *= 2; // exponential back off
|
|
|
|
}
|
|
|
|
|
|
|
|
self.connect();
|
|
|
|
self.publish('reconnecting', self.reconnectionDelay, self.reconnectionAttempts);
|
|
|
|
self.reconnectionTimer = setTimeout(maybeReconnect, self.reconnectionDelay);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options['try multiple transports'] = false;
|
|
|
|
this.reconnectionTimer = setTimeout(maybeReconnect, this.reconnectionDelay);
|
|
|
|
|
|
|
|
this.on('connect', maybeReconnect);
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
, this
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.SocketNamespace = SocketNamespace;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Socket namespace constructor.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function SocketNamespace (socket, name) {
|
|
|
|
this.socket = socket;
|
|
|
|
this.name = name || '';
|
|
|
|
this.flags = {};
|
|
|
|
this.json = new Flag(this, 'json');
|
|
|
|
this.ackPackets = 0;
|
|
|
|
this.acks = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply EventEmitter mixin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.mixin(SocketNamespace, io.EventEmitter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies emit since we override it
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.$emit = io.EventEmitter.prototype.emit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new namespace, by proxying the request to the socket. This
|
|
|
|
* allows us to use the synax as we do on the server.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.of = function () {
|
|
|
|
return this.socket.of.apply(this.socket, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a packet.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.packet = function (packet) {
|
|
|
|
packet.endpoint = this.name;
|
|
|
|
this.socket.packet(packet);
|
|
|
|
this.flags = {};
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a message
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.send = function (data, fn) {
|
|
|
|
var packet = {
|
|
|
|
type: this.flags.json ? 'json' : 'message'
|
|
|
|
, data: data
|
|
|
|
};
|
|
|
|
|
|
|
|
if ('function' == typeof fn) {
|
|
|
|
packet.id = ++this.ackPackets;
|
|
|
|
packet.ack = true;
|
|
|
|
this.acks[packet.id] = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.packet(packet);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits an event
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.emit = function (name) {
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1)
|
|
|
|
, lastArg = args[args.length - 1]
|
|
|
|
, packet = {
|
|
|
|
type: 'event'
|
|
|
|
, name: name
|
|
|
|
};
|
|
|
|
|
|
|
|
if ('function' == typeof lastArg) {
|
|
|
|
packet.id = ++this.ackPackets;
|
|
|
|
packet.ack = 'data';
|
|
|
|
this.acks[packet.id] = lastArg;
|
|
|
|
args = args.slice(0, args.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
packet.args = args;
|
|
|
|
|
|
|
|
return this.packet(packet);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects the namespace
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.disconnect = function () {
|
|
|
|
if (this.name === '') {
|
|
|
|
this.socket.disconnect();
|
|
|
|
} else {
|
|
|
|
this.packet({ type: 'disconnect' });
|
|
|
|
this.$emit('disconnect');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a packet
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
SocketNamespace.prototype.onPacket = function (packet) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
function ack () {
|
|
|
|
self.packet({
|
|
|
|
type: 'ack'
|
|
|
|
, args: io.util.toArray(arguments)
|
|
|
|
, ackId: packet.id
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (packet.type) {
|
|
|
|
case 'connect':
|
|
|
|
this.$emit('connect');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'disconnect':
|
|
|
|
if (this.name === '') {
|
|
|
|
this.socket.onDisconnect(packet.reason || 'booted');
|
|
|
|
} else {
|
|
|
|
this.$emit('disconnect', packet.reason);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'message':
|
|
|
|
case 'json':
|
|
|
|
var params = ['message', packet.data];
|
|
|
|
|
|
|
|
if (packet.ack == 'data') {
|
|
|
|
params.push(ack);
|
|
|
|
} else if (packet.ack) {
|
|
|
|
this.packet({ type: 'ack', ackId: packet.id });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit.apply(this, params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'event':
|
|
|
|
var params = [packet.name].concat(packet.args);
|
|
|
|
|
|
|
|
if (packet.ack == 'data')
|
|
|
|
params.push(ack);
|
|
|
|
|
|
|
|
this.$emit.apply(this, params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ack':
|
|
|
|
if (this.acks[packet.ackId]) {
|
|
|
|
this.acks[packet.ackId].apply(this, packet.args);
|
|
|
|
delete this.acks[packet.ackId];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'error':
|
|
|
|
if (packet.advice){
|
|
|
|
this.socket.onError(packet);
|
|
|
|
} else {
|
|
|
|
if (packet.reason == 'unauthorized') {
|
|
|
|
this.$emit('connect_failed', packet.reason);
|
|
|
|
} else {
|
|
|
|
this.$emit('error', packet.reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag interface.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Flag (nsp, name) {
|
|
|
|
this.namespace = nsp;
|
|
|
|
this.name = name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flag.prototype.send = function () {
|
|
|
|
this.namespace.flags[this.name] = true;
|
|
|
|
this.namespace.send.apply(this.namespace, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emit an event
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flag.prototype.emit = function () {
|
|
|
|
this.namespace.flags[this.name] = true;
|
|
|
|
this.namespace.emit.apply(this.namespace, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.websocket = WS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The WebSocket transport uses the HTML5 WebSocket API to establish an
|
|
|
|
* persistent connection with the Socket.IO server. This transport will also
|
|
|
|
* be inherited by the FlashSocket fallback as it provides a API compatible
|
|
|
|
* polyfill for the WebSockets.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {io.Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function WS (socket) {
|
|
|
|
io.Transport.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from Transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(WS, io.Transport);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport name
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.prototype.name = 'websocket';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new `WebSocket` connection with the Socket.IO server. We attach
|
|
|
|
* all the appropriate listeners to handle the responses from the server.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.prototype.open = function () {
|
|
|
|
var query = io.util.query(this.socket.options.query)
|
|
|
|
, self = this
|
|
|
|
, Socket
|
|
|
|
|
|
|
|
|
|
|
|
if (!Socket) {
|
|
|
|
Socket = global.MozWebSocket || global.WebSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.websocket = new Socket(this.prepareUrl() + query);
|
|
|
|
|
|
|
|
this.websocket.onopen = function () {
|
|
|
|
self.onOpen();
|
|
|
|
self.socket.setBuffer(false);
|
|
|
|
};
|
|
|
|
this.websocket.onmessage = function (ev) {
|
|
|
|
self.onData(ev.data);
|
|
|
|
};
|
|
|
|
this.websocket.onclose = function () {
|
|
|
|
self.onClose();
|
|
|
|
self.socket.setBuffer(true);
|
|
|
|
};
|
|
|
|
this.websocket.onerror = function (e) {
|
|
|
|
self.onError(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message to the Socket.IO server. The message will automatically be
|
|
|
|
* encoded in the correct message format.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Do to a bug in the current IDevices browser, we need to wrap the send in a
|
|
|
|
// setTimeout, when they resume from sleeping the browser will crash if
|
|
|
|
// we don't allow the browser time to detect the socket has been closed
|
|
|
|
if (io.util.ua.iDevice) {
|
|
|
|
WS.prototype.send = function (data) {
|
|
|
|
var self = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
self.websocket.send(data);
|
|
|
|
},0);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
WS.prototype.send = function (data) {
|
|
|
|
this.websocket.send(data);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Payload
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.prototype.payload = function (arr) {
|
|
|
|
for (var i = 0, l = arr.length; i < l; i++) {
|
|
|
|
this.packet(arr[i]);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect the established `WebSocket` connection.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.prototype.close = function () {
|
|
|
|
this.websocket.close();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the errors that `WebSocket` might be giving when we
|
|
|
|
* are attempting to connect or send messages.
|
|
|
|
*
|
|
|
|
* @param {Error} e The error.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.prototype.onError = function (e) {
|
|
|
|
this.socket.onError(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appropriate scheme for the URI generation.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
WS.prototype.scheme = function () {
|
|
|
|
return this.socket.options.secure ? 'wss' : 'ws';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the browser has support for native `WebSockets` and that
|
|
|
|
* it's not the polyfill created for the FlashSocket transport.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.check = function () {
|
|
|
|
return ('WebSocket' in global && !('__addTask' in WebSocket))
|
|
|
|
|| 'MozWebSocket' in global;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the `WebSocket` transport support cross domain communications.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS.xdomainCheck = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the transport to your public io.transports array.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports.push('websocket');
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
, this
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.flashsocket = Flashsocket;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The FlashSocket transport. This is a API wrapper for the HTML5 WebSocket
|
|
|
|
* specification. It uses a .swf file to communicate with the server. If you want
|
|
|
|
* to serve the .swf file from a other server than where the Socket.IO script is
|
|
|
|
* coming from you need to use the insecure version of the .swf. More information
|
|
|
|
* about this can be found on the github page.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {io.Transport.websocket}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Flashsocket () {
|
|
|
|
io.Transport.websocket.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from Transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(Flashsocket, io.Transport.websocket);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport name
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.prototype.name = 'flashsocket';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect the established `FlashSocket` connection. This is done by adding a
|
|
|
|
* new task to the FlashSocket. The rest will be handled off by the `WebSocket`
|
|
|
|
* transport.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.prototype.open = function () {
|
|
|
|
var self = this
|
|
|
|
, args = arguments;
|
|
|
|
|
|
|
|
WebSocket.__addTask(function () {
|
|
|
|
io.Transport.websocket.prototype.open.apply(self, args);
|
|
|
|
});
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a message to the Socket.IO server. This is done by adding a new
|
|
|
|
* task to the FlashSocket. The rest will be handled off by the `WebSocket`
|
|
|
|
* transport.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.prototype.send = function () {
|
|
|
|
var self = this, args = arguments;
|
|
|
|
WebSocket.__addTask(function () {
|
|
|
|
io.Transport.websocket.prototype.send.apply(self, args);
|
|
|
|
});
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects the established `FlashSocket` connection.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.prototype.close = function () {
|
|
|
|
WebSocket.__tasks.length = 0;
|
|
|
|
io.Transport.websocket.prototype.close.call(this);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The WebSocket fall back needs to append the flash container to the body
|
|
|
|
* element, so we need to make sure we have access to it. Or defer the call
|
|
|
|
* until we are sure there is a body element.
|
|
|
|
*
|
|
|
|
* @param {Socket} socket The socket instance that needs a transport
|
|
|
|
* @param {Function} fn The callback
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.prototype.ready = function (socket, fn) {
|
|
|
|
function init () {
|
|
|
|
var options = socket.options
|
|
|
|
, port = options['flash policy port']
|
|
|
|
, path = [
|
|
|
|
'http' + (options.secure ? 's' : '') + ':/'
|
|
|
|
, options.host + ':' + options.port
|
|
|
|
, options.resource
|
|
|
|
, 'static/flashsocket'
|
|
|
|
, 'WebSocketMain' + (socket.isXDomain() ? 'Insecure' : '') + '.swf'
|
|
|
|
];
|
|
|
|
|
|
|
|
// Only start downloading the swf file when the checked that this browser
|
|
|
|
// actually supports it
|
|
|
|
if (!Flashsocket.loaded) {
|
|
|
|
if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined') {
|
|
|
|
// Set the correct file based on the XDomain settings
|
|
|
|
WEB_SOCKET_SWF_LOCATION = path.join('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port !== 843) {
|
|
|
|
WebSocket.loadFlashPolicyFile('xmlsocket://' + options.host + ':' + port);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebSocket.__initialize();
|
|
|
|
Flashsocket.loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn.call(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
if (document.body) return init();
|
|
|
|
|
|
|
|
io.util.load(init);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the FlashSocket transport is supported as it requires that the Adobe
|
|
|
|
* Flash Player plug-in version `10.0.0` or greater is installed. And also check if
|
|
|
|
* the polyfill is correctly loaded.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.check = function () {
|
|
|
|
if (
|
|
|
|
typeof WebSocket == 'undefined'
|
|
|
|
|| !('__initialize' in WebSocket) || !swfobject
|
|
|
|
) return false;
|
|
|
|
|
|
|
|
return swfobject.getFlashPlayerVersion().major >= 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the FlashSocket transport can be used as cross domain / cross origin
|
|
|
|
* transport. Because we can't see which type (secure or insecure) of .swf is used
|
|
|
|
* we will just return true.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Flashsocket.xdomainCheck = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable AUTO_INITIALIZATION
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (typeof window != 'undefined') {
|
|
|
|
WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the transport to your public io.transports array.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports.push('flashsocket');
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
|
|
|
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
|
|
|
*/
|
|
|
|
if ('undefined' != typeof window) {
|
|
|
|
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O[(['Active'].concat('Object').join('X'))]!=D){try{var ad=new window[(['Active'].concat('Object').join('X'))](W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X
|
|
|
|
}
|
|
|
|
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
|
|
|
// License: New BSD License
|
|
|
|
// Reference: http://dev.w3.org/html5/websockets/
|
|
|
|
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
if ('undefined' == typeof window || window.WebSocket) return;
|
|
|
|
|
|
|
|
var console = window.console;
|
|
|
|
if (!console || !console.log || !console.error) {
|
|
|
|
console = {log: function(){ }, error: function(){ }};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!swfobject.hasFlashPlayerVersion("10.0.0")) {
|
|
|
|
console.error("Flash Player >= 10.0.0 is required.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (location.protocol == "file:") {
|
|
|
|
console.error(
|
|
|
|
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
|
|
|
"unless you set Flash Security Settings properly. " +
|
|
|
|
"Open the page via Web server i.e. http://...");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a faux web socket.
|
|
|
|
* @param {string} url
|
|
|
|
* @param {array or string} protocols
|
|
|
|
* @param {string} proxyHost
|
|
|
|
* @param {int} proxyPort
|
|
|
|
* @param {string} headers
|
|
|
|
*/
|
|
|
|
WebSocket = function(url, protocols, proxyHost, proxyPort, headers) {
|
|
|
|
var self = this;
|
|
|
|
self.__id = WebSocket.__nextId++;
|
|
|
|
WebSocket.__instances[self.__id] = self;
|
|
|
|
self.readyState = WebSocket.CONNECTING;
|
|
|
|
self.bufferedAmount = 0;
|
|
|
|
self.__events = {};
|
|
|
|
if (!protocols) {
|
|
|
|
protocols = [];
|
|
|
|
} else if (typeof protocols == "string") {
|
|
|
|
protocols = [protocols];
|
|
|
|
}
|
|
|
|
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
|
|
|
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
|
|
|
setTimeout(function() {
|
|
|
|
WebSocket.__addTask(function() {
|
|
|
|
WebSocket.__flash.create(
|
|
|
|
self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
|
|
|
|
});
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send data to the web socket.
|
|
|
|
* @param {string} data The data to send to the socket.
|
|
|
|
* @return {boolean} True for success, false for failure.
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.send = function(data) {
|
|
|
|
if (this.readyState == WebSocket.CONNECTING) {
|
|
|
|
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
|
|
|
}
|
|
|
|
// We use encodeURIComponent() here, because FABridge doesn't work if
|
|
|
|
// the argument includes some characters. We don't use escape() here
|
|
|
|
// because of this:
|
|
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
|
|
|
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
|
|
|
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
|
|
|
// Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
|
|
|
|
// additional testing.
|
|
|
|
var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
|
|
|
|
if (result < 0) { // success
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
this.bufferedAmount += result;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close this web socket gracefully.
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.close = function() {
|
|
|
|
if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.readyState = WebSocket.CLOSING;
|
|
|
|
WebSocket.__flash.close(this.__id);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
|
|
|
*
|
|
|
|
* @param {string} type
|
|
|
|
* @param {function} listener
|
|
|
|
* @param {boolean} useCapture
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
|
|
|
if (!(type in this.__events)) {
|
|
|
|
this.__events[type] = [];
|
|
|
|
}
|
|
|
|
this.__events[type].push(listener);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
|
|
|
*
|
|
|
|
* @param {string} type
|
|
|
|
* @param {function} listener
|
|
|
|
* @param {boolean} useCapture
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
|
|
|
if (!(type in this.__events)) return;
|
|
|
|
var events = this.__events[type];
|
|
|
|
for (var i = events.length - 1; i >= 0; --i) {
|
|
|
|
if (events[i] === listener) {
|
|
|
|
events.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
|
|
|
*
|
|
|
|
* @param {Event} event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.dispatchEvent = function(event) {
|
|
|
|
var events = this.__events[event.type] || [];
|
|
|
|
for (var i = 0; i < events.length; ++i) {
|
|
|
|
events[i](event);
|
|
|
|
}
|
|
|
|
var handler = this["on" + event.type];
|
|
|
|
if (handler) handler(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles an event from Flash.
|
|
|
|
* @param {Object} flashEvent
|
|
|
|
*/
|
|
|
|
WebSocket.prototype.__handleEvent = function(flashEvent) {
|
|
|
|
if ("readyState" in flashEvent) {
|
|
|
|
this.readyState = flashEvent.readyState;
|
|
|
|
}
|
|
|
|
if ("protocol" in flashEvent) {
|
|
|
|
this.protocol = flashEvent.protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
var jsEvent;
|
|
|
|
if (flashEvent.type == "open" || flashEvent.type == "error") {
|
|
|
|
jsEvent = this.__createSimpleEvent(flashEvent.type);
|
|
|
|
} else if (flashEvent.type == "close") {
|
|
|
|
// TODO implement jsEvent.wasClean
|
|
|
|
jsEvent = this.__createSimpleEvent("close");
|
|
|
|
} else if (flashEvent.type == "message") {
|
|
|
|
var data = decodeURIComponent(flashEvent.message);
|
|
|
|
jsEvent = this.__createMessageEvent("message", data);
|
|
|
|
} else {
|
|
|
|
throw "unknown event type: " + flashEvent.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dispatchEvent(jsEvent);
|
|
|
|
};
|
|
|
|
|
|
|
|
WebSocket.prototype.__createSimpleEvent = function(type) {
|
|
|
|
if (document.createEvent && window.Event) {
|
|
|
|
var event = document.createEvent("Event");
|
|
|
|
event.initEvent(type, false, false);
|
|
|
|
return event;
|
|
|
|
} else {
|
|
|
|
return {type: type, bubbles: false, cancelable: false};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebSocket.prototype.__createMessageEvent = function(type, data) {
|
|
|
|
if (document.createEvent && window.MessageEvent && !window.opera) {
|
|
|
|
var event = document.createEvent("MessageEvent");
|
|
|
|
event.initMessageEvent("message", false, false, data, null, null, window, null);
|
|
|
|
return event;
|
|
|
|
} else {
|
|
|
|
// IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
|
|
|
|
return {type: type, data: data, bubbles: false, cancelable: false};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the WebSocket readyState enumeration.
|
|
|
|
*/
|
|
|
|
WebSocket.CONNECTING = 0;
|
|
|
|
WebSocket.OPEN = 1;
|
|
|
|
WebSocket.CLOSING = 2;
|
|
|
|
WebSocket.CLOSED = 3;
|
|
|
|
|
|
|
|
WebSocket.__flash = null;
|
|
|
|
WebSocket.__instances = {};
|
|
|
|
WebSocket.__tasks = [];
|
|
|
|
WebSocket.__nextId = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a new flash security policy file.
|
|
|
|
* @param {string} url
|
|
|
|
*/
|
|
|
|
WebSocket.loadFlashPolicyFile = function(url){
|
|
|
|
WebSocket.__addTask(function() {
|
|
|
|
WebSocket.__flash.loadManualPolicyFile(url);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
|
|
|
|
*/
|
|
|
|
WebSocket.__initialize = function() {
|
|
|
|
if (WebSocket.__flash) return;
|
|
|
|
|
|
|
|
if (WebSocket.__swfLocation) {
|
|
|
|
// For backword compatibility.
|
|
|
|
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
|
|
|
}
|
|
|
|
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
|
|
|
console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var container = document.createElement("div");
|
|
|
|
container.id = "webSocketContainer";
|
|
|
|
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
|
|
|
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
|
|
|
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
|
|
|
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
|
|
|
// the best we can do as far as we know now.
|
|
|
|
container.style.position = "absolute";
|
|
|
|
if (WebSocket.__isFlashLite()) {
|
|
|
|
container.style.left = "0px";
|
|
|
|
container.style.top = "0px";
|
|
|
|
} else {
|
|
|
|
container.style.left = "-100px";
|
|
|
|
container.style.top = "-100px";
|
|
|
|
}
|
|
|
|
var holder = document.createElement("div");
|
|
|
|
holder.id = "webSocketFlash";
|
|
|
|
container.appendChild(holder);
|
|
|
|
document.body.appendChild(container);
|
|
|
|
// See this article for hasPriority:
|
|
|
|
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
|
|
|
swfobject.embedSWF(
|
|
|
|
WEB_SOCKET_SWF_LOCATION,
|
|
|
|
"webSocketFlash",
|
|
|
|
"1" /* width */,
|
|
|
|
"1" /* height */,
|
|
|
|
"10.0.0" /* SWF version */,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
{hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (!e.success) {
|
|
|
|
console.error("[WebSocket] swfobject.embedSWF failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by Flash to notify JS that it's fully loaded and ready
|
|
|
|
* for communication.
|
|
|
|
*/
|
|
|
|
WebSocket.__onFlashInitialized = function() {
|
|
|
|
// We need to set a timeout here to avoid round-trip calls
|
|
|
|
// to flash during the initialization process.
|
|
|
|
setTimeout(function() {
|
|
|
|
WebSocket.__flash = document.getElementById("webSocketFlash");
|
|
|
|
WebSocket.__flash.setCallerUrl(location.href);
|
|
|
|
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
|
|
|
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
|
|
|
WebSocket.__tasks[i]();
|
|
|
|
}
|
|
|
|
WebSocket.__tasks = [];
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by Flash to notify WebSockets events are fired.
|
|
|
|
*/
|
|
|
|
WebSocket.__onFlashEvent = function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
try {
|
|
|
|
// Gets events using receiveEvents() instead of getting it from event object
|
|
|
|
// of Flash event. This is to make sure to keep message order.
|
|
|
|
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
|
|
|
var events = WebSocket.__flash.receiveEvents();
|
|
|
|
for (var i = 0; i < events.length; ++i) {
|
|
|
|
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Called by Flash.
|
|
|
|
WebSocket.__log = function(message) {
|
|
|
|
console.log(decodeURIComponent(message));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Called by Flash.
|
|
|
|
WebSocket.__error = function(message) {
|
|
|
|
console.error(decodeURIComponent(message));
|
|
|
|
};
|
|
|
|
|
|
|
|
WebSocket.__addTask = function(task) {
|
|
|
|
if (WebSocket.__flash) {
|
|
|
|
task();
|
|
|
|
} else {
|
|
|
|
WebSocket.__tasks.push(task);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the browser is running flash lite.
|
|
|
|
* @return {boolean} True if flash lite is running, false otherwise.
|
|
|
|
*/
|
|
|
|
WebSocket.__isFlashLite = function() {
|
|
|
|
if (!window.navigator || !window.navigator.mimeTypes) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
|
|
|
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
|
|
|
if (window.addEventListener) {
|
|
|
|
window.addEventListener("load", function(){
|
|
|
|
WebSocket.__initialize();
|
|
|
|
}, false);
|
|
|
|
} else {
|
|
|
|
window.attachEvent("onload", function(){
|
|
|
|
WebSocket.__initialize();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.XHR = XHR;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XHR constructor
|
|
|
|
*
|
|
|
|
* @costructor
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function XHR (socket) {
|
|
|
|
if (!socket) return;
|
|
|
|
|
|
|
|
io.Transport.apply(this, arguments);
|
|
|
|
this.sendBuffer = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from Transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(XHR, io.Transport);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Establish a connection
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.open = function () {
|
|
|
|
this.socket.setBuffer(false);
|
|
|
|
this.onOpen();
|
|
|
|
this.get();
|
|
|
|
|
|
|
|
// we need to make sure the request succeeds since we have no indication
|
|
|
|
// whether the request opened or not until it succeeded.
|
|
|
|
this.setCloseTimeout();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we need to send data to the Socket.IO server, if we have data in our
|
|
|
|
* buffer we encode it and forward it to the `post` method.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.payload = function (payload) {
|
|
|
|
var msgs = [];
|
|
|
|
|
|
|
|
for (var i = 0, l = payload.length; i < l; i++) {
|
|
|
|
msgs.push(io.parser.encodePacket(payload[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.send(io.parser.encodePayload(msgs));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send data to the Socket.IO server.
|
|
|
|
*
|
|
|
|
* @param data The message
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.send = function (data) {
|
|
|
|
this.post(data);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts a encoded message to the Socket.IO server.
|
|
|
|
*
|
|
|
|
* @param {String} data A encoded message.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
function empty () { };
|
|
|
|
|
|
|
|
XHR.prototype.post = function (data) {
|
|
|
|
var self = this;
|
|
|
|
this.socket.setBuffer(true);
|
|
|
|
|
|
|
|
function stateChange () {
|
|
|
|
if (this.readyState == 4) {
|
|
|
|
this.onreadystatechange = empty;
|
|
|
|
self.posting = false;
|
|
|
|
|
|
|
|
if (this.status == 200){
|
|
|
|
self.socket.setBuffer(false);
|
|
|
|
} else {
|
|
|
|
self.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onload () {
|
|
|
|
this.onload = empty;
|
|
|
|
self.socket.setBuffer(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.sendXHR = this.request('POST');
|
|
|
|
|
|
|
|
if (global.XDomainRequest && this.sendXHR instanceof XDomainRequest) {
|
|
|
|
this.sendXHR.onload = this.sendXHR.onerror = onload;
|
|
|
|
} else {
|
|
|
|
this.sendXHR.onreadystatechange = stateChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sendXHR.send(data);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects the established `XHR` connection.
|
|
|
|
*
|
|
|
|
* @returns {Transport}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.close = function () {
|
|
|
|
this.onClose();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a configured XHR request
|
|
|
|
*
|
|
|
|
* @param {String} url The url that needs to be requested.
|
|
|
|
* @param {String} method The method the request should use.
|
|
|
|
* @returns {XMLHttpRequest}
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.request = function (method) {
|
|
|
|
var req = io.util.request(this.socket.isXDomain())
|
|
|
|
, query = io.util.query(this.socket.options.query, 't=' + +new Date);
|
|
|
|
|
|
|
|
req.open(method || 'GET', this.prepareUrl() + query, true);
|
|
|
|
|
|
|
|
if (method == 'POST') {
|
|
|
|
try {
|
|
|
|
if (req.setRequestHeader) {
|
|
|
|
req.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
|
|
|
|
} else {
|
|
|
|
// XDomainRequest
|
|
|
|
req.contentType = 'text/plain';
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scheme to use for the transport URLs.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.prototype.scheme = function () {
|
|
|
|
return this.socket.options.secure ? 'https' : 'http';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the XHR transports are supported
|
|
|
|
*
|
|
|
|
* @param {Boolean} xdomain Check if we support cross domain requests.
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.check = function (socket, xdomain) {
|
|
|
|
try {
|
|
|
|
var request = io.util.request(xdomain),
|
|
|
|
usesXDomReq = (global.XDomainRequest && request instanceof XDomainRequest),
|
|
|
|
socketProtocol = (socket && socket.options && socket.options.secure ? 'https:' : 'http:'),
|
|
|
|
isXProtocol = (global.location && socketProtocol != global.location.protocol);
|
|
|
|
if (request && !(usesXDomReq && isXProtocol)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the XHR transport supports cross domain requests.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHR.xdomainCheck = function (socket) {
|
|
|
|
return XHR.check(socket, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
, this
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.htmlfile = HTMLFile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The HTMLFile transport creates a `forever iframe` based transport
|
|
|
|
* for Internet Explorer. Regular forever iframe implementations will
|
|
|
|
* continuously trigger the browsers buzy indicators. If the forever iframe
|
|
|
|
* is created inside a `htmlfile` these indicators will not be trigged.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {io.Transport.XHR}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function HTMLFile (socket) {
|
|
|
|
io.Transport.XHR.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from XHR transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(HTMLFile, io.Transport.XHR);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport name
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.prototype.name = 'htmlfile';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Ac...eX `htmlfile` with a forever loading iframe
|
|
|
|
* that can be used to listen to messages. Inside the generated
|
|
|
|
* `htmlfile` a reference will be made to the HTMLFile transport.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.prototype.get = function () {
|
|
|
|
this.doc = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
|
|
|
|
this.doc.open();
|
|
|
|
this.doc.write('<html></html>');
|
|
|
|
this.doc.close();
|
|
|
|
this.doc.parentWindow.s = this;
|
|
|
|
|
|
|
|
var iframeC = this.doc.createElement('div');
|
|
|
|
iframeC.className = 'socketio';
|
|
|
|
|
|
|
|
this.doc.body.appendChild(iframeC);
|
|
|
|
this.iframe = this.doc.createElement('iframe');
|
|
|
|
|
|
|
|
iframeC.appendChild(this.iframe);
|
|
|
|
|
|
|
|
var self = this
|
|
|
|
, query = io.util.query(this.socket.options.query, 't='+ +new Date);
|
|
|
|
|
|
|
|
this.iframe.src = this.prepareUrl() + query;
|
|
|
|
|
|
|
|
io.util.on(window, 'unload', function () {
|
|
|
|
self.destroy();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Socket.IO server will write script tags inside the forever
|
|
|
|
* iframe, this function will be used as callback for the incoming
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* @param {String} data The message
|
|
|
|
* @param {document} doc Reference to the context
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.prototype._ = function (data, doc) {
|
|
|
|
// unescape all forward slashes. see GH-1251
|
|
|
|
data = data.replace(/\\\//g, '/');
|
|
|
|
this.onData(data);
|
|
|
|
try {
|
|
|
|
var script = doc.getElementsByTagName('script')[0];
|
|
|
|
script.parentNode.removeChild(script);
|
|
|
|
} catch (e) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the established connection, iframe and `htmlfile`.
|
|
|
|
* And calls the `CollectGarbage` function of Internet Explorer
|
|
|
|
* to release the memory.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.prototype.destroy = function () {
|
|
|
|
if (this.iframe){
|
|
|
|
try {
|
|
|
|
this.iframe.src = 'about:blank';
|
|
|
|
} catch(e){}
|
|
|
|
|
|
|
|
this.doc = null;
|
|
|
|
this.iframe.parentNode.removeChild(this.iframe);
|
|
|
|
this.iframe = null;
|
|
|
|
|
|
|
|
CollectGarbage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects the established connection.
|
|
|
|
*
|
|
|
|
* @returns {Transport} Chaining.
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.prototype.close = function () {
|
|
|
|
this.destroy();
|
|
|
|
return io.Transport.XHR.prototype.close.call(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the browser supports this transport. The browser
|
|
|
|
* must have an `Ac...eXObject` implementation.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.check = function (socket) {
|
|
|
|
if (typeof window != "undefined" && (['Active'].concat('Object').join('X')) in window){
|
|
|
|
try {
|
|
|
|
var a = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
|
|
|
|
return a && io.Transport.XHR.check(socket);
|
|
|
|
} catch(e){}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if cross domain requests are supported.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
HTMLFile.xdomainCheck = function () {
|
|
|
|
// we can probably do handling for sub-domains, we should
|
|
|
|
// test that it's cross domain but a subdomain here
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the transport to your public io.transports array.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports.push('htmlfile');
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io, global) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports['xhr-polling'] = XHRPolling;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The XHR-polling transport uses long polling XHR requests to create a
|
|
|
|
* "persistent" connection with the server.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function XHRPolling () {
|
|
|
|
io.Transport.XHR.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from XHR transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(XHRPolling, io.Transport.XHR);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge the properties from XHR transport
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.merge(XHRPolling, io.Transport.XHR);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport name
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHRPolling.prototype.name = 'xhr-polling';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether heartbeats is enabled for this transport
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHRPolling.prototype.heartbeats = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Establish a connection, for iPhone and Android this will be done once the page
|
|
|
|
* is loaded.
|
|
|
|
*
|
|
|
|
* @returns {Transport} Chaining.
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHRPolling.prototype.open = function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
io.Transport.XHR.prototype.open.call(self);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a XHR request to wait for incoming messages.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
function empty () {};
|
|
|
|
|
|
|
|
XHRPolling.prototype.get = function () {
|
|
|
|
if (!this.isOpen) return;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
function stateChange () {
|
|
|
|
if (this.readyState == 4) {
|
|
|
|
this.onreadystatechange = empty;
|
|
|
|
|
|
|
|
if (this.status == 200) {
|
|
|
|
self.onData(this.responseText);
|
|
|
|
self.get();
|
|
|
|
} else {
|
|
|
|
self.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onload () {
|
|
|
|
this.onload = empty;
|
|
|
|
this.onerror = empty;
|
|
|
|
self.retryCounter = 1;
|
|
|
|
self.onData(this.responseText);
|
|
|
|
self.get();
|
|
|
|
};
|
|
|
|
|
|
|
|
function onerror () {
|
|
|
|
self.retryCounter ++;
|
|
|
|
if(!self.retryCounter || self.retryCounter > 3) {
|
|
|
|
self.onClose();
|
|
|
|
} else {
|
|
|
|
self.get();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.xhr = this.request();
|
|
|
|
|
|
|
|
if (global.XDomainRequest && this.xhr instanceof XDomainRequest) {
|
|
|
|
this.xhr.onload = onload;
|
|
|
|
this.xhr.onerror = onerror;
|
|
|
|
} else {
|
|
|
|
this.xhr.onreadystatechange = stateChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.xhr.send(null);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the unclean close behavior.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHRPolling.prototype.onClose = function () {
|
|
|
|
io.Transport.XHR.prototype.onClose.call(this);
|
|
|
|
|
|
|
|
if (this.xhr) {
|
|
|
|
this.xhr.onreadystatechange = this.xhr.onload = this.xhr.onerror = empty;
|
|
|
|
try {
|
|
|
|
this.xhr.abort();
|
|
|
|
} catch(e){}
|
|
|
|
this.xhr = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Webkit based browsers show a infinit spinner when you start a XHR request
|
|
|
|
* before the browsers onload event is called so we need to defer opening of
|
|
|
|
* the transport until the onload event is called. Wrapping the cb in our
|
|
|
|
* defer method solve this.
|
|
|
|
*
|
|
|
|
* @param {Socket} socket The socket instance that needs a transport
|
|
|
|
* @param {Function} fn The callback
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
XHRPolling.prototype.ready = function (socket, fn) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
io.util.defer(function () {
|
|
|
|
fn.call(self);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the transport to your public io.transports array.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports.push('xhr-polling');
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
, this
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket.io
|
|
|
|
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (exports, io, global) {
|
|
|
|
/**
|
|
|
|
* There is a way to hide the loading indicator in Firefox. If you create and
|
|
|
|
* remove a iframe it will stop showing the current loading indicator.
|
|
|
|
* Unfortunately we can't feature detect that and UA sniffing is evil.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
var indicator = global.document && "MozAppearance" in
|
|
|
|
global.document.documentElement.style;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports['jsonp-polling'] = JSONPPolling;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JSONP transport creates an persistent connection by dynamically
|
|
|
|
* inserting a script tag in the page. This script tag will receive the
|
|
|
|
* information of the Socket.IO server. When new information is received
|
|
|
|
* it creates a new script tag for the new data stream.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {io.Transport.xhr-polling}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
function JSONPPolling (socket) {
|
|
|
|
io.Transport['xhr-polling'].apply(this, arguments);
|
|
|
|
|
|
|
|
this.index = io.j.length;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
io.j.push(function (msg) {
|
|
|
|
self._(msg);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from XHR polling transport.
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.util.inherit(JSONPPolling, io.Transport['xhr-polling']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport name
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.prototype.name = 'jsonp-polling';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts a encoded message to the Socket.IO server using an iframe.
|
|
|
|
* The iframe is used because script tags can create POST based requests.
|
|
|
|
* The iframe is positioned outside of the view so the user does not
|
|
|
|
* notice it's existence.
|
|
|
|
*
|
|
|
|
* @param {String} data A encoded message.
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.prototype.post = function (data) {
|
|
|
|
var self = this
|
|
|
|
, query = io.util.query(
|
|
|
|
this.socket.options.query
|
|
|
|
, 't='+ (+new Date) + '&i=' + this.index
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!this.form) {
|
|
|
|
var form = document.createElement('form')
|
|
|
|
, area = document.createElement('textarea')
|
|
|
|
, id = this.iframeId = 'socketio_iframe_' + this.index
|
|
|
|
, iframe;
|
|
|
|
|
|
|
|
form.className = 'socketio';
|
|
|
|
form.style.position = 'absolute';
|
|
|
|
form.style.top = '0px';
|
|
|
|
form.style.left = '0px';
|
|
|
|
form.style.display = 'none';
|
|
|
|
form.target = id;
|
|
|
|
form.method = 'POST';
|
|
|
|
form.setAttribute('accept-charset', 'utf-8');
|
|
|
|
area.name = 'd';
|
|
|
|
form.appendChild(area);
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
|
|
|
this.form = form;
|
|
|
|
this.area = area;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.form.action = this.prepareUrl() + query;
|
|
|
|
|
|
|
|
function complete () {
|
|
|
|
initIframe();
|
|
|
|
self.socket.setBuffer(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
function initIframe () {
|
|
|
|
if (self.iframe) {
|
|
|
|
self.form.removeChild(self.iframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
|
|
|
|
iframe = document.createElement('<iframe name="'+ self.iframeId +'">');
|
|
|
|
} catch (e) {
|
|
|
|
iframe = document.createElement('iframe');
|
|
|
|
iframe.name = self.iframeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe.id = self.iframeId;
|
|
|
|
|
|
|
|
self.form.appendChild(iframe);
|
|
|
|
self.iframe = iframe;
|
|
|
|
};
|
|
|
|
|
|
|
|
initIframe();
|
|
|
|
|
|
|
|
// we temporarily stringify until we figure out how to prevent
|
|
|
|
// browsers from turning `\n` into `\r\n` in form inputs
|
|
|
|
this.area.value = io.JSON.stringify(data);
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.form.submit();
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (this.iframe.attachEvent) {
|
|
|
|
iframe.onreadystatechange = function () {
|
|
|
|
if (self.iframe.readyState == 'complete') {
|
|
|
|
complete();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.iframe.onload = complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.socket.setBuffer(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new JSONP poll that can be used to listen
|
|
|
|
* for messages from the Socket.IO server.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.prototype.get = function () {
|
|
|
|
var self = this
|
|
|
|
, script = document.createElement('script')
|
|
|
|
, query = io.util.query(
|
|
|
|
this.socket.options.query
|
|
|
|
, 't='+ (+new Date) + '&i=' + this.index
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this.script) {
|
|
|
|
this.script.parentNode.removeChild(this.script);
|
|
|
|
this.script = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
script.async = true;
|
|
|
|
script.src = this.prepareUrl() + query;
|
|
|
|
script.onerror = function () {
|
|
|
|
self.onClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
var insertAt = document.getElementsByTagName('script')[0];
|
|
|
|
insertAt.parentNode.insertBefore(script, insertAt);
|
|
|
|
this.script = script;
|
|
|
|
|
|
|
|
if (indicator) {
|
|
|
|
setTimeout(function () {
|
|
|
|
var iframe = document.createElement('iframe');
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
document.body.removeChild(iframe);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function for the incoming message stream from the Socket.IO server.
|
|
|
|
*
|
|
|
|
* @param {String} data The message
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.prototype._ = function (msg) {
|
|
|
|
this.onData(msg);
|
|
|
|
if (this.isOpen) {
|
|
|
|
this.get();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator hack only works after onload
|
|
|
|
*
|
|
|
|
* @param {Socket} socket The socket instance that needs a transport
|
|
|
|
* @param {Function} fn The callback
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.prototype.ready = function (socket, fn) {
|
|
|
|
var self = this;
|
|
|
|
if (!indicator) return fn.call(this);
|
|
|
|
|
|
|
|
io.util.load(function () {
|
|
|
|
fn.call(self);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if browser supports this transport.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.check = function () {
|
|
|
|
return 'document' in global;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if cross domain requests are supported
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
JSONPPolling.xdomainCheck = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the transport to your public io.transports array.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
|
|
|
io.transports.push('jsonp-polling');
|
|
|
|
|
|
|
|
})(
|
|
|
|
'undefined' != typeof io ? io.Transport : module.exports
|
|
|
|
, 'undefined' != typeof io ? io : module.parent.exports
|
|
|
|
, this
|
|
|
|
);
|
|
|
|
|
|
|
|
if (typeof define === "function" && define.amd) {
|
|
|
|
define([], function () { return io; });
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
},{}],13:[function(require,module,exports){
|
|
|
|
// shim for using process in browser
|
|
|
|
|
|
|
|
var process = module.exports = {};
|
|
|
|
|
|
|
|
process.nextTick = (function () {
|
|
|
|
var canSetImmediate = typeof window !== 'undefined'
|
|
|
|
&& window.setImmediate;
|
|
|
|
var canPost = typeof window !== 'undefined'
|
|
|
|
&& window.postMessage && window.addEventListener
|
|
|
|
;
|
|
|
|
|
|
|
|
if (canSetImmediate) {
|
|
|
|
return function (f) { return window.setImmediate(f) };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canPost) {
|
|
|
|
var queue = [];
|
|
|
|
window.addEventListener('message', function (ev) {
|
|
|
|
var source = ev.source;
|
|
|
|
if ((source === window || source === null) && ev.data === 'process-tick') {
|
|
|
|
ev.stopPropagation();
|
|
|
|
if (queue.length > 0) {
|
|
|
|
var fn = queue.shift();
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
return function nextTick(fn) {
|
|
|
|
queue.push(fn);
|
|
|
|
window.postMessage('process-tick', '*');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return function nextTick(fn) {
|
|
|
|
setTimeout(fn, 0);
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
process.title = 'browser';
|
|
|
|
process.browser = true;
|
|
|
|
process.env = {};
|
|
|
|
process.argv = [];
|
|
|
|
|
|
|
|
process.binding = function (name) {
|
|
|
|
throw new Error('process.binding is not supported');
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(shtylman)
|
|
|
|
process.cwd = function () { return '/' };
|
|
|
|
process.chdir = function (dir) {
|
|
|
|
throw new Error('process.chdir is not supported');
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],12:[function(require,module,exports){
|
|
|
|
var process=require("__browserify_process");if (!process.EventEmitter) process.EventEmitter = function () {};
|
|
|
|
|
|
|
|
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
|
|
|
var isArray = typeof Array.isArray === 'function'
|
|
|
|
? Array.isArray
|
|
|
|
: function (xs) {
|
|
|
|
return Object.prototype.toString.call(xs) === '[object Array]'
|
|
|
|
}
|
|
|
|
;
|
|
|
|
function indexOf (xs, x) {
|
|
|
|
if (xs.indexOf) return xs.indexOf(x);
|
|
|
|
for (var i = 0; i < xs.length; i++) {
|
|
|
|
if (x === xs[i]) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default EventEmitters will print a warning if more than
|
|
|
|
// 10 listeners are added to it. This is a useful default which
|
|
|
|
// helps finding memory leaks.
|
|
|
|
//
|
|
|
|
// Obviously not all Emitters should be limited to 10. This function allows
|
|
|
|
// that to be increased. Set to zero for unlimited.
|
|
|
|
var defaultMaxListeners = 10;
|
|
|
|
EventEmitter.prototype.setMaxListeners = function(n) {
|
|
|
|
if (!this._events) this._events = {};
|
|
|
|
this._events.maxListeners = n;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.emit = function(type) {
|
|
|
|
// If there is no 'error' event listener then throw.
|
|
|
|
if (type === 'error') {
|
|
|
|
if (!this._events || !this._events.error ||
|
|
|
|
(isArray(this._events.error) && !this._events.error.length))
|
|
|
|
{
|
|
|
|
if (arguments[1] instanceof Error) {
|
|
|
|
throw arguments[1]; // Unhandled 'error' event
|
|
|
|
} else {
|
|
|
|
throw new Error("Uncaught, unspecified 'error' event.");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._events) return false;
|
|
|
|
var handler = this._events[type];
|
|
|
|
if (!handler) return false;
|
|
|
|
|
|
|
|
if (typeof handler == 'function') {
|
|
|
|
switch (arguments.length) {
|
|
|
|
// fast cases
|
|
|
|
case 1:
|
|
|
|
handler.call(this);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
handler.call(this, arguments[1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
handler.call(this, arguments[1], arguments[2]);
|
|
|
|
break;
|
|
|
|
// slower
|
|
|
|
default:
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
handler.apply(this, args);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (isArray(handler)) {
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
|
|
|
|
var listeners = handler.slice();
|
|
|
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
|
|
listeners[i].apply(this, args);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// EventEmitter is defined in src/node_events.cc
|
|
|
|
// EventEmitter.prototype.emit() is also defined there.
|
|
|
|
EventEmitter.prototype.addListener = function(type, listener) {
|
|
|
|
if ('function' !== typeof listener) {
|
|
|
|
throw new Error('addListener only takes instances of Function');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._events) this._events = {};
|
|
|
|
|
|
|
|
// To avoid recursion in the case that type == "newListeners"! Before
|
|
|
|
// adding it to the listeners, first emit "newListeners".
|
|
|
|
this.emit('newListener', type, listener);
|
|
|
|
|
|
|
|
if (!this._events[type]) {
|
|
|
|
// Optimize the case of one listener. Don't need the extra array object.
|
|
|
|
this._events[type] = listener;
|
|
|
|
} else if (isArray(this._events[type])) {
|
|
|
|
|
|
|
|
// Check for listener leak
|
|
|
|
if (!this._events[type].warned) {
|
|
|
|
var m;
|
|
|
|
if (this._events.maxListeners !== undefined) {
|
|
|
|
m = this._events.maxListeners;
|
|
|
|
} else {
|
|
|
|
m = defaultMaxListeners;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m && m > 0 && this._events[type].length > m) {
|
|
|
|
this._events[type].warned = true;
|
|
|
|
console.error('(node) warning: possible EventEmitter memory ' +
|
|
|
|
'leak detected. %d listeners added. ' +
|
|
|
|
'Use emitter.setMaxListeners() to increase limit.',
|
|
|
|
this._events[type].length);
|
|
|
|
console.trace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we've already got an array, just append.
|
|
|
|
this._events[type].push(listener);
|
|
|
|
} else {
|
|
|
|
// Adding the second element, need to change to array.
|
|
|
|
this._events[type] = [this._events[type], listener];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
|
|
|
|
|
|
EventEmitter.prototype.once = function(type, listener) {
|
|
|
|
var self = this;
|
|
|
|
self.on(type, function g() {
|
|
|
|
self.removeListener(type, g);
|
|
|
|
listener.apply(this, arguments);
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeListener = function(type, listener) {
|
|
|
|
if ('function' !== typeof listener) {
|
|
|
|
throw new Error('removeListener only takes instances of Function');
|
|
|
|
}
|
|
|
|
|
|
|
|
// does not use listeners(), so no side effect of creating _events[type]
|
|
|
|
if (!this._events || !this._events[type]) return this;
|
|
|
|
|
|
|
|
var list = this._events[type];
|
|
|
|
|
|
|
|
if (isArray(list)) {
|
|
|
|
var i = indexOf(list, listener);
|
|
|
|
if (i < 0) return this;
|
|
|
|
list.splice(i, 1);
|
|
|
|
if (list.length == 0)
|
|
|
|
delete this._events[type];
|
|
|
|
} else if (this._events[type] === listener) {
|
|
|
|
delete this._events[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
this._events = {};
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// does not use listeners(), so no side effect of creating _events[type]
|
|
|
|
if (type && this._events && this._events[type]) this._events[type] = null;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.listeners = function(type) {
|
|
|
|
if (!this._events) this._events = {};
|
|
|
|
if (!this._events[type]) this._events[type] = [];
|
|
|
|
if (!isArray(this._events[type])) {
|
|
|
|
this._events[type] = [this._events[type]];
|
|
|
|
}
|
|
|
|
return this._events[type];
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.listenerCount = function(emitter, type) {
|
|
|
|
var ret;
|
|
|
|
if (!emitter._events || !emitter._events[type])
|
|
|
|
ret = 0;
|
|
|
|
else if (typeof emitter._events[type] === 'function')
|
|
|
|
ret = 1;
|
|
|
|
else
|
|
|
|
ret = emitter._events[type].length;
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"__browserify_process":13}],9:[function(require,module,exports){
|
|
|
|
var util = require('util');
|
|
|
|
var webrtc = require('webrtcsupport');
|
|
|
|
var PeerConnection = require('rtcpeerconnection');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var FileTransfer = require('filetransfer');
|
|
|
|
|
|
|
|
// the inband-v1 protocol is sending metadata inband in a serialized JSON object
|
|
|
|
// followed by the actual data. Receiver closes the datachannel upon completion
|
|
|
|
var INBAND_FILETRANSFER_V1 = 'https://simplewebrtc.com/protocol/filetransfer#inband-v1';
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (self.parent.config.nick) offer.nick = self.parent.config.nick;
|
|
|
|
self.send('offer', offer);
|
|
|
|
});
|
|
|
|
this.pc.on('answer', function (answer) {
|
|
|
|
if (self.parent.config.nick) answer.nick = self.parent.config.nick;
|
|
|
|
self.send('answer', answer);
|
|
|
|
});
|
|
|
|
this.pc.on('addStream', this.handleRemoteStreamAdded.bind(this));
|
|
|
|
this.pc.on('addChannel', this.handleDataChannelAdded.bind(this));
|
|
|
|
this.pc.on('removeStream', this.handleStreamRemoved.bind(this));
|
|
|
|
// Just fire negotiation needed events for now
|
|
|
|
// When browser re-negotiation handling seems to work
|
|
|
|
// we can use this as the trigger for starting the offer/answer process
|
|
|
|
// automatically. We'll just leave it be for now while this stabalizes.
|
|
|
|
this.pc.on('negotiationNeeded', this.emit.bind(this, 'negotiationNeeded'));
|
|
|
|
this.pc.on('iceConnectionStateChange', this.emit.bind(this, 'iceConnectionStateChange'));
|
|
|
|
this.pc.on('iceConnectionStateChange', function () {
|
|
|
|
switch (self.pc.iceConnectionState) {
|
|
|
|
case 'failed':
|
|
|
|
// currently, in chrome only the initiator goes to failed
|
|
|
|
// so we need to signal this to the peer
|
|
|
|
if (self.pc.pc.peerconnection.localDescription.type === 'offer') {
|
|
|
|
self.parent.emit('iceFailed', self);
|
|
|
|
self.send('connectivityError');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.pc.on('signalingStateChange', this.emit.bind(this, 'signalingStateChange'));
|
|
|
|
this.logger = this.parent.logger;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
this.on('*', function () {
|
|
|
|
self.parent.emit.apply(self.parent, arguments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(Peer, WildEmitter);
|
|
|
|
|
|
|
|
Peer.prototype.handleMessage = function (message) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.logger.log('getting', message.type, message);
|
|
|
|
|
|
|
|
if (message.prefix) this.browserPrefix = message.prefix;
|
|
|
|
|
|
|
|
if (message.type === 'offer') {
|
|
|
|
if (!this.nick) this.nick = message.payload.nick;
|
|
|
|
delete message.payload.nick;
|
|
|
|
// workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1064247
|
|
|
|
message.payload.sdp = message.payload.sdp.replace('a=fmtp:0 profile-level-id=0x42e00c;packetization-mode=1\r\n', '');
|
|
|
|
this.pc.handleOffer(message.payload, function (err) {
|
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// auto-accept
|
|
|
|
self.pc.answer(self.receiveMedia, function (err, sessionDescription) {
|
|
|
|
//self.send('answer', sessionDescription);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (message.type === 'answer') {
|
|
|
|
if (!this.nick) this.nick = message.payload.nick;
|
|
|
|
delete message.payload.nick;
|
|
|
|
this.pc.handleAnswer(message.payload);
|
|
|
|
} else if (message.type === 'candidate') {
|
|
|
|
this.pc.processIce(message.payload);
|
|
|
|
} else if (message.type === 'connectivityError') {
|
|
|
|
this.parent.emit('connectivityError', self);
|
|
|
|
} else if (message.type === 'mute') {
|
|
|
|
this.parent.emit('mute', {id: message.from, name: message.payload.name});
|
|
|
|
} else if (message.type === 'unmute') {
|
|
|
|
this.parent.emit('unmute', {id: message.from, name: message.payload.name});
|
|
|
|
} else {
|
|
|
|
this.parent.emit(message.type, {id: message.from, payload: message.payload, roomType: message.roomType});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// send via signalling channel
|
|
|
|
Peer.prototype.send = function (messageType, payload) {
|
|
|
|
var message = {
|
|
|
|
to: this.id,
|
|
|
|
sid: this.sid,
|
|
|
|
broadcaster: this.broadcaster,
|
|
|
|
roomType: this.type,
|
|
|
|
type: messageType,
|
|
|
|
payload: payload,
|
|
|
|
prefix: webrtc.prefix
|
|
|
|
};
|
|
|
|
this.logger.log('sending', messageType, message);
|
|
|
|
this.parent.emit('message', message);
|
|
|
|
};
|
|
|
|
|
|
|
|
// send via data channel
|
|
|
|
// returns true when message was sent and false if channel is not open
|
|
|
|
Peer.prototype.sendDirectly = function (channel, messageType, payload) {
|
|
|
|
var message = {
|
|
|
|
type: messageType,
|
|
|
|
payload: payload
|
|
|
|
};
|
|
|
|
this.logger.log('sending via datachannel', channel, messageType, message);
|
|
|
|
var dc = this.getDataChannel(channel);
|
|
|
|
if (dc.readyState != 'open') return false;
|
|
|
|
dc.send(JSON.stringify(message));
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal method registering handlers for a data channel and emitting events on the peer
|
|
|
|
Peer.prototype._observeDataChannel = function (channel) {
|
|
|
|
var self = this;
|
|
|
|
channel.onclose = this.emit.bind(this, 'channelClose', channel);
|
|
|
|
channel.onerror = this.emit.bind(this, 'channelError', channel);
|
|
|
|
channel.onmessage = function (event) {
|
|
|
|
self.emit('channelMessage', self, channel.label, JSON.parse(event.data), channel, event);
|
|
|
|
};
|
|
|
|
channel.onopen = this.emit.bind(this, 'channelOpen', channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fetch or create a data channel by the given name
|
|
|
|
Peer.prototype.getDataChannel = function (name, opts) {
|
|
|
|
if (!webrtc.supportDataChannel) return this.emit('error', new Error('createDataChannel not supported'));
|
|
|
|
var channel = this.channels[name];
|
|
|
|
opts || (opts = {});
|
|
|
|
if (channel) return channel;
|
|
|
|
// if we don't have one by this label, create it
|
|
|
|
channel = this.channels[name] = this.pc.createDataChannel(name, opts);
|
|
|
|
this._observeDataChannel(channel);
|
|
|
|
return channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.onIceCandidate = function (candidate) {
|
|
|
|
if (this.closed) return;
|
|
|
|
if (candidate) {
|
|
|
|
var pcConfig = this.parent.config.peerConnectionConfig;
|
|
|
|
if (webrtc.prefix === 'moz' && pcConfig && pcConfig.iceTransports &&
|
|
|
|
candidate.candidate && candidate.candidate.candidate &&
|
|
|
|
candidate.candidate.candidate.indexOf(pcConfig.iceTransports) < 0) {
|
|
|
|
this.logger.log('Ignoring ice candidate not matching pcConfig iceTransports type: ', pcConfig.iceTransports);
|
|
|
|
} else {
|
|
|
|
this.send('candidate', candidate);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.logger.log("End of candidates.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.start = function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// well, the webrtc api requires that we either
|
|
|
|
// a) create a datachannel a priori
|
|
|
|
// b) do a renegotiation later to add the SCTP m-line
|
|
|
|
// Let's do (a) first...
|
|
|
|
if (this.enableDataChannels) {
|
|
|
|
this.getDataChannel('simplewebrtc');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pc.offer(this.receiveMedia, function (err, sessionDescription) {
|
|
|
|
//self.send('offer', sessionDescription);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.icerestart = function () {
|
|
|
|
var constraints = this.receiveMedia;
|
|
|
|
constraints.mandatory.IceRestart = true;
|
|
|
|
this.pc.offer(constraints, function (err, success) { });
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.end = function () {
|
|
|
|
if (this.closed) return;
|
|
|
|
this.pc.close();
|
|
|
|
this.handleStreamRemoved();
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.handleRemoteStreamAdded = function (event) {
|
|
|
|
var self = this;
|
|
|
|
if (this.stream) {
|
|
|
|
this.logger.warn('Already have a remote stream');
|
|
|
|
} else {
|
|
|
|
this.stream = event.stream;
|
|
|
|
// FIXME: addEventListener('ended', ...) would be nicer
|
|
|
|
// but does not work in firefox
|
|
|
|
this.stream.onended = function () {
|
|
|
|
self.end();
|
|
|
|
};
|
|
|
|
this.parent.emit('peerStreamAdded', this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.handleStreamRemoved = function () {
|
|
|
|
this.parent.peers.splice(this.parent.peers.indexOf(this), 1);
|
|
|
|
this.closed = true;
|
|
|
|
this.parent.emit('peerStreamRemoved', this);
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.handleDataChannelAdded = function (channel) {
|
|
|
|
this.channels[channel.label] = channel;
|
|
|
|
this._observeDataChannel(channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
Peer.prototype.sendFile = function (file) {
|
|
|
|
var sender = new FileTransfer.Sender();
|
|
|
|
var dc = this.getDataChannel('filetransfer' + (new Date()).getTime(), {
|
|
|
|
protocol: INBAND_FILETRANSFER_V1
|
|
|
|
});
|
|
|
|
// override onopen
|
|
|
|
dc.onopen = function () {
|
|
|
|
dc.send(JSON.stringify({
|
|
|
|
size: file.size,
|
|
|
|
name: file.name
|
|
|
|
}));
|
|
|
|
sender.send(file, dc);
|
|
|
|
};
|
|
|
|
// override onclose
|
|
|
|
dc.onclose = function () {
|
|
|
|
console.log('sender received transfer');
|
|
|
|
sender.emit('complete');
|
|
|
|
};
|
|
|
|
return sender;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Peer;
|
|
|
|
|
|
|
|
},{"filetransfer":15,"rtcpeerconnection":14,"util":8,"webrtcsupport":5,"wildemitter":4}],10:[function(require,module,exports){
|
|
|
|
var util = require('util');
|
|
|
|
var hark = require('hark');
|
|
|
|
var webrtc = require('webrtcsupport');
|
|
|
|
var getUserMedia = require('getusermedia');
|
|
|
|
var getScreenMedia = require('getscreenmedia');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var GainController = require('mediastream-gain');
|
|
|
|
var mockconsole = require('mockconsole');
|
|
|
|
|
|
|
|
|
|
|
|
function LocalMedia(opts) {
|
|
|
|
WildEmitter.call(this);
|
|
|
|
|
|
|
|
var config = this.config = {
|
|
|
|
autoAdjustMic: false,
|
|
|
|
detectSpeakingEvents: true,
|
|
|
|
audioFallback: false,
|
|
|
|
media: {
|
|
|
|
audio: true,
|
|
|
|
video: true
|
|
|
|
},
|
|
|
|
logger: mockconsole
|
|
|
|
};
|
|
|
|
|
|
|
|
var item;
|
|
|
|
for (item in opts) {
|
|
|
|
this.config[item] = opts[item];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.logger = config.logger;
|
|
|
|
this._log = this.logger.log.bind(this.logger, 'LocalMedia:');
|
|
|
|
this._logerror = this.logger.error.bind(this.logger, 'LocalMedia:');
|
|
|
|
|
|
|
|
this.screenSharingSupport = webrtc.screenSharing;
|
|
|
|
|
|
|
|
this.localStreams = [];
|
|
|
|
this.localScreens = [];
|
|
|
|
|
|
|
|
if (!webrtc.support) {
|
|
|
|
this._logerror('Your browser does not support local media capture.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(LocalMedia, WildEmitter);
|
|
|
|
|
|
|
|
|
|
|
|
LocalMedia.prototype.start = function (mediaConstraints, cb) {
|
|
|
|
var self = this;
|
|
|
|
var constraints = mediaConstraints || this.config.media;
|
|
|
|
|
|
|
|
getUserMedia(constraints, function (err, stream) {
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
if (constraints.audio && self.config.detectSpeakingEvents) {
|
|
|
|
self.setupAudioMonitor(stream, self.config.harkOptions);
|
|
|
|
}
|
|
|
|
self.localStreams.push(stream);
|
|
|
|
|
|
|
|
if (self.config.autoAdjustMic) {
|
|
|
|
self.gainController = new GainController(stream);
|
|
|
|
// start out somewhat muted if we can track audio
|
|
|
|
self.setMicIfEnabled(0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: might need to migrate to the video tracks onended
|
|
|
|
// FIXME: firefox does not seem to trigger this...
|
|
|
|
stream.onended = function () {
|
|
|
|
/*
|
|
|
|
var idx = self.localStreams.indexOf(stream);
|
|
|
|
if (idx > -1) {
|
|
|
|
self.localScreens.splice(idx, 1);
|
|
|
|
}
|
|
|
|
self.emit('localStreamStopped', stream);
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('localStream', stream);
|
|
|
|
} else {
|
|
|
|
// Fallback for users without a camera
|
|
|
|
if (self.config.audioFallback && err.name === 'DevicesNotFoundError' && constraints.video !== false) {
|
|
|
|
constraints.video = false;
|
|
|
|
self.start(constraints, cb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cb) {
|
|
|
|
return cb(err, stream);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.stop = function (stream) {
|
|
|
|
var self = this;
|
|
|
|
// FIXME: duplicates cleanup code until fixed in FF
|
|
|
|
if (stream) {
|
|
|
|
stream.getTracks().forEach(function (track) { track.stop(); });
|
|
|
|
var idx = self.localStreams.indexOf(stream);
|
|
|
|
if (idx > -1) {
|
|
|
|
self.emit('localStreamStopped', stream);
|
|
|
|
self.localStreams = self.localStreams.splice(idx, 1);
|
|
|
|
} else {
|
|
|
|
idx = self.localScreens.indexOf(stream);
|
|
|
|
if (idx > -1) {
|
|
|
|
self.emit('localScreenStopped', stream);
|
|
|
|
self.localScreens = self.localScreens.splce(idx, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.stopStreams();
|
|
|
|
this.stopScreenShare();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.stopStreams = function () {
|
|
|
|
var self = this;
|
|
|
|
if (this.audioMonitor) {
|
|
|
|
this.audioMonitor.stop();
|
|
|
|
delete this.audioMonitor;
|
|
|
|
}
|
|
|
|
this.localStreams.forEach(function (stream) {
|
|
|
|
stream.getTracks().forEach(function (track) { track.stop(); });
|
|
|
|
self.emit('localStreamStopped', stream);
|
|
|
|
});
|
|
|
|
this.localStreams = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.startScreenShare = function (cb) {
|
|
|
|
var self = this;
|
|
|
|
getScreenMedia(function (err, stream) {
|
|
|
|
if (!err) {
|
|
|
|
self.localScreens.push(stream);
|
|
|
|
|
|
|
|
// TODO: might need to migrate to the video tracks onended
|
|
|
|
// Firefox does not support .onended but it does not support
|
|
|
|
// screensharing either
|
|
|
|
stream.onended = function () {
|
|
|
|
var idx = self.localScreens.indexOf(stream);
|
|
|
|
if (idx > -1) {
|
|
|
|
self.localScreens.splice(idx, 1);
|
|
|
|
}
|
|
|
|
self.emit('localScreenStopped', stream);
|
|
|
|
};
|
|
|
|
self.emit('localScreen', stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable the callback
|
|
|
|
if (cb) {
|
|
|
|
return cb(err, stream);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.stopScreenShare = function (stream) {
|
|
|
|
var self = this;
|
|
|
|
if (stream) {
|
|
|
|
stream.getTracks().forEach(function (track) { track.stop(); });
|
|
|
|
this.emit('localScreenStopped', stream);
|
|
|
|
} else {
|
|
|
|
this.localScreens.forEach(function (stream) {
|
|
|
|
stream.getTracks().forEach(function (track) { track.stop(); });
|
|
|
|
self.emit('localScreenStopped', stream);
|
|
|
|
});
|
|
|
|
this.localScreens = [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Audio controls
|
|
|
|
LocalMedia.prototype.mute = function () {
|
|
|
|
this._audioEnabled(false);
|
|
|
|
this.hardMuted = true;
|
|
|
|
this.emit('audioOff');
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.unmute = function () {
|
|
|
|
this._audioEnabled(true);
|
|
|
|
this.hardMuted = false;
|
|
|
|
this.emit('audioOn');
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalMedia.prototype.setupAudioMonitor = function (stream, harkOptions) {
|
|
|
|
this._log('Setup audio');
|
|
|
|
var audio = this.audioMonitor = hark(stream, harkOptions);
|
|
|
|
var self = this;
|
|
|
|
var timeout;
|
|
|
|
|
|
|
|
audio.on('speaking', function () {
|
|
|
|
self.emit('speaking');
|
|
|
|
if (self.hardMuted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.setMicIfEnabled(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
audio.on('stopped_speaking', function () {
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = setTimeout(function () {
|
|
|
|
self.emit('stoppedSpeaking');
|
|
|
|
if (self.hardMuted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.setMicIfEnabled(0.5);
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
audio.on('volume_change', function (volume, treshold) {
|
|
|
|
self.emit('volumeChange', volume, treshold);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// We do this as a seperate method in order to
|
|
|
|
// still leave the "setMicVolume" as a working
|
|
|
|
// method.
|
|
|
|
LocalMedia.prototype.setMicIfEnabled = function (volume) {
|
|
|
|
if (!this.config.autoAdjustMic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.gainController.setGain(volume);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Video controls
|
|
|
|
LocalMedia.prototype.pauseVideo = function () {
|
|
|
|
this._videoEnabled(false);
|
|
|
|
this.emit('videoOff');
|
|
|
|
};
|
|
|
|
LocalMedia.prototype.resumeVideo = function () {
|
|
|
|
this._videoEnabled(true);
|
|
|
|
this.emit('videoOn');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Combined controls
|
|
|
|
LocalMedia.prototype.pause = function () {
|
|
|
|
this.mute();
|
|
|
|
this.pauseVideo();
|
|
|
|
};
|
|
|
|
LocalMedia.prototype.resume = function () {
|
|
|
|
this.unmute();
|
|
|
|
this.resumeVideo();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal methods for enabling/disabling audio/video
|
|
|
|
LocalMedia.prototype._audioEnabled = function (bool) {
|
|
|
|
// work around for chrome 27 bug where disabling tracks
|
|
|
|
// doesn't seem to work (works in canary, remove when working)
|
|
|
|
this.setMicIfEnabled(bool ? 1 : 0);
|
|
|
|
this.localStreams.forEach(function (stream) {
|
|
|
|
stream.getAudioTracks().forEach(function (track) {
|
|
|
|
track.enabled = !!bool;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
LocalMedia.prototype._videoEnabled = function (bool) {
|
|
|
|
this.localStreams.forEach(function (stream) {
|
|
|
|
stream.getVideoTracks().forEach(function (track) {
|
|
|
|
track.enabled = !!bool;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// check if all audio streams are enabled
|
|
|
|
LocalMedia.prototype.isAudioEnabled = function () {
|
|
|
|
var enabled = true;
|
|
|
|
this.localStreams.forEach(function (stream) {
|
|
|
|
stream.getAudioTracks().forEach(function (track) {
|
|
|
|
enabled = enabled && track.enabled;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
// check if all video streams are enabled
|
|
|
|
LocalMedia.prototype.isVideoEnabled = function () {
|
|
|
|
var enabled = true;
|
|
|
|
this.localStreams.forEach(function (stream) {
|
|
|
|
stream.getVideoTracks().forEach(function (track) {
|
|
|
|
enabled = enabled && track.enabled;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Backwards Compat
|
|
|
|
LocalMedia.prototype.startLocalMedia = LocalMedia.prototype.start;
|
|
|
|
LocalMedia.prototype.stopLocalMedia = LocalMedia.prototype.stop;
|
|
|
|
|
|
|
|
// fallback for old .localStream behaviour
|
|
|
|
Object.defineProperty(LocalMedia.prototype, 'localStream', {
|
|
|
|
get: function () {
|
|
|
|
return this.localStreams.length > 0 ? this.localStreams[0] : null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// fallback for old .localScreen behaviour
|
|
|
|
Object.defineProperty(LocalMedia.prototype, 'localScreen', {
|
|
|
|
get: function () {
|
|
|
|
return this.localScreens.length > 0 ? this.localScreens[0] : null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LocalMedia;
|
|
|
|
|
|
|
|
},{"getscreenmedia":17,"getusermedia":16,"hark":18,"mediastream-gain":19,"mockconsole":6,"util":8,"webrtcsupport":5,"wildemitter":4}],20:[function(require,module,exports){
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* More information about these options at jshint.com/docs/options */
|
|
|
|
/* jshint browser: true, camelcase: true, curly: true, devel: true,
|
|
|
|
eqeqeq: true, forin: false, globalstrict: true, node: true,
|
|
|
|
quotmark: single, undef: true, unused: strict */
|
|
|
|
/* global mozRTCIceCandidate, mozRTCPeerConnection, Promise,
|
|
|
|
mozRTCSessionDescription, webkitRTCPeerConnection, MediaStreamTrack */
|
|
|
|
/* exported trace,requestUserMedia */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var getUserMedia = null;
|
|
|
|
var attachMediaStream = null;
|
|
|
|
var reattachMediaStream = null;
|
|
|
|
var webrtcDetectedBrowser = null;
|
|
|
|
var webrtcDetectedVersion = null;
|
|
|
|
var webrtcMinimumVersion = null;
|
|
|
|
var webrtcUtils = {
|
|
|
|
log: function() {
|
|
|
|
// suppress console.log output when being included as a module.
|
|
|
|
if (typeof module !== 'undefined' ||
|
|
|
|
typeof require === 'function' && typeof define === 'function') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log.apply(console, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function trace(text) {
|
|
|
|
// This function is used for logging.
|
|
|
|
if (text[text.length - 1] === '\n') {
|
|
|
|
text = text.substring(0, text.length - 1);
|
|
|
|
}
|
|
|
|
if (window.performance) {
|
|
|
|
var now = (window.performance.now() / 1000).toFixed(3);
|
|
|
|
webrtcUtils.log(now + ': ' + text);
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof window === 'object') {
|
|
|
|
if (window.HTMLMediaElement &&
|
|
|
|
!('srcObject' in window.HTMLMediaElement.prototype)) {
|
|
|
|
// Shim the srcObject property, once, when HTMLMediaElement is found.
|
|
|
|
Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
|
|
|
|
get: function() {
|
|
|
|
// If prefixed srcObject property exists, return it.
|
|
|
|
// Otherwise use the shimmed property, _srcObject
|
|
|
|
return 'mozSrcObject' in this ? this.mozSrcObject : this._srcObject;
|
|
|
|
},
|
|
|
|
set: function(stream) {
|
|
|
|
if ('mozSrcObject' in this) {
|
|
|
|
this.mozSrcObject = stream;
|
|
|
|
} else {
|
|
|
|
// Use _srcObject as a private property for this shim
|
|
|
|
this._srcObject = stream;
|
|
|
|
// TODO: revokeObjectUrl(this.src) when !stream to release resources?
|
|
|
|
this.src = URL.createObjectURL(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Proxy existing globals
|
|
|
|
getUserMedia = window.navigator && window.navigator.getUserMedia;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach a media stream to an element.
|
|
|
|
attachMediaStream = function(element, stream) {
|
|
|
|
element.srcObject = stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
reattachMediaStream = function(to, from) {
|
|
|
|
to.srcObject = from.srcObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof window === 'undefined' || !window.navigator) {
|
|
|
|
webrtcUtils.log('This does not appear to be a browser');
|
|
|
|
webrtcDetectedBrowser = 'not a browser';
|
|
|
|
} else if (navigator.mozGetUserMedia && window.mozRTCPeerConnection) {
|
|
|
|
webrtcUtils.log('This appears to be Firefox');
|
|
|
|
|
|
|
|
webrtcDetectedBrowser = 'firefox';
|
|
|
|
|
|
|
|
// the detected firefox version.
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
|
|
|
|
|
|
|
|
// the minimum firefox version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 31;
|
|
|
|
|
|
|
|
// The RTCPeerConnection object.
|
|
|
|
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
|
|
|
|
if (webrtcDetectedVersion < 38) {
|
|
|
|
// .urls is not supported in FF < 38.
|
|
|
|
// create RTCIceServers with a single url.
|
|
|
|
if (pcConfig && pcConfig.iceServers) {
|
|
|
|
var newIceServers = [];
|
|
|
|
for (var i = 0; i < pcConfig.iceServers.length; i++) {
|
|
|
|
var server = pcConfig.iceServers[i];
|
|
|
|
if (server.hasOwnProperty('urls')) {
|
|
|
|
for (var j = 0; j < server.urls.length; j++) {
|
|
|
|
var newServer = {
|
|
|
|
url: server.urls[j]
|
|
|
|
};
|
|
|
|
if (server.urls[j].indexOf('turn') === 0) {
|
|
|
|
newServer.username = server.username;
|
|
|
|
newServer.credential = server.credential;
|
|
|
|
}
|
|
|
|
newIceServers.push(newServer);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newIceServers.push(pcConfig.iceServers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pcConfig.iceServers = newIceServers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new mozRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
|
|
|
|
};
|
|
|
|
|
|
|
|
// The RTCSessionDescription object.
|
|
|
|
window.RTCSessionDescription = mozRTCSessionDescription;
|
|
|
|
|
|
|
|
// The RTCIceCandidate object.
|
|
|
|
window.RTCIceCandidate = mozRTCIceCandidate;
|
|
|
|
|
|
|
|
// getUserMedia constraints shim.
|
|
|
|
getUserMedia = function(constraints, onSuccess, onError) {
|
|
|
|
var constraintsToFF37 = function(c) {
|
|
|
|
if (typeof c !== 'object' || c.require) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
var require = [];
|
|
|
|
Object.keys(c).forEach(function(key) {
|
|
|
|
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var r = c[key] = (typeof c[key] === 'object') ?
|
|
|
|
c[key] : {ideal: c[key]};
|
|
|
|
if (r.min !== undefined ||
|
|
|
|
r.max !== undefined || r.exact !== undefined) {
|
|
|
|
require.push(key);
|
|
|
|
}
|
|
|
|
if (r.exact !== undefined) {
|
|
|
|
if (typeof r.exact === 'number') {
|
|
|
|
r.min = r.max = r.exact;
|
|
|
|
} else {
|
|
|
|
c[key] = r.exact;
|
|
|
|
}
|
|
|
|
delete r.exact;
|
|
|
|
}
|
|
|
|
if (r.ideal !== undefined) {
|
|
|
|
c.advanced = c.advanced || [];
|
|
|
|
var oc = {};
|
|
|
|
if (typeof r.ideal === 'number') {
|
|
|
|
oc[key] = {min: r.ideal, max: r.ideal};
|
|
|
|
} else {
|
|
|
|
oc[key] = r.ideal;
|
|
|
|
}
|
|
|
|
c.advanced.push(oc);
|
|
|
|
delete r.ideal;
|
|
|
|
if (!Object.keys(r).length) {
|
|
|
|
delete c[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (require.length) {
|
|
|
|
c.require = require;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
};
|
|
|
|
if (webrtcDetectedVersion < 38) {
|
|
|
|
webrtcUtils.log('spec: ' + JSON.stringify(constraints));
|
|
|
|
if (constraints.audio) {
|
|
|
|
constraints.audio = constraintsToFF37(constraints.audio);
|
|
|
|
}
|
|
|
|
if (constraints.video) {
|
|
|
|
constraints.video = constraintsToFF37(constraints.video);
|
|
|
|
}
|
|
|
|
webrtcUtils.log('ff37: ' + JSON.stringify(constraints));
|
|
|
|
}
|
|
|
|
return navigator.mozGetUserMedia(constraints, onSuccess, onError);
|
|
|
|
};
|
|
|
|
|
|
|
|
navigator.getUserMedia = getUserMedia;
|
|
|
|
|
|
|
|
// Shim for mediaDevices on older versions.
|
|
|
|
if (!navigator.mediaDevices) {
|
|
|
|
navigator.mediaDevices = {getUserMedia: requestUserMedia,
|
|
|
|
addEventListener: function() { },
|
|
|
|
removeEventListener: function() { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
navigator.mediaDevices.enumerateDevices =
|
|
|
|
navigator.mediaDevices.enumerateDevices || function() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
var infos = [
|
|
|
|
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''},
|
|
|
|
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''}
|
|
|
|
];
|
|
|
|
resolve(infos);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (webrtcDetectedVersion < 41) {
|
|
|
|
// Work around http://bugzil.la/1169665
|
|
|
|
var orgEnumerateDevices =
|
|
|
|
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
|
|
|
|
navigator.mediaDevices.enumerateDevices = function() {
|
|
|
|
return orgEnumerateDevices().catch(function(e) {
|
|
|
|
if (e.name === 'NotFoundError') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else if (navigator.webkitGetUserMedia && !!window.chrome) {
|
|
|
|
webrtcUtils.log('This appears to be Chrome');
|
|
|
|
|
|
|
|
webrtcDetectedBrowser = 'chrome';
|
|
|
|
|
|
|
|
// the detected chrome version.
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
|
|
|
|
|
|
|
|
// the minimum chrome version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 38;
|
|
|
|
|
|
|
|
// The RTCPeerConnection object.
|
|
|
|
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
|
|
|
|
// Translate iceTransportPolicy to iceTransports,
|
|
|
|
// see https://code.google.com/p/webrtc/issues/detail?id=4869
|
|
|
|
if (pcConfig && pcConfig.iceTransportPolicy) {
|
|
|
|
pcConfig.iceTransports = pcConfig.iceTransportPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pc = new webkitRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
|
|
|
|
var origGetStats = pc.getStats.bind(pc);
|
|
|
|
pc.getStats = function(selector, successCallback, errorCallback) { // jshint ignore: line
|
|
|
|
var self = this;
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
// If selector is a function then we are in the old style stats so just
|
|
|
|
// pass back the original getStats format to avoid breaking old users.
|
|
|
|
if (arguments.length > 0 && typeof selector === 'function') {
|
|
|
|
return origGetStats(selector, successCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
var fixChromeStats = function(response) {
|
|
|
|
var standardReport = {};
|
|
|
|
var reports = response.result();
|
|
|
|
reports.forEach(function(report) {
|
|
|
|
var standardStats = {
|
|
|
|
id: report.id,
|
|
|
|
timestamp: report.timestamp,
|
|
|
|
type: report.type
|
|
|
|
};
|
|
|
|
report.names().forEach(function(name) {
|
|
|
|
standardStats[name] = report.stat(name);
|
|
|
|
});
|
|
|
|
standardReport[standardStats.id] = standardStats;
|
|
|
|
});
|
|
|
|
|
|
|
|
return standardReport;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
var successCallbackWrapper = function(response) {
|
|
|
|
args[1](fixChromeStats(response));
|
|
|
|
};
|
|
|
|
|
|
|
|
return origGetStats.apply(this, [successCallbackWrapper, arguments[0]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// promise-support
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
if (args.length === 1 && selector === null) {
|
|
|
|
origGetStats.apply(self, [
|
|
|
|
function(response) {
|
|
|
|
resolve.apply(null, [fixChromeStats(response)]);
|
|
|
|
}, reject]);
|
|
|
|
} else {
|
|
|
|
origGetStats.apply(self, [resolve, reject]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
};
|
|
|
|
|
|
|
|
// add promise support
|
|
|
|
['createOffer', 'createAnswer'].forEach(function(method) {
|
|
|
|
var nativeMethod = webkitRTCPeerConnection.prototype[method];
|
|
|
|
webkitRTCPeerConnection.prototype[method] = function() {
|
|
|
|
var self = this;
|
|
|
|
if (arguments.length < 1 || (arguments.length === 1 &&
|
|
|
|
typeof(arguments[0]) === 'object')) {
|
|
|
|
var opts = arguments.length === 1 ? arguments[0] : undefined;
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
nativeMethod.apply(self, [resolve, reject, opts]);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return nativeMethod.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
['setLocalDescription', 'setRemoteDescription',
|
|
|
|
'addIceCandidate'].forEach(function(method) {
|
|
|
|
var nativeMethod = webkitRTCPeerConnection.prototype[method];
|
|
|
|
webkitRTCPeerConnection.prototype[method] = function() {
|
|
|
|
var args = arguments;
|
|
|
|
var self = this;
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
nativeMethod.apply(self, [args[0],
|
|
|
|
function() {
|
|
|
|
resolve();
|
|
|
|
if (args.length >= 2) {
|
|
|
|
args[1].apply(null, []);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
reject(err);
|
|
|
|
if (args.length >= 3) {
|
|
|
|
args[2].apply(null, [err]);
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// getUserMedia constraints shim.
|
|
|
|
var constraintsToChrome = function(c) {
|
|
|
|
if (typeof c !== 'object' || c.mandatory || c.optional) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
var cc = {};
|
|
|
|
Object.keys(c).forEach(function(key) {
|
|
|
|
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]};
|
|
|
|
if (r.exact !== undefined && typeof r.exact === 'number') {
|
|
|
|
r.min = r.max = r.exact;
|
|
|
|
}
|
|
|
|
var oldname = function(prefix, name) {
|
|
|
|
if (prefix) {
|
|
|
|
return prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
|
|
}
|
|
|
|
return (name === 'deviceId') ? 'sourceId' : name;
|
|
|
|
};
|
|
|
|
if (r.ideal !== undefined) {
|
|
|
|
cc.optional = cc.optional || [];
|
|
|
|
var oc = {};
|
|
|
|
if (typeof r.ideal === 'number') {
|
|
|
|
oc[oldname('min', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
oc = {};
|
|
|
|
oc[oldname('max', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
} else {
|
|
|
|
oc[oldname('', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r.exact !== undefined && typeof r.exact !== 'number') {
|
|
|
|
cc.mandatory = cc.mandatory || {};
|
|
|
|
cc.mandatory[oldname('', key)] = r.exact;
|
|
|
|
} else {
|
|
|
|
['min', 'max'].forEach(function(mix) {
|
|
|
|
if (r[mix] !== undefined) {
|
|
|
|
cc.mandatory = cc.mandatory || {};
|
|
|
|
cc.mandatory[oldname(mix, key)] = r[mix];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (c.advanced) {
|
|
|
|
cc.optional = (cc.optional || []).concat(c.advanced);
|
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
getUserMedia = function(constraints, onSuccess, onError) {
|
|
|
|
if (constraints.audio) {
|
|
|
|
constraints.audio = constraintsToChrome(constraints.audio);
|
|
|
|
}
|
|
|
|
if (constraints.video) {
|
|
|
|
constraints.video = constraintsToChrome(constraints.video);
|
|
|
|
}
|
|
|
|
webrtcUtils.log('chrome: ' + JSON.stringify(constraints));
|
|
|
|
return navigator.webkitGetUserMedia(constraints, onSuccess, onError);
|
|
|
|
};
|
|
|
|
navigator.getUserMedia = getUserMedia;
|
|
|
|
|
|
|
|
if (!navigator.mediaDevices) {
|
|
|
|
navigator.mediaDevices = {getUserMedia: requestUserMedia,
|
|
|
|
enumerateDevices: function() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
var kinds = {audio: 'audioinput', video: 'videoinput'};
|
|
|
|
return MediaStreamTrack.getSources(function(devices) {
|
|
|
|
resolve(devices.map(function(device) {
|
|
|
|
return {label: device.label,
|
|
|
|
kind: kinds[device.kind],
|
|
|
|
deviceId: device.id,
|
|
|
|
groupId: ''};
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
// A shim for getUserMedia method on the mediaDevices object.
|
|
|
|
// TODO(KaptenJansson) remove once implemented in Chrome stable.
|
|
|
|
if (!navigator.mediaDevices.getUserMedia) {
|
|
|
|
navigator.mediaDevices.getUserMedia = function(constraints) {
|
|
|
|
return requestUserMedia(constraints);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
|
|
|
|
// function which returns a Promise, it does not accept spec-style
|
|
|
|
// constraints.
|
|
|
|
var origGetUserMedia = navigator.mediaDevices.getUserMedia.
|
|
|
|
bind(navigator.mediaDevices);
|
|
|
|
navigator.mediaDevices.getUserMedia = function(c) {
|
|
|
|
webrtcUtils.log('spec: ' + JSON.stringify(c)); // whitespace for alignment
|
|
|
|
c.audio = constraintsToChrome(c.audio);
|
|
|
|
c.video = constraintsToChrome(c.video);
|
|
|
|
webrtcUtils.log('chrome: ' + JSON.stringify(c));
|
|
|
|
return origGetUserMedia(c);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dummy devicechange event methods.
|
|
|
|
// TODO(KaptenJansson) remove once implemented in Chrome stable.
|
|
|
|
if (typeof navigator.mediaDevices.addEventListener === 'undefined') {
|
|
|
|
navigator.mediaDevices.addEventListener = function() {
|
|
|
|
webrtcUtils.log('Dummy mediaDevices.addEventListener called.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (typeof navigator.mediaDevices.removeEventListener === 'undefined') {
|
|
|
|
navigator.mediaDevices.removeEventListener = function() {
|
|
|
|
webrtcUtils.log('Dummy mediaDevices.removeEventListener called.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach a media stream to an element.
|
|
|
|
attachMediaStream = function(element, stream) {
|
|
|
|
if (webrtcDetectedVersion >= 43) {
|
|
|
|
element.srcObject = stream;
|
|
|
|
} else if (typeof element.src !== 'undefined') {
|
|
|
|
element.src = URL.createObjectURL(stream);
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log('Error attaching stream to element.');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
reattachMediaStream = function(to, from) {
|
|
|
|
if (webrtcDetectedVersion >= 43) {
|
|
|
|
to.srcObject = from.srcObject;
|
|
|
|
} else {
|
|
|
|
to.src = from.src;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} else if (navigator.mediaDevices && navigator.userAgent.match(
|
|
|
|
/Edge\/(\d+).(\d+)$/)) {
|
|
|
|
webrtcUtils.log('This appears to be Edge');
|
|
|
|
webrtcDetectedBrowser = 'edge';
|
|
|
|
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10);
|
|
|
|
|
|
|
|
// the minimum version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 12;
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log('Browser does not appear to be WebRTC-capable');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the result of getUserMedia as a Promise.
|
|
|
|
function requestUserMedia(constraints) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
getUserMedia(constraints, resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var webrtcTesting = {};
|
|
|
|
Object.defineProperty(webrtcTesting, 'version', {
|
|
|
|
set: function(version) {
|
|
|
|
webrtcDetectedVersion = version;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
var RTCPeerConnection;
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
RTCPeerConnection = window.RTCPeerConnection;
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
|
|
RTCPeerConnection: RTCPeerConnection,
|
|
|
|
getUserMedia: getUserMedia,
|
|
|
|
attachMediaStream: attachMediaStream,
|
|
|
|
reattachMediaStream: reattachMediaStream,
|
|
|
|
webrtcDetectedBrowser: webrtcDetectedBrowser,
|
|
|
|
webrtcDetectedVersion: webrtcDetectedVersion,
|
|
|
|
webrtcMinimumVersion: webrtcMinimumVersion,
|
|
|
|
webrtcTesting: webrtcTesting
|
|
|
|
//requestUserMedia: not exposed on purpose.
|
|
|
|
//trace: not exposed on purpose.
|
|
|
|
};
|
|
|
|
} else if ((typeof require === 'function') && (typeof define === 'function')) {
|
|
|
|
// Expose objects and functions when RequireJS is doing the loading.
|
|
|
|
define([], function() {
|
|
|
|
return {
|
|
|
|
RTCPeerConnection: window.RTCPeerConnection,
|
|
|
|
getUserMedia: getUserMedia,
|
|
|
|
attachMediaStream: attachMediaStream,
|
|
|
|
reattachMediaStream: reattachMediaStream,
|
|
|
|
webrtcDetectedBrowser: webrtcDetectedBrowser,
|
|
|
|
webrtcDetectedVersion: webrtcDetectedVersion,
|
|
|
|
webrtcMinimumVersion: webrtcMinimumVersion,
|
|
|
|
webrtcTesting: webrtcTesting
|
|
|
|
//requestUserMedia: not exposed on purpose.
|
|
|
|
//trace: not exposed on purpose.
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
},{}],15:[function(require,module,exports){
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Sender.prototype.send = function (file, channel) {
|
|
|
|
var self = this;
|
|
|
|
this.file = file;
|
|
|
|
this.channel = channel;
|
|
|
|
var sliceFile = function(offset) {
|
|
|
|
var reader = new window.FileReader();
|
|
|
|
reader.onload = (function() {
|
|
|
|
return function(e) {
|
|
|
|
self.channel.send(e.target.result);
|
|
|
|
self.emit('progress', offset, file.size, e.target.result);
|
|
|
|
if (file.size > offset + e.target.result.byteLength) {
|
|
|
|
window.setTimeout(sliceFile, self.config.pacing, offset + self.config.chunksize);
|
|
|
|
} else {
|
|
|
|
self.emit('progress', file.size, file.size, null);
|
|
|
|
self.emit('sentFile');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(file);
|
|
|
|
var slice = file.slice(offset, offset + self.config.chunksize);
|
|
|
|
reader.readAsArrayBuffer(slice);
|
|
|
|
};
|
|
|
|
window.setTimeout(sliceFile, 0, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
function Receiver() {
|
|
|
|
WildEmitter.call(this);
|
|
|
|
|
|
|
|
this.receiveBuffer = [];
|
|
|
|
this.received = 0;
|
|
|
|
this.metadata = {};
|
|
|
|
this.channel = null;
|
|
|
|
}
|
|
|
|
util.inherits(Receiver, WildEmitter);
|
|
|
|
|
|
|
|
Receiver.prototype.receive = function (metadata, channel) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (metadata) {
|
|
|
|
this.metadata = metadata;
|
|
|
|
}
|
|
|
|
this.channel = channel;
|
|
|
|
// chrome only supports arraybuffers and those make it easier to calc the hash
|
|
|
|
channel.binaryType = 'arraybuffer';
|
|
|
|
this.channel.onmessage = function (event) {
|
|
|
|
var len = event.data.byteLength;
|
|
|
|
self.received += len;
|
|
|
|
self.receiveBuffer.push(event.data);
|
|
|
|
|
|
|
|
self.emit('progress', self.received, self.metadata.size, event.data);
|
|
|
|
if (self.received === self.metadata.size) {
|
|
|
|
self.emit('receivedFile', new window.Blob(self.receiveBuffer), self.metadata);
|
|
|
|
self.receiveBuffer = []; // discard receivebuffer
|
|
|
|
} else if (self.received > self.metadata.size) {
|
|
|
|
// FIXME
|
|
|
|
console.error('received more than expected, discarding...');
|
|
|
|
self.receiveBuffer = []; // just discard...
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {};
|
|
|
|
module.exports.support = typeof window !== 'undefined' && window && window.File && window.FileReader && window.Blob;
|
|
|
|
module.exports.Sender = Sender;
|
|
|
|
module.exports.Receiver = Receiver;
|
|
|
|
|
|
|
|
},{"util":8,"wildemitter":4}],14:[function(require,module,exports){
|
|
|
|
var util = require('util');
|
|
|
|
var each = require('lodash.foreach');
|
|
|
|
var pluck = require('lodash.pluck');
|
|
|
|
var SJJ = require('sdp-jingle-json');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
var peerconn = require('traceablepeerconnection');
|
|
|
|
var adapter = require('webrtc-adapter-test');
|
|
|
|
|
|
|
|
function PeerConnection(config, constraints) {
|
|
|
|
var self = this;
|
|
|
|
var item;
|
|
|
|
WildEmitter.call(this);
|
|
|
|
|
|
|
|
config = config || {};
|
|
|
|
config.iceServers = config.iceServers || [];
|
|
|
|
|
|
|
|
// make sure this only gets enabled in Google Chrome
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
this.enableChromeNativeSimulcast = false;
|
|
|
|
if (constraints && constraints.optional &&
|
|
|
|
adapter.webrtcDetectedBrowser === 'chrome' &&
|
|
|
|
navigator.appVersion.match(/Chromium\//) === null) {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.enableChromeNativeSimulcast) {
|
|
|
|
self.enableChromeNativeSimulcast = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
this.enableMultiStreamHacks = false;
|
|
|
|
if (constraints && constraints.optional &&
|
|
|
|
adapter.webrtcDetectedBrowser === 'chrome') {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.enableMultiStreamHacks) {
|
|
|
|
self.enableMultiStreamHacks = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
this.restrictBandwidth = 0;
|
|
|
|
if (constraints && constraints.optional) {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetRestrictBandwidth) {
|
|
|
|
self.restrictBandwidth = constraint.andyetRestrictBandwidth;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
// bundle up ice candidates, only works for jingle mode
|
|
|
|
// number > 0 is the delay to wait for additional candidates
|
|
|
|
// ~20ms seems good
|
|
|
|
this.batchIceCandidates = 0;
|
|
|
|
if (constraints && constraints.optional) {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetBatchIce) {
|
|
|
|
self.batchIceCandidates = constraint.andyetBatchIce;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.batchedIceCandidates = [];
|
|
|
|
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
// this attemps to strip out candidates with an already known foundation
|
|
|
|
// and type -- i.e. those which are gathered via the same TURN server
|
|
|
|
// but different transports (TURN udp, tcp and tls respectively)
|
|
|
|
if (constraints && constraints.optional && adapter.webrtcDetectedBrowser === 'chrome') {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetFasterICE) {
|
|
|
|
self.eliminateDuplicateCandidates = constraint.andyetFasterICE;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
// when using a server such as the jitsi videobridge we don't need to signal
|
|
|
|
// our candidates
|
|
|
|
if (constraints && constraints.optional) {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetDontSignalCandidates) {
|
|
|
|
self.dontSignalCandidates = constraint.andyetDontSignalCandidates;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
this.assumeSetLocalSuccess = false;
|
|
|
|
if (constraints && constraints.optional) {
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetAssumeSetLocalSuccess) {
|
|
|
|
self.assumeSetLocalSuccess = constraint.andyetAssumeSetLocalSuccess;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXPERIMENTAL FLAG, might get removed without notice
|
|
|
|
// working around https://bugzilla.mozilla.org/show_bug.cgi?id=1087551
|
|
|
|
// pass in a timeout for this
|
|
|
|
if (adapter.webrtcDetectedBrowser === 'firefox') {
|
|
|
|
if (constraints && constraints.optional) {
|
|
|
|
this.wtFirefox = 0;
|
|
|
|
constraints.optional.forEach(function (constraint) {
|
|
|
|
if (constraint.andyetFirefoxMakesMeSad) {
|
|
|
|
self.wtFirefox = constraint.andyetFirefoxMakesMeSad;
|
|
|
|
if (self.wtFirefox > 0) {
|
|
|
|
self.firefoxcandidatebuffer = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.pc = new peerconn(config, constraints);
|
|
|
|
|
|
|
|
this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc);
|
|
|
|
this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc);
|
|
|
|
this.addStream = this.pc.addStream.bind(this.pc);
|
|
|
|
this.removeStream = this.pc.removeStream.bind(this.pc);
|
|
|
|
|
|
|
|
// proxy events
|
|
|
|
this.pc.on('*', function () {
|
|
|
|
self.emit.apply(self, arguments);
|
|
|
|
});
|
|
|
|
|
|
|
|
// proxy some events directly
|
|
|
|
this.pc.onremovestream = this.emit.bind(this, 'removeStream');
|
|
|
|
this.pc.onaddstream = this.emit.bind(this, 'addStream');
|
|
|
|
this.pc.onnegotiationneeded = this.emit.bind(this, 'negotiationNeeded');
|
|
|
|
this.pc.oniceconnectionstatechange = this.emit.bind(this, 'iceConnectionStateChange');
|
|
|
|
this.pc.onsignalingstatechange = this.emit.bind(this, 'signalingStateChange');
|
|
|
|
|
|
|
|
// handle ice candidate and data channel events
|
|
|
|
this.pc.onicecandidate = this._onIce.bind(this);
|
|
|
|
this.pc.ondatachannel = this._onDataChannel.bind(this);
|
|
|
|
|
|
|
|
this.localDescription = {
|
|
|
|
contents: []
|
|
|
|
};
|
|
|
|
this.remoteDescription = {
|
|
|
|
contents: []
|
|
|
|
};
|
|
|
|
|
|
|
|
this.config = {
|
|
|
|
debug: false,
|
|
|
|
ice: {},
|
|
|
|
sid: '',
|
|
|
|
isInitiator: true,
|
|
|
|
sdpSessionID: Date.now(),
|
|
|
|
useJingle: false
|
|
|
|
};
|
|
|
|
|
|
|
|
// apply our config
|
|
|
|
for (item in config) {
|
|
|
|
this.config[item] = config[item];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.config.debug) {
|
|
|
|
this.on('*', function () {
|
|
|
|
var logger = config.logger || console;
|
|
|
|
logger.log('PeerConnection event:', arguments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.hadLocalStunCandidate = false;
|
|
|
|
this.hadRemoteStunCandidate = false;
|
|
|
|
this.hadLocalRelayCandidate = false;
|
|
|
|
this.hadRemoteRelayCandidate = false;
|
|
|
|
|
|
|
|
this.hadLocalIPv6Candidate = false;
|
|
|
|
this.hadRemoteIPv6Candidate = false;
|
|
|
|
|
|
|
|
// keeping references for all our data channels
|
|
|
|
// so they dont get garbage collected
|
|
|
|
// can be removed once the following bugs have been fixed
|
|
|
|
// https://crbug.com/405545
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=964092
|
|
|
|
// to be filed for opera
|
|
|
|
this._remoteDataChannels = [];
|
|
|
|
this._localDataChannels = [];
|
|
|
|
|
|
|
|
this._candidateBuffer = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(PeerConnection, WildEmitter);
|
|
|
|
|
|
|
|
Object.defineProperty(PeerConnection.prototype, 'signalingState', {
|
|
|
|
get: function () {
|
|
|
|
return this.pc.signalingState;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.defineProperty(PeerConnection.prototype, 'iceConnectionState', {
|
|
|
|
get: function () {
|
|
|
|
return this.pc.iceConnectionState;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
PeerConnection.prototype._role = function () {
|
|
|
|
return this.isInitiator ? 'initiator' : 'responder';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add a stream to the peer connection object
|
|
|
|
PeerConnection.prototype.addStream = function (stream) {
|
|
|
|
this.localStream = stream;
|
|
|
|
this.pc.addStream(stream);
|
|
|
|
};
|
|
|
|
|
|
|
|
// helper function to check if a remote candidate is a stun/relay
|
|
|
|
// candidate or an ipv6 candidate
|
|
|
|
PeerConnection.prototype._checkLocalCandidate = function (candidate) {
|
|
|
|
var cand = SJJ.toCandidateJSON(candidate);
|
|
|
|
if (cand.type == 'srflx') {
|
|
|
|
this.hadLocalStunCandidate = true;
|
|
|
|
} else if (cand.type == 'relay') {
|
|
|
|
this.hadLocalRelayCandidate = true;
|
|
|
|
}
|
|
|
|
if (cand.ip.indexOf(':') != -1) {
|
|
|
|
this.hadLocalIPv6Candidate = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// helper function to check if a remote candidate is a stun/relay
|
|
|
|
// candidate or an ipv6 candidate
|
|
|
|
PeerConnection.prototype._checkRemoteCandidate = function (candidate) {
|
|
|
|
var cand = SJJ.toCandidateJSON(candidate);
|
|
|
|
if (cand.type == 'srflx') {
|
|
|
|
this.hadRemoteStunCandidate = true;
|
|
|
|
} else if (cand.type == 'relay') {
|
|
|
|
this.hadRemoteRelayCandidate = true;
|
|
|
|
}
|
|
|
|
if (cand.ip.indexOf(':') != -1) {
|
|
|
|
this.hadRemoteIPv6Candidate = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Init and add ice candidate object with correct constructor
|
|
|
|
PeerConnection.prototype.processIce = function (update, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// ignore any added ice candidates to avoid errors. why does the
|
|
|
|
// spec not do this?
|
|
|
|
if (this.pc.signalingState === 'closed') return cb();
|
|
|
|
|
|
|
|
if (update.contents || (update.jingle && update.jingle.contents)) {
|
|
|
|
var contentNames = pluck(this.remoteDescription.contents, 'name');
|
|
|
|
var contents = update.contents || update.jingle.contents;
|
|
|
|
|
|
|
|
contents.forEach(function (content) {
|
|
|
|
var transport = content.transport || {};
|
|
|
|
var candidates = transport.candidates || [];
|
|
|
|
var mline = contentNames.indexOf(content.name);
|
|
|
|
var mid = content.name;
|
|
|
|
|
|
|
|
candidates.forEach(
|
|
|
|
function (candidate) {
|
|
|
|
var iceCandidate = SJJ.toCandidateSDP(candidate) + '\r\n';
|
|
|
|
self.pc.addIceCandidate(
|
|
|
|
new RTCIceCandidate({
|
|
|
|
candidate: iceCandidate,
|
|
|
|
sdpMLineIndex: mline,
|
|
|
|
sdpMid: mid
|
|
|
|
}), function () {
|
|
|
|
// well, this success callback is pretty meaningless
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
self._checkRemoteCandidate(iceCandidate);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// working around https://code.google.com/p/webrtc/issues/detail?id=3669
|
|
|
|
if (update.candidate && update.candidate.candidate.indexOf('a=') !== 0) {
|
|
|
|
update.candidate.candidate = 'a=' + update.candidate.candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.wtFirefox && this.firefoxcandidatebuffer !== null) {
|
|
|
|
// we cant add this yet due to https://bugzilla.mozilla.org/show_bug.cgi?id=1087551
|
|
|
|
if (this.pc.localDescription && this.pc.localDescription.type === 'offer') {
|
|
|
|
this.firefoxcandidatebuffer.push(update.candidate);
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.pc.addIceCandidate(
|
|
|
|
new RTCIceCandidate(update.candidate),
|
|
|
|
function () { },
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
self._checkRemoteCandidate(update.candidate.candidate);
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate and emit an offer with the given constraints
|
|
|
|
PeerConnection.prototype.offer = function (constraints, cb) {
|
|
|
|
var self = this;
|
|
|
|
var hasConstraints = arguments.length === 2;
|
|
|
|
var mediaConstraints = hasConstraints && constraints ? constraints : {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: true,
|
|
|
|
OfferToReceiveVideo: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cb = hasConstraints ? cb : constraints;
|
|
|
|
cb = cb || function () {};
|
|
|
|
|
|
|
|
if (this.pc.signalingState === 'closed') return cb('Already closed');
|
|
|
|
|
|
|
|
// Actually generate the offer
|
|
|
|
this.pc.createOffer(
|
|
|
|
function (offer) {
|
|
|
|
// does not work for jingle, but jingle.js doesn't need
|
|
|
|
// this hack...
|
|
|
|
var expandedOffer = {
|
|
|
|
type: 'offer',
|
|
|
|
sdp: offer.sdp
|
|
|
|
};
|
|
|
|
if (self.assumeSetLocalSuccess) {
|
|
|
|
self.emit('offer', expandedOffer);
|
|
|
|
cb(null, expandedOffer);
|
|
|
|
}
|
|
|
|
self._candidateBuffer = [];
|
|
|
|
self.pc.setLocalDescription(offer,
|
|
|
|
function () {
|
|
|
|
var jingle;
|
|
|
|
if (self.config.useJingle) {
|
|
|
|
jingle = SJJ.toSessionJSON(offer.sdp, {
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
jingle.sid = self.config.sid;
|
|
|
|
self.localDescription = jingle;
|
|
|
|
|
|
|
|
// Save ICE credentials
|
|
|
|
each(jingle.contents, function (content) {
|
|
|
|
var transport = content.transport || {};
|
|
|
|
if (transport.ufrag) {
|
|
|
|
self.config.ice[content.name] = {
|
|
|
|
ufrag: transport.ufrag,
|
|
|
|
pwd: transport.pwd
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expandedOffer.jingle = jingle;
|
|
|
|
}
|
|
|
|
expandedOffer.sdp.split('\r\n').forEach(function (line) {
|
|
|
|
if (line.indexOf('a=candidate:') === 0) {
|
|
|
|
self._checkLocalCandidate(line);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!self.assumeSetLocalSuccess) {
|
|
|
|
self.emit('offer', expandedOffer);
|
|
|
|
cb(null, expandedOffer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
cb(err);
|
|
|
|
},
|
|
|
|
mediaConstraints
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Process an incoming offer so that ICE may proceed before deciding
|
|
|
|
// to answer the request.
|
|
|
|
PeerConnection.prototype.handleOffer = function (offer, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
var self = this;
|
|
|
|
offer.type = 'offer';
|
|
|
|
if (offer.jingle) {
|
|
|
|
if (this.enableChromeNativeSimulcast) {
|
|
|
|
offer.jingle.contents.forEach(function (content) {
|
|
|
|
if (content.name === 'video') {
|
|
|
|
content.description.googConferenceFlag = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.enableMultiStreamHacks) {
|
|
|
|
// add a mixed video stream as first stream
|
|
|
|
offer.jingle.contents.forEach(function (content) {
|
|
|
|
if (content.name === 'video') {
|
|
|
|
var sources = content.description.sources || [];
|
|
|
|
if (sources.length === 0 || sources[0].ssrc !== "3735928559") {
|
|
|
|
sources.unshift({
|
|
|
|
ssrc: "3735928559", // 0xdeadbeef
|
|
|
|
parameters: [
|
|
|
|
{
|
|
|
|
key: "cname",
|
|
|
|
value: "deadbeef"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "msid",
|
|
|
|
value: "mixyourfecintothis please"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
content.description.sources = sources;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (self.restrictBandwidth > 0) {
|
|
|
|
if (offer.jingle.contents.length >= 2 && offer.jingle.contents[1].name === 'video') {
|
|
|
|
var content = offer.jingle.contents[1];
|
|
|
|
var hasBw = content.description && content.description.bandwidth;
|
|
|
|
if (!hasBw) {
|
|
|
|
offer.jingle.contents[1].description.bandwidth = { type: 'AS', bandwidth: self.restrictBandwidth.toString() };
|
|
|
|
offer.sdp = SJJ.toSessionSDP(offer.jingle, {
|
|
|
|
sid: self.config.sdpSessionID,
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offer.sdp = SJJ.toSessionSDP(offer.jingle, {
|
|
|
|
sid: self.config.sdpSessionID,
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
self.remoteDescription = offer.jingle;
|
|
|
|
}
|
|
|
|
offer.sdp.split('\r\n').forEach(function (line) {
|
|
|
|
if (line.indexOf('a=candidate:') === 0) {
|
|
|
|
self._checkRemoteCandidate(line);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.pc.setRemoteDescription(new RTCSessionDescription(offer),
|
|
|
|
function () {
|
|
|
|
cb();
|
|
|
|
},
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Answer an offer with audio only
|
|
|
|
PeerConnection.prototype.answerAudioOnly = function (cb) {
|
|
|
|
var mediaConstraints = {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: true,
|
|
|
|
OfferToReceiveVideo: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this._answer(mediaConstraints, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Answer an offer without offering to recieve
|
|
|
|
PeerConnection.prototype.answerBroadcastOnly = function (cb) {
|
|
|
|
var mediaConstraints = {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: false,
|
|
|
|
OfferToReceiveVideo: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this._answer(mediaConstraints, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Answer an offer with given constraints default is audio/video
|
|
|
|
PeerConnection.prototype.answer = function (constraints, cb) {
|
|
|
|
var hasConstraints = arguments.length === 2;
|
|
|
|
var callback = hasConstraints ? cb : constraints;
|
|
|
|
var mediaConstraints = hasConstraints && constraints ? constraints : {
|
|
|
|
mandatory: {
|
|
|
|
OfferToReceiveAudio: true,
|
|
|
|
OfferToReceiveVideo: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this._answer(mediaConstraints, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Process an answer
|
|
|
|
PeerConnection.prototype.handleAnswer = function (answer, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
var self = this;
|
|
|
|
if (answer.jingle) {
|
|
|
|
answer.sdp = SJJ.toSessionSDP(answer.jingle, {
|
|
|
|
sid: self.config.sdpSessionID,
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
self.remoteDescription = answer.jingle;
|
|
|
|
}
|
|
|
|
answer.sdp.split('\r\n').forEach(function (line) {
|
|
|
|
if (line.indexOf('a=candidate:') === 0) {
|
|
|
|
self._checkRemoteCandidate(line);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.pc.setRemoteDescription(
|
|
|
|
new RTCSessionDescription(answer),
|
|
|
|
function () {
|
|
|
|
if (self.wtFirefox) {
|
|
|
|
window.setTimeout(function () {
|
|
|
|
self.firefoxcandidatebuffer.forEach(function (candidate) {
|
|
|
|
// add candidates later
|
|
|
|
self.pc.addIceCandidate(
|
|
|
|
new RTCIceCandidate(candidate),
|
|
|
|
function () { },
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
self._checkRemoteCandidate(candidate.candidate);
|
|
|
|
});
|
|
|
|
self.firefoxcandidatebuffer = null;
|
|
|
|
}, self.wtFirefox);
|
|
|
|
}
|
|
|
|
cb(null);
|
|
|
|
},
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Close the peer connection
|
|
|
|
PeerConnection.prototype.close = function () {
|
|
|
|
this.pc.close();
|
|
|
|
|
|
|
|
this._localDataChannels = [];
|
|
|
|
this._remoteDataChannels = [];
|
|
|
|
|
|
|
|
this.emit('close');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal code sharing for various types of answer methods
|
|
|
|
PeerConnection.prototype._answer = function (constraints, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
var self = this;
|
|
|
|
if (!this.pc.remoteDescription) {
|
|
|
|
// the old API is used, call handleOffer
|
|
|
|
throw new Error('remoteDescription not set');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.pc.signalingState === 'closed') return cb('Already closed');
|
|
|
|
|
|
|
|
self.pc.createAnswer(
|
|
|
|
function (answer) {
|
|
|
|
var sim = [];
|
|
|
|
if (self.enableChromeNativeSimulcast) {
|
|
|
|
// native simulcast part 1: add another SSRC
|
|
|
|
answer.jingle = SJJ.toSessionJSON(answer.sdp, {
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
if (answer.jingle.contents.length >= 2 && answer.jingle.contents[1].name === 'video') {
|
|
|
|
var groups = answer.jingle.contents[1].description.sourceGroups || [];
|
|
|
|
var hasSim = false;
|
|
|
|
groups.forEach(function (group) {
|
|
|
|
if (group.semantics == 'SIM') hasSim = true;
|
|
|
|
});
|
|
|
|
if (!hasSim &&
|
|
|
|
answer.jingle.contents[1].description.sources.length) {
|
|
|
|
var newssrc = JSON.parse(JSON.stringify(answer.jingle.contents[1].description.sources[0]));
|
|
|
|
newssrc.ssrc = '' + Math.floor(Math.random() * 0xffffffff); // FIXME: look for conflicts
|
|
|
|
answer.jingle.contents[1].description.sources.push(newssrc);
|
|
|
|
|
|
|
|
sim.push(answer.jingle.contents[1].description.sources[0].ssrc);
|
|
|
|
sim.push(newssrc.ssrc);
|
|
|
|
groups.push({
|
|
|
|
semantics: 'SIM',
|
|
|
|
sources: sim
|
|
|
|
});
|
|
|
|
|
|
|
|
// also create an RTX one for the SIM one
|
|
|
|
var rtxssrc = JSON.parse(JSON.stringify(newssrc));
|
|
|
|
rtxssrc.ssrc = '' + Math.floor(Math.random() * 0xffffffff); // FIXME: look for conflicts
|
|
|
|
answer.jingle.contents[1].description.sources.push(rtxssrc);
|
|
|
|
groups.push({
|
|
|
|
semantics: 'FID',
|
|
|
|
sources: [newssrc.ssrc, rtxssrc.ssrc]
|
|
|
|
});
|
|
|
|
|
|
|
|
answer.jingle.contents[1].description.sourceGroups = groups;
|
|
|
|
answer.sdp = SJJ.toSessionSDP(answer.jingle, {
|
|
|
|
sid: self.config.sdpSessionID,
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var expandedAnswer = {
|
|
|
|
type: 'answer',
|
|
|
|
sdp: answer.sdp
|
|
|
|
};
|
|
|
|
if (self.assumeSetLocalSuccess) {
|
|
|
|
// not safe to do when doing simulcast mangling
|
|
|
|
self.emit('answer', expandedAnswer);
|
|
|
|
cb(null, expandedAnswer);
|
|
|
|
}
|
|
|
|
self._candidateBuffer = [];
|
|
|
|
self.pc.setLocalDescription(answer,
|
|
|
|
function () {
|
|
|
|
if (self.config.useJingle) {
|
|
|
|
var jingle = SJJ.toSessionJSON(answer.sdp, {
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
jingle.sid = self.config.sid;
|
|
|
|
self.localDescription = jingle;
|
|
|
|
expandedAnswer.jingle = jingle;
|
|
|
|
}
|
|
|
|
if (self.enableChromeNativeSimulcast) {
|
|
|
|
// native simulcast part 2:
|
|
|
|
// signal multiple tracks to the receiver
|
|
|
|
// for anything in the SIM group
|
|
|
|
if (!expandedAnswer.jingle) {
|
|
|
|
expandedAnswer.jingle = SJJ.toSessionJSON(answer.sdp, {
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
expandedAnswer.jingle.contents[1].description.sources.forEach(function (source, idx) {
|
|
|
|
// the floor idx/2 is a hack that relies on a particular order
|
|
|
|
// of groups, alternating between sim and rtx
|
|
|
|
source.parameters = source.parameters.map(function (parameter) {
|
|
|
|
if (parameter.key === 'msid') {
|
|
|
|
parameter.value += '-' + Math.floor(idx / 2);
|
|
|
|
}
|
|
|
|
return parameter;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
expandedAnswer.sdp = SJJ.toSessionSDP(expandedAnswer.jingle, {
|
|
|
|
sid: self.sdpSessionID,
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
expandedAnswer.sdp.split('\r\n').forEach(function (line) {
|
|
|
|
if (line.indexOf('a=candidate:') === 0) {
|
|
|
|
self._checkLocalCandidate(line);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!self.assumeSetLocalSuccess) {
|
|
|
|
self.emit('answer', expandedAnswer);
|
|
|
|
cb(null, expandedAnswer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
cb(err);
|
|
|
|
},
|
|
|
|
constraints
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal method for emitting ice candidates on our peer object
|
|
|
|
PeerConnection.prototype._onIce = function (event) {
|
|
|
|
var self = this;
|
|
|
|
if (event.candidate) {
|
|
|
|
if (this.dontSignalCandidates) return;
|
|
|
|
var ice = event.candidate;
|
|
|
|
|
|
|
|
var expandedCandidate = {
|
|
|
|
candidate: {
|
|
|
|
candidate: ice.candidate,
|
|
|
|
sdpMid: ice.sdpMid,
|
|
|
|
sdpMLineIndex: ice.sdpMLineIndex
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this._checkLocalCandidate(ice.candidate);
|
|
|
|
|
|
|
|
var cand = SJJ.toCandidateJSON(ice.candidate);
|
|
|
|
|
|
|
|
var already;
|
|
|
|
var idx;
|
|
|
|
if (this.eliminateDuplicateCandidates && cand.type === 'relay') {
|
|
|
|
// drop candidates with same foundation, component
|
|
|
|
// take local type pref into account so we don't ignore udp
|
|
|
|
// ones when we know about a TCP one. unlikely but...
|
|
|
|
already = this._candidateBuffer.filter(
|
|
|
|
function (c) {
|
|
|
|
return c.type === 'relay';
|
|
|
|
}).map(function (c) {
|
|
|
|
return c.foundation + ':' + c.component;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
idx = already.indexOf(cand.foundation + ':' + cand.component);
|
|
|
|
// remember: local type pref of udp is 0, tcp 1, tls 2
|
|
|
|
if (idx > -1 && ((cand.priority >> 24) >= (already[idx].priority >> 24))) {
|
|
|
|
// drop it, same foundation with higher (worse) type pref
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.config.bundlePolicy === 'max-bundle') {
|
|
|
|
// drop candidates which are duplicate for audio/video/data
|
|
|
|
// duplicate means same host/port but different sdpMid
|
|
|
|
already = this._candidateBuffer.filter(
|
|
|
|
function (c) {
|
|
|
|
return cand.type === c.type;
|
|
|
|
}).map(function (cand) {
|
|
|
|
return cand.address + ':' + cand.port;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
idx = already.indexOf(cand.address + ':' + cand.port);
|
|
|
|
if (idx > -1) return;
|
|
|
|
}
|
|
|
|
// also drop rtcp candidates since we know the peer supports RTCP-MUX
|
|
|
|
// this is a workaround until browsers implement this natively
|
|
|
|
if (this.config.rtcpMuxPolicy === 'require' && cand.component === '2') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._candidateBuffer.push(cand);
|
|
|
|
|
|
|
|
if (self.config.useJingle) {
|
|
|
|
if (!ice.sdpMid) { // firefox doesn't set this
|
|
|
|
if (self.pc.remoteDescription && self.pc.remoteDescription.type === 'offer') {
|
|
|
|
// preserve name from remote
|
|
|
|
ice.sdpMid = self.remoteDescription.contents[ice.sdpMLineIndex].name;
|
|
|
|
} else {
|
|
|
|
ice.sdpMid = self.localDescription.contents[ice.sdpMLineIndex].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!self.config.ice[ice.sdpMid]) {
|
|
|
|
var jingle = SJJ.toSessionJSON(self.pc.localDescription.sdp, {
|
|
|
|
role: self._role(),
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
each(jingle.contents, function (content) {
|
|
|
|
var transport = content.transport || {};
|
|
|
|
if (transport.ufrag) {
|
|
|
|
self.config.ice[content.name] = {
|
|
|
|
ufrag: transport.ufrag,
|
|
|
|
pwd: transport.pwd
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
expandedCandidate.jingle = {
|
|
|
|
contents: [{
|
|
|
|
name: ice.sdpMid,
|
|
|
|
creator: self._role(),
|
|
|
|
transport: {
|
|
|
|
transType: 'iceUdp',
|
|
|
|
ufrag: self.config.ice[ice.sdpMid].ufrag,
|
|
|
|
pwd: self.config.ice[ice.sdpMid].pwd,
|
|
|
|
candidates: [
|
|
|
|
cand
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
if (self.batchIceCandidates > 0) {
|
|
|
|
if (self.batchedIceCandidates.length === 0) {
|
|
|
|
window.setTimeout(function () {
|
|
|
|
var contents = {};
|
|
|
|
self.batchedIceCandidates.forEach(function (content) {
|
|
|
|
content = content.contents[0];
|
|
|
|
if (!contents[content.name]) contents[content.name] = content;
|
|
|
|
contents[content.name].transport.candidates.push(content.transport.candidates[0]);
|
|
|
|
});
|
|
|
|
var newCand = {
|
|
|
|
jingle: {
|
|
|
|
contents: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Object.keys(contents).forEach(function (name) {
|
|
|
|
newCand.jingle.contents.push(contents[name]);
|
|
|
|
});
|
|
|
|
self.batchedIceCandidates = [];
|
|
|
|
self.emit('ice', newCand);
|
|
|
|
}, self.batchIceCandidates);
|
|
|
|
}
|
|
|
|
self.batchedIceCandidates.push(expandedCandidate.jingle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
this.emit('ice', expandedCandidate);
|
|
|
|
} else {
|
|
|
|
this.emit('endOfCandidates');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal method for processing a new data channel being added by the
|
|
|
|
// other peer.
|
|
|
|
PeerConnection.prototype._onDataChannel = function (event) {
|
|
|
|
// make sure we keep a reference so this doesn't get garbage collected
|
|
|
|
var channel = event.channel;
|
|
|
|
this._remoteDataChannels.push(channel);
|
|
|
|
|
|
|
|
this.emit('addChannel', channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a data channel spec reference:
|
|
|
|
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCDataChannelInit
|
|
|
|
PeerConnection.prototype.createDataChannel = function (name, opts) {
|
|
|
|
var channel = this.pc.createDataChannel(name, opts);
|
|
|
|
|
|
|
|
// make sure we keep a reference so this doesn't get garbage collected
|
|
|
|
this._localDataChannels.push(channel);
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a wrapper around getStats which hides the differences (where possible)
|
|
|
|
// TODO: remove in favor of adapter.js shim
|
|
|
|
PeerConnection.prototype.getStats = function (cb) {
|
|
|
|
if (adapter.webrtcDetectedBrowser === 'firefox') {
|
|
|
|
this.pc.getStats(
|
|
|
|
function (res) {
|
|
|
|
var items = [];
|
|
|
|
for (var result in res) {
|
|
|
|
if (typeof res[result] === 'object') {
|
|
|
|
items.push(res[result]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cb(null, items);
|
|
|
|
},
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.pc.getStats(function (res) {
|
|
|
|
var items = [];
|
|
|
|
res.result().forEach(function (result) {
|
|
|
|
var item = {};
|
|
|
|
result.names().forEach(function (name) {
|
|
|
|
item[name] = result.stat(name);
|
|
|
|
});
|
|
|
|
item.id = result.id;
|
|
|
|
item.type = result.type;
|
|
|
|
item.timestamp = result.timestamp;
|
|
|
|
items.push(item);
|
|
|
|
});
|
|
|
|
cb(null, items);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PeerConnection;
|
|
|
|
|
|
|
|
},{"lodash.foreach":23,"lodash.pluck":24,"sdp-jingle-json":21,"traceablepeerconnection":22,"util":8,"webrtc-adapter-test":20,"wildemitter":4}],16:[function(require,module,exports){
|
|
|
|
// getUserMedia helper by @HenrikJoreteg
|
|
|
|
var adapter = require('webrtc-adapter-test');
|
|
|
|
|
|
|
|
module.exports = function (constraints, cb) {
|
|
|
|
var options, error;
|
|
|
|
var haveOpts = arguments.length === 2;
|
|
|
|
var defaultOpts = {video: true, audio: true};
|
|
|
|
|
|
|
|
var denied = 'PermissionDeniedError';
|
|
|
|
var altDenied = 'PERMISSION_DENIED';
|
|
|
|
var notSatisfied = 'ConstraintNotSatisfiedError';
|
|
|
|
|
|
|
|
// make constraints optional
|
|
|
|
if (!haveOpts) {
|
|
|
|
cb = constraints;
|
|
|
|
constraints = defaultOpts;
|
|
|
|
}
|
|
|
|
|
|
|
|
// treat lack of browser support like an error
|
|
|
|
if (!navigator.getUserMedia) {
|
|
|
|
// throw proper error per spec
|
|
|
|
error = new Error('MediaStreamError');
|
|
|
|
error.name = 'NotSupportedError';
|
|
|
|
|
|
|
|
// keep all callbacks async
|
|
|
|
return window.setTimeout(function () {
|
|
|
|
cb(error);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// normalize error handling when no media types are requested
|
|
|
|
if (!constraints.audio && !constraints.video) {
|
|
|
|
error = new Error('MediaStreamError');
|
|
|
|
error.name = 'NoMediaRequestedError';
|
|
|
|
|
|
|
|
// keep all callbacks async
|
|
|
|
return window.setTimeout(function () {
|
|
|
|
cb(error);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// testing support
|
|
|
|
if (localStorage && localStorage.useFirefoxFakeDevice === "true") {
|
|
|
|
constraints.fake = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigator.getUserMedia(constraints, function (stream) {
|
|
|
|
cb(null, stream);
|
|
|
|
}, function (err) {
|
|
|
|
var error;
|
|
|
|
// coerce into an error object since FF gives us a string
|
|
|
|
// there are only two valid names according to the spec
|
|
|
|
// we coerce all non-denied to "constraint not satisfied".
|
|
|
|
if (typeof err === 'string') {
|
|
|
|
error = new Error('MediaStreamError');
|
|
|
|
if (err === denied || err === altDenied) {
|
|
|
|
error.name = denied;
|
|
|
|
} else {
|
|
|
|
error.name = notSatisfied;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if we get an error object make sure '.name' property is set
|
|
|
|
// according to spec: http://dev.w3.org/2011/webrtc/editor/getusermedia.html#navigatorusermediaerror-and-navigatorusermediaerrorcallback
|
|
|
|
error = err;
|
|
|
|
if (!error.name) {
|
|
|
|
// this is likely chrome which
|
|
|
|
// sets a property called "ERROR_DENIED" on the error object
|
|
|
|
// if so we make sure to set a name
|
|
|
|
if (error[denied]) {
|
|
|
|
err.name = denied;
|
|
|
|
} else {
|
|
|
|
err.name = notSatisfied;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"webrtc-adapter-test":25}],18:[function(require,module,exports){
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
|
|
|
|
function getMaxVolume (analyser, fftBins) {
|
|
|
|
var maxVolume = -Infinity;
|
|
|
|
analyser.getFloatFrequencyData(fftBins);
|
|
|
|
|
|
|
|
for(var i=4, ii=fftBins.length; i < ii; i++) {
|
|
|
|
if (fftBins[i] > maxVolume && fftBins[i] < 0) {
|
|
|
|
maxVolume = fftBins[i];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return maxVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var audioContextType = window.AudioContext || window.webkitAudioContext;
|
|
|
|
// use a single audio context due to hardware limits
|
|
|
|
var audioContext = null;
|
|
|
|
module.exports = function(stream, options) {
|
|
|
|
var harker = new WildEmitter();
|
|
|
|
|
|
|
|
|
|
|
|
// make it not break in non-supported browsers
|
|
|
|
if (!audioContextType) return harker;
|
|
|
|
|
|
|
|
//Config
|
|
|
|
var options = options || {},
|
|
|
|
smoothing = (options.smoothing || 0.1),
|
|
|
|
interval = (options.interval || 50),
|
|
|
|
threshold = options.threshold,
|
|
|
|
play = options.play,
|
|
|
|
history = options.history || 10,
|
|
|
|
running = true;
|
|
|
|
|
|
|
|
//Setup Audio Context
|
|
|
|
if (!audioContext) {
|
|
|
|
audioContext = new audioContextType();
|
|
|
|
}
|
|
|
|
var sourceNode, fftBins, analyser;
|
|
|
|
|
|
|
|
analyser = audioContext.createAnalyser();
|
|
|
|
analyser.fftSize = 512;
|
|
|
|
analyser.smoothingTimeConstant = smoothing;
|
|
|
|
fftBins = new Float32Array(analyser.fftSize);
|
|
|
|
|
|
|
|
if (stream.jquery) stream = stream[0];
|
|
|
|
if (stream instanceof HTMLAudioElement || stream instanceof HTMLVideoElement) {
|
|
|
|
//Audio Tag
|
|
|
|
sourceNode = audioContext.createMediaElementSource(stream);
|
|
|
|
if (typeof play === 'undefined') play = true;
|
|
|
|
threshold = threshold || -50;
|
|
|
|
} else {
|
|
|
|
//WebRTC Stream
|
|
|
|
sourceNode = audioContext.createMediaStreamSource(stream);
|
|
|
|
threshold = threshold || -50;
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceNode.connect(analyser);
|
|
|
|
if (play) analyser.connect(audioContext.destination);
|
|
|
|
|
|
|
|
harker.speaking = false;
|
|
|
|
|
|
|
|
harker.setThreshold = function(t) {
|
|
|
|
threshold = t;
|
|
|
|
};
|
|
|
|
|
|
|
|
harker.setInterval = function(i) {
|
|
|
|
interval = i;
|
|
|
|
};
|
|
|
|
|
|
|
|
harker.stop = function() {
|
|
|
|
running = false;
|
|
|
|
harker.emit('volume_change', -100, threshold);
|
|
|
|
if (harker.speaking) {
|
|
|
|
harker.speaking = false;
|
|
|
|
harker.emit('stopped_speaking');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
harker.speakingHistory = [];
|
|
|
|
for (var i = 0; i < history; i++) {
|
|
|
|
harker.speakingHistory.push(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Poll the analyser node to determine if speaking
|
|
|
|
// and emit events if changed
|
|
|
|
var looper = function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
//check if stop has been called
|
|
|
|
if(!running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentVolume = getMaxVolume(analyser, fftBins);
|
|
|
|
|
|
|
|
harker.emit('volume_change', currentVolume, threshold);
|
|
|
|
|
|
|
|
var history = 0;
|
|
|
|
if (currentVolume > threshold && !harker.speaking) {
|
|
|
|
// trigger quickly, short history
|
|
|
|
for (var i = harker.speakingHistory.length - 3; i < harker.speakingHistory.length; i++) {
|
|
|
|
history += harker.speakingHistory[i];
|
|
|
|
}
|
|
|
|
if (history >= 2) {
|
|
|
|
harker.speaking = true;
|
|
|
|
harker.emit('speaking');
|
|
|
|
}
|
|
|
|
} else if (currentVolume < threshold && harker.speaking) {
|
|
|
|
for (var i = 0; i < harker.speakingHistory.length; i++) {
|
|
|
|
history += harker.speakingHistory[i];
|
|
|
|
}
|
|
|
|
if (history == 0) {
|
|
|
|
harker.speaking = false;
|
|
|
|
harker.emit('stopped_speaking');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
harker.speakingHistory.shift();
|
|
|
|
harker.speakingHistory.push(0 + (currentVolume > threshold));
|
|
|
|
|
|
|
|
looper();
|
|
|
|
}, interval);
|
|
|
|
};
|
|
|
|
looper();
|
|
|
|
|
|
|
|
|
|
|
|
return harker;
|
|
|
|
}
|
|
|
|
|
|
|
|
},{"wildemitter":26}],25:[function(require,module,exports){
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* More information about these options at jshint.com/docs/options */
|
|
|
|
/* jshint browser: true, camelcase: true, curly: true, devel: true,
|
|
|
|
eqeqeq: true, forin: false, globalstrict: true, node: true,
|
|
|
|
quotmark: single, undef: true, unused: strict */
|
|
|
|
/* global mozRTCIceCandidate, mozRTCPeerConnection, Promise,
|
|
|
|
mozRTCSessionDescription, webkitRTCPeerConnection, MediaStreamTrack */
|
|
|
|
/* exported trace,requestUserMedia */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var getUserMedia = null;
|
|
|
|
var attachMediaStream = null;
|
|
|
|
var reattachMediaStream = null;
|
|
|
|
var webrtcDetectedBrowser = null;
|
|
|
|
var webrtcDetectedVersion = null;
|
|
|
|
var webrtcMinimumVersion = null;
|
|
|
|
var webrtcUtils = {
|
|
|
|
log: function() {
|
|
|
|
// suppress console.log output when being included as a module.
|
|
|
|
if (typeof module !== 'undefined' ||
|
|
|
|
typeof require === 'function' && typeof define === 'function') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log.apply(console, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function trace(text) {
|
|
|
|
// This function is used for logging.
|
|
|
|
if (text[text.length - 1] === '\n') {
|
|
|
|
text = text.substring(0, text.length - 1);
|
|
|
|
}
|
|
|
|
if (window.performance) {
|
|
|
|
var now = (window.performance.now() / 1000).toFixed(3);
|
|
|
|
webrtcUtils.log(now + ': ' + text);
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof window === 'object') {
|
|
|
|
if (window.HTMLMediaElement &&
|
|
|
|
!('srcObject' in window.HTMLMediaElement.prototype)) {
|
|
|
|
// Shim the srcObject property, once, when HTMLMediaElement is found.
|
|
|
|
Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
|
|
|
|
get: function() {
|
|
|
|
// If prefixed srcObject property exists, return it.
|
|
|
|
// Otherwise use the shimmed property, _srcObject
|
|
|
|
return 'mozSrcObject' in this ? this.mozSrcObject : this._srcObject;
|
|
|
|
},
|
|
|
|
set: function(stream) {
|
|
|
|
if ('mozSrcObject' in this) {
|
|
|
|
this.mozSrcObject = stream;
|
|
|
|
} else {
|
|
|
|
// Use _srcObject as a private property for this shim
|
|
|
|
this._srcObject = stream;
|
|
|
|
// TODO: revokeObjectUrl(this.src) when !stream to release resources?
|
|
|
|
this.src = URL.createObjectURL(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Proxy existing globals
|
|
|
|
getUserMedia = window.navigator && window.navigator.getUserMedia;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach a media stream to an element.
|
|
|
|
attachMediaStream = function(element, stream) {
|
|
|
|
element.srcObject = stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
reattachMediaStream = function(to, from) {
|
|
|
|
to.srcObject = from.srcObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof window === 'undefined' || !window.navigator) {
|
|
|
|
webrtcUtils.log('This does not appear to be a browser');
|
|
|
|
webrtcDetectedBrowser = 'not a browser';
|
|
|
|
} else if (navigator.mozGetUserMedia && window.mozRTCPeerConnection) {
|
|
|
|
webrtcUtils.log('This appears to be Firefox');
|
|
|
|
|
|
|
|
webrtcDetectedBrowser = 'firefox';
|
|
|
|
|
|
|
|
// the detected firefox version.
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
|
|
|
|
|
|
|
|
// the minimum firefox version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 31;
|
|
|
|
|
|
|
|
// The RTCPeerConnection object.
|
|
|
|
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
|
|
|
|
if (webrtcDetectedVersion < 38) {
|
|
|
|
// .urls is not supported in FF < 38.
|
|
|
|
// create RTCIceServers with a single url.
|
|
|
|
if (pcConfig && pcConfig.iceServers) {
|
|
|
|
var newIceServers = [];
|
|
|
|
for (var i = 0; i < pcConfig.iceServers.length; i++) {
|
|
|
|
var server = pcConfig.iceServers[i];
|
|
|
|
if (server.hasOwnProperty('urls')) {
|
|
|
|
for (var j = 0; j < server.urls.length; j++) {
|
|
|
|
var newServer = {
|
|
|
|
url: server.urls[j]
|
|
|
|
};
|
|
|
|
if (server.urls[j].indexOf('turn') === 0) {
|
|
|
|
newServer.username = server.username;
|
|
|
|
newServer.credential = server.credential;
|
|
|
|
}
|
|
|
|
newIceServers.push(newServer);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newIceServers.push(pcConfig.iceServers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pcConfig.iceServers = newIceServers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new mozRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
|
|
|
|
};
|
|
|
|
|
|
|
|
// The RTCSessionDescription object.
|
|
|
|
window.RTCSessionDescription = mozRTCSessionDescription;
|
|
|
|
|
|
|
|
// The RTCIceCandidate object.
|
|
|
|
window.RTCIceCandidate = mozRTCIceCandidate;
|
|
|
|
|
|
|
|
// getUserMedia constraints shim.
|
|
|
|
getUserMedia = function(constraints, onSuccess, onError) {
|
|
|
|
var constraintsToFF37 = function(c) {
|
|
|
|
if (typeof c !== 'object' || c.require) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
var require = [];
|
|
|
|
Object.keys(c).forEach(function(key) {
|
|
|
|
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var r = c[key] = (typeof c[key] === 'object') ?
|
|
|
|
c[key] : {ideal: c[key]};
|
|
|
|
if (r.min !== undefined ||
|
|
|
|
r.max !== undefined || r.exact !== undefined) {
|
|
|
|
require.push(key);
|
|
|
|
}
|
|
|
|
if (r.exact !== undefined) {
|
|
|
|
if (typeof r.exact === 'number') {
|
|
|
|
r.min = r.max = r.exact;
|
|
|
|
} else {
|
|
|
|
c[key] = r.exact;
|
|
|
|
}
|
|
|
|
delete r.exact;
|
|
|
|
}
|
|
|
|
if (r.ideal !== undefined) {
|
|
|
|
c.advanced = c.advanced || [];
|
|
|
|
var oc = {};
|
|
|
|
if (typeof r.ideal === 'number') {
|
|
|
|
oc[key] = {min: r.ideal, max: r.ideal};
|
|
|
|
} else {
|
|
|
|
oc[key] = r.ideal;
|
|
|
|
}
|
|
|
|
c.advanced.push(oc);
|
|
|
|
delete r.ideal;
|
|
|
|
if (!Object.keys(r).length) {
|
|
|
|
delete c[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (require.length) {
|
|
|
|
c.require = require;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
};
|
|
|
|
if (webrtcDetectedVersion < 38) {
|
|
|
|
webrtcUtils.log('spec: ' + JSON.stringify(constraints));
|
|
|
|
if (constraints.audio) {
|
|
|
|
constraints.audio = constraintsToFF37(constraints.audio);
|
|
|
|
}
|
|
|
|
if (constraints.video) {
|
|
|
|
constraints.video = constraintsToFF37(constraints.video);
|
|
|
|
}
|
|
|
|
webrtcUtils.log('ff37: ' + JSON.stringify(constraints));
|
|
|
|
}
|
|
|
|
return navigator.mozGetUserMedia(constraints, onSuccess, onError);
|
|
|
|
};
|
|
|
|
|
|
|
|
navigator.getUserMedia = getUserMedia;
|
|
|
|
|
|
|
|
// Shim for mediaDevices on older versions.
|
|
|
|
if (!navigator.mediaDevices) {
|
|
|
|
navigator.mediaDevices = {getUserMedia: requestUserMedia,
|
|
|
|
addEventListener: function() { },
|
|
|
|
removeEventListener: function() { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
navigator.mediaDevices.enumerateDevices =
|
|
|
|
navigator.mediaDevices.enumerateDevices || function() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
var infos = [
|
|
|
|
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''},
|
|
|
|
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''}
|
|
|
|
];
|
|
|
|
resolve(infos);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (webrtcDetectedVersion < 41) {
|
|
|
|
// Work around http://bugzil.la/1169665
|
|
|
|
var orgEnumerateDevices =
|
|
|
|
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
|
|
|
|
navigator.mediaDevices.enumerateDevices = function() {
|
|
|
|
return orgEnumerateDevices().catch(function(e) {
|
|
|
|
if (e.name === 'NotFoundError') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else if (navigator.webkitGetUserMedia && !!window.chrome) {
|
|
|
|
webrtcUtils.log('This appears to be Chrome');
|
|
|
|
|
|
|
|
webrtcDetectedBrowser = 'chrome';
|
|
|
|
|
|
|
|
// the detected chrome version.
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
|
|
|
|
|
|
|
|
// the minimum chrome version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 38;
|
|
|
|
|
|
|
|
// The RTCPeerConnection object.
|
|
|
|
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
|
|
|
|
// Translate iceTransportPolicy to iceTransports,
|
|
|
|
// see https://code.google.com/p/webrtc/issues/detail?id=4869
|
|
|
|
if (pcConfig && pcConfig.iceTransportPolicy) {
|
|
|
|
pcConfig.iceTransports = pcConfig.iceTransportPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pc = new webkitRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
|
|
|
|
var origGetStats = pc.getStats.bind(pc);
|
|
|
|
pc.getStats = function(selector, successCallback, errorCallback) { // jshint ignore: line
|
|
|
|
var self = this;
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
// If selector is a function then we are in the old style stats so just
|
|
|
|
// pass back the original getStats format to avoid breaking old users.
|
|
|
|
if (arguments.length > 0 && typeof selector === 'function') {
|
|
|
|
return origGetStats(selector, successCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
var fixChromeStats = function(response) {
|
|
|
|
var standardReport = {};
|
|
|
|
var reports = response.result();
|
|
|
|
reports.forEach(function(report) {
|
|
|
|
var standardStats = {
|
|
|
|
id: report.id,
|
|
|
|
timestamp: report.timestamp,
|
|
|
|
type: report.type
|
|
|
|
};
|
|
|
|
report.names().forEach(function(name) {
|
|
|
|
standardStats[name] = report.stat(name);
|
|
|
|
});
|
|
|
|
standardReport[standardStats.id] = standardStats;
|
|
|
|
});
|
|
|
|
|
|
|
|
return standardReport;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
var successCallbackWrapper = function(response) {
|
|
|
|
args[1](fixChromeStats(response));
|
|
|
|
};
|
|
|
|
|
|
|
|
return origGetStats.apply(this, [successCallbackWrapper, arguments[0]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// promise-support
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
if (args.length === 1 && selector === null) {
|
|
|
|
origGetStats.apply(self, [
|
|
|
|
function(response) {
|
|
|
|
resolve.apply(null, [fixChromeStats(response)]);
|
|
|
|
}, reject]);
|
|
|
|
} else {
|
|
|
|
origGetStats.apply(self, [resolve, reject]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
};
|
|
|
|
|
|
|
|
// add promise support
|
|
|
|
['createOffer', 'createAnswer'].forEach(function(method) {
|
|
|
|
var nativeMethod = webkitRTCPeerConnection.prototype[method];
|
|
|
|
webkitRTCPeerConnection.prototype[method] = function() {
|
|
|
|
var self = this;
|
|
|
|
if (arguments.length < 1 || (arguments.length === 1 &&
|
|
|
|
typeof(arguments[0]) === 'object')) {
|
|
|
|
var opts = arguments.length === 1 ? arguments[0] : undefined;
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
nativeMethod.apply(self, [resolve, reject, opts]);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return nativeMethod.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
['setLocalDescription', 'setRemoteDescription',
|
|
|
|
'addIceCandidate'].forEach(function(method) {
|
|
|
|
var nativeMethod = webkitRTCPeerConnection.prototype[method];
|
|
|
|
webkitRTCPeerConnection.prototype[method] = function() {
|
|
|
|
var args = arguments;
|
|
|
|
var self = this;
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
nativeMethod.apply(self, [args[0],
|
|
|
|
function() {
|
|
|
|
resolve();
|
|
|
|
if (args.length >= 2) {
|
|
|
|
args[1].apply(null, []);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
reject(err);
|
|
|
|
if (args.length >= 3) {
|
|
|
|
args[2].apply(null, [err]);
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// getUserMedia constraints shim.
|
|
|
|
var constraintsToChrome = function(c) {
|
|
|
|
if (typeof c !== 'object' || c.mandatory || c.optional) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
var cc = {};
|
|
|
|
Object.keys(c).forEach(function(key) {
|
|
|
|
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]};
|
|
|
|
if (r.exact !== undefined && typeof r.exact === 'number') {
|
|
|
|
r.min = r.max = r.exact;
|
|
|
|
}
|
|
|
|
var oldname = function(prefix, name) {
|
|
|
|
if (prefix) {
|
|
|
|
return prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
|
|
}
|
|
|
|
return (name === 'deviceId') ? 'sourceId' : name;
|
|
|
|
};
|
|
|
|
if (r.ideal !== undefined) {
|
|
|
|
cc.optional = cc.optional || [];
|
|
|
|
var oc = {};
|
|
|
|
if (typeof r.ideal === 'number') {
|
|
|
|
oc[oldname('min', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
oc = {};
|
|
|
|
oc[oldname('max', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
} else {
|
|
|
|
oc[oldname('', key)] = r.ideal;
|
|
|
|
cc.optional.push(oc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r.exact !== undefined && typeof r.exact !== 'number') {
|
|
|
|
cc.mandatory = cc.mandatory || {};
|
|
|
|
cc.mandatory[oldname('', key)] = r.exact;
|
|
|
|
} else {
|
|
|
|
['min', 'max'].forEach(function(mix) {
|
|
|
|
if (r[mix] !== undefined) {
|
|
|
|
cc.mandatory = cc.mandatory || {};
|
|
|
|
cc.mandatory[oldname(mix, key)] = r[mix];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (c.advanced) {
|
|
|
|
cc.optional = (cc.optional || []).concat(c.advanced);
|
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
getUserMedia = function(constraints, onSuccess, onError) {
|
|
|
|
if (constraints.audio) {
|
|
|
|
constraints.audio = constraintsToChrome(constraints.audio);
|
|
|
|
}
|
|
|
|
if (constraints.video) {
|
|
|
|
constraints.video = constraintsToChrome(constraints.video);
|
|
|
|
}
|
|
|
|
webrtcUtils.log('chrome: ' + JSON.stringify(constraints));
|
|
|
|
return navigator.webkitGetUserMedia(constraints, onSuccess, onError);
|
|
|
|
};
|
|
|
|
navigator.getUserMedia = getUserMedia;
|
|
|
|
|
|
|
|
if (!navigator.mediaDevices) {
|
|
|
|
navigator.mediaDevices = {getUserMedia: requestUserMedia,
|
|
|
|
enumerateDevices: function() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
var kinds = {audio: 'audioinput', video: 'videoinput'};
|
|
|
|
return MediaStreamTrack.getSources(function(devices) {
|
|
|
|
resolve(devices.map(function(device) {
|
|
|
|
return {label: device.label,
|
|
|
|
kind: kinds[device.kind],
|
|
|
|
deviceId: device.id,
|
|
|
|
groupId: ''};
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
// A shim for getUserMedia method on the mediaDevices object.
|
|
|
|
// TODO(KaptenJansson) remove once implemented in Chrome stable.
|
|
|
|
if (!navigator.mediaDevices.getUserMedia) {
|
|
|
|
navigator.mediaDevices.getUserMedia = function(constraints) {
|
|
|
|
return requestUserMedia(constraints);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
|
|
|
|
// function which returns a Promise, it does not accept spec-style
|
|
|
|
// constraints.
|
|
|
|
var origGetUserMedia = navigator.mediaDevices.getUserMedia.
|
|
|
|
bind(navigator.mediaDevices);
|
|
|
|
navigator.mediaDevices.getUserMedia = function(c) {
|
|
|
|
webrtcUtils.log('spec: ' + JSON.stringify(c)); // whitespace for alignment
|
|
|
|
c.audio = constraintsToChrome(c.audio);
|
|
|
|
c.video = constraintsToChrome(c.video);
|
|
|
|
webrtcUtils.log('chrome: ' + JSON.stringify(c));
|
|
|
|
return origGetUserMedia(c);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dummy devicechange event methods.
|
|
|
|
// TODO(KaptenJansson) remove once implemented in Chrome stable.
|
|
|
|
if (typeof navigator.mediaDevices.addEventListener === 'undefined') {
|
|
|
|
navigator.mediaDevices.addEventListener = function() {
|
|
|
|
webrtcUtils.log('Dummy mediaDevices.addEventListener called.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (typeof navigator.mediaDevices.removeEventListener === 'undefined') {
|
|
|
|
navigator.mediaDevices.removeEventListener = function() {
|
|
|
|
webrtcUtils.log('Dummy mediaDevices.removeEventListener called.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach a media stream to an element.
|
|
|
|
attachMediaStream = function(element, stream) {
|
|
|
|
if (webrtcDetectedVersion >= 43) {
|
|
|
|
element.srcObject = stream;
|
|
|
|
} else if (typeof element.src !== 'undefined') {
|
|
|
|
element.src = URL.createObjectURL(stream);
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log('Error attaching stream to element.');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
reattachMediaStream = function(to, from) {
|
|
|
|
if (webrtcDetectedVersion >= 43) {
|
|
|
|
to.srcObject = from.srcObject;
|
|
|
|
} else {
|
|
|
|
to.src = from.src;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} else if (navigator.mediaDevices && navigator.userAgent.match(
|
|
|
|
/Edge\/(\d+).(\d+)$/)) {
|
|
|
|
webrtcUtils.log('This appears to be Edge');
|
|
|
|
webrtcDetectedBrowser = 'edge';
|
|
|
|
|
|
|
|
webrtcDetectedVersion =
|
|
|
|
parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10);
|
|
|
|
|
|
|
|
// the minimum version still supported by adapter.
|
|
|
|
webrtcMinimumVersion = 12;
|
|
|
|
} else {
|
|
|
|
webrtcUtils.log('Browser does not appear to be WebRTC-capable');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the result of getUserMedia as a Promise.
|
|
|
|
function requestUserMedia(constraints) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
getUserMedia(constraints, resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var webrtcTesting = {};
|
|
|
|
Object.defineProperty(webrtcTesting, 'version', {
|
|
|
|
set: function(version) {
|
|
|
|
webrtcDetectedVersion = version;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
var RTCPeerConnection;
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
RTCPeerConnection = window.RTCPeerConnection;
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
|
|
RTCPeerConnection: RTCPeerConnection,
|
|
|
|
getUserMedia: getUserMedia,
|
|
|
|
attachMediaStream: attachMediaStream,
|
|
|
|
reattachMediaStream: reattachMediaStream,
|
|
|
|
webrtcDetectedBrowser: webrtcDetectedBrowser,
|
|
|
|
webrtcDetectedVersion: webrtcDetectedVersion,
|
|
|
|
webrtcMinimumVersion: webrtcMinimumVersion,
|
|
|
|
webrtcTesting: webrtcTesting
|
|
|
|
//requestUserMedia: not exposed on purpose.
|
|
|
|
//trace: not exposed on purpose.
|
|
|
|
};
|
|
|
|
} else if ((typeof require === 'function') && (typeof define === 'function')) {
|
|
|
|
// Expose objects and functions when RequireJS is doing the loading.
|
|
|
|
define([], function() {
|
|
|
|
return {
|
|
|
|
RTCPeerConnection: window.RTCPeerConnection,
|
|
|
|
getUserMedia: getUserMedia,
|
|
|
|
attachMediaStream: attachMediaStream,
|
|
|
|
reattachMediaStream: reattachMediaStream,
|
|
|
|
webrtcDetectedBrowser: webrtcDetectedBrowser,
|
|
|
|
webrtcDetectedVersion: webrtcDetectedVersion,
|
|
|
|
webrtcMinimumVersion: webrtcMinimumVersion,
|
|
|
|
webrtcTesting: webrtcTesting
|
|
|
|
//requestUserMedia: not exposed on purpose.
|
|
|
|
//trace: not exposed on purpose.
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
},{}],26:[function(require,module,exports){
|
|
|
|
/*
|
|
|
|
WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based
|
|
|
|
on @visionmedia's Emitter from UI Kit.
|
|
|
|
|
|
|
|
Why? I wanted it standalone.
|
|
|
|
|
|
|
|
I also wanted support for wildcard emitters like this:
|
|
|
|
|
|
|
|
emitter.on('*', function (eventName, other, event, payloads) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
emitter.on('somenamespace*', function (eventName, payloads) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Please note that callbacks triggered by wildcard registered events also get
|
|
|
|
the event name as the first argument.
|
|
|
|
*/
|
|
|
|
module.exports = WildEmitter;
|
|
|
|
|
|
|
|
function WildEmitter() {
|
|
|
|
this.callbacks = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listen on the given `event` with `fn`. Store a group name if present.
|
|
|
|
WildEmitter.prototype.on = function (event, groupName, fn) {
|
|
|
|
var hasGroup = (arguments.length === 3),
|
|
|
|
group = hasGroup ? arguments[1] : undefined,
|
|
|
|
func = hasGroup ? arguments[2] : arguments[1];
|
|
|
|
func._groupName = group;
|
|
|
|
(this.callbacks[event] = this.callbacks[event] || []).push(func);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adds an `event` listener that will be invoked a single
|
|
|
|
// time then automatically removed.
|
|
|
|
WildEmitter.prototype.once = function (event, groupName, fn) {
|
|
|
|
var self = this,
|
|
|
|
hasGroup = (arguments.length === 3),
|
|
|
|
group = hasGroup ? arguments[1] : undefined,
|
|
|
|
func = hasGroup ? arguments[2] : arguments[1];
|
|
|
|
function on() {
|
|
|
|
self.off(event, on);
|
|
|
|
func.apply(this, arguments);
|
|
|
|
}
|
|
|
|
this.on(event, group, on);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unbinds an entire group
|
|
|
|
WildEmitter.prototype.releaseGroup = function (groupName) {
|
|
|
|
var item, i, len, handlers;
|
|
|
|
for (item in this.callbacks) {
|
|
|
|
handlers = this.callbacks[item];
|
|
|
|
for (i = 0, len = handlers.length; i < len; i++) {
|
|
|
|
if (handlers[i]._groupName === groupName) {
|
|
|
|
//console.log('removing');
|
|
|
|
// remove it and shorten the array we're looping through
|
|
|
|
handlers.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Remove the given callback for `event` or all
|
|
|
|
// registered callbacks.
|
|
|
|
WildEmitter.prototype.off = function (event, fn) {
|
|
|
|
var callbacks = this.callbacks[event],
|
|
|
|
i;
|
|
|
|
|
|
|
|
if (!callbacks) return this;
|
|
|
|
|
|
|
|
// remove all handlers
|
|
|
|
if (arguments.length === 1) {
|
|
|
|
delete this.callbacks[event];
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove specific handler
|
|
|
|
i = callbacks.indexOf(fn);
|
|
|
|
callbacks.splice(i, 1);
|
|
|
|
if (callbacks.length === 0) {
|
|
|
|
delete this.callbacks[event];
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Emit `event` with the given args.
|
|
|
|
// also calls any `*` handlers
|
|
|
|
WildEmitter.prototype.emit = function (event) {
|
|
|
|
var args = [].slice.call(arguments, 1),
|
|
|
|
callbacks = this.callbacks[event],
|
|
|
|
specialCallbacks = this.getWildcardCallbacks(event),
|
|
|
|
i,
|
|
|
|
len,
|
|
|
|
item,
|
|
|
|
listeners;
|
|
|
|
|
|
|
|
if (callbacks) {
|
|
|
|
listeners = callbacks.slice();
|
|
|
|
for (i = 0, len = listeners.length; i < len; ++i) {
|
|
|
|
if (listeners[i]) {
|
|
|
|
listeners[i].apply(this, args);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specialCallbacks) {
|
|
|
|
len = specialCallbacks.length;
|
|
|
|
listeners = specialCallbacks.slice();
|
|
|
|
for (i = 0, len = listeners.length; i < len; ++i) {
|
|
|
|
if (listeners[i]) {
|
|
|
|
listeners[i].apply(this, [event].concat(args));
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper for for finding special wildcard event handlers that match the event
|
|
|
|
WildEmitter.prototype.getWildcardCallbacks = function (eventName) {
|
|
|
|
var item,
|
|
|
|
split,
|
|
|
|
result = [];
|
|
|
|
|
|
|
|
for (item in this.callbacks) {
|
|
|
|
split = item.split('*');
|
|
|
|
if (item === '*' || (split.length === 2 && eventName.slice(0, split[0].length) === split[0])) {
|
|
|
|
result = result.concat(this.callbacks[item]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],21:[function(require,module,exports){
|
|
|
|
var toSDP = require('./lib/tosdp');
|
|
|
|
var toJSON = require('./lib/tojson');
|
|
|
|
|
|
|
|
|
|
|
|
// Converstion from JSON to SDP
|
|
|
|
|
|
|
|
exports.toIncomingSDPOffer = function (session) {
|
|
|
|
return toSDP.toSessionSDP(session, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingSDPOffer = function (session) {
|
|
|
|
return toSDP.toSessionSDP(session, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingSDPAnswer = function (session) {
|
|
|
|
return toSDP.toSessionSDP(session, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingSDPAnswer = function (session) {
|
|
|
|
return toSDP.toSessionSDP(session, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingMediaSDPOffer = function (media) {
|
|
|
|
return toSDP.toMediaSDP(media, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingMediaSDPOffer = function (media) {
|
|
|
|
return toSDP.toMediaSDP(media, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingMediaSDPAnswer = function (media) {
|
|
|
|
return toSDP.toMediaSDP(media, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'incoming'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingMediaSDPAnswer = function (media) {
|
|
|
|
return toSDP.toMediaSDP(media, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'outgoing'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toCandidateSDP = toSDP.toCandidateSDP;
|
|
|
|
exports.toMediaSDP = toSDP.toMediaSDP;
|
|
|
|
exports.toSessionSDP = toSDP.toSessionSDP;
|
|
|
|
|
|
|
|
|
|
|
|
// Conversion from SDP to JSON
|
|
|
|
|
|
|
|
exports.toIncomingJSONOffer = function (sdp, creators) {
|
|
|
|
return toJSON.toSessionJSON(sdp, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'incoming',
|
|
|
|
creators: creators
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingJSONOffer = function (sdp, creators) {
|
|
|
|
return toJSON.toSessionJSON(sdp, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'outgoing',
|
|
|
|
creators: creators
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingJSONAnswer = function (sdp, creators) {
|
|
|
|
return toJSON.toSessionJSON(sdp, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'incoming',
|
|
|
|
creators: creators
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingJSONAnswer = function (sdp, creators) {
|
|
|
|
return toJSON.toSessionJSON(sdp, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'outgoing',
|
|
|
|
creators: creators
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingMediaJSONOffer = function (sdp, creator) {
|
|
|
|
return toJSON.toMediaJSON(sdp, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'incoming',
|
|
|
|
creator: creator
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingMediaJSONOffer = function (sdp, creator) {
|
|
|
|
return toJSON.toMediaJSON(sdp, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'outgoing',
|
|
|
|
creator: creator
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toIncomingMediaJSONAnswer = function (sdp, creator) {
|
|
|
|
return toJSON.toMediaJSON(sdp, {
|
|
|
|
role: 'initiator',
|
|
|
|
direction: 'incoming',
|
|
|
|
creator: creator
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toOutgoingMediaJSONAnswer = function (sdp, creator) {
|
|
|
|
return toJSON.toMediaJSON(sdp, {
|
|
|
|
role: 'responder',
|
|
|
|
direction: 'outgoing',
|
|
|
|
creator: creator
|
|
|
|
});
|
|
|
|
};
|
|
|
|
exports.toCandidateJSON = toJSON.toCandidateJSON;
|
|
|
|
exports.toMediaJSON = toJSON.toMediaJSON;
|
|
|
|
exports.toSessionJSON = toJSON.toSessionJSON;
|
|
|
|
|
|
|
|
},{"./lib/tojson":28,"./lib/tosdp":27}],17:[function(require,module,exports){
|
|
|
|
// getScreenMedia helper by @HenrikJoreteg
|
|
|
|
var getUserMedia = require('getusermedia');
|
|
|
|
|
|
|
|
// cache for constraints and callback
|
|
|
|
var cache = {};
|
|
|
|
|
|
|
|
module.exports = function (constraints, cb) {
|
|
|
|
var hasConstraints = arguments.length === 2;
|
|
|
|
var callback = hasConstraints ? cb : constraints;
|
|
|
|
var error;
|
|
|
|
|
|
|
|
if (typeof window === 'undefined' || window.location.protocol === 'http:') {
|
|
|
|
error = new Error('NavigatorUserMediaError');
|
|
|
|
error.name = 'HTTPS_REQUIRED';
|
|
|
|
return callback(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.navigator.userAgent.match('Chrome')) {
|
|
|
|
var chromever = parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1], 10);
|
|
|
|
var maxver = 33;
|
|
|
|
var isCef = !window.chrome.webstore;
|
|
|
|
// "known" crash in chrome 34 and 35 on linux
|
|
|
|
if (window.navigator.userAgent.match('Linux')) maxver = 35;
|
|
|
|
|
|
|
|
// check that the extension is installed by looking for a
|
|
|
|
// sessionStorage variable that contains the extension id
|
|
|
|
// this has to be set after installation unless the contest
|
|
|
|
// script does that
|
|
|
|
if (sessionStorage.getScreenMediaJSExtensionId) {
|
|
|
|
chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
|
|
|
|
{type:'getScreen', id: 1}, null,
|
|
|
|
function (data) {
|
|
|
|
if (data.sourceId === '') { // user canceled
|
|
|
|
var error = new Error('NavigatorUserMediaError');
|
|
|
|
error.name = 'PERMISSION_DENIED';
|
|
|
|
callback(error);
|
|
|
|
} else {
|
|
|
|
constraints = (hasConstraints && constraints) || {audio: false, video: {
|
|
|
|
mandatory: {
|
|
|
|
chromeMediaSource: 'desktop',
|
|
|
|
maxWidth: window.screen.width,
|
|
|
|
maxHeight: window.screen.height,
|
|
|
|
maxFrameRate: 3
|
|
|
|
},
|
|
|
|
optional: [
|
|
|
|
{googLeakyBucket: true},
|
|
|
|
{googTemporalLayeredScreencast: true}
|
|
|
|
]
|
|
|
|
}};
|
|
|
|
constraints.video.mandatory.chromeMediaSourceId = data.sourceId;
|
|
|
|
getUserMedia(constraints, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else if (window.cefGetScreenMedia) {
|
|
|
|
//window.cefGetScreenMedia is experimental - may be removed without notice
|
|
|
|
window.cefGetScreenMedia(function(sourceId) {
|
|
|
|
if (!sourceId) {
|
|
|
|
var error = new Error('cefGetScreenMediaError');
|
|
|
|
error.name = 'CEF_GETSCREENMEDIA_CANCELED';
|
|
|
|
callback(error);
|
|
|
|
} else {
|
|
|
|
constraints = (hasConstraints && constraints) || {audio: false, video: {
|
|
|
|
mandatory: {
|
|
|
|
chromeMediaSource: 'desktop',
|
|
|
|
maxWidth: window.screen.width,
|
|
|
|
maxHeight: window.screen.height,
|
|
|
|
maxFrameRate: 3
|
|
|
|
},
|
|
|
|
optional: [
|
|
|
|
{googLeakyBucket: true},
|
|
|
|
{googTemporalLayeredScreencast: true}
|
|
|
|
]
|
|
|
|
}};
|
|
|
|
constraints.video.mandatory.chromeMediaSourceId = sourceId;
|
|
|
|
getUserMedia(constraints, callback);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (isCef || (chromever >= 26 && chromever <= maxver)) {
|
|
|
|
// chrome 26 - chrome 33 way to do it -- requires bad chrome://flags
|
|
|
|
// note: this is basically in maintenance mode and will go away soon
|
|
|
|
constraints = (hasConstraints && constraints) || {
|
|
|
|
video: {
|
|
|
|
mandatory: {
|
|
|
|
googLeakyBucket: true,
|
|
|
|
maxWidth: window.screen.width,
|
|
|
|
maxHeight: window.screen.height,
|
|
|
|
maxFrameRate: 3,
|
|
|
|
chromeMediaSource: 'screen'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
getUserMedia(constraints, callback);
|
|
|
|
} else {
|
|
|
|
// chrome 34+ way requiring an extension
|
|
|
|
var pending = window.setTimeout(function () {
|
|
|
|
error = new Error('NavigatorUserMediaError');
|
|
|
|
error.name = 'EXTENSION_UNAVAILABLE';
|
|
|
|
return callback(error);
|
|
|
|
}, 1000);
|
|
|
|
cache[pending] = [callback, hasConstraints ? constraint : null];
|
|
|
|
window.postMessage({ type: 'getScreen', id: pending }, '*');
|
|
|
|
}
|
|
|
|
} else if (window.navigator.userAgent.match('Firefox')) {
|
|
|
|
var ffver = parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1], 10);
|
|
|
|
if (ffver >= 33) {
|
|
|
|
constraints = (hasConstraints && constraints) || {
|
|
|
|
video: {
|
|
|
|
mozMediaSource: 'window',
|
|
|
|
mediaSource: 'window'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getUserMedia(constraints, function (err, stream) {
|
|
|
|
callback(err, stream);
|
|
|
|
// workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1045810
|
|
|
|
if (!err) {
|
|
|
|
var lastTime = stream.currentTime;
|
|
|
|
var polly = window.setInterval(function () {
|
|
|
|
if (!stream) window.clearInterval(polly);
|
|
|
|
if (stream.currentTime == lastTime) {
|
|
|
|
window.clearInterval(polly);
|
|
|
|
if (stream.onended) {
|
|
|
|
stream.onended();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastTime = stream.currentTime;
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
error = new Error('NavigatorUserMediaError');
|
|
|
|
error.name = 'EXTENSION_UNAVAILABLE'; // does not make much sense but...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', function (event) {
|
|
|
|
if (event.origin != window.location.origin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.data.type == 'gotScreen' && cache[event.data.id]) {
|
|
|
|
var data = cache[event.data.id];
|
|
|
|
var constraints = data[1];
|
|
|
|
var callback = data[0];
|
|
|
|
delete cache[event.data.id];
|
|
|
|
|
|
|
|
if (event.data.sourceId === '') { // user canceled
|
|
|
|
var error = new Error('NavigatorUserMediaError');
|
|
|
|
error.name = 'PERMISSION_DENIED';
|
|
|
|
callback(error);
|
|
|
|
} else {
|
|
|
|
constraints = constraints || {audio: false, video: {
|
|
|
|
mandatory: {
|
|
|
|
chromeMediaSource: 'desktop',
|
|
|
|
maxWidth: window.screen.width,
|
|
|
|
maxHeight: window.screen.height,
|
|
|
|
maxFrameRate: 3
|
|
|
|
},
|
|
|
|
optional: [
|
|
|
|
{googLeakyBucket: true},
|
|
|
|
{googTemporalLayeredScreencast: true}
|
|
|
|
]
|
|
|
|
}};
|
|
|
|
constraints.video.mandatory.chromeMediaSourceId = event.data.sourceId;
|
|
|
|
getUserMedia(constraints, callback);
|
|
|
|
}
|
|
|
|
} else if (event.data.type == 'getScreenPending') {
|
|
|
|
window.clearTimeout(event.data.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
},{"getusermedia":16}],19:[function(require,module,exports){
|
|
|
|
var support = require('webrtcsupport');
|
|
|
|
|
|
|
|
|
|
|
|
function GainController(stream) {
|
|
|
|
this.support = support.webAudio && support.mediaStream;
|
|
|
|
|
|
|
|
// set our starting value
|
|
|
|
this.gain = 1;
|
|
|
|
|
|
|
|
if (this.support) {
|
|
|
|
var context = this.context = new support.AudioContext();
|
|
|
|
this.microphone = context.createMediaStreamSource(stream);
|
|
|
|
this.gainFilter = context.createGain();
|
|
|
|
this.destination = context.createMediaStreamDestination();
|
|
|
|
this.outputStream = this.destination.stream;
|
|
|
|
this.microphone.connect(this.gainFilter);
|
|
|
|
this.gainFilter.connect(this.destination);
|
|
|
|
stream.addTrack(this.outputStream.getAudioTracks()[0]);
|
|
|
|
stream.removeTrack(stream.getAudioTracks()[0]);
|
|
|
|
}
|
|
|
|
this.stream = stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setting
|
|
|
|
GainController.prototype.setGain = function (val) {
|
|
|
|
// check for support
|
|
|
|
if (!this.support) return;
|
|
|
|
this.gainFilter.gain.value = val;
|
|
|
|
this.gain = val;
|
|
|
|
};
|
|
|
|
|
|
|
|
GainController.prototype.getGain = function () {
|
|
|
|
return this.gain;
|
|
|
|
};
|
|
|
|
|
|
|
|
GainController.prototype.off = function () {
|
|
|
|
return this.setGain(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
GainController.prototype.on = function () {
|
|
|
|
this.setGain(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = GainController;
|
|
|
|
|
|
|
|
},{"webrtcsupport":5}],23:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.3 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var arrayEach = require('lodash._arrayeach'),
|
|
|
|
baseEach = require('lodash._baseeach'),
|
|
|
|
bindCallback = require('lodash._bindcallback'),
|
|
|
|
isArray = require('lodash.isarray');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a function for `_.forEach` or `_.forEachRight`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} arrayFunc The function to iterate over an array.
|
|
|
|
* @param {Function} eachFunc The function to iterate over a collection.
|
|
|
|
* @returns {Function} Returns the new each function.
|
|
|
|
*/
|
|
|
|
function createForEach(arrayFunc, eachFunc) {
|
|
|
|
return function(collection, iteratee, thisArg) {
|
|
|
|
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
|
|
|
|
? arrayFunc(collection, iteratee)
|
|
|
|
: eachFunc(collection, bindCallback(iteratee, thisArg, 3));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
|
|
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
|
|
|
* (value, index|key, collection). Iteratee functions may exit iteration early
|
|
|
|
* by explicitly returning `false`.
|
|
|
|
*
|
|
|
|
* **Note:** As with other "Collections" methods, objects with a "length" property
|
|
|
|
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
|
|
|
* may be used for object iteration.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @alias each
|
|
|
|
* @category Collection
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|
|
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
|
|
|
* @returns {Array|Object|string} Returns `collection`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _([1, 2]).forEach(function(n) {
|
|
|
|
* console.log(n);
|
|
|
|
* }).value();
|
|
|
|
* // => logs each value from left to right and returns the array
|
|
|
|
*
|
|
|
|
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
|
|
|
|
* console.log(n, key);
|
|
|
|
* });
|
|
|
|
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
|
|
|
*/
|
|
|
|
var forEach = createForEach(arrayEach, baseEach);
|
|
|
|
|
|
|
|
module.exports = forEach;
|
|
|
|
|
|
|
|
},{"lodash._arrayeach":29,"lodash._baseeach":30,"lodash._bindcallback":31,"lodash.isarray":32}],24:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.1.2 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var baseGet = require('lodash._baseget'),
|
|
|
|
toPath = require('lodash._topath'),
|
|
|
|
isArray = require('lodash.isarray'),
|
|
|
|
map = require('lodash.map');
|
|
|
|
|
|
|
|
/** Used to match property names within property paths. */
|
|
|
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
|
|
|
|
reIsPlainProp = /^\w*$/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseProperty` which supports deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array|string} path The path of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function basePropertyDeep(path) {
|
|
|
|
var pathKey = (path + '');
|
|
|
|
path = toPath(path);
|
|
|
|
return function(object) {
|
|
|
|
return baseGet(object, path, pathKey);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a property name and not a property path.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @param {Object} [object] The object to query keys on.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
|
|
*/
|
|
|
|
function isKey(value, object) {
|
|
|
|
var type = typeof value;
|
|
|
|
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (isArray(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var result = !reIsDeepProp.test(value);
|
|
|
|
return result || (object != null && value in toObject(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the property value of `path` from all elements in `collection`.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Collection
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Array|string} path The path of the property to pluck.
|
|
|
|
* @returns {Array} Returns the property values.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var users = [
|
|
|
|
* { 'user': 'barney', 'age': 36 },
|
|
|
|
* { 'user': 'fred', 'age': 40 }
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* _.pluck(users, 'user');
|
|
|
|
* // => ['barney', 'fred']
|
|
|
|
*
|
|
|
|
* var userIndex = _.indexBy(users, 'user');
|
|
|
|
* _.pluck(userIndex, 'age');
|
|
|
|
* // => [36, 40] (iteration order is not guaranteed)
|
|
|
|
*/
|
|
|
|
function pluck(collection, path) {
|
|
|
|
return map(collection, property(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a function which returns the property value at `path` on a
|
|
|
|
* given object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Utility
|
|
|
|
* @param {Array|string} path The path of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var objects = [
|
|
|
|
* { 'a': { 'b': { 'c': 2 } } },
|
|
|
|
* { 'a': { 'b': { 'c': 1 } } }
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* _.map(objects, _.property('a.b.c'));
|
|
|
|
* // => [2, 1]
|
|
|
|
*
|
|
|
|
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
|
|
|
* // => [1, 2]
|
|
|
|
*/
|
|
|
|
function property(path) {
|
|
|
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = pluck;
|
|
|
|
|
|
|
|
},{"lodash._baseget":33,"lodash._topath":34,"lodash.isarray":35,"lodash.map":36}],27:[function(require,module,exports){
|
|
|
|
var SENDERS = require('./senders');
|
|
|
|
|
|
|
|
|
|
|
|
exports.toSessionSDP = function (session, opts) {
|
|
|
|
var role = opts.role || 'initiator';
|
|
|
|
var direction = opts.direction || 'outgoing';
|
|
|
|
var sid = opts.sid || session.sid || Date.now();
|
|
|
|
var time = opts.time || Date.now();
|
|
|
|
|
|
|
|
var sdp = [
|
|
|
|
'v=0',
|
|
|
|
'o=- ' + sid + ' ' + time + ' IN IP4 0.0.0.0',
|
|
|
|
's=-',
|
|
|
|
't=0 0',
|
|
|
|
'a=msid-semantic: WMS *'
|
|
|
|
];
|
|
|
|
|
|
|
|
var groups = session.groups || [];
|
|
|
|
groups.forEach(function (group) {
|
|
|
|
sdp.push('a=group:' + group.semantics + ' ' + group.contents.join(' '));
|
|
|
|
});
|
|
|
|
|
|
|
|
var contents = session.contents || [];
|
|
|
|
contents.forEach(function (content) {
|
|
|
|
sdp.push(exports.toMediaSDP(content, opts));
|
|
|
|
});
|
|
|
|
|
|
|
|
return sdp.join('\r\n') + '\r\n';
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toMediaSDP = function (content, opts) {
|
|
|
|
var sdp = [];
|
|
|
|
|
|
|
|
var role = opts.role || 'initiator';
|
|
|
|
var direction = opts.direction || 'outgoing';
|
|
|
|
|
|
|
|
var desc = content.description;
|
|
|
|
var transport = content.transport;
|
|
|
|
var payloads = desc.payloads || [];
|
|
|
|
var fingerprints = (transport && transport.fingerprints) || [];
|
|
|
|
|
|
|
|
var mline = [];
|
|
|
|
if (desc.descType == 'datachannel') {
|
|
|
|
mline.push('application');
|
|
|
|
mline.push('1');
|
|
|
|
mline.push('DTLS/SCTP');
|
|
|
|
if (transport.sctp) {
|
|
|
|
transport.sctp.forEach(function (map) {
|
|
|
|
mline.push(map.number);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mline.push(desc.media);
|
|
|
|
mline.push('1');
|
|
|
|
if ((desc.encryption && desc.encryption.length > 0) || (fingerprints.length > 0)) {
|
|
|
|
mline.push('RTP/SAVPF');
|
|
|
|
} else {
|
|
|
|
mline.push('RTP/AVPF');
|
|
|
|
}
|
|
|
|
payloads.forEach(function (payload) {
|
|
|
|
mline.push(payload.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sdp.push('m=' + mline.join(' '));
|
|
|
|
|
|
|
|
sdp.push('c=IN IP4 0.0.0.0');
|
|
|
|
if (desc.bandwidth && desc.bandwidth.type && desc.bandwidth.bandwidth) {
|
|
|
|
sdp.push('b=' + desc.bandwidth.type + ':' + desc.bandwidth.bandwidth);
|
|
|
|
}
|
|
|
|
if (desc.descType == 'rtp') {
|
|
|
|
sdp.push('a=rtcp:1 IN IP4 0.0.0.0');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transport) {
|
|
|
|
if (transport.ufrag) {
|
|
|
|
sdp.push('a=ice-ufrag:' + transport.ufrag);
|
|
|
|
}
|
|
|
|
if (transport.pwd) {
|
|
|
|
sdp.push('a=ice-pwd:' + transport.pwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
var pushedSetup = false;
|
|
|
|
fingerprints.forEach(function (fingerprint) {
|
|
|
|
sdp.push('a=fingerprint:' + fingerprint.hash + ' ' + fingerprint.value);
|
|
|
|
if (fingerprint.setup && !pushedSetup) {
|
|
|
|
sdp.push('a=setup:' + fingerprint.setup);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (transport.sctp) {
|
|
|
|
transport.sctp.forEach(function (map) {
|
|
|
|
sdp.push('a=sctpmap:' + map.number + ' ' + map.protocol + ' ' + map.streams);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.descType == 'rtp') {
|
|
|
|
sdp.push('a=' + (SENDERS[role][direction][content.senders] || 'sendrecv'));
|
|
|
|
}
|
|
|
|
sdp.push('a=mid:' + content.name);
|
|
|
|
|
|
|
|
if (desc.sources && desc.sources.length) {
|
|
|
|
(desc.sources[0].parameters || []).forEach(function (param) {
|
|
|
|
if (param.key === 'msid') {
|
|
|
|
sdp.push('a=msid:' + param.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.mux) {
|
|
|
|
sdp.push('a=rtcp-mux');
|
|
|
|
}
|
|
|
|
|
|
|
|
var encryption = desc.encryption || [];
|
|
|
|
encryption.forEach(function (crypto) {
|
|
|
|
sdp.push('a=crypto:' + crypto.tag + ' ' + crypto.cipherSuite + ' ' + crypto.keyParams + (crypto.sessionParams ? ' ' + crypto.sessionParams : ''));
|
|
|
|
});
|
|
|
|
if (desc.googConferenceFlag) {
|
|
|
|
sdp.push('a=x-google-flag:conference');
|
|
|
|
}
|
|
|
|
|
|
|
|
payloads.forEach(function (payload) {
|
|
|
|
var rtpmap = 'a=rtpmap:' + payload.id + ' ' + payload.name + '/' + payload.clockrate;
|
|
|
|
if (payload.channels && payload.channels != '1') {
|
|
|
|
rtpmap += '/' + payload.channels;
|
|
|
|
}
|
|
|
|
sdp.push(rtpmap);
|
|
|
|
|
|
|
|
if (payload.parameters && payload.parameters.length) {
|
|
|
|
var fmtp = ['a=fmtp:' + payload.id];
|
|
|
|
var parameters = [];
|
|
|
|
payload.parameters.forEach(function (param) {
|
|
|
|
parameters.push((param.key ? param.key + '=' : '') + param.value);
|
|
|
|
});
|
|
|
|
fmtp.push(parameters.join(';'));
|
|
|
|
sdp.push(fmtp.join(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (payload.feedback) {
|
|
|
|
payload.feedback.forEach(function (fb) {
|
|
|
|
if (fb.type === 'trr-int') {
|
|
|
|
sdp.push('a=rtcp-fb:' + payload.id + ' trr-int ' + (fb.value ? fb.value : '0'));
|
|
|
|
} else {
|
|
|
|
sdp.push('a=rtcp-fb:' + payload.id + ' ' + fb.type + (fb.subtype ? ' ' + fb.subtype : ''));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (desc.feedback) {
|
|
|
|
desc.feedback.forEach(function (fb) {
|
|
|
|
if (fb.type === 'trr-int') {
|
|
|
|
sdp.push('a=rtcp-fb:* trr-int ' + (fb.value ? fb.value : '0'));
|
|
|
|
} else {
|
|
|
|
sdp.push('a=rtcp-fb:* ' + fb.type + (fb.subtype ? ' ' + fb.subtype : ''));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var hdrExts = desc.headerExtensions || [];
|
|
|
|
hdrExts.forEach(function (hdr) {
|
|
|
|
sdp.push('a=extmap:' + hdr.id + (hdr.senders ? '/' + SENDERS[role][direction][hdr.senders] : '') + ' ' + hdr.uri);
|
|
|
|
});
|
|
|
|
|
|
|
|
var ssrcGroups = desc.sourceGroups || [];
|
|
|
|
ssrcGroups.forEach(function (ssrcGroup) {
|
|
|
|
sdp.push('a=ssrc-group:' + ssrcGroup.semantics + ' ' + ssrcGroup.sources.join(' '));
|
|
|
|
});
|
|
|
|
|
|
|
|
var ssrcs = desc.sources || [];
|
|
|
|
ssrcs.forEach(function (ssrc) {
|
|
|
|
for (var i = 0; i < ssrc.parameters.length; i++) {
|
|
|
|
var param = ssrc.parameters[i];
|
|
|
|
sdp.push('a=ssrc:' + (ssrc.ssrc || desc.ssrc) + ' ' + param.key + (param.value ? (':' + param.value) : ''));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var candidates = transport.candidates || [];
|
|
|
|
candidates.forEach(function (candidate) {
|
|
|
|
sdp.push(exports.toCandidateSDP(candidate));
|
|
|
|
});
|
|
|
|
|
|
|
|
return sdp.join('\r\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toCandidateSDP = function (candidate) {
|
|
|
|
var sdp = [];
|
|
|
|
|
|
|
|
sdp.push(candidate.foundation);
|
|
|
|
sdp.push(candidate.component);
|
|
|
|
sdp.push(candidate.protocol.toUpperCase());
|
|
|
|
sdp.push(candidate.priority);
|
|
|
|
sdp.push(candidate.ip);
|
|
|
|
sdp.push(candidate.port);
|
|
|
|
|
|
|
|
var type = candidate.type;
|
|
|
|
sdp.push('typ');
|
|
|
|
sdp.push(type);
|
|
|
|
if (type === 'srflx' || type === 'prflx' || type === 'relay') {
|
|
|
|
if (candidate.relAddr && candidate.relPort) {
|
|
|
|
sdp.push('raddr');
|
|
|
|
sdp.push(candidate.relAddr);
|
|
|
|
sdp.push('rport');
|
|
|
|
sdp.push(candidate.relPort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (candidate.tcpType && candidate.protocol.toUpperCase() == 'TCP') {
|
|
|
|
sdp.push('tcptype');
|
|
|
|
sdp.push(candidate.tcpType);
|
|
|
|
}
|
|
|
|
|
|
|
|
sdp.push('generation');
|
|
|
|
sdp.push(candidate.generation || '0');
|
|
|
|
|
|
|
|
// FIXME: apparently this is wrong per spec
|
|
|
|
// but then, we need this when actually putting this into
|
|
|
|
// SDP so it's going to stay.
|
|
|
|
// decision needs to be revisited when browsers dont
|
|
|
|
// accept this any longer
|
|
|
|
return 'a=candidate:' + sdp.join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./senders":37}],28:[function(require,module,exports){
|
|
|
|
var SENDERS = require('./senders');
|
|
|
|
var parsers = require('./parsers');
|
|
|
|
var idCounter = Math.random();
|
|
|
|
|
|
|
|
|
|
|
|
exports._setIdCounter = function (counter) {
|
|
|
|
idCounter = counter;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toSessionJSON = function (sdp, opts) {
|
|
|
|
var i;
|
|
|
|
var creators = opts.creators || [];
|
|
|
|
var role = opts.role || 'initiator';
|
|
|
|
var direction = opts.direction || 'outgoing';
|
|
|
|
|
|
|
|
|
|
|
|
// Divide the SDP into session and media sections.
|
|
|
|
var media = sdp.split('\r\nm=');
|
|
|
|
for (i = 1; i < media.length; i++) {
|
|
|
|
media[i] = 'm=' + media[i];
|
|
|
|
if (i !== media.length - 1) {
|
|
|
|
media[i] += '\r\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var session = media.shift() + '\r\n';
|
|
|
|
var sessionLines = parsers.lines(session);
|
|
|
|
var parsed = {};
|
|
|
|
|
|
|
|
var contents = [];
|
|
|
|
for (i = 0; i < media.length; i++) {
|
|
|
|
contents.push(exports.toMediaJSON(media[i], session, {
|
|
|
|
role: role,
|
|
|
|
direction: direction,
|
|
|
|
creator: creators[i] || 'initiator'
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
parsed.contents = contents;
|
|
|
|
|
|
|
|
var groupLines = parsers.findLines('a=group:', sessionLines);
|
|
|
|
if (groupLines.length) {
|
|
|
|
parsed.groups = parsers.groups(groupLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toMediaJSON = function (media, session, opts) {
|
|
|
|
var creator = opts.creator || 'initiator';
|
|
|
|
var role = opts.role || 'initiator';
|
|
|
|
var direction = opts.direction || 'outgoing';
|
|
|
|
|
|
|
|
var lines = parsers.lines(media);
|
|
|
|
var sessionLines = parsers.lines(session);
|
|
|
|
var mline = parsers.mline(lines[0]);
|
|
|
|
|
|
|
|
var content = {
|
|
|
|
creator: creator,
|
|
|
|
name: mline.media,
|
|
|
|
description: {
|
|
|
|
descType: 'rtp',
|
|
|
|
media: mline.media,
|
|
|
|
payloads: [],
|
|
|
|
encryption: [],
|
|
|
|
feedback: [],
|
|
|
|
headerExtensions: []
|
|
|
|
},
|
|
|
|
transport: {
|
|
|
|
transType: 'iceUdp',
|
|
|
|
candidates: [],
|
|
|
|
fingerprints: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (mline.media == 'application') {
|
|
|
|
// FIXME: the description is most likely to be independent
|
|
|
|
// of the SDP and should be processed by other parts of the library
|
|
|
|
content.description = {
|
|
|
|
descType: 'datachannel'
|
|
|
|
};
|
|
|
|
content.transport.sctp = [];
|
|
|
|
}
|
|
|
|
var desc = content.description;
|
|
|
|
var trans = content.transport;
|
|
|
|
|
|
|
|
// If we have a mid, use that for the content name instead.
|
|
|
|
var mid = parsers.findLine('a=mid:', lines);
|
|
|
|
if (mid) {
|
|
|
|
content.name = mid.substr(6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsers.findLine('a=sendrecv', lines, sessionLines)) {
|
|
|
|
content.senders = 'both';
|
|
|
|
} else if (parsers.findLine('a=sendonly', lines, sessionLines)) {
|
|
|
|
content.senders = SENDERS[role][direction].sendonly;
|
|
|
|
} else if (parsers.findLine('a=recvonly', lines, sessionLines)) {
|
|
|
|
content.senders = SENDERS[role][direction].recvonly;
|
|
|
|
} else if (parsers.findLine('a=inactive', lines, sessionLines)) {
|
|
|
|
content.senders = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.descType == 'rtp') {
|
|
|
|
var bandwidth = parsers.findLine('b=', lines);
|
|
|
|
if (bandwidth) {
|
|
|
|
desc.bandwidth = parsers.bandwidth(bandwidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
var ssrc = parsers.findLine('a=ssrc:', lines);
|
|
|
|
if (ssrc) {
|
|
|
|
desc.ssrc = ssrc.substr(7).split(' ')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
var rtpmapLines = parsers.findLines('a=rtpmap:', lines);
|
|
|
|
rtpmapLines.forEach(function (line) {
|
|
|
|
var payload = parsers.rtpmap(line);
|
|
|
|
payload.parameters = [];
|
|
|
|
payload.feedback = [];
|
|
|
|
|
|
|
|
var fmtpLines = parsers.findLines('a=fmtp:' + payload.id, lines);
|
|
|
|
// There should only be one fmtp line per payload
|
|
|
|
fmtpLines.forEach(function (line) {
|
|
|
|
payload.parameters = parsers.fmtp(line);
|
|
|
|
});
|
|
|
|
|
|
|
|
var fbLines = parsers.findLines('a=rtcp-fb:' + payload.id, lines);
|
|
|
|
fbLines.forEach(function (line) {
|
|
|
|
payload.feedback.push(parsers.rtcpfb(line));
|
|
|
|
});
|
|
|
|
|
|
|
|
desc.payloads.push(payload);
|
|
|
|
});
|
|
|
|
|
|
|
|
var cryptoLines = parsers.findLines('a=crypto:', lines, sessionLines);
|
|
|
|
cryptoLines.forEach(function (line) {
|
|
|
|
desc.encryption.push(parsers.crypto(line));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (parsers.findLine('a=rtcp-mux', lines)) {
|
|
|
|
desc.mux = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var fbLines = parsers.findLines('a=rtcp-fb:*', lines);
|
|
|
|
fbLines.forEach(function (line) {
|
|
|
|
desc.feedback.push(parsers.rtcpfb(line));
|
|
|
|
});
|
|
|
|
|
|
|
|
var extLines = parsers.findLines('a=extmap:', lines);
|
|
|
|
extLines.forEach(function (line) {
|
|
|
|
var ext = parsers.extmap(line);
|
|
|
|
|
|
|
|
ext.senders = SENDERS[role][direction][ext.senders];
|
|
|
|
|
|
|
|
desc.headerExtensions.push(ext);
|
|
|
|
});
|
|
|
|
|
|
|
|
var ssrcGroupLines = parsers.findLines('a=ssrc-group:', lines);
|
|
|
|
desc.sourceGroups = parsers.sourceGroups(ssrcGroupLines || []);
|
|
|
|
|
|
|
|
var ssrcLines = parsers.findLines('a=ssrc:', lines);
|
|
|
|
var sources = desc.sources = parsers.sources(ssrcLines || []);
|
|
|
|
|
|
|
|
var msidLine = parsers.findLine('a=msid:', lines);
|
|
|
|
if (msidLine) {
|
|
|
|
var msid = parsers.msid(msidLine);
|
|
|
|
['msid', 'mslabel', 'label'].forEach(function (key) {
|
|
|
|
for (var i = 0; i < sources.length; i++) {
|
|
|
|
var found = false;
|
|
|
|
for (var j = 0; j < sources[i].parameters.length; j++) {
|
|
|
|
if (sources[i].parameters[j].key === key) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
sources[i].parameters.push({ key: key, value: msid[key] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsers.findLine('a=x-google-flag:conference', lines, sessionLines)) {
|
|
|
|
desc.googConferenceFlag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// transport specific attributes
|
|
|
|
var fingerprintLines = parsers.findLines('a=fingerprint:', lines, sessionLines);
|
|
|
|
var setup = parsers.findLine('a=setup:', lines, sessionLines);
|
|
|
|
fingerprintLines.forEach(function (line) {
|
|
|
|
var fp = parsers.fingerprint(line);
|
|
|
|
if (setup) {
|
|
|
|
fp.setup = setup.substr(8);
|
|
|
|
}
|
|
|
|
trans.fingerprints.push(fp);
|
|
|
|
});
|
|
|
|
|
|
|
|
var ufragLine = parsers.findLine('a=ice-ufrag:', lines, sessionLines);
|
|
|
|
var pwdLine = parsers.findLine('a=ice-pwd:', lines, sessionLines);
|
|
|
|
if (ufragLine && pwdLine) {
|
|
|
|
trans.ufrag = ufragLine.substr(12);
|
|
|
|
trans.pwd = pwdLine.substr(10);
|
|
|
|
trans.candidates = [];
|
|
|
|
|
|
|
|
var candidateLines = parsers.findLines('a=candidate:', lines, sessionLines);
|
|
|
|
candidateLines.forEach(function (line) {
|
|
|
|
trans.candidates.push(exports.toCandidateJSON(line));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.descType == 'datachannel') {
|
|
|
|
var sctpmapLines = parsers.findLines('a=sctpmap:', lines);
|
|
|
|
sctpmapLines.forEach(function (line) {
|
|
|
|
var sctp = parsers.sctpmap(line);
|
|
|
|
trans.sctp.push(sctp);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toCandidateJSON = function (line) {
|
|
|
|
var candidate = parsers.candidate(line.split('\r\n')[0]);
|
|
|
|
candidate.id = (idCounter++).toString(36).substr(0, 12);
|
|
|
|
return candidate;
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./parsers":38,"./senders":37}],29:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.0 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `_.forEach` for arrays without support for callback
|
|
|
|
* shorthands or `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Array} Returns `array`.
|
|
|
|
*/
|
|
|
|
function arrayEach(array, iteratee) {
|
|
|
|
var index = -1,
|
|
|
|
length = array.length;
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
if (iteratee(array[index], index, array) === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = arrayEach;
|
|
|
|
|
|
|
|
},{}],31:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseCallback` which only supports `this` binding
|
|
|
|
* and specifying the number of arguments to provide to `func`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} func The function to bind.
|
|
|
|
* @param {*} thisArg The `this` binding of `func`.
|
|
|
|
* @param {number} [argCount] The number of arguments to provide to `func`.
|
|
|
|
* @returns {Function} Returns the callback.
|
|
|
|
*/
|
|
|
|
function bindCallback(func, thisArg, argCount) {
|
|
|
|
if (typeof func != 'function') {
|
|
|
|
return identity;
|
|
|
|
}
|
|
|
|
if (thisArg === undefined) {
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
switch (argCount) {
|
|
|
|
case 1: return function(value) {
|
|
|
|
return func.call(thisArg, value);
|
|
|
|
};
|
|
|
|
case 3: return function(value, index, collection) {
|
|
|
|
return func.call(thisArg, value, index, collection);
|
|
|
|
};
|
|
|
|
case 4: return function(accumulator, value, index, collection) {
|
|
|
|
return func.call(thisArg, accumulator, value, index, collection);
|
|
|
|
};
|
|
|
|
case 5: return function(value, other, key, object, source) {
|
|
|
|
return func.call(thisArg, value, other, key, object, source);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return function() {
|
|
|
|
return func.apply(thisArg, arguments);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method returns the first argument provided to it.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Utility
|
|
|
|
* @param {*} value Any value.
|
|
|
|
* @returns {*} Returns `value`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var object = { 'user': 'fred' };
|
|
|
|
*
|
|
|
|
* _.identity(object) === object;
|
|
|
|
* // => true
|
|
|
|
*/
|
|
|
|
function identity(value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = bindCallback;
|
|
|
|
|
|
|
|
},{}],32:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var arrayTag = '[object Array]',
|
|
|
|
funcTag = '[object Function]';
|
|
|
|
|
|
|
|
/** Used to detect host constructors (Safari > 5). */
|
|
|
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to resolve the decompiled source of functions. */
|
|
|
|
var fnToString = Function.prototype.toString;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/** Used to detect if a method is native. */
|
|
|
|
var reIsNative = RegExp('^' +
|
|
|
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
|
|
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Native method references for those with the same name as other `lodash` methods. */
|
|
|
|
var nativeIsArray = getNative(Array, 'isArray');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the native function at `key` of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {string} key The key of the method to get.
|
|
|
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
|
|
*/
|
|
|
|
function getNative(object, key) {
|
|
|
|
var value = object == null ? undefined : object[key];
|
|
|
|
return isNative(value) ? value : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as an `Array` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isArray([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isArray(function() { return arguments; }());
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
var isArray = nativeIsArray || function(value) {
|
|
|
|
return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as a `Function` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isFunction(_);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isFunction(/abc/);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isFunction(value) {
|
|
|
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
|
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
|
|
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
|
|
|
return isObject(value) && objToString.call(value) == funcTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a native function.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isNative(Array.prototype.push);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isNative(_);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isNative(value) {
|
|
|
|
if (value == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isFunction(value)) {
|
|
|
|
return reIsNative.test(fnToString.call(value));
|
|
|
|
}
|
|
|
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isArray;
|
|
|
|
|
|
|
|
},{}],33:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.7.2 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `get` without support for string paths
|
|
|
|
* and default values.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {Array} path The path of the property to get.
|
|
|
|
* @param {string} [pathKey] The key representation of path.
|
|
|
|
* @returns {*} Returns the resolved value.
|
|
|
|
*/
|
|
|
|
function baseGet(object, path, pathKey) {
|
|
|
|
if (object == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pathKey !== undefined && pathKey in toObject(object)) {
|
|
|
|
path = [pathKey];
|
|
|
|
}
|
|
|
|
var index = 0,
|
|
|
|
length = path.length;
|
|
|
|
|
|
|
|
while (object != null && index < length) {
|
|
|
|
object = object[path[index++]];
|
|
|
|
}
|
|
|
|
return (index && index == length) ? object : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseGet;
|
|
|
|
|
|
|
|
},{}],35:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var arrayTag = '[object Array]',
|
|
|
|
funcTag = '[object Function]';
|
|
|
|
|
|
|
|
/** Used to detect host constructors (Safari > 5). */
|
|
|
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to resolve the decompiled source of functions. */
|
|
|
|
var fnToString = Function.prototype.toString;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/** Used to detect if a method is native. */
|
|
|
|
var reIsNative = RegExp('^' +
|
|
|
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
|
|
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Native method references for those with the same name as other `lodash` methods. */
|
|
|
|
var nativeIsArray = getNative(Array, 'isArray');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the native function at `key` of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {string} key The key of the method to get.
|
|
|
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
|
|
*/
|
|
|
|
function getNative(object, key) {
|
|
|
|
var value = object == null ? undefined : object[key];
|
|
|
|
return isNative(value) ? value : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as an `Array` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isArray([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isArray(function() { return arguments; }());
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
var isArray = nativeIsArray || function(value) {
|
|
|
|
return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as a `Function` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isFunction(_);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isFunction(/abc/);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isFunction(value) {
|
|
|
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
|
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
|
|
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
|
|
|
return isObject(value) && objToString.call(value) == funcTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a native function.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isNative(Array.prototype.push);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isNative(_);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isNative(value) {
|
|
|
|
if (value == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isFunction(value)) {
|
|
|
|
return reIsNative.test(fnToString.call(value));
|
|
|
|
}
|
|
|
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isArray;
|
|
|
|
|
|
|
|
},{}],38:[function(require,module,exports){
|
|
|
|
exports.lines = function (sdp) {
|
|
|
|
return sdp.split('\r\n').filter(function (line) {
|
|
|
|
return line.length > 0;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.findLine = function (prefix, mediaLines, sessionLines) {
|
|
|
|
var prefixLength = prefix.length;
|
|
|
|
for (var i = 0; i < mediaLines.length; i++) {
|
|
|
|
if (mediaLines[i].substr(0, prefixLength) === prefix) {
|
|
|
|
return mediaLines[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Continue searching in parent session section
|
|
|
|
if (!sessionLines) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var j = 0; j < sessionLines.length; j++) {
|
|
|
|
if (sessionLines[j].substr(0, prefixLength) === prefix) {
|
|
|
|
return sessionLines[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.findLines = function (prefix, mediaLines, sessionLines) {
|
|
|
|
var results = [];
|
|
|
|
var prefixLength = prefix.length;
|
|
|
|
for (var i = 0; i < mediaLines.length; i++) {
|
|
|
|
if (mediaLines[i].substr(0, prefixLength) === prefix) {
|
|
|
|
results.push(mediaLines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (results.length || !sessionLines) {
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
for (var j = 0; j < sessionLines.length; j++) {
|
|
|
|
if (sessionLines[j].substr(0, prefixLength) === prefix) {
|
|
|
|
results.push(sessionLines[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.mline = function (line) {
|
|
|
|
var parts = line.substr(2).split(' ');
|
|
|
|
var parsed = {
|
|
|
|
media: parts[0],
|
|
|
|
port: parts[1],
|
|
|
|
proto: parts[2],
|
|
|
|
formats: []
|
|
|
|
};
|
|
|
|
for (var i = 3; i < parts.length; i++) {
|
|
|
|
if (parts[i]) {
|
|
|
|
parsed.formats.push(parts[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.rtpmap = function (line) {
|
|
|
|
var parts = line.substr(9).split(' ');
|
|
|
|
var parsed = {
|
|
|
|
id: parts.shift()
|
|
|
|
};
|
|
|
|
|
|
|
|
parts = parts[0].split('/');
|
|
|
|
|
|
|
|
parsed.name = parts[0];
|
|
|
|
parsed.clockrate = parts[1];
|
|
|
|
parsed.channels = parts.length == 3 ? parts[2] : '1';
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.sctpmap = function (line) {
|
|
|
|
// based on -05 draft
|
|
|
|
var parts = line.substr(10).split(' ');
|
|
|
|
var parsed = {
|
|
|
|
number: parts.shift(),
|
|
|
|
protocol: parts.shift(),
|
|
|
|
streams: parts.shift()
|
|
|
|
};
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.fmtp = function (line) {
|
|
|
|
var kv, key, value;
|
|
|
|
var parts = line.substr(line.indexOf(' ') + 1).split(';');
|
|
|
|
var parsed = [];
|
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
kv = parts[i].split('=');
|
|
|
|
key = kv[0].trim();
|
|
|
|
value = kv[1];
|
|
|
|
if (key && value) {
|
|
|
|
parsed.push({key: key, value: value});
|
|
|
|
} else if (key) {
|
|
|
|
parsed.push({key: '', value: key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.crypto = function (line) {
|
|
|
|
var parts = line.substr(9).split(' ');
|
|
|
|
var parsed = {
|
|
|
|
tag: parts[0],
|
|
|
|
cipherSuite: parts[1],
|
|
|
|
keyParams: parts[2],
|
|
|
|
sessionParams: parts.slice(3).join(' ')
|
|
|
|
};
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fingerprint = function (line) {
|
|
|
|
var parts = line.substr(14).split(' ');
|
|
|
|
return {
|
|
|
|
hash: parts[0],
|
|
|
|
value: parts[1]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.extmap = function (line) {
|
|
|
|
var parts = line.substr(9).split(' ');
|
|
|
|
var parsed = {};
|
|
|
|
|
|
|
|
var idpart = parts.shift();
|
|
|
|
var sp = idpart.indexOf('/');
|
|
|
|
if (sp >= 0) {
|
|
|
|
parsed.id = idpart.substr(0, sp);
|
|
|
|
parsed.senders = idpart.substr(sp + 1);
|
|
|
|
} else {
|
|
|
|
parsed.id = idpart;
|
|
|
|
parsed.senders = 'sendrecv';
|
|
|
|
}
|
|
|
|
|
|
|
|
parsed.uri = parts.shift() || '';
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.rtcpfb = function (line) {
|
|
|
|
var parts = line.substr(10).split(' ');
|
|
|
|
var parsed = {};
|
|
|
|
parsed.id = parts.shift();
|
|
|
|
parsed.type = parts.shift();
|
|
|
|
if (parsed.type === 'trr-int') {
|
|
|
|
parsed.value = parts.shift();
|
|
|
|
} else {
|
|
|
|
parsed.subtype = parts.shift() || '';
|
|
|
|
}
|
|
|
|
parsed.parameters = parts;
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.candidate = function (line) {
|
|
|
|
var parts;
|
|
|
|
if (line.indexOf('a=candidate:') === 0) {
|
|
|
|
parts = line.substring(12).split(' ');
|
|
|
|
} else { // no a=candidate
|
|
|
|
parts = line.substring(10).split(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
var candidate = {
|
|
|
|
foundation: parts[0],
|
|
|
|
component: parts[1],
|
|
|
|
protocol: parts[2].toLowerCase(),
|
|
|
|
priority: parts[3],
|
|
|
|
ip: parts[4],
|
|
|
|
port: parts[5],
|
|
|
|
// skip parts[6] == 'typ'
|
|
|
|
type: parts[7],
|
|
|
|
generation: '0'
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 8; i < parts.length; i += 2) {
|
|
|
|
if (parts[i] === 'raddr') {
|
|
|
|
candidate.relAddr = parts[i + 1];
|
|
|
|
} else if (parts[i] === 'rport') {
|
|
|
|
candidate.relPort = parts[i + 1];
|
|
|
|
} else if (parts[i] === 'generation') {
|
|
|
|
candidate.generation = parts[i + 1];
|
|
|
|
} else if (parts[i] === 'tcptype') {
|
|
|
|
candidate.tcpType = parts[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
candidate.network = '1';
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.sourceGroups = function (lines) {
|
|
|
|
var parsed = [];
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
var parts = lines[i].substr(13).split(' ');
|
|
|
|
parsed.push({
|
|
|
|
semantics: parts.shift(),
|
|
|
|
sources: parts
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.sources = function (lines) {
|
|
|
|
// http://tools.ietf.org/html/rfc5576
|
|
|
|
var parsed = [];
|
|
|
|
var sources = {};
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
var parts = lines[i].substr(7).split(' ');
|
|
|
|
var ssrc = parts.shift();
|
|
|
|
|
|
|
|
if (!sources[ssrc]) {
|
|
|
|
var source = {
|
|
|
|
ssrc: ssrc,
|
|
|
|
parameters: []
|
|
|
|
};
|
|
|
|
parsed.push(source);
|
|
|
|
|
|
|
|
// Keep an index
|
|
|
|
sources[ssrc] = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
parts = parts.join(' ').split(':');
|
|
|
|
var attribute = parts.shift();
|
|
|
|
var value = parts.join(':') || null;
|
|
|
|
|
|
|
|
sources[ssrc].parameters.push({
|
|
|
|
key: attribute,
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.groups = function (lines) {
|
|
|
|
// http://tools.ietf.org/html/rfc5888
|
|
|
|
var parsed = [];
|
|
|
|
var parts;
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
parts = lines[i].substr(8).split(' ');
|
|
|
|
parsed.push({
|
|
|
|
semantics: parts.shift(),
|
|
|
|
contents: parts
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.bandwidth = function (line) {
|
|
|
|
var parts = line.substr(2).split(':');
|
|
|
|
var parsed = {};
|
|
|
|
parsed.type = parts.shift();
|
|
|
|
parsed.bandwidth = parts.shift();
|
|
|
|
return parsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.msid = function (line) {
|
|
|
|
var data = line.substr(7);
|
|
|
|
var parts = data.split(' ');
|
|
|
|
return {
|
|
|
|
msid: data,
|
|
|
|
mslabel: parts[0],
|
|
|
|
label: parts[1]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],37:[function(require,module,exports){
|
|
|
|
module.exports = {
|
|
|
|
initiator: {
|
|
|
|
incoming: {
|
|
|
|
initiator: 'recvonly',
|
|
|
|
responder: 'sendonly',
|
|
|
|
both: 'sendrecv',
|
|
|
|
none: 'inactive',
|
|
|
|
recvonly: 'initiator',
|
|
|
|
sendonly: 'responder',
|
|
|
|
sendrecv: 'both',
|
|
|
|
inactive: 'none'
|
|
|
|
},
|
|
|
|
outgoing: {
|
|
|
|
initiator: 'sendonly',
|
|
|
|
responder: 'recvonly',
|
|
|
|
both: 'sendrecv',
|
|
|
|
none: 'inactive',
|
|
|
|
recvonly: 'responder',
|
|
|
|
sendonly: 'initiator',
|
|
|
|
sendrecv: 'both',
|
|
|
|
inactive: 'none'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
responder: {
|
|
|
|
incoming: {
|
|
|
|
initiator: 'sendonly',
|
|
|
|
responder: 'recvonly',
|
|
|
|
both: 'sendrecv',
|
|
|
|
none: 'inactive',
|
|
|
|
recvonly: 'responder',
|
|
|
|
sendonly: 'initiator',
|
|
|
|
sendrecv: 'both',
|
|
|
|
inactive: 'none'
|
|
|
|
},
|
|
|
|
outgoing: {
|
|
|
|
initiator: 'recvonly',
|
|
|
|
responder: 'sendonly',
|
|
|
|
both: 'sendrecv',
|
|
|
|
none: 'inactive',
|
|
|
|
recvonly: 'initiator',
|
|
|
|
sendonly: 'responder',
|
|
|
|
sendrecv: 'both',
|
|
|
|
inactive: 'none'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}],22:[function(require,module,exports){
|
|
|
|
// based on https://github.com/ESTOS/strophe.jingle/
|
|
|
|
// adds wildemitter support
|
|
|
|
var util = require('util');
|
|
|
|
var adapter = require('webrtc-adapter-test');
|
|
|
|
var WildEmitter = require('wildemitter');
|
|
|
|
|
|
|
|
function dumpSDP(description) {
|
|
|
|
return {
|
|
|
|
type: description.type,
|
|
|
|
sdp: description.sdp
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function dumpStream(stream) {
|
|
|
|
var info = {
|
|
|
|
label: stream.id,
|
|
|
|
};
|
|
|
|
if (stream.getAudioTracks().length) {
|
|
|
|
info.audio = stream.getAudioTracks().map(function (track) {
|
|
|
|
return track.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (stream.getVideoTracks().length) {
|
|
|
|
info.video = stream.getVideoTracks().map(function (track) {
|
|
|
|
return track.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function TraceablePeerConnection(config, constraints) {
|
|
|
|
var self = this;
|
|
|
|
WildEmitter.call(this);
|
|
|
|
|
|
|
|
this.peerconnection = new window.RTCPeerConnection(config, constraints);
|
|
|
|
|
|
|
|
this.trace = function (what, info) {
|
|
|
|
self.emit('PeerConnectionTrace', {
|
|
|
|
time: new Date(),
|
|
|
|
type: what,
|
|
|
|
value: info || ""
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onicecandidate = null;
|
|
|
|
this.peerconnection.onicecandidate = function (event) {
|
|
|
|
self.trace('onicecandidate', event.candidate);
|
|
|
|
if (self.onicecandidate !== null) {
|
|
|
|
self.onicecandidate(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.onaddstream = null;
|
|
|
|
this.peerconnection.onaddstream = function (event) {
|
|
|
|
self.trace('onaddstream', dumpStream(event.stream));
|
|
|
|
if (self.onaddstream !== null) {
|
|
|
|
self.onaddstream(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.onremovestream = null;
|
|
|
|
this.peerconnection.onremovestream = function (event) {
|
|
|
|
self.trace('onremovestream', dumpStream(event.stream));
|
|
|
|
if (self.onremovestream !== null) {
|
|
|
|
self.onremovestream(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.onsignalingstatechange = null;
|
|
|
|
this.peerconnection.onsignalingstatechange = function (event) {
|
|
|
|
self.trace('onsignalingstatechange', self.signalingState);
|
|
|
|
if (self.onsignalingstatechange !== null) {
|
|
|
|
self.onsignalingstatechange(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.oniceconnectionstatechange = null;
|
|
|
|
this.peerconnection.oniceconnectionstatechange = function (event) {
|
|
|
|
self.trace('oniceconnectionstatechange', self.iceConnectionState);
|
|
|
|
if (self.oniceconnectionstatechange !== null) {
|
|
|
|
self.oniceconnectionstatechange(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.onnegotiationneeded = null;
|
|
|
|
this.peerconnection.onnegotiationneeded = function (event) {
|
|
|
|
self.trace('onnegotiationneeded');
|
|
|
|
if (self.onnegotiationneeded !== null) {
|
|
|
|
self.onnegotiationneeded(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
self.ondatachannel = null;
|
|
|
|
this.peerconnection.ondatachannel = function (event) {
|
|
|
|
self.trace('ondatachannel', event);
|
|
|
|
if (self.ondatachannel !== null) {
|
|
|
|
self.ondatachannel(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.getLocalStreams = this.peerconnection.getLocalStreams.bind(this.peerconnection);
|
|
|
|
this.getRemoteStreams = this.peerconnection.getRemoteStreams.bind(this.peerconnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(TraceablePeerConnection, WildEmitter);
|
|
|
|
|
|
|
|
['signalingState', 'iceConnectionState', 'localDescription', 'remoteDescription'].forEach(function (prop) {
|
|
|
|
Object.defineProperty(TraceablePeerConnection.prototype, prop, {
|
|
|
|
get: function () {
|
|
|
|
return this.peerconnection[prop];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.addStream = function (stream) {
|
|
|
|
this.trace('addStream', dumpStream(stream));
|
|
|
|
this.peerconnection.addStream(stream);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.removeStream = function (stream) {
|
|
|
|
this.trace('removeStream', dumpStream(stream));
|
|
|
|
this.peerconnection.removeStream(stream);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
|
|
|
|
this.trace('createDataChannel', label, opts);
|
|
|
|
return this.peerconnection.createDataChannel(label, opts);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) {
|
|
|
|
var self = this;
|
|
|
|
this.trace('setLocalDescription', dumpSDP(description));
|
|
|
|
this.peerconnection.setLocalDescription(description,
|
|
|
|
function () {
|
|
|
|
self.trace('setLocalDescriptionOnSuccess');
|
|
|
|
if (successCallback) successCallback();
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.trace('setLocalDescriptionOnFailure', err);
|
|
|
|
if (failureCallback) failureCallback(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) {
|
|
|
|
var self = this;
|
|
|
|
this.trace('setRemoteDescription', dumpSDP(description));
|
|
|
|
this.peerconnection.setRemoteDescription(description,
|
|
|
|
function () {
|
|
|
|
self.trace('setRemoteDescriptionOnSuccess');
|
|
|
|
if (successCallback) successCallback();
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.trace('setRemoteDescriptionOnFailure', err);
|
|
|
|
if (failureCallback) failureCallback(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.close = function () {
|
|
|
|
this.trace('stop');
|
|
|
|
if (this.peerconnection.signalingState != 'closed') {
|
|
|
|
this.peerconnection.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.createOffer = function (successCallback, failureCallback, constraints) {
|
|
|
|
var self = this;
|
|
|
|
this.trace('createOffer', constraints);
|
|
|
|
this.peerconnection.createOffer(
|
|
|
|
function (offer) {
|
|
|
|
self.trace('createOfferOnSuccess', dumpSDP(offer));
|
|
|
|
if (successCallback) successCallback(offer);
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.trace('createOfferOnFailure', err);
|
|
|
|
if (failureCallback) failureCallback(err);
|
|
|
|
},
|
|
|
|
constraints
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) {
|
|
|
|
var self = this;
|
|
|
|
this.trace('createAnswer', constraints);
|
|
|
|
this.peerconnection.createAnswer(
|
|
|
|
function (answer) {
|
|
|
|
self.trace('createAnswerOnSuccess', dumpSDP(answer));
|
|
|
|
if (successCallback) successCallback(answer);
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.trace('createAnswerOnFailure', err);
|
|
|
|
if (failureCallback) failureCallback(err);
|
|
|
|
},
|
|
|
|
constraints
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.addIceCandidate = function (candidate, successCallback, failureCallback) {
|
|
|
|
var self = this;
|
|
|
|
this.trace('addIceCandidate', candidate);
|
|
|
|
this.peerconnection.addIceCandidate(candidate,
|
|
|
|
function () {
|
|
|
|
//self.trace('addIceCandidateOnSuccess');
|
|
|
|
if (successCallback) successCallback();
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
self.trace('addIceCandidateOnFailure', err);
|
|
|
|
if (failureCallback) failureCallback(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.getStats = function () {
|
|
|
|
this.peerconnection.getStats.apply(this.peerconnection, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TraceablePeerConnection;
|
|
|
|
|
|
|
|
},{"util":8,"webrtc-adapter-test":20,"wildemitter":4}],30:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var keys = require('lodash.keys');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.forEach` without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Array|Object|string} Returns `collection`.
|
|
|
|
*/
|
|
|
|
var baseEach = createBaseEach(baseForOwn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
|
|
|
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
|
|
|
* each property. Iteratee functions may exit iteration early by explicitly
|
|
|
|
* returning `false`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @param {Function} keysFunc The function to get the keys of `object`.
|
|
|
|
* @returns {Object} Returns `object`.
|
|
|
|
*/
|
|
|
|
var baseFor = createBaseFor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.forOwn` without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Object} Returns `object`.
|
|
|
|
*/
|
|
|
|
function baseForOwn(object, iteratee) {
|
|
|
|
return baseFor(object, iteratee, keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a `baseEach` or `baseEachRight` function.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} eachFunc The function to iterate over a collection.
|
|
|
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
|
|
|
* @returns {Function} Returns the new base function.
|
|
|
|
*/
|
|
|
|
function createBaseEach(eachFunc, fromRight) {
|
|
|
|
return function(collection, iteratee) {
|
|
|
|
var length = collection ? getLength(collection) : 0;
|
|
|
|
if (!isLength(length)) {
|
|
|
|
return eachFunc(collection, iteratee);
|
|
|
|
}
|
|
|
|
var index = fromRight ? length : -1,
|
|
|
|
iterable = toObject(collection);
|
|
|
|
|
|
|
|
while ((fromRight ? index-- : ++index < length)) {
|
|
|
|
if (iteratee(iterable[index], index, iterable) === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return collection;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a base function for `_.forIn` or `_.forInRight`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
|
|
|
* @returns {Function} Returns the new base function.
|
|
|
|
*/
|
|
|
|
function createBaseFor(fromRight) {
|
|
|
|
return function(object, iteratee, keysFunc) {
|
|
|
|
var iterable = toObject(object),
|
|
|
|
props = keysFunc(object),
|
|
|
|
length = props.length,
|
|
|
|
index = fromRight ? length : -1;
|
|
|
|
|
|
|
|
while ((fromRight ? index-- : ++index < length)) {
|
|
|
|
var key = props[index];
|
|
|
|
if (iteratee(iterable[key], key, iterable) === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseEach;
|
|
|
|
|
|
|
|
},{"lodash.keys":39}],40:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.0 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `_.map` for arrays without support for callback
|
|
|
|
* shorthands or `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Array} Returns the new mapped array.
|
|
|
|
*/
|
|
|
|
function arrayMap(array, iteratee) {
|
|
|
|
var index = -1,
|
|
|
|
length = array.length,
|
|
|
|
result = Array(length);
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
result[index] = iteratee(array[index], index, array);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = arrayMap;
|
|
|
|
|
|
|
|
},{}],34:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.8.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var isArray = require('lodash.isarray');
|
|
|
|
|
|
|
|
/** Used to match property names within property paths. */
|
|
|
|
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
|
|
|
|
|
|
|
/** Used to match backslashes in property paths. */
|
|
|
|
var reEscapeChar = /\\(\\)?/g;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to a string if it's not one. An empty string is returned
|
|
|
|
* for `null` or `undefined` values.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {string} Returns the string.
|
|
|
|
*/
|
|
|
|
function baseToString(value) {
|
|
|
|
return value == null ? '' : (value + '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to property path array if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Array} Returns the property path array.
|
|
|
|
*/
|
|
|
|
function toPath(value) {
|
|
|
|
if (isArray(value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
var result = [];
|
|
|
|
baseToString(value).replace(rePropName, function(match, number, quote, string) {
|
|
|
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = toPath;
|
|
|
|
|
|
|
|
},{"lodash.isarray":35}],36:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.1.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var arrayMap = require('lodash._arraymap'),
|
|
|
|
baseCallback = require('lodash._basecallback'),
|
|
|
|
baseEach = require('lodash._baseeach'),
|
|
|
|
isArray = require('lodash.isarray');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.map` without support for callback shorthands
|
|
|
|
* and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Array} Returns the new mapped array.
|
|
|
|
*/
|
|
|
|
function baseMap(collection, iteratee) {
|
|
|
|
var index = -1,
|
|
|
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
|
|
|
|
|
|
|
baseEach(collection, function(value, key, collection) {
|
|
|
|
result[++index] = iteratee(value, key, collection);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is array-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isArrayLike(value) {
|
|
|
|
return value != null && isLength(getLength(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of values by running each element in `collection` through
|
|
|
|
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
|
|
|
|
* arguments: (value, index|key, collection).
|
|
|
|
*
|
|
|
|
* If a property name is provided for `iteratee` the created `_.property`
|
|
|
|
* style callback returns the property value of the given element.
|
|
|
|
*
|
|
|
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
|
|
* style callback returns `true` for elements that have a matching property
|
|
|
|
* value, else `false`.
|
|
|
|
*
|
|
|
|
* If an object is provided for `iteratee` the created `_.matches` style
|
|
|
|
* callback returns `true` for elements that have the properties of the given
|
|
|
|
* object, else `false`.
|
|
|
|
*
|
|
|
|
* Many lodash methods are guarded to work as iteratees for methods like
|
|
|
|
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
|
|
|
*
|
|
|
|
* The guarded methods are:
|
|
|
|
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
|
|
|
|
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
|
|
|
|
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
|
|
|
|
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
|
|
|
|
* `sum`, `uniq`, and `words`
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @alias collect
|
|
|
|
* @category Collection
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
|
|
|
* per iteration.
|
|
|
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
|
|
|
* @returns {Array} Returns the new mapped array.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* function timesThree(n) {
|
|
|
|
* return n * 3;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* _.map([1, 2], timesThree);
|
|
|
|
* // => [3, 6]
|
|
|
|
*
|
|
|
|
* _.map({ 'a': 1, 'b': 2 }, timesThree);
|
|
|
|
* // => [3, 6] (iteration order is not guaranteed)
|
|
|
|
*
|
|
|
|
* var users = [
|
|
|
|
* { 'user': 'barney' },
|
|
|
|
* { 'user': 'fred' }
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* // using the `_.property` callback shorthand
|
|
|
|
* _.map(users, 'user');
|
|
|
|
* // => ['barney', 'fred']
|
|
|
|
*/
|
|
|
|
function map(collection, iteratee, thisArg) {
|
|
|
|
var func = isArray(collection) ? arrayMap : baseMap;
|
|
|
|
iteratee = baseCallback(iteratee, thisArg, 3);
|
|
|
|
return func(collection, iteratee);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = map;
|
|
|
|
|
|
|
|
},{"lodash._arraymap":40,"lodash._basecallback":41,"lodash._baseeach":42,"lodash.isarray":35}],43:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.9.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var funcTag = '[object Function]';
|
|
|
|
|
|
|
|
/** Used to detect host constructors (Safari > 5). */
|
|
|
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to resolve the decompiled source of functions. */
|
|
|
|
var fnToString = Function.prototype.toString;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/** Used to detect if a method is native. */
|
|
|
|
var reIsNative = RegExp('^' +
|
|
|
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
|
|
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the native function at `key` of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {string} key The key of the method to get.
|
|
|
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
|
|
*/
|
|
|
|
function getNative(object, key) {
|
|
|
|
var value = object == null ? undefined : object[key];
|
|
|
|
return isNative(value) ? value : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as a `Function` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isFunction(_);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isFunction(/abc/);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isFunction(value) {
|
|
|
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
|
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
|
|
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
|
|
|
return isObject(value) && objToString.call(value) == funcTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a native function.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isNative(Array.prototype.push);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isNative(_);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isNative(value) {
|
|
|
|
if (value == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isFunction(value)) {
|
|
|
|
return reIsNative.test(fnToString.call(value));
|
|
|
|
}
|
|
|
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getNative;
|
|
|
|
|
|
|
|
},{}],44:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/** Native method references. */
|
|
|
|
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is array-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isArrayLike(value) {
|
|
|
|
return value != null && isLength(getLength(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as an `arguments` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isArguments(function() { return arguments; }());
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isArguments([1, 2, 3]);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isArguments(value) {
|
|
|
|
return isObjectLike(value) && isArrayLike(value) &&
|
|
|
|
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isArguments;
|
|
|
|
|
|
|
|
},{}],45:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseCallback` which only supports `this` binding
|
|
|
|
* and specifying the number of arguments to provide to `func`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} func The function to bind.
|
|
|
|
* @param {*} thisArg The `this` binding of `func`.
|
|
|
|
* @param {number} [argCount] The number of arguments to provide to `func`.
|
|
|
|
* @returns {Function} Returns the callback.
|
|
|
|
*/
|
|
|
|
function bindCallback(func, thisArg, argCount) {
|
|
|
|
if (typeof func != 'function') {
|
|
|
|
return identity;
|
|
|
|
}
|
|
|
|
if (thisArg === undefined) {
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
switch (argCount) {
|
|
|
|
case 1: return function(value) {
|
|
|
|
return func.call(thisArg, value);
|
|
|
|
};
|
|
|
|
case 3: return function(value, index, collection) {
|
|
|
|
return func.call(thisArg, value, index, collection);
|
|
|
|
};
|
|
|
|
case 4: return function(accumulator, value, index, collection) {
|
|
|
|
return func.call(thisArg, accumulator, value, index, collection);
|
|
|
|
};
|
|
|
|
case 5: return function(value, other, key, object, source) {
|
|
|
|
return func.call(thisArg, value, other, key, object, source);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return function() {
|
|
|
|
return func.apply(thisArg, arguments);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method returns the first argument provided to it.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Utility
|
|
|
|
* @param {*} value Any value.
|
|
|
|
* @returns {*} Returns `value`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var object = { 'user': 'fred' };
|
|
|
|
*
|
|
|
|
* _.identity(object) === object;
|
|
|
|
* // => true
|
|
|
|
*/
|
|
|
|
function identity(value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = bindCallback;
|
|
|
|
|
|
|
|
},{}],42:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var keys = require('lodash.keys');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.forEach` without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Array|Object|string} Returns `collection`.
|
|
|
|
*/
|
|
|
|
var baseEach = createBaseEach(baseForOwn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
|
|
|
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
|
|
|
* each property. Iteratee functions may exit iteration early by explicitly
|
|
|
|
* returning `false`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @param {Function} keysFunc The function to get the keys of `object`.
|
|
|
|
* @returns {Object} Returns `object`.
|
|
|
|
*/
|
|
|
|
var baseFor = createBaseFor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.forOwn` without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
|
|
* @returns {Object} Returns `object`.
|
|
|
|
*/
|
|
|
|
function baseForOwn(object, iteratee) {
|
|
|
|
return baseFor(object, iteratee, keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a `baseEach` or `baseEachRight` function.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} eachFunc The function to iterate over a collection.
|
|
|
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
|
|
|
* @returns {Function} Returns the new base function.
|
|
|
|
*/
|
|
|
|
function createBaseEach(eachFunc, fromRight) {
|
|
|
|
return function(collection, iteratee) {
|
|
|
|
var length = collection ? getLength(collection) : 0;
|
|
|
|
if (!isLength(length)) {
|
|
|
|
return eachFunc(collection, iteratee);
|
|
|
|
}
|
|
|
|
var index = fromRight ? length : -1,
|
|
|
|
iterable = toObject(collection);
|
|
|
|
|
|
|
|
while ((fromRight ? index-- : ++index < length)) {
|
|
|
|
if (iteratee(iterable[index], index, iterable) === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return collection;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a base function for `_.forIn` or `_.forInRight`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
|
|
|
* @returns {Function} Returns the new base function.
|
|
|
|
*/
|
|
|
|
function createBaseFor(fromRight) {
|
|
|
|
return function(object, iteratee, keysFunc) {
|
|
|
|
var iterable = toObject(object),
|
|
|
|
props = keysFunc(object),
|
|
|
|
length = props.length,
|
|
|
|
index = fromRight ? length : -1;
|
|
|
|
|
|
|
|
while ((fromRight ? index-- : ++index < length)) {
|
|
|
|
var key = props[index];
|
|
|
|
if (iteratee(iterable[key], key, iterable) === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseEach;
|
|
|
|
|
|
|
|
},{"lodash.keys":46}],39:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.1.2 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var getNative = require('lodash._getnative'),
|
|
|
|
isArguments = require('lodash.isarguments'),
|
|
|
|
isArray = require('lodash.isarray');
|
|
|
|
|
|
|
|
/** Used to detect unsigned integer values. */
|
|
|
|
var reIsUint = /^\d+$/;
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/* Native method references for those with the same name as other `lodash` methods. */
|
|
|
|
var nativeKeys = getNative(Object, 'keys');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is array-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isArrayLike(value) {
|
|
|
|
return value != null && isLength(getLength(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like index.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
|
|
*/
|
|
|
|
function isIndex(value, length) {
|
|
|
|
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
|
|
|
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
|
|
return value > -1 && value % 1 == 0 && value < length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A fallback implementation of `Object.keys` which creates an array of the
|
|
|
|
* own enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
*/
|
|
|
|
function shimKeys(object) {
|
|
|
|
var props = keysIn(object),
|
|
|
|
propsLength = props.length,
|
|
|
|
length = propsLength && object.length;
|
|
|
|
|
|
|
|
var allowIndexes = !!length && isLength(length) &&
|
|
|
|
(isArray(object) || isArguments(object));
|
|
|
|
|
|
|
|
var index = -1,
|
|
|
|
result = [];
|
|
|
|
|
|
|
|
while (++index < propsLength) {
|
|
|
|
var key = props[index];
|
|
|
|
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
|
|
|
|
result.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of the own enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** Non-object values are coerced to objects. See the
|
|
|
|
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* function Foo() {
|
|
|
|
* this.a = 1;
|
|
|
|
* this.b = 2;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Foo.prototype.c = 3;
|
|
|
|
*
|
|
|
|
* _.keys(new Foo);
|
|
|
|
* // => ['a', 'b'] (iteration order is not guaranteed)
|
|
|
|
*
|
|
|
|
* _.keys('hi');
|
|
|
|
* // => ['0', '1']
|
|
|
|
*/
|
|
|
|
var keys = !nativeKeys ? shimKeys : function(object) {
|
|
|
|
var Ctor = object == null ? undefined : object.constructor;
|
|
|
|
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
|
|
|
|
(typeof object != 'function' && isArrayLike(object))) {
|
|
|
|
return shimKeys(object);
|
|
|
|
}
|
|
|
|
return isObject(object) ? nativeKeys(object) : [];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of the own and inherited enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** Non-object values are coerced to objects.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* function Foo() {
|
|
|
|
* this.a = 1;
|
|
|
|
* this.b = 2;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Foo.prototype.c = 3;
|
|
|
|
*
|
|
|
|
* _.keysIn(new Foo);
|
|
|
|
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
|
|
|
*/
|
|
|
|
function keysIn(object) {
|
|
|
|
if (object == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
if (!isObject(object)) {
|
|
|
|
object = Object(object);
|
|
|
|
}
|
|
|
|
var length = object.length;
|
|
|
|
length = (length && isLength(length) &&
|
|
|
|
(isArray(object) || isArguments(object)) && length) || 0;
|
|
|
|
|
|
|
|
var Ctor = object.constructor,
|
|
|
|
index = -1,
|
|
|
|
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
|
|
|
|
result = Array(length),
|
|
|
|
skipIndexes = length > 0;
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
result[index] = (index + '');
|
|
|
|
}
|
|
|
|
for (var key in object) {
|
|
|
|
if (!(skipIndexes && isIndex(key, length)) &&
|
|
|
|
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
|
|
|
result.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = keys;
|
|
|
|
|
|
|
|
},{"lodash._getnative":43,"lodash.isarguments":44,"lodash.isarray":32}],41:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.3.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var baseIsEqual = require('lodash._baseisequal'),
|
|
|
|
bindCallback = require('lodash._bindcallback'),
|
|
|
|
isArray = require('lodash.isarray'),
|
|
|
|
pairs = require('lodash.pairs');
|
|
|
|
|
|
|
|
/** Used to match property names within property paths. */
|
|
|
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
|
|
|
|
reIsPlainProp = /^\w*$/,
|
|
|
|
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
|
|
|
|
|
|
|
/** Used to match backslashes in property paths. */
|
|
|
|
var reEscapeChar = /\\(\\)?/g;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to a string if it's not one. An empty string is returned
|
|
|
|
* for `null` or `undefined` values.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {string} Returns the string.
|
|
|
|
*/
|
|
|
|
function baseToString(value) {
|
|
|
|
return value == null ? '' : (value + '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.callback` which supports specifying the
|
|
|
|
* number of arguments to provide to `func`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} [func=_.identity] The value to convert to a callback.
|
|
|
|
* @param {*} [thisArg] The `this` binding of `func`.
|
|
|
|
* @param {number} [argCount] The number of arguments to provide to `func`.
|
|
|
|
* @returns {Function} Returns the callback.
|
|
|
|
*/
|
|
|
|
function baseCallback(func, thisArg, argCount) {
|
|
|
|
var type = typeof func;
|
|
|
|
if (type == 'function') {
|
|
|
|
return thisArg === undefined
|
|
|
|
? func
|
|
|
|
: bindCallback(func, thisArg, argCount);
|
|
|
|
}
|
|
|
|
if (func == null) {
|
|
|
|
return identity;
|
|
|
|
}
|
|
|
|
if (type == 'object') {
|
|
|
|
return baseMatches(func);
|
|
|
|
}
|
|
|
|
return thisArg === undefined
|
|
|
|
? property(func)
|
|
|
|
: baseMatchesProperty(func, thisArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `get` without support for string paths
|
|
|
|
* and default values.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {Array} path The path of the property to get.
|
|
|
|
* @param {string} [pathKey] The key representation of path.
|
|
|
|
* @returns {*} Returns the resolved value.
|
|
|
|
*/
|
|
|
|
function baseGet(object, path, pathKey) {
|
|
|
|
if (object == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pathKey !== undefined && pathKey in toObject(object)) {
|
|
|
|
path = [pathKey];
|
|
|
|
}
|
|
|
|
var index = 0,
|
|
|
|
length = path.length;
|
|
|
|
|
|
|
|
while (object != null && index < length) {
|
|
|
|
object = object[path[index++]];
|
|
|
|
}
|
|
|
|
return (index && index == length) ? object : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.isMatch` without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to inspect.
|
|
|
|
* @param {Array} matchData The propery names, values, and compare flags to match.
|
|
|
|
* @param {Function} [customizer] The function to customize comparing objects.
|
|
|
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|
|
|
*/
|
|
|
|
function baseIsMatch(object, matchData, customizer) {
|
|
|
|
var index = matchData.length,
|
|
|
|
length = index,
|
|
|
|
noCustomizer = !customizer;
|
|
|
|
|
|
|
|
if (object == null) {
|
|
|
|
return !length;
|
|
|
|
}
|
|
|
|
object = toObject(object);
|
|
|
|
while (index--) {
|
|
|
|
var data = matchData[index];
|
|
|
|
if ((noCustomizer && data[2])
|
|
|
|
? data[1] !== object[data[0]]
|
|
|
|
: !(data[0] in object)
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (++index < length) {
|
|
|
|
data = matchData[index];
|
|
|
|
var key = data[0],
|
|
|
|
objValue = object[key],
|
|
|
|
srcValue = data[1];
|
|
|
|
|
|
|
|
if (noCustomizer && data[2]) {
|
|
|
|
if (objValue === undefined && !(key in object)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
|
|
|
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.matches` which does not clone `source`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} source The object of property values to match.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseMatches(source) {
|
|
|
|
var matchData = getMatchData(source);
|
|
|
|
if (matchData.length == 1 && matchData[0][2]) {
|
|
|
|
var key = matchData[0][0],
|
|
|
|
value = matchData[0][1];
|
|
|
|
|
|
|
|
return function(object) {
|
|
|
|
if (object == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return object[key] === value && (value !== undefined || (key in toObject(object)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return function(object) {
|
|
|
|
return baseIsMatch(object, matchData);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} path The path of the property to get.
|
|
|
|
* @param {*} srcValue The value to compare.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseMatchesProperty(path, srcValue) {
|
|
|
|
var isArr = isArray(path),
|
|
|
|
isCommon = isKey(path) && isStrictComparable(srcValue),
|
|
|
|
pathKey = (path + '');
|
|
|
|
|
|
|
|
path = toPath(path);
|
|
|
|
return function(object) {
|
|
|
|
if (object == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var key = pathKey;
|
|
|
|
object = toObject(object);
|
|
|
|
if ((isArr || !isCommon) && !(key in object)) {
|
|
|
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
|
|
|
if (object == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
key = last(path);
|
|
|
|
object = toObject(object);
|
|
|
|
}
|
|
|
|
return object[key] === srcValue
|
|
|
|
? (srcValue !== undefined || (key in object))
|
|
|
|
: baseIsEqual(srcValue, object[key], undefined, true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseProperty` which supports deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array|string} path The path of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function basePropertyDeep(path) {
|
|
|
|
var pathKey = (path + '');
|
|
|
|
path = toPath(path);
|
|
|
|
return function(object) {
|
|
|
|
return baseGet(object, path, pathKey);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.slice` without an iteratee call guard.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} array The array to slice.
|
|
|
|
* @param {number} [start=0] The start position.
|
|
|
|
* @param {number} [end=array.length] The end position.
|
|
|
|
* @returns {Array} Returns the slice of `array`.
|
|
|
|
*/
|
|
|
|
function baseSlice(array, start, end) {
|
|
|
|
var index = -1,
|
|
|
|
length = array.length;
|
|
|
|
|
|
|
|
start = start == null ? 0 : (+start || 0);
|
|
|
|
if (start < 0) {
|
|
|
|
start = -start > length ? 0 : (length + start);
|
|
|
|
}
|
|
|
|
end = (end === undefined || end > length) ? length : (+end || 0);
|
|
|
|
if (end < 0) {
|
|
|
|
end += length;
|
|
|
|
}
|
|
|
|
length = start > end ? 0 : ((end - start) >>> 0);
|
|
|
|
start >>>= 0;
|
|
|
|
|
|
|
|
var result = Array(length);
|
|
|
|
while (++index < length) {
|
|
|
|
result[index] = array[index + start];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the propery names, values, and compare flags of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the match data of `object`.
|
|
|
|
*/
|
|
|
|
function getMatchData(object) {
|
|
|
|
var result = pairs(object),
|
|
|
|
length = result.length;
|
|
|
|
|
|
|
|
while (length--) {
|
|
|
|
result[length][2] = isStrictComparable(result[length][1]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a property name and not a property path.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @param {Object} [object] The object to query keys on.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
|
|
*/
|
|
|
|
function isKey(value, object) {
|
|
|
|
var type = typeof value;
|
|
|
|
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (isArray(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var result = !reIsDeepProp.test(value);
|
|
|
|
return result || (object != null && value in toObject(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` if suitable for strict
|
|
|
|
* equality comparisons, else `false`.
|
|
|
|
*/
|
|
|
|
function isStrictComparable(value) {
|
|
|
|
return value === value && !isObject(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to property path array if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Array} Returns the property path array.
|
|
|
|
*/
|
|
|
|
function toPath(value) {
|
|
|
|
if (isArray(value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
var result = [];
|
|
|
|
baseToString(value).replace(rePropName, function(match, number, quote, string) {
|
|
|
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the last element of `array`.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Array
|
|
|
|
* @param {Array} array The array to query.
|
|
|
|
* @returns {*} Returns the last element of `array`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.last([1, 2, 3]);
|
|
|
|
* // => 3
|
|
|
|
*/
|
|
|
|
function last(array) {
|
|
|
|
var length = array ? array.length : 0;
|
|
|
|
return length ? array[length - 1] : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method returns the first argument provided to it.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Utility
|
|
|
|
* @param {*} value Any value.
|
|
|
|
* @returns {*} Returns `value`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var object = { 'user': 'fred' };
|
|
|
|
*
|
|
|
|
* _.identity(object) === object;
|
|
|
|
* // => true
|
|
|
|
*/
|
|
|
|
function identity(value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a function that returns the property value at `path` on a
|
|
|
|
* given object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Utility
|
|
|
|
* @param {Array|string} path The path of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var objects = [
|
|
|
|
* { 'a': { 'b': { 'c': 2 } } },
|
|
|
|
* { 'a': { 'b': { 'c': 1 } } }
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* _.map(objects, _.property('a.b.c'));
|
|
|
|
* // => [2, 1]
|
|
|
|
*
|
|
|
|
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
|
|
|
* // => [1, 2]
|
|
|
|
*/
|
|
|
|
function property(path) {
|
|
|
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseCallback;
|
|
|
|
|
|
|
|
},{"lodash._baseisequal":47,"lodash._bindcallback":45,"lodash.isarray":35,"lodash.pairs":48}],49:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.2 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var argsTag = '[object Arguments]',
|
|
|
|
arrayTag = '[object Array]',
|
|
|
|
boolTag = '[object Boolean]',
|
|
|
|
dateTag = '[object Date]',
|
|
|
|
errorTag = '[object Error]',
|
|
|
|
funcTag = '[object Function]',
|
|
|
|
mapTag = '[object Map]',
|
|
|
|
numberTag = '[object Number]',
|
|
|
|
objectTag = '[object Object]',
|
|
|
|
regexpTag = '[object RegExp]',
|
|
|
|
setTag = '[object Set]',
|
|
|
|
stringTag = '[object String]',
|
|
|
|
weakMapTag = '[object WeakMap]';
|
|
|
|
|
|
|
|
var arrayBufferTag = '[object ArrayBuffer]',
|
|
|
|
float32Tag = '[object Float32Array]',
|
|
|
|
float64Tag = '[object Float64Array]',
|
|
|
|
int8Tag = '[object Int8Array]',
|
|
|
|
int16Tag = '[object Int16Array]',
|
|
|
|
int32Tag = '[object Int32Array]',
|
|
|
|
uint8Tag = '[object Uint8Array]',
|
|
|
|
uint8ClampedTag = '[object Uint8ClampedArray]',
|
|
|
|
uint16Tag = '[object Uint16Array]',
|
|
|
|
uint32Tag = '[object Uint32Array]';
|
|
|
|
|
|
|
|
/** Used to identify `toStringTag` values of typed arrays. */
|
|
|
|
var typedArrayTags = {};
|
|
|
|
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
|
|
|
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
|
|
|
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
|
|
|
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
|
|
|
typedArrayTags[uint32Tag] = true;
|
|
|
|
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
|
|
|
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
|
|
|
typedArrayTags[dateTag] = typedArrayTags[errorTag] =
|
|
|
|
typedArrayTags[funcTag] = typedArrayTags[mapTag] =
|
|
|
|
typedArrayTags[numberTag] = typedArrayTags[objectTag] =
|
|
|
|
typedArrayTags[regexpTag] = typedArrayTags[setTag] =
|
|
|
|
typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as a typed array.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isTypedArray(new Uint8Array);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isTypedArray([]);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isTypedArray(value) {
|
|
|
|
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isTypedArray;
|
|
|
|
|
|
|
|
},{}],50:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.9.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var funcTag = '[object Function]';
|
|
|
|
|
|
|
|
/** Used to detect host constructors (Safari > 5). */
|
|
|
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to resolve the decompiled source of functions. */
|
|
|
|
var fnToString = Function.prototype.toString;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/** Used to detect if a method is native. */
|
|
|
|
var reIsNative = RegExp('^' +
|
|
|
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
|
|
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the native function at `key` of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @param {string} key The key of the method to get.
|
|
|
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
|
|
*/
|
|
|
|
function getNative(object, key) {
|
|
|
|
var value = object == null ? undefined : object[key];
|
|
|
|
return isNative(value) ? value : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as a `Function` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isFunction(_);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isFunction(/abc/);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isFunction(value) {
|
|
|
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
|
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
|
|
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
|
|
|
return isObject(value) && objToString.call(value) == funcTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a native function.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isNative(Array.prototype.push);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isNative(_);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isNative(value) {
|
|
|
|
if (value == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isFunction(value)) {
|
|
|
|
return reIsNative.test(fnToString.call(value));
|
|
|
|
}
|
|
|
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getNative;
|
|
|
|
|
|
|
|
},{}],51:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.4 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/** Native method references. */
|
|
|
|
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is array-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isArrayLike(value) {
|
|
|
|
return value != null && isLength(getLength(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is classified as an `arguments` object.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isArguments(function() { return arguments; }());
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isArguments([1, 2, 3]);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isArguments(value) {
|
|
|
|
return isObjectLike(value) && isArrayLike(value) &&
|
|
|
|
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isArguments;
|
|
|
|
|
|
|
|
},{}],48:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.1 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var keys = require('lodash.keys');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts `value` to an object if it's not one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to process.
|
|
|
|
* @returns {Object} Returns the object.
|
|
|
|
*/
|
|
|
|
function toObject(value) {
|
|
|
|
return isObject(value) ? value : Object(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a two dimensional array of the key-value pairs for `object`,
|
|
|
|
* e.g. `[[key1, value1], [key2, value2]]`.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the new array of key-value pairs.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.pairs({ 'barney': 36, 'fred': 40 });
|
|
|
|
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
|
|
|
|
*/
|
|
|
|
function pairs(object) {
|
|
|
|
object = toObject(object);
|
|
|
|
|
|
|
|
var index = -1,
|
|
|
|
props = keys(object),
|
|
|
|
length = props.length,
|
|
|
|
result = Array(length);
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
var key = props[index];
|
|
|
|
result[index] = [key, object[key]];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = pairs;
|
|
|
|
|
|
|
|
},{"lodash.keys":46}],47:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.0.7 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var isArray = require('lodash.isarray'),
|
|
|
|
isTypedArray = require('lodash.istypedarray'),
|
|
|
|
keys = require('lodash.keys');
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
|
var argsTag = '[object Arguments]',
|
|
|
|
arrayTag = '[object Array]',
|
|
|
|
boolTag = '[object Boolean]',
|
|
|
|
dateTag = '[object Date]',
|
|
|
|
errorTag = '[object Error]',
|
|
|
|
numberTag = '[object Number]',
|
|
|
|
objectTag = '[object Object]',
|
|
|
|
regexpTag = '[object RegExp]',
|
|
|
|
stringTag = '[object String]';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is object-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && typeof value == 'object';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
|
|
|
* of values.
|
|
|
|
*/
|
|
|
|
var objToString = objectProto.toString;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `_.some` for arrays without support for callback
|
|
|
|
* shorthands and `this` binding.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
* @param {Function} predicate The function invoked per iteration.
|
|
|
|
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
|
|
|
* else `false`.
|
|
|
|
*/
|
|
|
|
function arraySome(array, predicate) {
|
|
|
|
var index = -1,
|
|
|
|
length = array.length;
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
if (predicate(array[index], index, array)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.isEqual` without support for `this` binding
|
|
|
|
* `customizer` functions.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to compare.
|
|
|
|
* @param {*} other The other value to compare.
|
|
|
|
* @param {Function} [customizer] The function to customize comparing values.
|
|
|
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
|
|
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
|
|
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
|
|
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
|
|
*/
|
|
|
|
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
|
|
|
|
if (value === other) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
|
|
|
return value !== value && other !== other;
|
|
|
|
}
|
|
|
|
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseIsEqual` for arrays and objects which performs
|
|
|
|
* deep comparisons and tracks traversed objects enabling objects with circular
|
|
|
|
* references to be compared.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to compare.
|
|
|
|
* @param {Object} other The other object to compare.
|
|
|
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
|
|
|
* @param {Function} [customizer] The function to customize comparing objects.
|
|
|
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
|
|
|
* @param {Array} [stackA=[]] Tracks traversed `value` objects.
|
|
|
|
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
|
|
|
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|
|
|
*/
|
|
|
|
function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
|
|
|
var objIsArr = isArray(object),
|
|
|
|
othIsArr = isArray(other),
|
|
|
|
objTag = arrayTag,
|
|
|
|
othTag = arrayTag;
|
|
|
|
|
|
|
|
if (!objIsArr) {
|
|
|
|
objTag = objToString.call(object);
|
|
|
|
if (objTag == argsTag) {
|
|
|
|
objTag = objectTag;
|
|
|
|
} else if (objTag != objectTag) {
|
|
|
|
objIsArr = isTypedArray(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!othIsArr) {
|
|
|
|
othTag = objToString.call(other);
|
|
|
|
if (othTag == argsTag) {
|
|
|
|
othTag = objectTag;
|
|
|
|
} else if (othTag != objectTag) {
|
|
|
|
othIsArr = isTypedArray(other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var objIsObj = objTag == objectTag,
|
|
|
|
othIsObj = othTag == objectTag,
|
|
|
|
isSameTag = objTag == othTag;
|
|
|
|
|
|
|
|
if (isSameTag && !(objIsArr || objIsObj)) {
|
|
|
|
return equalByTag(object, other, objTag);
|
|
|
|
}
|
|
|
|
if (!isLoose) {
|
|
|
|
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
|
|
|
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
|
|
|
|
|
|
|
if (objIsWrapped || othIsWrapped) {
|
|
|
|
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isSameTag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Assume cyclic values are equal.
|
|
|
|
// For more information on detecting circular references see https://es5.github.io/#JO.
|
|
|
|
stackA || (stackA = []);
|
|
|
|
stackB || (stackB = []);
|
|
|
|
|
|
|
|
var length = stackA.length;
|
|
|
|
while (length--) {
|
|
|
|
if (stackA[length] == object) {
|
|
|
|
return stackB[length] == other;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add `object` and `other` to the stack of traversed objects.
|
|
|
|
stackA.push(object);
|
|
|
|
stackB.push(other);
|
|
|
|
|
|
|
|
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
|
|
|
|
|
|
|
|
stackA.pop();
|
|
|
|
stackB.pop();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseIsEqualDeep` for arrays with support for
|
|
|
|
* partial deep comparisons.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} array The array to compare.
|
|
|
|
* @param {Array} other The other array to compare.
|
|
|
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
|
|
|
* @param {Function} [customizer] The function to customize comparing arrays.
|
|
|
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
|
|
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
|
|
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
|
|
|
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
|
|
|
*/
|
|
|
|
function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
|
|
|
var index = -1,
|
|
|
|
arrLength = array.length,
|
|
|
|
othLength = other.length;
|
|
|
|
|
|
|
|
if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Ignore non-index properties.
|
|
|
|
while (++index < arrLength) {
|
|
|
|
var arrValue = array[index],
|
|
|
|
othValue = other[index],
|
|
|
|
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
|
|
|
|
|
|
|
|
if (result !== undefined) {
|
|
|
|
if (result) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Recursively compare arrays (susceptible to call stack limits).
|
|
|
|
if (isLoose) {
|
|
|
|
if (!arraySome(other, function(othValue) {
|
|
|
|
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
|
|
|
|
})) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseIsEqualDeep` for comparing objects of
|
|
|
|
* the same `toStringTag`.
|
|
|
|
*
|
|
|
|
* **Note:** This function only supports comparing values with tags of
|
|
|
|
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} value The object to compare.
|
|
|
|
* @param {Object} other The other object to compare.
|
|
|
|
* @param {string} tag The `toStringTag` of the objects to compare.
|
|
|
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|
|
|
*/
|
|
|
|
function equalByTag(object, other, tag) {
|
|
|
|
switch (tag) {
|
|
|
|
case boolTag:
|
|
|
|
case dateTag:
|
|
|
|
// Coerce dates and booleans to numbers, dates to milliseconds and booleans
|
|
|
|
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
|
|
|
|
return +object == +other;
|
|
|
|
|
|
|
|
case errorTag:
|
|
|
|
return object.name == other.name && object.message == other.message;
|
|
|
|
|
|
|
|
case numberTag:
|
|
|
|
// Treat `NaN` vs. `NaN` as equal.
|
|
|
|
return (object != +object)
|
|
|
|
? other != +other
|
|
|
|
: object == +other;
|
|
|
|
|
|
|
|
case regexpTag:
|
|
|
|
case stringTag:
|
|
|
|
// Coerce regexes to strings and treat strings primitives and string
|
|
|
|
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
|
|
|
|
return object == (other + '');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specialized version of `baseIsEqualDeep` for objects with support for
|
|
|
|
* partial deep comparisons.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to compare.
|
|
|
|
* @param {Object} other The other object to compare.
|
|
|
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
|
|
|
* @param {Function} [customizer] The function to customize comparing values.
|
|
|
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
|
|
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
|
|
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
|
|
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|
|
|
*/
|
|
|
|
function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
|
|
|
var objProps = keys(object),
|
|
|
|
objLength = objProps.length,
|
|
|
|
othProps = keys(other),
|
|
|
|
othLength = othProps.length;
|
|
|
|
|
|
|
|
if (objLength != othLength && !isLoose) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var index = objLength;
|
|
|
|
while (index--) {
|
|
|
|
var key = objProps[index];
|
|
|
|
if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var skipCtor = isLoose;
|
|
|
|
while (++index < objLength) {
|
|
|
|
key = objProps[index];
|
|
|
|
var objValue = object[key],
|
|
|
|
othValue = other[key],
|
|
|
|
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
|
|
|
|
|
|
|
|
// Recursively compare objects (susceptible to call stack limits).
|
|
|
|
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
skipCtor || (skipCtor = key == 'constructor');
|
|
|
|
}
|
|
|
|
if (!skipCtor) {
|
|
|
|
var objCtor = object.constructor,
|
|
|
|
othCtor = other.constructor;
|
|
|
|
|
|
|
|
// Non `Object` object instances with different constructors are not equal.
|
|
|
|
if (objCtor != othCtor &&
|
|
|
|
('constructor' in object && 'constructor' in other) &&
|
|
|
|
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
|
|
|
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseIsEqual;
|
|
|
|
|
|
|
|
},{"lodash.isarray":35,"lodash.istypedarray":49,"lodash.keys":46}],46:[function(require,module,exports){
|
|
|
|
/**
|
|
|
|
* lodash 3.1.2 (Custom Build) <https://lodash.com/>
|
|
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
|
|
* Available under MIT license <https://lodash.com/license>
|
|
|
|
*/
|
|
|
|
var getNative = require('lodash._getnative'),
|
|
|
|
isArguments = require('lodash.isarguments'),
|
|
|
|
isArray = require('lodash.isarray');
|
|
|
|
|
|
|
|
/** Used to detect unsigned integer values. */
|
|
|
|
var reIsUint = /^\d+$/;
|
|
|
|
|
|
|
|
/** Used for native method references. */
|
|
|
|
var objectProto = Object.prototype;
|
|
|
|
|
|
|
|
/** Used to check objects for own properties. */
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
|
|
|
|
/* Native method references for those with the same name as other `lodash` methods. */
|
|
|
|
var nativeKeys = getNative(Object, 'keys');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
|
|
|
* of an array-like value.
|
|
|
|
*/
|
|
|
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base implementation of `_.property` without support for deep paths.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} key The key of the property to get.
|
|
|
|
* @returns {Function} Returns the new function.
|
|
|
|
*/
|
|
|
|
function baseProperty(key) {
|
|
|
|
return function(object) {
|
|
|
|
return object == null ? undefined : object[key];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the "length" property value of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
|
|
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {*} Returns the "length" value.
|
|
|
|
*/
|
|
|
|
var getLength = baseProperty('length');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is array-like.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
|
|
*/
|
|
|
|
function isArrayLike(value) {
|
|
|
|
return value != null && isLength(getLength(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like index.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
|
|
*/
|
|
|
|
function isIndex(value, length) {
|
|
|
|
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
|
|
|
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
|
|
return value > -1 && value % 1 == 0 && value < length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is a valid array-like length.
|
|
|
|
*
|
|
|
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
|
|
*/
|
|
|
|
function isLength(value) {
|
|
|
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A fallback implementation of `Object.keys` which creates an array of the
|
|
|
|
* own enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
*/
|
|
|
|
function shimKeys(object) {
|
|
|
|
var props = keysIn(object),
|
|
|
|
propsLength = props.length,
|
|
|
|
length = propsLength && object.length;
|
|
|
|
|
|
|
|
var allowIndexes = !!length && isLength(length) &&
|
|
|
|
(isArray(object) || isArguments(object));
|
|
|
|
|
|
|
|
var index = -1,
|
|
|
|
result = [];
|
|
|
|
|
|
|
|
while (++index < propsLength) {
|
|
|
|
var key = props[index];
|
|
|
|
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
|
|
|
|
result.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Lang
|
|
|
|
* @param {*} value The value to check.
|
|
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* _.isObject({});
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject([1, 2, 3]);
|
|
|
|
* // => true
|
|
|
|
*
|
|
|
|
* _.isObject(1);
|
|
|
|
* // => false
|
|
|
|
*/
|
|
|
|
function isObject(value) {
|
|
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
|
|
var type = typeof value;
|
|
|
|
return !!value && (type == 'object' || type == 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of the own enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** Non-object values are coerced to objects. See the
|
|
|
|
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* function Foo() {
|
|
|
|
* this.a = 1;
|
|
|
|
* this.b = 2;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Foo.prototype.c = 3;
|
|
|
|
*
|
|
|
|
* _.keys(new Foo);
|
|
|
|
* // => ['a', 'b'] (iteration order is not guaranteed)
|
|
|
|
*
|
|
|
|
* _.keys('hi');
|
|
|
|
* // => ['0', '1']
|
|
|
|
*/
|
|
|
|
var keys = !nativeKeys ? shimKeys : function(object) {
|
|
|
|
var Ctor = object == null ? undefined : object.constructor;
|
|
|
|
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
|
|
|
|
(typeof object != 'function' && isArrayLike(object))) {
|
|
|
|
return shimKeys(object);
|
|
|
|
}
|
|
|
|
return isObject(object) ? nativeKeys(object) : [];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of the own and inherited enumerable property names of `object`.
|
|
|
|
*
|
|
|
|
* **Note:** Non-object values are coerced to objects.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
* @returns {Array} Returns the array of property names.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* function Foo() {
|
|
|
|
* this.a = 1;
|
|
|
|
* this.b = 2;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Foo.prototype.c = 3;
|
|
|
|
*
|
|
|
|
* _.keysIn(new Foo);
|
|
|
|
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
|
|
|
*/
|
|
|
|
function keysIn(object) {
|
|
|
|
if (object == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
if (!isObject(object)) {
|
|
|
|
object = Object(object);
|
|
|
|
}
|
|
|
|
var length = object.length;
|
|
|
|
length = (length && isLength(length) &&
|
|
|
|
(isArray(object) || isArguments(object)) && length) || 0;
|
|
|
|
|
|
|
|
var Ctor = object.constructor,
|
|
|
|
index = -1,
|
|
|
|
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
|
|
|
|
result = Array(length),
|
|
|
|
skipIndexes = length > 0;
|
|
|
|
|
|
|
|
while (++index < length) {
|
|
|
|
result[index] = (index + '');
|
|
|
|
}
|
|
|
|
for (var key in object) {
|
|
|
|
if (!(skipIndexes && isIndex(key, length)) &&
|
|
|
|
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
|
|
|
result.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = keys;
|
|
|
|
|
|
|
|
},{"lodash._getnative":50,"lodash.isarguments":51,"lodash.isarray":35}]},{},[1])(1)
|
|
|
|
});
|
|
|
|
;
|