rtcdemo/js/libs/peer.js

1 line
38 KiB
JavaScript
Raw Normal View History

2014-09-10 17:05:35 +00:00
/*! peerjs.min.js build:0.3.9, production. Copyright(c) 2013 Michelle Bu <michelle@michellebu.com> */(function(e){function n(){this._pieces=[],this._parts=[]}function r(e){this.index=0,this.dataBuffer=e,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}function i(){this.bufferBuilder=new n}function s(e){var t=e.charCodeAt(0);return t<=2047?"00":t<=65535?"000":t<=2097151?"0000":t<=67108863?"00000":"000000"}function o(e){return e.length>600?(new Blob([e])).size:e.replace(/[^\u0000-\u007F]/g,s).length}function u(){this._events={}}function f(e,t){if(!(this instanceof f))return new f(e);this._dc=e,h.debug=t,this._outgoing={},this._incoming={},this._received={},this._window=1e3,this._mtu=500,this._interval=0,this._count=0,this._queue=[],this._setupDC()}function p(e,t){if(!(this instanceof p))return new p(e,t);u.call(this),e&&e.constructor==Object?(t=e,e=undefined):e&&(e=e.toString()),t=h.extend({debug:0,host:h.CLOUD_HOST,port:h.CLOUD_PORT,key:"peerjs",path:"/",token:h.randomToken(),config:h.defaultConfig},t),this.options=t,t.host==="/"&&(t.host=window.location.hostname),t.path[0]!=="/"&&(t.path="/"+t.path),t.path[t.path.length-1]!=="/"&&(t.path+="/"),t.secure===undefined&&t.host!==h.CLOUD_HOST&&(t.secure=h.isSecure()),t.logFunction&&h.setLogFunction(t.logFunction),h.setLogLevel(t.debug);if(!h.supports.audioVideo&&!h.supports.data){this._delayedAbort("browser-incompatible","The current browser does not support WebRTC");return}if(!h.validateId(e)){this._delayedAbort("invalid-id",'ID "'+e+'" is invalid');return}if(!h.validateKey(t.key)){this._delayedAbort("invalid-key",'API KEY "'+t.key+'" is invalid');return}if(t.secure&&t.host==="0.peerjs.com"){this._delayedAbort("ssl-unavailable","The cloud server currently does not support HTTPS. Please run your own PeerServer to use HTTPS.");return}this.destroyed=!1,this.disconnected=!1,this.open=!1,this.connections={},this._lostMessages={},this._initializeServerConnection(),e?this._initialize(e):this._retrieveId()}function d(e,t,n){if(!(this instanceof d))return new d(e,t,n);u.call(this),this.options=h.extend({serialization:"binary",reliable:!1},n),this.open=!1,this.type="data",this.peer=e,this.provider=t,this.id=this.options.connectionId||d._idPrefix+h.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),m.startConnection(this,this.options._payload||{originator:!0})}function v(e,t,n){if(!(this instanceof v))return new v(e,t,n);u.call(this),this.options=h.extend({},n),this.open=!1,this.type="media",this.peer=e,this.provider=t,this.metadata=this.options.metadata,this.localStream=this.options._stream,this.id=this.options.connectionId||v._idPrefix+h.randomToken(),this.localStream&&m.startConnection(this,{_stream:this.localStream,originator:!0})}function g(e,t,n,r,i){if(!(this instanceof g))return new g(e,t,n,r,i);u.call(this),this.disconnected=!1,this._queue=[];var s=e?"https://":"http://",o=e?"wss://":"ws://";this._httpUrl=s+t+":"+n+r+i,this._wsUrl=o+t+":"+n+r+"peerjs?key="+i}var t={};t.useBlobBuilder=function(){try{return new Blob([]),!1}catch(e){return!0}}(),t.useArrayBufferView=!t.useBlobBuilder&&function(){try{return(new Blob([new Uint8Array([])])).size===0}catch(e){return!0}}(),e.binaryFeatures=t,e.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder,n.prototype.append=function(e){typeof e=="number"?this._pieces.push(e):(this.flush(),this._parts.push(e))},n.prototype.flush=function(){if(this._pieces.length>0){var e=new Uint8Array(this._pieces);t.useArrayBufferView||(e=e.buffer),this._parts.push(e),this._pieces=[]}},n.prototype.getBuffer=function(){this.flush();if(t.useBlobBuilder){var e=new BlobBuilder;for(var n=0,r=this._parts.length;n<r;n++)e.append(this._parts[n]);return e.getBlob()}return new Blob(this._parts)},e.BinaryPack={unpack:function