-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer.min.js
30 lines (30 loc) · 44.2 KB
/
peer.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
parcelRequire=function(e,r,n,t){var i="function"==typeof parcelRequire&&parcelRequire,o="function"==typeof require&&require;function u(n,t){if(!r[n]){if(!e[n]){var f="function"==typeof parcelRequire&&parcelRequire;if(!t&&f)return f(n,!0);if(i)return i(n,!0);if(o&&"string"==typeof n)return o(n);var c=new Error("Cannot find module '"+n+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[n][1][r]||r},p.cache={};var l=r[n]=new u.Module(n);e[n][0].call(l.exports,p,l,l.exports,this)}return r[n].exports;function p(e){return u(p.resolve(e))}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.exports={}},u.modules=e,u.cache=r,u.parent=i,u.register=function(r,n){e[r]=[function(e,r){r.exports=n},{}]};for(var f=0;f<n.length;f++)u(n[f]);if(n.length){var c=u(n[n.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=c:"function"==typeof define&&define.amd?define(function(){return c}):t&&(this[t]=c)}return u}({"vHo1":[function(require,module,exports) {
var e={};e.useBlobBuilder=function(){try{return new Blob([]),!1}catch(e){return!0}}(),e.useArrayBufferView=!e.useBlobBuilder&&function(){try{return 0===new Blob([new Uint8Array([])]).size}catch(e){return!0}}(),module.exports.binaryFeatures=e;var r=module.exports.BlobBuilder;function t(){this._pieces=[],this._parts=[]}"undefined"!=typeof window&&(r=module.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder),t.prototype.append=function(e){"number"==typeof e?this._pieces.push(e):(this.flush(),this._parts.push(e))},t.prototype.flush=function(){if(this._pieces.length>0){var r=new Uint8Array(this._pieces);e.useArrayBufferView||(r=r.buffer),this._parts.push(r),this._pieces=[]}},t.prototype.getBuffer=function(){if(this.flush(),e.useBlobBuilder){for(var t=new r,i=0,u=this._parts.length;i<u;i++)t.append(this._parts[i]);return t.getBlob()}return new Blob(this._parts)},module.exports.BufferBuilder=t;
},{}],"lHOc":[function(require,module,exports) {
var t=require("./bufferbuilder").BufferBuilder,e=require("./bufferbuilder").binaryFeatures,i={unpack:function(t){return new r(t).unpack()},pack:function(t){var e=new n;return e.pack(t),e.getBuffer()}};function r(t){this.index=0,this.dataBuffer=t,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}function n(){this.bufferBuilder=new t}function u(t){var e=t.charCodeAt(0);return e<=2047?"00":e<=65535?"000":e<=2097151?"0000":e<=67108863?"00000":"000000"}function a(t){return t.length>600?new Blob([t]).size:t.replace(/[^\u0000-\u007F]/g,u).length}module.exports=i,r.prototype.unpack=function(){var t,e=this.unpack_uint8();if(e<128)return e;if((224^e)<32)return(224^e)-32;if((t=160^e)<=15)return this.unpack_raw(t);if((t=176^e)<=15)return this.unpack_string(t);if((t=144^e)<=15)return this.unpack_array(t);if((t=128^e)<=15)return this.unpack_map(t);switch(e){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:case 213:case 214:case 215:return;case 216:return t=this.unpack_uint16(),this.unpack_string(t);case 217:return t=this.unpack_uint32(),this.unpack_string(t);case 218:return t=this.unpack_uint16(),this.unpack_raw(t);case 219:return t=this.unpack_uint32(),this.unpack_raw(t);case 220:return t=this.unpack_uint16(),this.unpack_array(t);case 221:return t=this.unpack_uint32(),this.unpack_array(t);case 222:return t=this.unpack_uint16(),this.unpack_map(t);case 223:return t=this.unpack_uint32(),this.unpack_map(t)}},r.prototype.unpack_uint8=function(){var t=255&this.dataView[this.index];return this.index++,t},r.prototype.unpack_uint16=function(){var t=this.read(2),e=256*(255&t[0])+(255&t[1]);return this.index+=2,e},r.prototype.unpack_uint32=function(){var t=this.read(4),e=256*(256*(256*t[0]+t[1])+t[2])+t[3];return this.index+=4,e},r.prototype.unpack_uint64=function(){var t=this.read(8),e=256*(256*(256*(256*(256*(256*(256*t[0]+t[1])+t[2])+t[3])+t[4])+t[5])+t[6])+t[7];return this.index+=8,e},r.prototype.unpack_int8=function(){var t=this.unpack_uint8();return t<128?t:t-256},r.prototype.unpack_int16=function(){var t=this.unpack_uint16();return t<32768?t:t-65536},r.prototype.unpack_int32=function(){var t=this.unpack_uint32();return t<Math.pow(2,31)?t:t-Math.pow(2,32)},r.prototype.unpack_int64=function(){var t=this.unpack_uint64();return t<Math.pow(2,63)?t:t-Math.pow(2,64)},r.prototype.unpack_raw=function(t){if(this.length<this.index+t)throw new Error("BinaryPackFailure: index is out of range "+this.index+" "+t+" "+this.length);var e=this.dataBuffer.slice(this.index,this.index+t);return this.index+=t,e},r.prototype.unpack_string=function(t){for(var e,i,r=this.read(t),n=0,u="";n<t;)(e=r[n])<128?(u+=String.fromCharCode(e),n++):(192^e)<32?(i=(192^e)<<6|63&r[n+1],u+=String.fromCharCode(i),n+=2):(i=(15&e)<<12|(63&r[n+1])<<6|63&r[n+2],u+=String.fromCharCode(i),n+=3);return this.index+=t,u},r.prototype.unpack_array=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=this.unpack();return e},r.prototype.unpack_map=function(t){for(var e={},i=0;i<t;i++){var r=this.unpack(),n=this.unpack();e[r]=n}return e},r.prototype.unpack_float=function(){var t=this.unpack_uint32(),e=(t>>23&255)-127;return(0==t>>31?1:-1)*(8388607&t|8388608)*Math.pow(2,e-23)},r.prototype.unpack_double=function(){var t=this.unpack_uint32(),e=this.unpack_uint32(),i=(t>>20&2047)-1023;return(0==t>>31?1:-1)*((1048575&t|1048576)*Math.pow(2,i-20)+e*Math.pow(2,i-52))},r.prototype.read=function(t){var e=this.index;if(e+t<=this.length)return this.dataView.subarray(e,e+t);throw new Error("BinaryPackFailure: read index out of range")},n.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},n.prototype.pack=function(t){var i=typeof t;if("string"==i)this.pack_string(t);else if("number"==i)Math.floor(t)===t?this.pack_integer(t):this.pack_double(t);else if("boolean"==i)!0===t?this.bufferBuilder.append(195):!1===t&&this.bufferBuilder.append(194);else if("undefined"==i)this.bufferBuilder.append(192);else{if("object"!=i)throw new Error('Type "'+i+'" not yet supported');if(null===t)this.bufferBuilder.append(192);else{var r=t.constructor;if(r==Array)this.pack_array(t);else if(r==Blob||r==File)this.pack_bin(t);else if(r==ArrayBuffer)e.useArrayBufferView?this.pack_bin(new Uint8Array(t)):this.pack_bin(t);else if("BYTES_PER_ELEMENT"in t)e.useArrayBufferView?this.pack_bin(new Uint8Array(t.buffer)):this.pack_bin(t.buffer);else if(r==Object)this.pack_object(t);else if(r==Date)this.pack_string(t.toString());else{if("function"!=typeof t.toBinaryPack)throw new Error('Type "'+r.toString()+'" not yet supported');this.bufferBuilder.append(t.toBinaryPack())}}}this.bufferBuilder.flush()},n.prototype.pack_bin=function(t){var e=t.length||t.byteLength||t.size;if(e<=15)this.pack_uint8(160+e);else if(e<=65535)this.bufferBuilder.append(218),this.pack_uint16(e);else{if(!(e<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(219),this.pack_uint32(e)}this.bufferBuilder.append(t)},n.prototype.pack_string=function(t){var e=a(t);if(e<=15)this.pack_uint8(176+e);else if(e<=65535)this.bufferBuilder.append(216),this.pack_uint16(e);else{if(!(e<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(217),this.pack_uint32(e)}this.bufferBuilder.append(t)},n.prototype.pack_array=function(t){var e=t.length;if(e<=15)this.pack_uint8(144+e);else if(e<=65535)this.bufferBuilder.append(220),this.pack_uint16(e);else{if(!(e<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(221),this.pack_uint32(e)}for(var i=0;i<e;i++)this.pack(t[i])},n.prototype.pack_integer=function(t){if(-32<=t&&t<=127)this.bufferBuilder.append(255&t);else if(0<=t&&t<=255)this.bufferBuilder.append(204),this.pack_uint8(t);else if(-128<=t&&t<=127)this.bufferBuilder.append(208),this.pack_int8(t);else if(0<=t&&t<=65535)this.bufferBuilder.append(205),this.pack_uint16(t);else if(-32768<=t&&t<=32767)this.bufferBuilder.append(209),this.pack_int16(t);else if(0<=t&&t<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(t);else if(-2147483648<=t&&t<=2147483647)this.bufferBuilder.append(210),this.pack_int32(t);else if(-0x8000000000000000<=t&&t<=0x8000000000000000)this.bufferBuilder.append(211),this.pack_int64(t);else{if(!(0<=t&&t<=0x10000000000000000))throw new Error("Invalid integer");this.bufferBuilder.append(207),this.pack_uint64(t)}},n.prototype.pack_double=function(t){var e=0;t<0&&(e=1,t=-t);var i=Math.floor(Math.log(t)/Math.LN2),r=t/Math.pow(2,i)-1,n=Math.floor(r*Math.pow(2,52)),u=Math.pow(2,32),a=e<<31|i+1023<<20|n/u&1048575,p=n%u;this.bufferBuilder.append(203),this.pack_int32(a),this.pack_int32(p)},n.prototype.pack_object=function(t){var e=Object.keys(t).length;if(e<=15)this.pack_uint8(128+e);else if(e<=65535)this.bufferBuilder.append(222),this.pack_uint16(e);else{if(!(e<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(223),this.pack_uint32(e)}for(var i in t)t.hasOwnProperty(i)&&(this.pack(i),this.pack(t[i]))},n.prototype.pack_uint8=function(t){this.bufferBuilder.append(t)},n.prototype.pack_uint16=function(t){this.bufferBuilder.append(t>>8),this.bufferBuilder.append(255&t)},n.prototype.pack_uint32=function(t){var e=4294967295&t;this.bufferBuilder.append((4278190080&e)>>>24),this.bufferBuilder.append((16711680&e)>>>16),this.bufferBuilder.append((65280&e)>>>8),this.bufferBuilder.append(255&e)},n.prototype.pack_uint64=function(t){var e=t/Math.pow(2,32),i=t%Math.pow(2,32);this.bufferBuilder.append((4278190080&e)>>>24),this.bufferBuilder.append((16711680&e)>>>16),this.bufferBuilder.append((65280&e)>>>8),this.bufferBuilder.append(255&e),this.bufferBuilder.append((4278190080&i)>>>24),this.bufferBuilder.append((16711680&i)>>>16),this.bufferBuilder.append((65280&i)>>>8),this.bufferBuilder.append(255&i)},n.prototype.pack_int8=function(t){this.bufferBuilder.append(255&t)},n.prototype.pack_int16=function(t){this.bufferBuilder.append((65280&t)>>8),this.bufferBuilder.append(255&t)},n.prototype.pack_int32=function(t){this.bufferBuilder.append(t>>>24&255),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t)},n.prototype.pack_int64=function(t){var e=Math.floor(t/Math.pow(2,32)),i=t%Math.pow(2,32);this.bufferBuilder.append((4278190080&e)>>>24),this.bufferBuilder.append((16711680&e)>>>16),this.bufferBuilder.append((65280&e)>>>8),this.bufferBuilder.append(255&e),this.bufferBuilder.append((4278190080&i)>>>24),this.bufferBuilder.append((16711680&i)>>>16),this.bufferBuilder.append((65280&i)>>>8),this.bufferBuilder.append(255&i)};
},{"./bufferbuilder":"vHo1"}],"sXtV":[function(require,module,exports) {
"use strict";exports.__esModule=!0,exports.RTCSessionDescription=window.RTCSessionDescription||window.mozRTCSessionDescription,exports.RTCPeerConnection=window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,exports.RTCIceCandidate=window.RTCIceCandidate||window.mozRTCIceCandidate;
},{}],"BHXf":[function(require,module,exports) {
var global = arguments[3];
var e=arguments[3],t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0;var r={iceServers:[{urls:"stun:stun.l.google.com:19302"}]},o=1,n=t(require("js-binarypack")),a=require("./adapter");exports.util={noop:function(){},CLOUD_HOST:"0.peerjs.com",CLOUD_PORT:443,chunkedBrowsers:{Chrome:1},chunkedMTU:16300,logLevel:0,setLogLevel:function(e){var t=parseInt(e,10);isNaN(parseInt(e,10))?exports.util.logLevel=e?3:0:exports.util.logLevel=t,exports.util.log=exports.util.warn=exports.util.error=exports.util.noop,exports.util.logLevel>0&&(exports.util.error=exports.util._printWith("ERROR")),exports.util.logLevel>1&&(exports.util.warn=exports.util._printWith("WARNING")),exports.util.logLevel>2&&(exports.util.log=exports.util._print)},setLogFunction:function(e){e.constructor!==Function?exports.util.warn("The log function you passed in is not a function. Defaulting to regular logs."):exports.util._print=e},_printWith:function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e),exports.util._print.apply(exports.util,t)}},_print:function(){var e=!1,t=Array.prototype.slice.call(arguments);t.unshift("PeerJS: ");for(var r=0,o=t.length;r<o;r++)t[r]instanceof Error&&(t[r]="("+t[r].name+") "+t[r].message,e=!0);e?console.error.apply(console,t):console.log.apply(console,t)},defaultConfig:r,browser:window.mozRTCPeerConnection?"Firefox":window.webkitRTCPeerConnection?"Chrome":window.RTCPeerConnection?"Supported":"Unsupported",supports:function(){if(void 0===a.RTCPeerConnection)return{};var e,t,o=!0,n=!0,i=!1,u=!1,l=!!window.webkitRTCPeerConnection;try{e=new a.RTCPeerConnection(r,{optional:[{RtpDataChannels:!0}]})}catch(c){o=!1,n=!1}if(o)try{t=e.createDataChannel("_PEERJSTEST")}catch(c){o=!1}if(o){try{t.binaryType="blob",i=!0}catch(c){}var s=new a.RTCPeerConnection(r,{});try{u=s.createDataChannel("_PEERJSRELIABLETEST",{}).reliable}catch(c){}s.close()}return n&&(n=!!e.addStream),e&&e.close(),{audioVideo:n,data:o,binaryBlob:i,binary:u,reliable:u,sctp:u,onnegotiationneeded:l}}(),validateId:function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(e)},validateKey:function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(e)},debug:!1,inherits:function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},extend:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e},pack:n.default.pack,unpack:n.default.unpack,log:function(){if(exports.util.debug){var e=!1,t=Array.prototype.slice.call(arguments);t.unshift("PeerJS: ");for(var r=0,o=t.length;r<o;r++)t[r]instanceof Error&&(t[r]="("+t[r].name+") "+t[r].message,e=!0);e?console.error.apply(console,t):console.log.apply(console,t)}},setZeroTimeout:function(e){var t=[],r="zero-timeout-message";function o(o){o.source==e&&o.data==r&&(o.stopPropagation&&o.stopPropagation(),t.length&&t.shift()())}return e.addEventListener?e.addEventListener("message",o,!0):e.attachEvent&&e.attachEvent("onmessage",o),function(o){t.push(o),e.postMessage(r,"*")}}(window),chunk:function(e){for(var t,r=[],n=e.size,a=t=0,i=Math.ceil(n/exports.util.chunkedMTU);a<n;){var u=Math.min(n,a+exports.util.chunkedMTU),l=e.slice(a,u),s={__peerData:o,n:t,data:l,total:i};r.push(s),a=u,t+=1}return o+=1,r},blobToArrayBuffer:function(e,t){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.readAsArrayBuffer(e)},blobToBinaryString:function(e,t){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.readAsBinaryString(e)},binaryStringToArrayBuffer:function(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=255&e.charCodeAt(r);return t.buffer},randomToken:function(){return Math.random().toString(36).substr(2)},isSecure:function(){return"https:"===location.protocol}};
},{"js-binarypack":"lHOc","./adapter":"sXtV"}],"2JJl":[function(require,module,exports) {
"use strict";function t(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function e(){}e.prototype._events=void 0,e.prototype.listeners=function(t){if(!this._events||!this._events[t])return[];if(this._events[t].fn)return[this._events[t].fn];for(var e=0,n=this._events[t].length,s=new Array(n);e<n;e++)s[e]=this._events[t][e].fn;return s},e.prototype.emit=function(t,e,n,s,r,i){if(!this._events||!this._events[t])return!1;var o,h,f=this._events[t],v=arguments.length;if("function"==typeof f.fn){switch(f.once&&this.removeListener(t,f.fn,!0),v){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,e),!0;case 3:return f.fn.call(f.context,e,n),!0;case 4:return f.fn.call(f.context,e,n,s),!0;case 5:return f.fn.call(f.context,e,n,s,r),!0;case 6:return f.fn.call(f.context,e,n,s,r,i),!0}for(h=1,o=new Array(v-1);h<v;h++)o[h-1]=arguments[h];f.fn.apply(f.context,o)}else{var c,a=f.length;for(h=0;h<a;h++)switch(f[h].once&&this.removeListener(t,f[h].fn,!0),v){case 1:f[h].fn.call(f[h].context);break;case 2:f[h].fn.call(f[h].context,e);break;case 3:f[h].fn.call(f[h].context,e,n);break;default:if(!o)for(c=1,o=new Array(v-1);c<v;c++)o[c-1]=arguments[c];f[h].fn.apply(f[h].context,o)}}return!0},e.prototype.on=function(e,n,s){var r=new t(n,s||this);return this._events||(this._events={}),this._events[e]?this._events[e].fn?this._events[e]=[this._events[e],r]:this._events[e].push(r):this._events[e]=r,this},e.prototype.once=function(e,n,s){var r=new t(n,s||this,!0);return this._events||(this._events={}),this._events[e]?this._events[e].fn?this._events[e]=[this._events[e],r]:this._events[e].push(r):this._events[e]=r,this},e.prototype.removeListener=function(t,e,n){if(!this._events||!this._events[t])return this;var s=this._events[t],r=[];if(e&&(s.fn&&(s.fn!==e||n&&!s.once)&&r.push(s),!s.fn))for(var i=0,o=s.length;i<o;i++)(s[i].fn!==e||n&&!s[i].once)&&r.push(s[i]);return r.length?this._events[t]=1===r.length?r[0]:r:delete this._events[t],this},e.prototype.removeAllListeners=function(t){return this._events?(t?delete this._events[t]:this._events={},this):this},e.prototype.off=e.prototype.removeListener,e.prototype.addListener=e.prototype.on,e.prototype.setMaxListeners=function(){return this},e.EventEmitter=e,e.EventEmitter2=e,e.EventEmitter3=e,module.exports=e;
},{}],"wJlv":[function(require,module,exports) {
"use strict";exports.__esModule=!0;var t=require("./util"),e=require("eventemitter3");function s(t,i,o,n,r,h){if(!(this instanceof s))return new s(t,i,o,n,r,h);h=h||o,e.EventEmitter.call(this),this.disconnected=!1,this._queue=[];var a=t?"https://":"http://",u=t?"wss://":"ws://";this._httpUrl=a+i+":"+o+n+r,this._wsUrl=u+i+":"+h+n+"peerjs?key="+r}exports.Socket=s,t.util.inherits(s,e.EventEmitter),s.prototype.start=function(t,e){this.id=t,this._httpUrl+="/"+t+"/"+e,this._wsUrl+="&id="+t+"&token="+e,this._startXhrStream(),this._startWebSocket()},s.prototype._startWebSocket=function(e){var s=this;this._socket||(this._socket=new WebSocket(this._wsUrl),this._socket.onmessage=function(e){try{var i=JSON.parse(e.data)}catch(o){return void t.util.log("Invalid server message",e.data)}s.emit("message",i)},this._socket.onclose=function(e){t.util.log("Socket closed."),s.disconnected=!0,s.emit("disconnected")},this._socket.onopen=function(){s._timeout&&(clearTimeout(s._timeout),setTimeout(function(){s._http.abort(),s._http=null},5e3)),s._sendQueuedMessages(),t.util.log("Socket open")})},s.prototype._startXhrStream=function(e){try{var s=this;this._http=new XMLHttpRequest,this._http._index=1,this._http._streamIndex=e||0,this._http.open("post",this._httpUrl+"/id?i="+this._http._streamIndex,!0),this._http.onerror=function(){clearTimeout(s._timeout),s.emit("disconnected")},this._http.onreadystatechange=function(){2==this.readyState&&this.old?(this.old.abort(),delete this.old):this.readyState>2&&200===this.status&&this.responseText&&s._handleStream(this)},this._http.send(null),this._setHTTPTimeout()}catch(i){t.util.log("XMLHttpRequest not available; defaulting to WebSockets")}},s.prototype._handleStream=function(e){var s=e.responseText.split("\n");if(e._buffer)for(;e._buffer.length>0;){var i=e._buffer.shift(),o=s[i];try{o=JSON.parse(o)}catch(r){e._buffer.shift(i);break}this.emit("message",o)}var n=s[e._index];if(n)if(e._index+=1,e._index===s.length)e._buffer||(e._buffer=[]),e._buffer.push(e._index-1);else{try{n=JSON.parse(n)}catch(r){return void t.util.log("Invalid server message",n)}this.emit("message",n)}},s.prototype._setHTTPTimeout=function(){var t=this;this._timeout=setTimeout(function(){var e=t._http;t._wsOpen()?e.abort():(t._startXhrStream(e._streamIndex+1),t._http.old=e)},25e3)},s.prototype._wsOpen=function(){return this._socket&&1==this._socket.readyState},s.prototype._sendQueuedMessages=function(){for(var t=0,e=this._queue.length;t<e;t+=1)this.send(this._queue[t])},s.prototype.send=function(t){if(!this.disconnected)if(this.id)if(t.type){var e=JSON.stringify(t);if(this._wsOpen())this._socket.send(e);else{var s=new XMLHttpRequest,i=this._httpUrl+"/"+t.type.toLowerCase();s.open("post",i,!0),s.setRequestHeader("Content-Type","application/json"),s.send(e)}}else this.emit("error","Invalid message");else this._queue.push(t)},s.prototype.close=function(){!this.disconnected&&this._wsOpen()&&(this._socket.close(),this.disconnected=!0)};
},{"./util":"BHXf","eventemitter3":"2JJl"}],"HCdX":[function(require,module,exports) {
"use strict";exports.__esModule=!0;var e=require("./util"),t=require("./adapter");function o(e,t){"addTrack"in t?e.getTracks().forEach(function(o){t.addTrack(o,e)}):"addStream"in t&&t.addStream(e)}exports.Negotiator={pcs:{data:{},media:{}},queue:[]},exports.Negotiator._idPrefix="pc_",exports.Negotiator.startConnection=function(t,i){var r=exports.Negotiator._getPeerConnection(t,i);if(t.pc=t.peerConnection=r,"media"===t.type&&i._stream&&o(i._stream,r),i.originator){if("data"===t.type){var n={};e.util.supports.sctp||(n={reliable:i.reliable});var a=r.createDataChannel(t.label,n);t.initialize(a)}exports.Negotiator._makeOffer(t)}else exports.Negotiator.handleSDP("OFFER",t,i.sdp)},exports.Negotiator._getPeerConnection=function(t,o){exports.Negotiator.pcs[t.type]||e.util.error(t.type+" is not a valid connection type. Maybe you overrode the `type` property somewhere."),exports.Negotiator.pcs[t.type][t.peer]||(exports.Negotiator.pcs[t.type][t.peer]={});var i;exports.Negotiator.pcs[t.type][t.peer];return o.pc&&(i=exports.Negotiator.pcs[t.type][t.peer][o.pc]),i&&"stable"===i.signalingState||(i=exports.Negotiator._startPeerConnection(t)),i},exports.Negotiator._startPeerConnection=function(o){e.util.log("Creating RTCPeerConnection.");var i=exports.Negotiator._idPrefix+e.util.randomToken(),r={};"data"!==o.type||e.util.supports.sctp?"media"===o.type&&(r={optional:[{DtlsSrtpKeyAgreement:!0}]}):r={optional:[{RtpDataChannels:!0}]};var n=new t.RTCPeerConnection(o.provider.options.config,r);return exports.Negotiator.pcs[o.type][o.peer][i]=n,exports.Negotiator._setupListeners(o,n,i),n},exports.Negotiator._setupListeners=function(t,i,r){var n=t.peer,a=t.id,c=t.provider;e.util.log("Listening for ICE candidates."),i.onicecandidate=function(o){o.candidate&&(e.util.log("Received ICE candidates for:",t.peer),c.socket.send({type:"CANDIDATE",payload:{candidate:o.candidate,type:t.type,connectionId:t.id},dst:n}))},i.oniceconnectionstatechange=function(){switch(i.iceConnectionState){case"failed":e.util.log("iceConnectionState is disconnected, closing connections to "+n),t.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.close();break;case"disconnected":e.util.log("iceConnectionState is disconnected, closing connections to "+n);break;case"completed":i.onicecandidate=e.util.noop}},i.onicechange=i.oniceconnectionstatechange,e.util.log("Listening for data channel"),i.ondatachannel=function(t){e.util.log("Received data channel");var o=t.channel;c.getConnection(n,a).initialize(o)},e.util.log("Listening for remote stream"),i.ontrack=function(t){e.util.log("Received remote stream");var i=t.streams[0],r=c.getConnection(n,a);"media"===r.type&&o(i,r)}},exports.Negotiator.cleanup=function(t){e.util.log("Cleaning up PeerConnection to "+t.peer);var o=t.pc;o&&(o.readyState&&"closed"!==o.readyState||"closed"!==o.signalingState)&&(o.close(),t.pc=null)},exports.Negotiator._makeOffer=function(t){var o=t.pc,i=function(i){e.util.log("Created offer."),!e.util.supports.sctp&&"data"===t.type&&t.reliable&&(i.sdp=Reliable.higherBandwidthSDP(i.sdp));o.setLocalDescription(i).then(function(){return e.util.log("Set localDescription: offer","for:",t.peer),void t.provider.socket.send({type:"OFFER",payload:{sdp:i,type:t.type,label:t.label,connectionId:t.id,reliable:t.reliable,serialization:t.serialization,metadata:t.metadata,browser:e.util.browser},dst:t.peer})}).catch(function(o){return function(o){"OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"!=o&&(t.provider.emitError("webrtc",o),e.util.log("Failed to setLocalDescription, ",o))}(o)})};o.createOffer(t.options.constraints).then(function(e){return i(e)}).catch(function(o){return function(o){t.provider.emitError("webrtc",o),e.util.log("Failed to createOffer, ",o)}(o)})},exports.Negotiator._makeAnswer=function(t){var o=t.pc,i=function(i){e.util.log("Created answer."),!e.util.supports.sctp&&"data"===t.type&&t.reliable&&(i.sdp=Reliable.higherBandwidthSDP(i.sdp));o.setLocalDescription(i).then(function(){return e.util.log("Set localDescription: answer","for:",t.peer),void t.provider.socket.send({type:"ANSWER",payload:{sdp:i,type:t.type,connectionId:t.id,browser:e.util.browser},dst:t.peer})}).catch(function(o){t.provider.emitError("webrtc",o),e.util.log("Failed to setLocalDescription, ",o)})};o.createAnswer().then(function(e){return i(e)}).catch(function(o){t.provider.emitError("webrtc",o),e.util.log("Failed to create answer, ",o)})},exports.Negotiator.handleSDP=function(o,i,r){r=new t.RTCSessionDescription(r);var n=i.pc;e.util.log("Setting remote description",r);n.setRemoteDescription(r).then(function(){return e.util.log("Set remoteDescription:",o,"for:",i.peer),void("OFFER"===o&&exports.Negotiator._makeAnswer(i))}).catch(function(t){i.provider.emitError("webrtc",t),e.util.log("Failed to setRemoteDescription, ",t)})},exports.Negotiator.handleCandidate=function(o,i){var r=i.candidate,n=i.sdpMLineIndex;o.pc.addIceCandidate(new t.RTCIceCandidate({sdpMLineIndex:n,candidate:r})),e.util.log("Added ICE candidate for:",o.peer)};
},{"./util":"BHXf","./adapter":"sXtV"}],"dbHP":[function(require,module,exports) {
"use strict";exports.__esModule=!0;var t=require("./util"),e=require("eventemitter3"),i=require("./negotiator");function o(s,a,r){if(!(this instanceof o))return new o(s,a,r);e.EventEmitter.call(this),this.options=t.util.extend({},r),this.open=!1,this.type="media",this.peer=s,this.provider=a,this.metadata=this.options.metadata,this.localStream=this.options._stream,this.id=this.options.connectionId||o._idPrefix+t.util.randomToken(),this.localStream&&i.Negotiator.startConnection(this,{_stream:this.localStream,originator:!0})}exports.MediaConnection=o,t.util.inherits(o,e.EventEmitter),o._idPrefix="mc_",o.prototype.addStream=function(e){t.util.log("Receiving stream",e),this.remoteStream=e,this.emit("stream",e)},o.prototype.handleMessage=function(e){var o=e.payload;switch(e.type){case"ANSWER":i.Negotiator.handleSDP(e.type,this,o.sdp),this.open=!0;break;case"CANDIDATE":i.Negotiator.handleCandidate(this,o.candidate);break;default:t.util.warn("Unrecognized message type:",e.type,"from peer:",this.peer)}},o.prototype.answer=function(e){if(this.localStream)t.util.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");else{this.options._payload._stream=e,this.localStream=e,i.Negotiator.startConnection(this,this.options._payload);for(var o=this.provider._getMessages(this.id),s=0,a=o.length;s<a;s+=1)this.handleMessage(o[s]);this.open=!0}},o.prototype.close=function(){this.open&&(this.open=!1,i.Negotiator.cleanup(this),this.emit("close"))};
},{"./util":"BHXf","eventemitter3":"2JJl","./negotiator":"HCdX"}],"T9kO":[function(require,module,exports) {
var global = arguments[3];
var e=arguments[3],r=require("js-binarypack"),t={debug:!1,inherits:function(e,r){e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},extend:function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t]);return e},pack:r.pack,unpack:r.unpack,log:function(){if(t.debug){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];e.unshift("Reliable: "),console.log.apply(console,e)}},setZeroTimeout:function(e){var r=[],t="zero-timeout-message";function n(n){n.source==e&&n.data==t&&(n.stopPropagation&&n.stopPropagation(),r.length&&r.shift()())}return e.addEventListener?e.addEventListener("message",n,!0):e.attachEvent&&e.attachEvent("onmessage",n),function(n){r.push(n),e.postMessage(t,"*")}}(this),blobToArrayBuffer:function(e,r){var t=new FileReader;t.onload=function(e){r(e.target.result)},t.readAsArrayBuffer(e)},blobToBinaryString:function(e,r){var t=new FileReader;t.onload=function(e){r(e.target.result)},t.readAsBinaryString(e)},binaryStringToArrayBuffer:function(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=255&e.charCodeAt(t);return r.buffer},randomToken:function(){return Math.random().toString(36).substr(2)}};module.exports=t;
},{"js-binarypack":"lHOc"}],"aYFJ":[function(require,module,exports) {
var t=require("./util");function e(n,i){if(!(this instanceof e))return new e(n);this._dc=n,t.debug=i,this._outgoing={},this._incoming={},this._received={},this._window=1e3,this._mtu=500,this._interval=0,this._count=0,this._queue=[],this._setupDC()}e.prototype.send=function(e){var n=t.pack(e);n.size<this._mtu?this._handleSend(["no",n]):(this._outgoing[this._count]={ack:0,chunks:this._chunk(n)},t.debug&&(this._outgoing[this._count].timer=new Date),this._sendWindowedChunks(this._count),this._count+=1)},e.prototype._setupInterval=function(){var t=this;this._timeout=setInterval(function(){var e=t._queue.shift();if(e._multiple)for(var n=0,i=e.length;n<i;n+=1)t._intervalSend(e[n]);else t._intervalSend(e)},this._interval)},e.prototype._intervalSend=function(e){var n=this;e=t.pack(e),t.blobToBinaryString(e,function(t){n._dc.send(t)}),0===n._queue.length&&(clearTimeout(n._timeout),n._timeout=null)},e.prototype._processAcks=function(){for(var t in this._outgoing)this._outgoing.hasOwnProperty(t)&&this._sendWindowedChunks(t)},e.prototype._handleSend=function(t){for(var e=!0,n=0,i=this._queue.length;n<i;n+=1){var o=this._queue[n];o===t?e=!1:o._multiple&&-1!==o.indexOf(t)&&(e=!1)}e&&(this._queue.push(t),this._timeout||this._setupInterval())},e.prototype._setupDC=function(){var e=this;this._dc.onmessage=function(n){var i=n.data;if(i.constructor===String){var o=t.binaryStringToArrayBuffer(i);i=t.unpack(o),e._handleMessage(i)}}},e.prototype._handleMessage=function(e){var n,i=e[1],o=this._incoming[i],s=this._outgoing[i];switch(e[0]){case"no":var a=i;a&&this.onmessage(t.unpack(a));break;case"end":if(n=o,this._received[i]=e[2],!n)break;this._ack(i);break;case"ack":if(n=s){var h=e[2];n.ack=Math.max(h,n.ack),n.ack>=n.chunks.length?(t.log("Time: ",new Date-n.timer),delete this._outgoing[i]):this._processAcks()}break;case"chunk":if(!(n=o)){if(!0===this._received[i])break;n={ack:["ack",i,0],chunks:[]},this._incoming[i]=n}var r=e[2],u=e[3];n.chunks[r]=new Uint8Array(u),r===n.ack[2]&&this._calculateNextAck(i),this._ack(i);break;default:this._handleSend(e)}},e.prototype._chunk=function(e){for(var n=[],i=e.size,o=0;o<i;){var s=Math.min(i,o+this._mtu),a={payload:e.slice(o,s)};n.push(a),o=s}return t.log("Created",n.length,"chunks."),n},e.prototype._ack=function(t){var e=this._incoming[t].ack;this._received[t]===e[2]&&(this._complete(t),this._received[t]=!0),this._handleSend(e)},e.prototype._calculateNextAck=function(t){for(var e=this._incoming[t],n=e.chunks,i=0,o=n.length;i<o;i+=1)if(void 0===n[i])return void(e.ack[2]=i);e.ack[2]=n.length},e.prototype._sendWindowedChunks=function(e){t.log("sendWindowedChunks for: ",e);for(var n=this._outgoing[e],i=n.chunks,o=[],s=Math.min(n.ack+this._window,i.length),a=n.ack;a<s;a+=1)i[a].sent&&a!==n.ack||(i[a].sent=!0,o.push(["chunk",e,a,i[a].payload]));n.ack+this._window>=i.length&&o.push(["end",e,i.length]),o._multiple=!0,this._handleSend(o)},e.prototype._complete=function(e){t.log("Completed called for",e);var n=this,i=this._incoming[e].chunks,o=new Blob(i);t.blobToArrayBuffer(o,function(e){n.onmessage(t.unpack(e))}),delete this._incoming[e]},e.higherBandwidthSDP=function(t){var e=navigator.appVersion.match(/Chrome\/(.*?) /);if(e&&(e=parseInt(e[1].split(".").shift()))<31){var n=t.split("b=AS:30");if(n.length>1)return n[0]+"b=AS:102400"+n[1]}return t},e.prototype.onmessage=function(t){},module.exports.Reliable=e;
},{"./util":"T9kO"}],"GBTQ":[function(require,module,exports) {
"use strict";exports.__esModule=!0;var t=require("./util"),e=require("eventemitter3"),i=require("./negotiator"),n=require("reliable");function s(n,r,a){if(!(this instanceof s))return new s(n,r,a);e.EventEmitter.call(this),this.options=t.util.extend({serialization:"binary",reliable:!1},a),this.open=!1,this.type="data",this.peer=n,this.provider=r,this.id=this.options.connectionId||s._idPrefix+t.util.randomToken(),this.label=this.options.label||this.id,this.metadata=this.options.metadata,this.serialization=this.options.serialization,this.reliable=this.options.reliable,this._buffer=[],this._buffering=!1,this.bufferSize=0,this._chunkedData={},this.options._payload&&(this._peerBrowser=this.options._payload.browser),i.Negotiator.startConnection(this,this.options._payload||{originator:!0})}exports.DataConnection=s,t.util.inherits(s,e.EventEmitter),s._idPrefix="dc_",s.prototype.initialize=function(t){this._dc=this.dataChannel=t,this._configureDataChannel()},s.prototype._configureDataChannel=function(){var e=this;t.util.supports.sctp&&(this._dc.binaryType="arraybuffer"),this._dc.onopen=function(){t.util.log("Data channel connection success"),e.open=!0,e.emit("open")},!t.util.supports.sctp&&this.reliable&&(this._reliable=new n.Reliable(this._dc,t.util.debug)),this._reliable?this._reliable.onmessage=function(t){e.emit("data",t)}:this._dc.onmessage=function(t){e._handleDataMessage(t)},this._dc.onclose=function(i){t.util.log("DataChannel closed for:",e.peer),e.close()}},s.prototype._handleDataMessage=function(e){var i=this,n=e.data,s=n.constructor;if("binary"===this.serialization||"binary-utf8"===this.serialization){if(s===Blob)return void t.util.blobToArrayBuffer(n,function(e){n=t.util.unpack(e),i.emit("data",n)});if(s===ArrayBuffer)n=t.util.unpack(n);else if(s===String){var r=t.util.binaryStringToArrayBuffer(n);n=t.util.unpack(r)}}else"json"===this.serialization&&(n=JSON.parse(n));if(n.__peerData){var a=n.__peerData,o=this._chunkedData[a]||{data:[],count:0,total:n.total};return o.data[n.n]=n.data,o.count+=1,o.total===o.count&&(delete this._chunkedData[a],n=new Blob(o.data),this._handleDataMessage({data:n})),void(this._chunkedData[a]=o)}this.emit("data",n)},s.prototype.close=function(){this.open&&(this.open=!1,i.Negotiator.cleanup(this),this.emit("close"))},s.prototype.send=function(e,i){if(this.open)if(this._reliable)this._reliable.send(e);else{var n=this;if("json"===this.serialization)this._bufferedSend(JSON.stringify(e));else if("binary"===this.serialization||"binary-utf8"===this.serialization){var s=t.util.pack(e);if((t.util.chunkedBrowsers[this._peerBrowser]||t.util.chunkedBrowsers[t.util.browser])&&!i&&s.size>t.util.chunkedMTU)return void this._sendChunks(s);t.util.supports.sctp?t.util.supports.binaryBlob?this._bufferedSend(s):t.util.blobToArrayBuffer(s,function(t){n._bufferedSend(t)}):t.util.blobToBinaryString(s,function(t){n._bufferedSend(t)})}else this._bufferedSend(e)}else this.emit("error",new Error("Connection is not open. You should listen for the `open` event before sending messages."))},s.prototype._bufferedSend=function(t){!this._buffering&&this._trySend(t)||(this._buffer.push(t),this.bufferSize=this._buffer.length)},s.prototype._trySend=function(t){try{this._dc.send(t)}catch(i){this._buffering=!0;var e=this;return setTimeout(function(){e._buffering=!1,e._tryBuffer()},100),!1}return!0},s.prototype._tryBuffer=function(){if(0!==this._buffer.length){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this.bufferSize=this._buffer.length,this._tryBuffer())}},s.prototype._sendChunks=function(e){for(var i=t.util.chunk(e),n=0,s=i.length;n<s;n+=1){e=i[n];this.send(e,!0)}},s.prototype.handleMessage=function(e){var n=e.payload;switch(e.type){case"ANSWER":this._peerBrowser=n.browser,i.Negotiator.handleSDP(e.type,this,n.sdp);break;case"CANDIDATE":i.Negotiator.handleCandidate(this,n.candidate);break;default:t.util.warn("Unrecognized message type:",e.type,"from peer:",this.peer)}};
},{"./util":"BHXf","eventemitter3":"2JJl","./negotiator":"HCdX","reliable":"aYFJ"}],"Hxpd":[function(require,module,exports) {
"use strict";exports.__esModule=!0;var e=require("./util"),t=require("eventemitter3"),o=require("./socket"),n=require("./mediaconnection"),i=require("./dataconnection");function s(o,n){if(!(this instanceof s))return new s(o,n);t.EventEmitter.call(this),o&&o.constructor==Object?(n=o,o=void 0):o&&(o=o.toString()),(n=e.util.extend({debug:0,host:e.util.CLOUD_HOST,port:e.util.CLOUD_PORT,path:"/",token:e.util.randomToken(),config:e.util.defaultConfig},n)).key="peerjs",this.options=n,"/"===n.host&&(n.host=window.location.hostname),"/"!==n.path[0]&&(n.path="/"+n.path),"/"!==n.path[n.path.length-1]&&(n.path+="/"),void 0===n.secure&&n.host!==e.util.CLOUD_HOST?n.secure=e.util.isSecure():n.host==e.util.CLOUD_HOST&&(n.secure=!0),n.logFunction&&e.util.setLogFunction(n.logFunction),e.util.setLogLevel(n.debug),e.util.supports.audioVideo||e.util.supports.data?e.util.validateId(o)?(this.destroyed=!1,this.disconnected=!1,this.open=!1,this.connections={},this._lostMessages={},this._initializeServerConnection(),o?this._initialize(o):this._retrieveId()):this._delayedAbort("invalid-id",'ID "'+o+'" is invalid'):this._delayedAbort("browser-incompatible","The current browser does not support WebRTC")}exports.Peer=s,e.util.inherits(s,t.EventEmitter),s.prototype._initializeServerConnection=function(){var e=this;this.socket=new o.Socket(this.options.secure,this.options.host,this.options.port,this.options.path,this.options.key,this.options.wsport),this.socket.on("message",function(t){e._handleMessage(t)}),this.socket.on("error",function(t){e._abort("socket-error",t)}),this.socket.on("disconnected",function(){e.disconnected||(e.emitError("network","Lost connection to server."),e.disconnect())}),this.socket.on("close",function(){e.disconnected||e._abort("socket-closed","Underlying socket is already closed.")})},s.prototype._retrieveId=function(t){var o=this,n=new XMLHttpRequest,i=(this.options.secure?"https://":"http://")+this.options.host+":"+this.options.port+this.options.path+this.options.key+"/id";i+="?ts="+(new Date).getTime()+Math.random(),n.open("get",i,!0),n.onerror=function(t){e.util.error("Error retrieving ID",t);var n="";"/"===o.options.path&&o.options.host!==e.util.CLOUD_HOST&&(n=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),o._abort("server-error","Could not get an ID from the server."+n)},n.onreadystatechange=function(){4===n.readyState&&(200===n.status?o._initialize(n.responseText):n.onerror())},n.send(null)},s.prototype._initialize=function(e){this.id=e,this.socket.start(this.id,this.options.token)},s.prototype._handleMessage=function(t){var o,s=t.type,r=t.payload,a=t.src;switch(s){case"OPEN":this.emit("open",this.id),this.open=!0;break;case"ERROR":this._abort("server-error",r.msg);break;case"ID-TAKEN":this._abort("unavailable-id","ID `"+this.id+"` is taken");break;case"INVALID-KEY":this._abort("invalid-key",'API KEY "'+this.options.key+'" is invalid');break;case"LEAVE":e.util.log("Received leave message from",a),this._cleanupPeer(a);break;case"EXPIRE":this.emitError("peer-unavailable","Could not connect to peer "+a);break;case"OFFER":var c=r.connectionId;if((o=this.getConnection(a,c))&&(o.close(),e.util.warn("Offer received for existing Connection ID:",c)),"media"===r.type)o=new n.MediaConnection(a,this,{connectionId:c,_payload:r,metadata:r.metadata}),this._addConnection(a,o),this.emit("call",o);else{if("data"!==r.type)return void e.util.warn("Received malformed connection type:",r.type);o=new i.DataConnection(a,this,{connectionId:c,_payload:r,metadata:r.metadata,label:r.label,serialization:r.serialization,reliable:r.reliable}),this._addConnection(a,o),this.emit("connection",o)}for(var h=this._getMessages(c),d=0,l=h.length;d<l;d+=1)o.handleMessage(h[d]);break;default:if(!r)return void e.util.warn("You received a malformed message from "+a+" of type "+s);var u=r.connectionId;(o=this.getConnection(a,u))&&o.pc?o.handleMessage(t):u?this._storeMessage(u,t):e.util.warn("You received an unrecognized message:",t)}},s.prototype._storeMessage=function(e,t){this._lostMessages[e]||(this._lostMessages[e]=[]),this._lostMessages[e].push(t)},s.prototype._getMessages=function(e){var t=this._lostMessages[e];return t?(delete this._lostMessages[e],t):[]},s.prototype.connect=function(t,o){if(this.disconnected)return e.util.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),void this.emitError("disconnected","Cannot connect to new Peer after disconnecting from server.");var n=new i.DataConnection(t,this,o);return this._addConnection(t,n),n},s.prototype.call=function(t,o,i){if(this.disconnected)return e.util.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),void this.emitError("disconnected","Cannot connect to new Peer after disconnecting from server.");if(o){(i=i||{})._stream=o;var s=new n.MediaConnection(t,this,i);return this._addConnection(t,s),s}e.util.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.")},s.prototype._addConnection=function(e,t){this.connections[e]||(this.connections[e]=[]),this.connections[e].push(t)},s.prototype.getConnection=function(e,t){var o=this.connections[e];if(!o)return null;for(var n=0,i=o.length;n<i;n++)if(o[n].id===t)return o[n];return null},s.prototype._delayedAbort=function(t,o){var n=this;e.util.setZeroTimeout(function(){n._abort(t,o)})},s.prototype._abort=function(t,o){e.util.error("Aborting!"),this._lastServerId?this.disconnect():this.destroy(),this.emitError(t,o)},s.prototype.emitError=function(t,o){e.util.error("Error:",o),"string"==typeof o&&(o=new Error(o)),o.type=t,this.emit("error",o)},s.prototype.destroy=function(){this.destroyed||(this._cleanup(),this.disconnect(),this.destroyed=!0)},s.prototype._cleanup=function(){if(this.connections)for(var e=Object.keys(this.connections),t=0,o=e.length;t<o;t++)this._cleanupPeer(e[t]);this.emit("close")},s.prototype._cleanupPeer=function(e){for(var t=this.connections[e],o=0,n=t.length;o<n;o+=1)t[o].close()},s.prototype.disconnect=function(){var t=this;e.util.setZeroTimeout(function(){t.disconnected||(t.disconnected=!0,t.open=!1,t.socket&&t.socket.close(),t.emit("disconnected",t.id),t._lastServerId=t.id,t.id=null)})},s.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)e.util.log("Attempting reconnection to server with ID "+this._lastServerId),this.disconnected=!1,this._initializeServerConnection(),this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(this.disconnected||this.open)throw new Error("Peer "+this.id+" cannot reconnect because it is not disconnected from the server!");e.util.error("In a hurry? We're still trying to make the initial connection!")}},s.prototype.listAllPeers=function(t){t=t||function(){};var o=this,n=new XMLHttpRequest,i=(this.options.secure?"https://":"http://")+this.options.host+":"+this.options.port+this.options.path+this.options.key+"/peers";i+="?ts="+(new Date).getTime()+Math.random(),n.open("get",i,!0),n.onerror=function(e){o._abort("server-error","Could not get peers from the server."),t([])},n.onreadystatechange=function(){if(4===n.readyState){if(401===n.status){var i="";throw i=o.options.host!==e.util.CLOUD_HOST?"It looks like you're using the cloud server. You can email [email protected] to enable peer listing for your API key.":"You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",t([]),new Error("It doesn't look like you have permission to list peers IDs. "+i)}200!==n.status?t([]):t(JSON.parse(n.responseText))}},n.send(null)};
},{"./util":"BHXf","eventemitter3":"2JJl","./socket":"wJlv","./mediaconnection":"dbHP","./dataconnection":"GBTQ"}],"iTK6":[function(require,module,exports) {
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0;var i=require("./util"),n=require("./adapter"),o=require("./socket"),t=require("./mediaconnection"),r=require("./dataconnection"),a=require("./peer"),d=require("./negotiator"),c=e(require("js-binarypack"));window.Socket=o.Socket,window.MediaConnection=t.MediaConnection,window.DataConnection=r.DataConnection,window.Peer=a.Peer,window.RTCPeerConnection=n.RTCPeerConnection,window.RTCSessionDescription=n.RTCSessionDescription,window.RTCIceCandidate=n.RTCIceCandidate,window.Negotiator=d.Negotiator,window.util=i.util,window.BinaryPack=c.default,exports.default=a.Peer;
},{"./util":"BHXf","./adapter":"sXtV","./socket":"wJlv","./mediaconnection":"dbHP","./dataconnection":"GBTQ","./peer":"Hxpd","./negotiator":"HCdX","js-binarypack":"lHOc"}]},{},["iTK6"], null)
//# sourceMappingURL=/peerjs.min.map