var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this.parsedData=[];for(var b=[],d=0,e=this.data.length;e>d;d++){var f=this.data.charCodeAt(d);f>65536?(b[0]=240|(1835008&f)>>>18,b[1]=128|(258048&f)>>>12,b[2]=128|(4032&f)>>>6,b[3]=128|63&f):f>2048?(b[0]=224|(61440&f)>>>12,b[1]=128|(4032&f)>>>6,b[2]=128|63&f):f>128?(b[0]=192|(1984&f)>>>6,b[1]=128|63&f):b[0]=f,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(a,b){this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function i(a,b){if(void 0==a.length)throw new Error(a.length+"/"+b);for(var c=0;c=f;f++){var h=0;switch(b){case d.L:h=l[f][0];break;case d.M:h=l[f][1];break;case d.Q:h=l[f][2];break;case d.H:h=l[f][3]}if(h>=e)break;c++}if(c>l.length)throw new Error("Too long data");return c}function s(a){var b=encodeURI(a).toString().replace(/\%[0-9a-fA-F]{2}/g,"a");return b.length+(b.length!=a?3:0)}a.prototype={getLength:function(){return this.parsedData.length},write:function(a){for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={addData:function(b){var c=new a(b);this.dataList.push(c),this.dataCache=null},isDark:function(a,b){if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;d=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,b){for(var c=-1;7>=c;c++)if(!(-1>=a+c||this.moduleCount<=a+c))for(var d=-1;7>=d;d++)-1>=b+d||this.moduleCount<=b+d||(this.modules[a+c][b+d]=c>=0&&6>=c&&(0==d||6==d)||d>=0&&6>=d&&(0==c||6==c)||c>=2&&4>=c&&d>=2&&4>=d?!0:!1)},getBestMaskPattern:function(){for(var a=0,b=0,c=0;8>c;c++){this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b},createMovieClip:function(a,b,c){var d=a.createEmptyMovieClip(b,c),e=1;this.make();for(var f=0;f=g;g++)for(var h=-2;2>=h;h++)this.modules[d+g][e+h]=-2==g||2==g||-2==h||2==h||0==g&&0==h?!0:!1}},setupTypeNumber:function(a){for(var b=f.getBCHTypeNumber(this.typeNumber),c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[Math.floor(c/3)][c%3+this.moduleCount-8-3]=d}for(var c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[c%3+this.moduleCount-8-3][Math.floor(c/3)]=d}},setupTypeInfo:function(a,b){for(var c=this.errorCorrectLevel<<3|b,d=f.getBCHTypeInfo(c),e=0;15>e;e++){var g=!a&&1==(1&d>>e);6>e?this.modules[e][8]=g:8>e?this.modules[e+1][8]=g:this.modules[this.moduleCount-15+e][8]=g}for(var e=0;15>e;e++){var g=!a&&1==(1&d>>e);8>e?this.modules[8][this.moduleCount-e-1]=g:9>e?this.modules[8][15-e-1+1]=g:this.modules[8][15-e-1]=g}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,b){for(var c=-1,d=this.moduleCount-1,e=7,g=0,h=this.moduleCount-1;h>0;h-=2)for(6==h&&h--;;){for(var i=0;2>i;i++)if(null==this.modules[d][h-i]){var j=!1;g>>e));var k=f.getMask(b,d,h-i);k&&(j=!j),this.modules[d][h-i]=j,e--,-1==e&&(g++,e=7)}if(d+=c,0>d||this.moduleCount<=d){d-=c,c=-c;break}}}},b.PAD0=236,b.PAD1=17,b.createData=function(a,c,d){for(var e=j.getRSBlocks(a,c),g=new k,h=0;h8*l)throw new Error("code length overflow. ("+g.getLengthInBits()+">"+8*l+")");for(g.getLengthInBits()+4<=8*l&&g.put(0,4);0!=g.getLengthInBits()%8;)g.putBit(!1);for(;;){if(g.getLengthInBits()>=8*l)break;if(g.put(b.PAD0,8),g.getLengthInBits()>=8*l)break;g.put(b.PAD1,8)}return b.createBytes(g,e)},b.createBytes=function(a,b){for(var c=0,d=0,e=0,g=new Array(b.length),h=new Array(b.length),j=0;j=0?p.get(q):0}}for(var r=0,m=0;mm;m++)for(var j=0;jm;m++)for(var j=0;j=0;)b^=f.G15<=0;)b^=f.G18<>>=1;return b},getPatternPosition:function(a){return f.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,b,c){switch(a){case e.PATTERN000:return 0==(b+c)%2;case e.PATTERN001:return 0==b%2;case e.PATTERN010:return 0==c%3;case e.PATTERN011:return 0==(b+c)%3;case e.PATTERN100:return 0==(Math.floor(b/2)+Math.floor(c/3))%2;case e.PATTERN101:return 0==b*c%2+b*c%3;case e.PATTERN110:return 0==(b*c%2+b*c%3)%2;case e.PATTERN111:return 0==(b*c%3+(b+c)%2)%2;default:throw new Error("bad maskPattern:"+a)}},getErrorCorrectPolynomial:function(a){for(var b=new i([1],0),c=0;a>c;c++)b=b.multiply(new i([1,g.gexp(c)],0));return b},getLengthInBits:function(a,b){if(b>=1&&10>b)switch(a){case c.MODE_NUMBER:return 10;case c.MODE_ALPHA_NUM:return 9;case c.MODE_8BIT_BYTE:return 8;case c.MODE_KANJI:return 8;default:throw new Error("mode:"+a)}else if(27>b)switch(a){case c.MODE_NUMBER:return 12;case c.MODE_ALPHA_NUM:return 11;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 10;default:throw new Error("mode:"+a)}else{if(!(41>b))throw new Error("type:"+b);switch(a){case c.MODE_NUMBER:return 14;case c.MODE_ALPHA_NUM:return 13;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 12;default:throw new Error("mode:"+a)}}},getLostPoint:function(a){for(var b=a.getModuleCount(),c=0,d=0;b>d;d++)for(var e=0;b>e;e++){for(var f=0,g=a.isDark(d,e),h=-1;1>=h;h++)if(!(0>d+h||d+h>=b))for(var i=-1;1>=i;i++)0>e+i||e+i>=b||(0!=h||0!=i)&&g==a.isDark(d+h,e+i)&&f++;f>5&&(c+=3+f-5)}for(var d=0;b-1>d;d++)for(var e=0;b-1>e;e++){var j=0;a.isDark(d,e)&&j++,a.isDark(d+1,e)&&j++,a.isDark(d,e+1)&&j++,a.isDark(d+1,e+1)&&j++,(0==j||4==j)&&(c+=3)}for(var d=0;b>d;d++)for(var e=0;b-6>e;e++)a.isDark(d,e)&&!a.isDark(d,e+1)&&a.isDark(d,e+2)&&a.isDark(d,e+3)&&a.isDark(d,e+4)&&!a.isDark(d,e+5)&&a.isDark(d,e+6)&&(c+=40);for(var e=0;b>e;e++)for(var d=0;b-6>d;d++)a.isDark(d,e)&&!a.isDark(d+1,e)&&a.isDark(d+2,e)&&a.isDark(d+3,e)&&a.isDark(d+4,e)&&!a.isDark(d+5,e)&&a.isDark(d+6,e)&&(c+=40);for(var k=0,e=0;b>e;e++)for(var d=0;b>d;d++)a.isDark(d,e)&&k++;var l=Math.abs(100*k/b/b-50)/5;return c+=10*l}},g={glog:function(a){if(1>a)throw new Error("glog("+a+")");return g.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;a>=256;)a-=255;return g.EXP_TABLE[a]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},h=0;8>h;h++)g.EXP_TABLE[h]=1<h;h++)g.EXP_TABLE[h]=g.EXP_TABLE[h-4]^g.EXP_TABLE[h-5]^g.EXP_TABLE[h-6]^g.EXP_TABLE[h-8];for(var h=0;255>h;h++)g.LOG_TABLE[g.EXP_TABLE[h]]=h;i.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var b=new Array(this.getLength()+a.getLength()-1),c=0;cf;f++)for(var g=c[3*f+0],h=c[3*f+1],i=c[3*f+2],k=0;g>k;k++)e.push(new j(h,i));return e},j.getRsBlockTable=function(a,b){switch(b){case d.L:return j.RS_BLOCK_TABLE[4*(a-1)+0];case d.M:return j.RS_BLOCK_TABLE[4*(a-1)+1];case d.Q:return j.RS_BLOCK_TABLE[4*(a-1)+2];case d.H:return j.RS_BLOCK_TABLE[4*(a-1)+3];default:return void 0}},k.prototype={get:function(a){var b=Math.floor(a/8);return 1==(1&this.buffer[b]>>>7-a%8)},put:function(a,b){for(var c=0;b>c;c++)this.putBit(1==(1&a>>>b-c-1))},getLengthInBits:function(){return this.length},putBit:function(a){var b=Math.floor(this.length/8);this.buffer.length<=b&&this.buffer.push(0),a&&(this.buffer[b]|=128>>>this.length%8),this.length++}};var l=[[17,14,11,7],[32,26,20,14],[53,42,32,24],[78,62,46,34],[106,84,60,44],[134,106,74,58],[154,122,86,64],[192,152,108,84],[230,180,130,98],[271,213,151,119],[321,251,177,137],[367,287,203,155],[425,331,241,177],[458,362,258,194],[520,412,292,220],[586,450,322,250],[644,504,364,280],[718,560,394,310],[792,624,442,338],[858,666,482,382],[929,711,509,403],[1003,779,565,439],[1091,857,611,461],[1171,911,661,511],[1273,997,715,535],[1367,1059,751,593],[1465,1125,805,625],[1528,1190,868,658],[1628,1264,908,698],[1732,1370,982,742],[1840,1452,1030,790],[1952,1538,1112,842],[2068,1628,1168,898],[2188,1722,1228,958],[2303,1809,1283,983],[2431,1911,1351,1051],[2563,1989,1423,1093],[2699,2099,1499,1139],[2809,2213,1579,1219],[2953,2331,1663,1273]],o=function(){var a=function(a,b){this._el=a,this._htOption=b};return a.prototype.draw=function(a){function g(a,b){var c=document.createElementNS("http://www.w3.org/2000/svg",a);for(var d in b)b.hasOwnProperty(d)&&c.setAttribute(d,b[d]);return c}var b=this._htOption,c=this._el,d=a.getModuleCount();Math.floor(b.width/d),Math.floor(b.height/d),this.clear();var h=g("svg",{viewBox:"0 0 "+String(d)+" "+String(d),width:"100%",height:"100%",fill:b.colorLight});h.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),c.appendChild(h),h.appendChild(g("rect",{fill:b.colorDark,width:"1",height:"1",id:"template"}));for(var i=0;d>i;i++)for(var j=0;d>j;j++)if(a.isDark(i,j)){var k=g("use",{x:String(i),y:String(j)});k.setAttributeNS("http://www.w3.org/1999/xlink","href","#template"),h.appendChild(k)}},a.prototype.clear=function(){for(;this._el.hasChildNodes();)this._el.removeChild(this._el.lastChild)},a}(),p="svg"===document.documentElement.tagName.toLowerCase(),q=p?o:m()?function(){function a(){this._elImage.src=this._elCanvas.toDataURL("image/png"),this._elImage.style.display="block",this._elCanvas.style.display="none"}function d(a,b){var c=this;if(c._fFail=b,c._fSuccess=a,null===c._bSupportDataURI){var d=document.createElement("img"),e=function(){c._bSupportDataURI=!1,c._fFail&&_fFail.call(c)},f=function(){c._bSupportDataURI=!0,c._fSuccess&&c._fSuccess.call(c)};return d.onabort=e,d.onerror=e,d.onload=f,d.src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",void 0}c._bSupportDataURI===!0&&c._fSuccess?c._fSuccess.call(c):c._bSupportDataURI===!1&&c._fFail&&c._fFail.call(c)}if(this._android&&this._android<=2.1){var b=1/window.devicePixelRatio,c=CanvasRenderingContext2D.prototype.drawImage;CanvasRenderingContext2D.prototype.drawImage=function(a,d,e,f,g,h,i,j){if("nodeName"in a&&/img/i.test(a.nodeName))for(var l=arguments.length-1;l>=1;l--)arguments[l]=arguments[l]*b;else"undefined"==typeof j&&(arguments[1]*=b,arguments[2]*=b,arguments[3]*=b,arguments[4]*=b);c.apply(this,arguments)}}var e=function(a,b){this._bIsPainted=!1,this._android=n(),this._htOption=b,this._elCanvas=document.createElement("canvas"),this._elCanvas.width=b.width,this._elCanvas.height=b.height,a.appendChild(this._elCanvas),this._el=a,this._oContext=this._elCanvas.getContext("2d"),this._bIsPainted=!1,this._elImage=document.createElement("img"),this._elImage.style.display="none",this._el.appendChild(this._elImage),this._bSupportDataURI=null};return e.prototype.draw=function(a){var b=this._elImage,c=this._oContext,d=this._htOption,e=a.getModuleCount(),f=d.width/e,g=d.height/e,h=Math.round(f),i=Math.round(g);b.style.display="none",this.clear();for(var j=0;e>j;j++)for(var k=0;e>k;k++){var l=a.isDark(j,k),m=k*f,n=j*g;c.strokeStyle=l?d.colorDark:d.colorLight,c.lineWidth=1,c.fillStyle=l?d.colorDark:d.colorLight,c.fillRect(m,n,f,g),c.strokeRect(Math.floor(m)+.5,Math.floor(n)+.5,h,i),c.strokeRect(Math.ceil(m)-.5,Math.ceil(n)-.5,h,i)}this._bIsPainted=!0},e.prototype.makeImage=function(){this._bIsPainted&&d.call(this,a)},e.prototype.isPainted=function(){return this._bIsPainted},e.prototype.clear=function(){this._oContext.clearRect(0,0,this._elCanvas.width,this._elCanvas.height),this._bIsPainted=!1},e.prototype.round=function(a){return a?Math.floor(1e3*a)/1e3:a},e}():function(){var a=function(a,b){this._el=a,this._htOption=b};return a.prototype.draw=function(a){for(var b=this._htOption,c=this._el,d=a.getModuleCount(),e=Math.floor(b.width/d),f=Math.floor(b.height/d),g=[''],h=0;d>h;h++){g.push("");for(var i=0;d>i;i++)g.push('');g.push("")}g.push("
"),c.innerHTML=g.join("");var j=c.childNodes[0],k=(b.width-j.offsetWidth)/2,l=(b.height-j.offsetHeight)/2;k>0&&l>0&&(j.style.margin=l+"px "+k+"px")},a.prototype.clear=function(){this._el.innerHTML=""},a}();QRCode=function(a,b){if(this._htOption={width:256,height:256,typeNumber:4,colorDark:"#000000",colorLight:"#ffffff",correctLevel:d.H},"string"==typeof b&&(b={text:b}),b)for(var c in b)this._htOption[c]=b[c];"string"==typeof a&&(a=document.getElementById(a)),this._android=n(),this._el=a,this._oQRCode=null,this._oDrawing=new q(this._el,this._htOption),this._htOption.text&&this.makeCode(this._htOption.text)},QRCode.prototype.makeCode=function(a){this._oQRCode=new b(r(a,this._htOption.correctLevel),this._htOption.correctLevel),this._oQRCode.addData(a),this._oQRCode.make(),this._el.title=a,this._oDrawing.draw(this._oQRCode),this.makeImage()},QRCode.prototype.makeImage=function(){"function"==typeof this._oDrawing.makeImage&&(!this._android||this._android>=3)&&this._oDrawing.makeImage()},QRCode.prototype.clear=function(){this._oDrawing.clear()},QRCode.CorrectLevel=d}();!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;ge.chunkedMTU)return void this._sendChunks(d);e.supports.sctp?e.supports.binaryBlob?this._bufferedSend(d):e.blobToArrayBuffer(d,function(a){c._bufferedSend(a)}):e.blobToBinaryString(d,function(a){c._bufferedSend(a)})}else this._bufferedSend(a)},d.prototype._bufferedSend=function(a){!this._buffering&&this._trySend(a)||(this._buffer.push(a),this.bufferSize=this._buffer.length)},d.prototype._trySend=function(a){try{this._dc.send(a)}catch(a){this._buffering=!0;var b=this;return setTimeout(function(){b._buffering=!1,b._tryBuffer()},100),!1}return!0},d.prototype._tryBuffer=function(){if(0!==this._buffer.length){var a=this._buffer[0];this._trySend(a)&&(this._buffer.shift(),this.bufferSize=this._buffer.length,this._tryBuffer())}},d.prototype._sendChunks=function(a){for(var b=e.chunk(a),c=0,d=b.length;c2&&200===this.status&&this.responseText&&b._handleStream(this)},this._http.send(null),this._setHTTPTimeout()}catch(a){e.log("XMLHttpRequest not available; defaulting to WebSockets")}},d.prototype._handleStream=function(a){var b=a.responseText.split("\n");if(a._buffer)for(;a._buffer.length>0;){var c=a._buffer.shift(),d=b[c];try{d=JSON.parse(d)}catch(b){a._buffer.shift(c);break}this.emit("message",d)}var f=b[a._index];if(f)if(a._index+=1,a._index===b.length)a._buffer||(a._buffer=[]),a._buffer.push(a._index-1);else{try{f=JSON.parse(f)}catch(a){return void e.log("Invalid server message",f)}this.emit("message",f)}},d.prototype._setHTTPTimeout=function(){var a=this;this._timeout=setTimeout(function(){var b=a._http;a._wsOpen()?b.abort():(a._startXhrStream(b._streamIndex+1),a._http.old=b)},25e3)},d.prototype._wsOpen=function(){return this._socket&&1==this._socket.readyState},d.prototype._sendQueuedMessages=function(){for(var a=0,b=this._queue.length;a0&&(h.error=h._printWith("ERROR")),h.logLevel>1&&(h.warn=h._printWith("WARNING")),h.logLevel>2&&(h.log=h._print)},setLogFunction:function(a){a.constructor!==Function?h.warn("The log function you passed in is not a function. Defaulting to regular logs."):h._print=a},_printWith:function(a){return function(){var b=Array.prototype.slice.call(arguments);b.unshift(a),h._print.apply(h,b)}},_print:function(){var a=!1,b=Array.prototype.slice.call(arguments);b.unshift("PeerJS: ");for(var c=0,d=b.length;c600?new Blob([a]).size:a.replace(/[^\u0000-\u007F]/g,f).length}var h=a("./bufferbuilder").BufferBuilder,i=a("./bufferbuilder").binaryFeatures,j={unpack:function(a){return new d(a).unpack()},pack:function(a){var b=new e;return b.pack(a),b.getBuffer()}};b.exports=j,d.prototype.unpack=function(){var a=this.unpack_uint8();if(a<128){return a}if((224^a)<32){return(224^a)-32}var b;if((b=160^a)<=15)return this.unpack_raw(b);if((b=176^a)<=15)return this.unpack_string(b);if((b=144^a)<=15)return this.unpack_array(b);if((b=128^a)<=15)return this.unpack_map(b);switch(a){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 b=this.unpack_uint16(),this.unpack_string(b);case 217:return b=this.unpack_uint32(),this.unpack_string(b);case 218:return b=this.unpack_uint16(),this.unpack_raw(b);case 219:return b=this.unpack_uint32(),this.unpack_raw(b);case 220:return b=this.unpack_uint16(),this.unpack_array(b);case 221:return b=this.unpack_uint32(),this.unpack_array(b);case 222:return b=this.unpack_uint16(),this.unpack_map(b);case 223:return b=this.unpack_uint32(),this.unpack_map(b)}},d.prototype.unpack_uint8=function(){var a=255&this.dataView[this.index];return this.index++,a},d.prototype.unpack_uint16=function(){var a=this.read(2),b=256*(255&a[0])+(255&a[1]);return this.index+=2,b},d.prototype.unpack_uint32=function(){var a=this.read(4),b=256*(256*(256*a[0]+a[1])+a[2])+a[3];return this.index+=4,b},d.prototype.unpack_uint64=function(){var a=this.read(8),b=256*(256*(256*(256*(256*(256*(256*a[0]+a[1])+a[2])+a[3])+a[4])+a[5])+a[6])+a[7];return this.index+=8,b},d.prototype.unpack_int8=function(){var a=this.unpack_uint8();return a<128?a:a-256},d.prototype.unpack_int16=function(){var a=this.unpack_uint16();return a<32768?a:a-65536},d.prototype.unpack_int32=function(){var a=this.unpack_uint32();return a>31,c=(a>>23&255)-127,d=8388607&a|8388608;return(0==b?1:-1)*d*Math.pow(2,c-23)},d.prototype.unpack_double=function(){var a=this.unpack_uint32(),b=this.unpack_uint32(),c=a>>31,d=(a>>20&2047)-1023,e=1048575&a|1048576,f=e*Math.pow(2,d-20)+b*Math.pow(2,d-52);return(0==c?1:-1)*f},d.prototype.read=function(a){var b=this.index;if(b+a<=this.length)return this.dataView.subarray(b,b+a);throw new Error("BinaryPackFailure: read index out of range")},e.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},e.prototype.pack=function(a){var b=typeof a;if("string"==b)this.pack_string(a);else if("number"==b)Math.floor(a)===a?this.pack_integer(a):this.pack_double(a);else if("boolean"==b)!0===a?this.bufferBuilder.append(195):!1===a&&this.bufferBuilder.append(194);else if("undefined"==b)this.bufferBuilder.append(192);else{if("object"!=b)throw new Error('Type "'+b+'" not yet supported');if(null===a)this.bufferBuilder.append(192);else{var c=a.constructor;if(c==Array)this.pack_array(a);else if(c==Blob||c==File)this.pack_bin(a);else if(c==ArrayBuffer)i.useArrayBufferView?this.pack_bin(new Uint8Array(a)):this.pack_bin(a);else if("BYTES_PER_ELEMENT"in a)i.useArrayBufferView?this.pack_bin(new Uint8Array(a.buffer)):this.pack_bin(a.buffer);else if(c==Object)this.pack_object(a);else if(c==Date)this.pack_string(a.toString());else{if("function"!=typeof a.toBinaryPack)throw new Error('Type "'+c.toString()+'" not yet supported');this.bufferBuilder.append(a.toBinaryPack())}}}this.bufferBuilder.flush()},e.prototype.pack_bin=function(a){var b=a.length||a.byteLength||a.size;if(b<=15)this.pack_uint8(160+b);else if(b<=65535)this.bufferBuilder.append(218),this.pack_uint16(b);else{if(!(b<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(219),this.pack_uint32(b)}this.bufferBuilder.append(a)},e.prototype.pack_string=function(a){var b=g(a);if(b<=15)this.pack_uint8(176+b);else if(b<=65535)this.bufferBuilder.append(216),this.pack_uint16(b);else{if(!(b<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(217),this.pack_uint32(b)}this.bufferBuilder.append(a)},e.prototype.pack_array=function(a){var b=a.length;if(b<=15)this.pack_uint8(144+b);else if(b<=65535)this.bufferBuilder.append(220),this.pack_uint16(b);else{if(!(b<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(221),this.pack_uint32(b)}for(var c=0;c>8),this.bufferBuilder.append(255&a)},e.prototype.pack_uint32=function(a){var b=4294967295&a;this.bufferBuilder.append((4278190080&b)>>>24),this.bufferBuilder.append((16711680&b)>>>16),this.bufferBuilder.append((65280&b)>>>8),this.bufferBuilder.append(255&b)},e.prototype.pack_uint64=function(a){var b=a/Math.pow(2,32),c=a%Math.pow(2,32);this.bufferBuilder.append((4278190080&b)>>>24),this.bufferBuilder.append((16711680&b)>>>16),this.bufferBuilder.append((65280&b)>>>8),this.bufferBuilder.append(255&b),this.bufferBuilder.append((4278190080&c)>>>24),this.bufferBuilder.append((16711680&c)>>>16),this.bufferBuilder.append((65280&c)>>>8),this.bufferBuilder.append(255&c)},e.prototype.pack_int8=function(a){this.bufferBuilder.append(255&a)},e.prototype.pack_int16=function(a){this.bufferBuilder.append((65280&a)>>8),this.bufferBuilder.append(255&a)},e.prototype.pack_int32=function(a){this.bufferBuilder.append(a>>>24&255),this.bufferBuilder.append((16711680&a)>>>16),this.bufferBuilder.append((65280&a)>>>8),this.bufferBuilder.append(255&a)},e.prototype.pack_int64=function(a){var b=Math.floor(a/Math.pow(2,32)),c=a%Math.pow(2,32);this.bufferBuilder.append((4278190080&b)>>>24),this.bufferBuilder.append((16711680&b)>>>16),this.bufferBuilder.append((65280&b)>>>8),this.bufferBuilder.append(255&b),this.bufferBuilder.append((4278190080&c)>>>24),this.bufferBuilder.append((16711680&c)>>>16),this.bufferBuilder.append((65280&c)>>>8),this.bufferBuilder.append(255&c)}},{"./bufferbuilder":11}],11:[function(a,b,c){function d(){this._pieces=[],this._parts=[]}var e={};e.useBlobBuilder=function(){try{return new Blob([]),!1}catch(a){return!0}}(),e.useArrayBufferView=!e.useBlobBuilder&&function(){try{return 0===new Blob([new Uint8Array([])]).size}catch(a){return!0}}(),b.exports.binaryFeatures=e;var f=b.exports.BlobBuilder;"undefined"!=typeof window&&(f=b.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder),d.prototype.append=function(a){"number"==typeof a?this._pieces.push(a):(this.flush(),this._parts.push(a))},d.prototype.flush=function(){if(this._pieces.length>0){var a=new Uint8Array(this._pieces);e.useArrayBufferView||(a=a.buffer),this._parts.push(a),this._pieces=[]}},d.prototype.getBuffer=function(){if(this.flush(),e.useBlobBuilder){for(var a=new f,b=0,c=this._parts.length;b=b.chunks.length?(e.log("Time: ",new Date-b.timer),delete this._outgoing[c]):this._processAcks()}break;case"chunk":if(!(b=d)){if(!0===this._received[c])break;b={ack:["ack",c,0],chunks:[]},this._incoming[c]=b}var i=a[2],j=a[3];b.chunks[i]=new Uint8Array(j),i===b.ack[2]&&this._calculateNextAck(c),this._ack(c);break;default:this._handleSend(a)}},d.prototype._chunk=function(a){for(var b=[],c=a.size,d=0;d=c.length&&d.push(["end",a,c.length]),d._multiple=!0,this._handleSend(d)},d.prototype._complete=function(a){e.log("Completed called for",a);var b=this,c=this._incoming[a].chunks,d=new Blob(c);e.blobToArrayBuffer(d,function(a){b.onmessage(e.unpack(a))}),delete this._incoming[a]},d.higherBandwidthSDP=function(a){var b=navigator.appVersion.match(/Chrome\/(.*?) /);if(b&&(b=parseInt(b[1].split(".").shift()))<31){var c=a.split("b=AS:30");if(c.length>1)return c[0]+"b=AS:102400"+c[1]}return a},d.prototype.onmessage=function(a){},b.exports.Reliable=d},{"./util":13}],13:[function(a,b,c){var d=a("js-binarypack"),e={debug:!1,inherits:function(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})},extend:function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a},pack:d.pack,unpack:d.unpack,log:function(){if(e.debug){for(var a=[],b=0;b=14393&&-1===a.indexOf("?transport=udp"):(c=!0,!0)}),delete a.url,a.urls=e?d[0]:d,!!d.length}})}function g(a,b){var c={codecs:[],headerExtensions:[],fecMechanisms:[]},d=function(a,b){a=parseInt(a,10);for(var c=0;c0;g--)this._iceGatherers.push(new a.RTCIceGatherer({iceServers:c.iceServers,gatherPolicy:c.iceTransportPolicy}));else c.iceCandidatePoolSize=0;this._config=c,this.transceivers=[],this._sdpSessionId=k.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(n.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(n.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),n.prototype.onicecandidate=null,n.prototype.onaddstream=null,n.prototype.ontrack=null,n.prototype.onremovestream=null,n.prototype.onsignalingstatechange=null,n.prototype.oniceconnectionstatechange=null,n.prototype.onconnectionstatechange=null,n.prototype.onicegatheringstatechange=null,n.prototype.onnegotiationneeded=null,n.prototype.ondatachannel=null,n.prototype._dispatchEvent=function(a,b){this._isClosed||(this.dispatchEvent(b),"function"==typeof this["on"+a]&&this["on"+a](b))},n.prototype._emitGatheringStateChange=function(){var a=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",a)},n.prototype.getConfiguration=function(){return this._config},n.prototype.getLocalStreams=function(){return this.localStreams},n.prototype.getRemoteStreams=function(){return this.remoteStreams},n.prototype._createTransceiver=function(a,b){var c=this.transceivers.length>0,d={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:a,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&c)d.iceTransport=this.transceivers[0].iceTransport,d.dtlsTransport=this.transceivers[0].dtlsTransport;else{var e=this._createIceAndDtlsTransports();d.iceTransport=e.iceTransport,d.dtlsTransport=e.dtlsTransport}return b||this.transceivers.push(d),d},n.prototype.addTrack=function(b,c){if(this._isClosed)throw j("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");if(this.transceivers.find(function(a){return a.track===b}))throw j("InvalidAccessError","Track already exists.");for(var d,e=0;e=15025)a.getTracks().forEach(function(b){c.addTrack(b,a)});else{var d=a.clone();a.getTracks().forEach(function(a,b){var c=d.getTracks()[b];a.addEventListener("enabled",function(a){c.enabled=a.enabled})}),d.getTracks().forEach(function(a){c.addTrack(a,d)})}},n.prototype.removeTrack=function(b){if(this._isClosed)throw j("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(b instanceof a.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var c=this.transceivers.find(function(a){return a.rtpSender===b});if(!c)throw j("InvalidAccessError","Sender was not created by this connection.");var d=c.stream;c.rtpSender.stop(),c.rtpSender=null,c.track=null,c.stream=null,-1===this.transceivers.map(function(a){return a.stream}).indexOf(d)&&this.localStreams.indexOf(d)>-1&&this.localStreams.splice(this.localStreams.indexOf(d),1),this._maybeFireNegotiationNeeded()},n.prototype.removeStream=function(a){var b=this;a.getTracks().forEach(function(a){var c=b.getSenders().find(function(b){return b.track===a});c&&b.removeTrack(c)})},n.prototype.getSenders=function(){return this.transceivers.filter(function(a){return!!a.rtpSender}).map(function(a){return a.rtpSender})},n.prototype.getReceivers=function(){return this.transceivers.filter(function(a){return!!a.rtpReceiver}).map(function(a){return a.rtpReceiver})},n.prototype._createIceGatherer=function(b,c){var d=this;if(c&&b>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var e=new a.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(e,"state",{value:"new",writable:!0}),this.transceivers[b].bufferedCandidateEvents=[],this.transceivers[b].bufferCandidates=function(a){var c=!a.candidate||0===Object.keys(a.candidate).length;e.state=c?"completed":"gathering",null!==d.transceivers[b].bufferedCandidateEvents&&d.transceivers[b].bufferedCandidateEvents.push(a)},e.addEventListener("localcandidate",this.transceivers[b].bufferCandidates),e},n.prototype._gather=function(b,c){var d=this,e=this.transceivers[c].iceGatherer;if(!e.onlocalcandidate){var f=this.transceivers[c].bufferedCandidateEvents;this.transceivers[c].bufferedCandidateEvents=null,e.removeEventListener("localcandidate",this.transceivers[c].bufferCandidates),e.onlocalcandidate=function(a){if(!(d.usingBundle&&c>0)){var f=new Event("icecandidate");f.candidate={sdpMid:b,sdpMLineIndex:c};var g=a.candidate,h=!g||0===Object.keys(g).length;if(h)"new"!==e.state&&"gathering"!==e.state||(e.state="completed");else{"new"===e.state&&(e.state="gathering"),g.component=1,g.ufrag=e.getLocalParameters().usernameFragment;var i=k.writeCandidate(g);f.candidate=Object.assign(f.candidate,k.parseCandidate(i)),f.candidate.candidate=i,f.candidate.toJSON=function(){return{candidate:f.candidate.candidate,sdpMid:f.candidate.sdpMid,sdpMLineIndex:f.candidate.sdpMLineIndex,usernameFragment:f.candidate.usernameFragment}}}var j=k.getMediaSections(d._localDescription.sdp);j[f.candidate.sdpMLineIndex]+=h?"a=end-of-candidates\r\n":"a="+f.candidate.candidate+"\r\n",d._localDescription.sdp=k.getDescription(d._localDescription.sdp)+j.join("");var l=d.transceivers.every(function(a){return a.iceGatherer&&"completed"===a.iceGatherer.state});"gathering"!==d.iceGatheringState&&(d.iceGatheringState="gathering",d._emitGatheringStateChange()),h||d._dispatchEvent("icecandidate",f),l&&(d._dispatchEvent("icecandidate",new Event("icecandidate")),d.iceGatheringState="complete",d._emitGatheringStateChange())}},a.setTimeout(function(){f.forEach(function(a){e.onlocalcandidate(a)})},0)}},n.prototype._createIceAndDtlsTransports=function(){var b=this,c=new a.RTCIceTransport(null);c.onicestatechange=function(){b._updateIceConnectionState(),b._updateConnectionState()};var d=new a.RTCDtlsTransport(c);return d.ondtlsstatechange=function(){b._updateConnectionState()},d.onerror=function(){Object.defineProperty(d,"state",{value:"failed",writable:!0}),b._updateConnectionState()},{iceTransport:c,dtlsTransport:d}},n.prototype._disposeIceAndDtlsTransports=function(a){var b=this.transceivers[a].iceGatherer;b&&(delete b.onlocalcandidate,delete this.transceivers[a].iceGatherer);var c=this.transceivers[a].iceTransport;c&&(delete c.onicestatechange,delete this.transceivers[a].iceTransport);var d=this.transceivers[a].dtlsTransport;d&&(delete d.ondtlsstatechange,delete d.onerror,delete this.transceivers[a].dtlsTransport)},n.prototype._transceive=function(a,c,d){var e=g(a.localCapabilities,a.remoteCapabilities);c&&a.rtpSender&&(e.encodings=a.sendEncodingParameters,e.rtcp={cname:k.localCName,compound:a.rtcpParameters.compound},a.recvEncodingParameters.length&&(e.rtcp.ssrc=a.recvEncodingParameters[0].ssrc),a.rtpSender.send(e)),d&&a.rtpReceiver&&e.codecs.length>0&&("video"===a.kind&&a.recvEncodingParameters&&b<15019&&a.recvEncodingParameters.forEach(function(a){delete a.rtx}),a.recvEncodingParameters.length?e.encodings=a.recvEncodingParameters:e.encodings=[{}],e.rtcp={compound:a.rtcpParameters.compound},a.rtcpParameters.cname&&(e.rtcp.cname=a.rtcpParameters.cname),a.sendEncodingParameters.length&&(e.rtcp.ssrc=a.sendEncodingParameters[0].ssrc),a.rtpReceiver.receive(e))},n.prototype.setLocalDescription=function(a){var b=this;if(-1===["offer","answer"].indexOf(a.type))return Promise.reject(j("TypeError",'Unsupported type "'+a.type+'"'));if(!h("setLocalDescription",a.type,b.signalingState)||b._isClosed)return Promise.reject(j("InvalidStateError","Can not set local "+a.type+" in state "+b.signalingState));var c,d;if("offer"===a.type)c=k.splitSections(a.sdp),d=c.shift(),c.forEach(function(a,c){var d=k.parseRtpParameters(a);b.transceivers[c].localCapabilities=d}),b.transceivers.forEach(function(a,c){b._gather(a.mid,c)});else if("answer"===a.type){c=k.splitSections(b._remoteDescription.sdp),d=c.shift();var e=k.matchPrefix(d,"a=ice-lite").length>0;c.forEach(function(a,c){var f=b.transceivers[c],h=f.iceGatherer,i=f.iceTransport,j=f.dtlsTransport,l=f.localCapabilities,m=f.remoteCapabilities;if(!(k.isRejected(a)&&0===k.matchPrefix(a,"a=bundle-only").length||f.rejected)){var n=k.getIceParameters(a,d),o=k.getDtlsParameters(a,d);e&&(o.role="server"),b.usingBundle&&0!==c||(b._gather(f.mid,c),"new"===i.state&&i.start(h,n,e?"controlling":"controlled"),"new"===j.state&&j.start(o));var p=g(l,m);b._transceive(f,p.codecs.length>0,!1)}})}return b._localDescription={type:a.type,sdp:a.sdp},"offer"===a.type?b._updateSignalingState("have-local-offer"):b._updateSignalingState("stable"),Promise.resolve()},n.prototype.setRemoteDescription=function(d){var e=this;if(-1===["offer","answer"].indexOf(d.type))return Promise.reject(j("TypeError",'Unsupported type "'+d.type+'"'));if(!h("setRemoteDescription",d.type,e.signalingState)||e._isClosed)return Promise.reject(j("InvalidStateError","Can not set remote "+d.type+" in state "+e.signalingState));var f={};e.remoteStreams.forEach(function(a){f[a.id]=a});var n=[],o=k.splitSections(d.sdp),p=o.shift(),q=k.matchPrefix(p,"a=ice-lite").length>0,r=k.matchPrefix(p,"a=group:BUNDLE ").length>0;e.usingBundle=r;var s=k.matchPrefix(p,"a=ice-options:")[0];return e.canTrickleIceCandidates=!!s&&s.substr(14).split(" ").indexOf("trickle")>=0,o.forEach(function(h,j){var m=k.splitLines(h),o=k.getKind(h),s=k.isRejected(h)&&0===k.matchPrefix(h,"a=bundle-only").length,t=m[0].substr(2).split(" ")[2],u=k.getDirection(h,p),v=k.parseMsid(h),w=k.getMid(h)||k.generateIdentifier();if(s||"application"===o&&("DTLS/SCTP"===t||"UDP/DTLS/SCTP"===t))return void(e.transceivers[j]={mid:w,kind:o,protocol:t,rejected:!0});!s&&e.transceivers[j]&&e.transceivers[j].rejected&&(e.transceivers[j]=e._createTransceiver(o,!0));var x,y,z,A,B,C,D,E,F,G,H,I=k.parseRtpParameters(h);s||(G=k.getIceParameters(h,p),H=k.getDtlsParameters(h,p),H.role="client"),D=k.parseRtpEncodingParameters(h);var J=k.parseRtcpParameters(h),K=k.matchPrefix(h,"a=end-of-candidates",p).length>0,L=k.matchPrefix(h,"a=candidate:").map(function(a){return k.parseCandidate(a)}).filter(function(a){return 1===a.component});if(("offer"===d.type||"answer"===d.type)&&!s&&r&&j>0&&e.transceivers[j]&&(e._disposeIceAndDtlsTransports(j),e.transceivers[j].iceGatherer=e.transceivers[0].iceGatherer,e.transceivers[j].iceTransport=e.transceivers[0].iceTransport,e.transceivers[j].dtlsTransport=e.transceivers[0].dtlsTransport,e.transceivers[j].rtpSender&&e.transceivers[j].rtpSender.setTransport(e.transceivers[0].dtlsTransport),e.transceivers[j].rtpReceiver&&e.transceivers[j].rtpReceiver.setTransport(e.transceivers[0].dtlsTransport)),"offer"!==d.type||s){if("answer"===d.type&&!s){x=e.transceivers[j],y=x.iceGatherer,z=x.iceTransport,A=x.dtlsTransport,B=x.rtpReceiver,C=x.sendEncodingParameters,E=x.localCapabilities,e.transceivers[j].recvEncodingParameters=D,e.transceivers[j].remoteCapabilities=I,e.transceivers[j].rtcpParameters=J,L.length&&"new"===z.state&&(!q&&!K||r&&0!==j?L.forEach(function(a){i(x.iceTransport,a)}):z.setRemoteCandidates(L)),r&&0!==j||("new"===z.state&&z.start(y,G,"controlling"),"new"===A.state&&A.start(H));var M=g(x.localCapabilities,x.remoteCapabilities),N=M.codecs.filter(function(a){return"rtx"===a.name.toLowerCase()}).length;!N&&x.sendEncodingParameters[0].rtx&&delete x.sendEncodingParameters[0].rtx,e._transceive(x,"sendrecv"===u||"recvonly"===u,"sendrecv"===u||"sendonly"===u),!B||"sendrecv"!==u&&"sendonly"!==u?delete x.rtpReceiver:(F=B.track,v?(f[v.stream]||(f[v.stream]=new a.MediaStream),c(F,f[v.stream]),n.push([F,B,f[v.stream]])):(f.default||(f.default=new a.MediaStream),c(F,f.default),n.push([F,B,f.default])))}}else{x=e.transceivers[j]||e._createTransceiver(o),x.mid=w,x.iceGatherer||(x.iceGatherer=e._createIceGatherer(j,r)),L.length&&"new"===x.iceTransport.state&&(!K||r&&0!==j?L.forEach(function(a){i(x.iceTransport,a)}):x.iceTransport.setRemoteCandidates(L)),E=a.RTCRtpReceiver.getCapabilities(o),b<15019&&(E.codecs=E.codecs.filter(function(a){return"rtx"!==a.name})),C=x.sendEncodingParameters||[{ssrc:1001*(2*j+2)}];var O=!1;if("sendrecv"===u||"sendonly"===u){if(O=!x.rtpReceiver,B=x.rtpReceiver||new a.RTCRtpReceiver(x.dtlsTransport,o),O){var P;F=B.track,v&&"-"===v.stream||(v?(f[v.stream]||(f[v.stream]=new a.MediaStream,Object.defineProperty(f[v.stream],"id",{get:function(){return v.stream}})),Object.defineProperty(F,"id",{get:function(){return v.track}}),P=f[v.stream]):(f.default||(f.default=new a.MediaStream),P=f.default)),P&&(c(F,P),x.associatedRemoteMediaStreams.push(P)),n.push([F,B,P])}}else x.rtpReceiver&&x.rtpReceiver.track&&(x.associatedRemoteMediaStreams.forEach(function(a){var b=a.getTracks().find(function(a){return a.id===x.rtpReceiver.track.id});b&&l(b,a)}),x.associatedRemoteMediaStreams=[]);x.localCapabilities=E,x.remoteCapabilities=I,x.rtpReceiver=B,x.rtcpParameters=J,x.sendEncodingParameters=C,x.recvEncodingParameters=D,e._transceive(e.transceivers[j],!1,O)}}),void 0===e._dtlsRole&&(e._dtlsRole="offer"===d.type?"active":"passive"),e._remoteDescription={type:d.type,sdp:d.sdp},"offer"===d.type?e._updateSignalingState("have-remote-offer"):e._updateSignalingState("stable"),Object.keys(f).forEach(function(b){var c=f[b];if(c.getTracks().length){if(-1===e.remoteStreams.indexOf(c)){e.remoteStreams.push(c);var d=new Event("addstream");d.stream=c,a.setTimeout(function(){e._dispatchEvent("addstream",d)})}n.forEach(function(a){var b=a[0],d=a[1];c.id===a[2].id&&m(e,b,d,[c])})}}),n.forEach(function(a){a[2]||m(e,a[0],a[1],[])}),a.setTimeout(function(){e&&e.transceivers&&e.transceivers.forEach(function(a){a.iceTransport&&"new"===a.iceTransport.state&&a.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),a.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},n.prototype.close=function(){this.transceivers.forEach(function(a){a.iceTransport&&a.iceTransport.stop(),a.dtlsTransport&&a.dtlsTransport.stop(),a.rtpSender&&a.rtpSender.stop(),a.rtpReceiver&&a.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},n.prototype._updateSignalingState=function(a){this.signalingState=a;var b=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",b)},n.prototype._maybeFireNegotiationNeeded=function(){var b=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,a.setTimeout(function(){if(b.needNegotiation){b.needNegotiation=!1;var a=new Event("negotiationneeded");b._dispatchEvent("negotiationneeded",a)}},0))},n.prototype._updateIceConnectionState=function(){var a,b={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(a){b[a.iceTransport.state]++}),a="new",b.failed>0?a="failed":b.checking>0?a="checking":b.disconnected>0?a="disconnected":b.new>0?a="new":b.connected>0?a="connected":b.completed>0&&(a="completed"),a!==this.iceConnectionState){this.iceConnectionState=a;var c=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",c)}},n.prototype._updateConnectionState=function(){var a,b={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(a){b[a.iceTransport.state]++,b[a.dtlsTransport.state]++}),b.connected+=b.completed,a="new",b.failed>0?a="failed":b.connecting>0?a="connecting":b.disconnected>0?a="disconnected":b.new>0?a="new":b.connected>0&&(a="connected"),a!==this.connectionState){this.connectionState=a;var c=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",c)}},n.prototype.createOffer=function(){var c=this;if(c._isClosed)return Promise.reject(j("InvalidStateError","Can not call createOffer after close"));var d=c.transceivers.filter(function(a){return"audio"===a.kind}).length,f=c.transceivers.filter(function(a){return"video"===a.kind}).length,g=arguments[0];if(g){if(g.mandatory||g.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==g.offerToReceiveAudio&&(d=!0===g.offerToReceiveAudio?1:!1===g.offerToReceiveAudio?0:g.offerToReceiveAudio),void 0!==g.offerToReceiveVideo&&(f=!0===g.offerToReceiveVideo?1:!1===g.offerToReceiveVideo?0:g.offerToReceiveVideo)}for(c.transceivers.forEach(function(a){"audio"===a.kind?--d<0&&(a.wantReceive=!1):"video"===a.kind&&--f<0&&(a.wantReceive=!1)});d>0||f>0;)d>0&&(c._createTransceiver("audio"),d--),f>0&&(c._createTransceiver("video"),f--);var h=k.writeSessionBoilerplate(c._sdpSessionId,c._sdpSessionVersion++);c.transceivers.forEach(function(d,e){var f=d.track,g=d.kind,h=d.mid||k.generateIdentifier();d.mid=h,d.iceGatherer||(d.iceGatherer=c._createIceGatherer(e,c.usingBundle));var i=a.RTCRtpSender.getCapabilities(g);b<15019&&(i.codecs=i.codecs.filter(function(a){return"rtx"!==a.name})),i.codecs.forEach(function(a){"H264"===a.name&&void 0===a.parameters["level-asymmetry-allowed"]&&(a.parameters["level-asymmetry-allowed"]="1"),d.remoteCapabilities&&d.remoteCapabilities.codecs&&d.remoteCapabilities.codecs.forEach(function(b){a.name.toLowerCase()===b.name.toLowerCase()&&a.clockRate===b.clockRate&&(a.preferredPayloadType=b.payloadType)})}),i.headerExtensions.forEach(function(a){(d.remoteCapabilities&&d.remoteCapabilities.headerExtensions||[]).forEach(function(b){a.uri===b.uri&&(a.id=b.id)})});var j=d.sendEncodingParameters||[{ssrc:1001*(2*e+1)}];f&&b>=15019&&"video"===g&&!j[0].rtx&&(j[0].rtx={ssrc:j[0].ssrc+1}),d.wantReceive&&(d.rtpReceiver=new a.RTCRtpReceiver(d.dtlsTransport,g)),d.localCapabilities=i,d.sendEncodingParameters=j}),"max-compat"!==c._config.bundlePolicy&&(h+="a=group:BUNDLE "+c.transceivers.map(function(a){return a.mid}).join(" ")+"\r\n"),h+="a=ice-options:trickle\r\n",c.transceivers.forEach(function(a,b){h+=e(a,a.localCapabilities,"offer",a.stream,c._dtlsRole),h+="a=rtcp-rsize\r\n",!a.iceGatherer||"new"===c.iceGatheringState||0!==b&&c.usingBundle||(a.iceGatherer.getLocalCandidates().forEach(function(a){a.component=1,h+="a="+k.writeCandidate(a)+"\r\n"}),"completed"===a.iceGatherer.state&&(h+="a=end-of-candidates\r\n"))});var i=new a.RTCSessionDescription({type:"offer",sdp:h});return Promise.resolve(i)},n.prototype.createAnswer=function(){var c=this;if(c._isClosed)return Promise.reject(j("InvalidStateError","Can not call createAnswer after close"));if("have-remote-offer"!==c.signalingState&&"have-local-pranswer"!==c.signalingState)return Promise.reject(j("InvalidStateError","Can not call createAnswer in signalingState "+c.signalingState));var d=k.writeSessionBoilerplate(c._sdpSessionId,c._sdpSessionVersion++);c.usingBundle&&(d+="a=group:BUNDLE "+c.transceivers.map(function(a){return a.mid}).join(" ")+"\r\n"),d+="a=ice-options:trickle\r\n";var f=k.getMediaSections(c._remoteDescription.sdp).length;c.transceivers.forEach(function(a,h){if(!(h+1>f)){if(a.rejected)return"application"===a.kind?"DTLS/SCTP"===a.protocol?d+="m=application 0 DTLS/SCTP 5000\r\n":d+="m=application 0 "+a.protocol+" webrtc-datachannel\r\n":"audio"===a.kind?d+="m=audio 0 UDP/TLS/RTP/SAVPF 0\r\na=rtpmap:0 PCMU/8000\r\n":"video"===a.kind&&(d+="m=video 0 UDP/TLS/RTP/SAVPF 120\r\na=rtpmap:120 VP8/90000\r\n"),void(d+="c=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:"+a.mid+"\r\n");if(a.stream){var i;"audio"===a.kind?i=a.stream.getAudioTracks()[0]:"video"===a.kind&&(i=a.stream.getVideoTracks()[0]),i&&b>=15019&&"video"===a.kind&&!a.sendEncodingParameters[0].rtx&&(a.sendEncodingParameters[0].rtx={ssrc:a.sendEncodingParameters[0].ssrc+1})}var j=g(a.localCapabilities,a.remoteCapabilities);!j.codecs.filter(function(a){return"rtx"===a.name.toLowerCase()}).length&&a.sendEncodingParameters[0].rtx&&delete a.sendEncodingParameters[0].rtx,d+=e(a,j,"answer",a.stream,c._dtlsRole),a.rtcpParameters&&a.rtcpParameters.reducedSize&&(d+="a=rtcp-rsize\r\n")}});var h=new a.RTCSessionDescription({type:"answer",sdp:d});return Promise.resolve(h)},n.prototype.addIceCandidate=function(a){var b,c=this;return a&&void 0===a.sdpMLineIndex&&!a.sdpMid?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(d,e){if(!c._remoteDescription)return e(j("InvalidStateError","Can not add ICE candidate without a remote description"));if(a&&""!==a.candidate){var f=a.sdpMLineIndex;if(a.sdpMid)for(var g=0;g0?k.parseCandidate(a.candidate):{};if("tcp"===l.protocol&&(0===l.port||9===l.port))return d();if(l.component&&1!==l.component)return d();if((0===f||f>0&&h.iceTransport!==c.transceivers[0].iceTransport)&&!i(h.iceTransport,l))return e(j("OperationError","Can not add ICE candidate"));var m=a.candidate.trim();0===m.indexOf("a=")&&(m=m.substr(2)),b=k.getMediaSections(c._remoteDescription.sdp),b[f]+="a="+(l.type?m:"end-of-candidates")+"\r\n",c._remoteDescription.sdp=k.getDescription(c._remoteDescription.sdp)+b.join("")}else for(var n=0;n0?b[0].split("/")[1]:"sendrecv",uri:b[1]}},d.writeExtmap=function(a){return"a=extmap:"+(a.id||a.preferredId)+(a.direction&&"sendrecv"!==a.direction?"/"+a.direction:"")+" "+a.uri+"\r\n"},d.parseFmtp=function(a){for(var b,c={},d=a.substr(a.indexOf(" ")+1).split(";"),e=0;e-1?(c.attribute=a.substr(b+1,d-b-1),c.value=a.substr(d+1)):c.attribute=a.substr(b+1),c},d.parseSsrcGroup=function(a){var b=a.substr(13).split(" ");return{semantics:b.shift(),ssrcs:b.map(function(a){return parseInt(a,10)})}},d.getMid=function(a){var b=d.matchPrefix(a,"a=mid:")[0];if(b)return b.substr(6)},d.parseFingerprint=function(a){var b=a.substr(14).split(" ");return{algorithm:b[0].toLowerCase(),value:b[1]}},d.getDtlsParameters=function(a,b){return{role:"auto",fingerprints:d.matchPrefix(a+b,"a=fingerprint:").map(d.parseFingerprint)}},d.writeDtlsParameters=function(a,b){var c="a=setup:"+b+"\r\n";return a.fingerprints.forEach(function(a){c+="a=fingerprint:"+a.algorithm+" "+a.value+"\r\n"}),c},d.getIceParameters=function(a,b){var c=d.splitLines(a);return c=c.concat(d.splitLines(b)),{usernameFragment:c.filter(function(a){return 0===a.indexOf("a=ice-ufrag:")})[0].substr(12),password:c.filter(function(a){return 0===a.indexOf("a=ice-pwd:")})[0].substr(10)}},d.writeIceParameters=function(a){return"a=ice-ufrag:"+a.usernameFragment+"\r\na=ice-pwd:"+a.password+"\r\n"},d.parseRtpParameters=function(a){for(var b={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},c=d.splitLines(a),e=c[0].split(" "),f=3;f0?"9":"0",c+=" UDP/TLS/RTP/SAVPF ",c+=b.codecs.map(function(a){return void 0!==a.preferredPayloadType?a.preferredPayloadType:a.payloadType}).join(" ")+"\r\n",c+="c=IN IP4 0.0.0.0\r\n", c+="a=rtcp:9 IN IP4 0.0.0.0\r\n",b.codecs.forEach(function(a){c+=d.writeRtpMap(a),c+=d.writeFmtp(a),c+=d.writeRtcpFb(a)});var e=0;return b.codecs.forEach(function(a){a.maxptime>e&&(e=a.maxptime)}),e>0&&(c+="a=maxptime:"+e+"\r\n"),c+="a=rtcp-mux\r\n",b.headerExtensions&&b.headerExtensions.forEach(function(a){c+=d.writeExtmap(a)}),c},d.parseRtpEncodingParameters=function(a){var b,c=[],e=d.parseRtpParameters(a),f=-1!==e.fecMechanisms.indexOf("RED"),g=-1!==e.fecMechanisms.indexOf("ULPFEC"),h=d.matchPrefix(a,"a=ssrc:").map(function(a){return d.parseSsrcMedia(a)}).filter(function(a){return"cname"===a.attribute}),i=h.length>0&&h[0].ssrc,j=d.matchPrefix(a,"a=ssrc-group:FID").map(function(a){return a.substr(17).split(" ").map(function(a){return parseInt(a,10)})});j.length>0&&j[0].length>1&&j[0][0]===i&&(b=j[0][1]),e.codecs.forEach(function(a){if("RTX"===a.name.toUpperCase()&&a.parameters.apt){var d={ssrc:i,codecPayloadType:parseInt(a.parameters.apt,10)};i&&b&&(d.rtx={ssrc:b}),c.push(d),f&&(d=JSON.parse(JSON.stringify(d)),d.fec={ssrc:i,mechanism:g?"red+ulpfec":"red"},c.push(d))}}),0===c.length&&i&&c.push({ssrc:i});var k=d.matchPrefix(a,"b=");return k.length&&(k=0===k[0].indexOf("b=TIAS:")?parseInt(k[0].substr(7),10):0===k[0].indexOf("b=AS:")?1e3*parseInt(k[0].substr(5),10)*.95-16e3:void 0,c.forEach(function(a){a.maxBitrate=k})),c},d.parseRtcpParameters=function(a){var b={},c=d.matchPrefix(a,"a=ssrc:").map(function(a){return d.parseSsrcMedia(a)}).filter(function(a){return"cname"===a.attribute})[0];c&&(b.cname=c.value,b.ssrc=c.ssrc);var e=d.matchPrefix(a,"a=rtcp-rsize");b.reducedSize=e.length>0,b.compound=0===e.length;var f=d.matchPrefix(a,"a=rtcp-mux");return b.mux=f.length>0,b},d.parseMsid=function(a){var b,c=d.matchPrefix(a,"a=msid:");if(1===c.length)return b=c[0].substr(7).split(" "),{stream:b[0],track:b[1]};var e=d.matchPrefix(a,"a=ssrc:").map(function(a){return d.parseSsrcMedia(a)}).filter(function(a){return"msid"===a.attribute});return e.length>0?(b=e[0].value.split(" "),{stream:b[0],track:b[1]}):void 0},d.generateSessionId=function(){return Math.random().toString().substr(2,21)},d.writeSessionBoilerplate=function(a,b,c){var e,f=void 0!==b?b:2;return e=a||d.generateSessionId(),"v=0\r\no="+(c||"thisisadapterortc")+" "+e+" "+f+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},d.writeMediaSection=function(a,b,c,e){var f=d.writeRtpDescription(a.kind,b);if(f+=d.writeIceParameters(a.iceGatherer.getLocalParameters()),f+=d.writeDtlsParameters(a.dtlsTransport.getLocalParameters(),"offer"===c?"actpass":"active"),f+="a=mid:"+a.mid+"\r\n",a.direction?f+="a="+a.direction+"\r\n":a.rtpSender&&a.rtpReceiver?f+="a=sendrecv\r\n":a.rtpSender?f+="a=sendonly\r\n":a.rtpReceiver?f+="a=recvonly\r\n":f+="a=inactive\r\n",a.rtpSender){var g="msid:"+e.id+" "+a.rtpSender.track.id+"\r\n";f+="a="+g,f+="a=ssrc:"+a.sendEncodingParameters[0].ssrc+" "+g,a.sendEncodingParameters[0].rtx&&(f+="a=ssrc:"+a.sendEncodingParameters[0].rtx.ssrc+" "+g,f+="a=ssrc-group:FID "+a.sendEncodingParameters[0].ssrc+" "+a.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return f+="a=ssrc:"+a.sendEncodingParameters[0].ssrc+" cname:"+d.localCName+"\r\n",a.rtpSender&&a.sendEncodingParameters[0].rtx&&(f+="a=ssrc:"+a.sendEncodingParameters[0].rtx.ssrc+" cname:"+d.localCName+"\r\n"),f},d.getDirection=function(a,b){for(var c=d.splitLines(a),e=0;e0&&arguments[0]instanceof a.MediaStreamTrack){var c,d,e,f=arguments[0];return b.getSenders().forEach(function(a){a.track===f&&(c?e=!0:c=a)}),b.getReceivers().forEach(function(a){return a.track===f&&(d?e=!0:d=a),a.track===f}),e||c&&d?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):c?c.getStats():d?d.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return g.apply(b,arguments)}}}},shimSourceObject:function(a){var b=a&&a.URL;"object"==typeof a&&(!a.HTMLMediaElement||"srcObject"in a.HTMLMediaElement.prototype||Object.defineProperty(a.HTMLMediaElement.prototype,"srcObject",{get:function(){return this._srcObject},set:function(a){var c=this;if(this._srcObject=a,this.src&&b.revokeObjectURL(this.src),!a)return void(this.src="");this.src=b.createObjectURL(a),a.addEventListener("addtrack",function(){c.src&&b.revokeObjectURL(c.src),c.src=b.createObjectURL(a)}),a.addEventListener("removetrack",function(){c.src&&b.revokeObjectURL(c.src),c.src=b.createObjectURL(a)})}}))},shimAddTrackRemoveTrackWithNative:function(a){a.RTCPeerConnection.prototype.getLocalStreams=function(){var a=this;return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(function(b){return a._shimmedLocalStreams[b][0]})};var b=a.RTCPeerConnection.prototype.addTrack;a.RTCPeerConnection.prototype.addTrack=function(a,c){if(!c)return b.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};var d=b.apply(this,arguments);return this._shimmedLocalStreams[c.id]?-1===this._shimmedLocalStreams[c.id].indexOf(d)&&this._shimmedLocalStreams[c.id].push(d):this._shimmedLocalStreams[c.id]=[c,d],d};var c=a.RTCPeerConnection.prototype.addStream;a.RTCPeerConnection.prototype.addStream=function(a){var b=this;this._shimmedLocalStreams=this._shimmedLocalStreams||{},a.getTracks().forEach(function(a){if(b.getSenders().find(function(b){return b.track===a}))throw new DOMException("Track already exists.","InvalidAccessError")});var d=b.getSenders();c.apply(this,arguments);var e=b.getSenders().filter(function(a){return-1===d.indexOf(a)});this._shimmedLocalStreams[a.id]=[a].concat(e)};var d=a.RTCPeerConnection.prototype.removeStream;a.RTCPeerConnection.prototype.removeStream=function(a){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[a.id],d.apply(this,arguments)};var e=a.RTCPeerConnection.prototype.removeTrack;a.RTCPeerConnection.prototype.removeTrack=function(a){var b=this;return this._shimmedLocalStreams=this._shimmedLocalStreams||{},a&&Object.keys(this._shimmedLocalStreams).forEach(function(c){var d=b._shimmedLocalStreams[c].indexOf(a);-1!==d&&b._shimmedLocalStreams[c].splice(d,1),1===b._shimmedLocalStreams[c].length&&delete b._shimmedLocalStreams[c]}),e.apply(this,arguments)}},shimAddTrackRemoveTrack:function(a){function b(a,b){var c=b.sdp;return Object.keys(a._reverseStreams||[]).forEach(function(b){var d=a._reverseStreams[b],e=a._streams[d.id];c=c.replace(new RegExp(e.id,"g"),d.id)}),new RTCSessionDescription({type:b.type,sdp:c})}function c(a,b){var c=b.sdp;return Object.keys(a._reverseStreams||[]).forEach(function(b){var d=a._reverseStreams[b],e=a._streams[d.id];c=c.replace(new RegExp(d.id,"g"),e.id)}),new RTCSessionDescription({type:b.type,sdp:c})}var d=f.detectBrowser(a);if(a.RTCPeerConnection.prototype.addTrack&&d.version>=65)return this.shimAddTrackRemoveTrackWithNative(a);var e=a.RTCPeerConnection.prototype.getLocalStreams;a.RTCPeerConnection.prototype.getLocalStreams=function(){var a=this,b=e.apply(this);return a._reverseStreams=a._reverseStreams||{},b.map(function(b){return a._reverseStreams[b.id]})};var g=a.RTCPeerConnection.prototype.addStream;a.RTCPeerConnection.prototype.addStream=function(b){var c=this;if(c._streams=c._streams||{},c._reverseStreams=c._reverseStreams||{},b.getTracks().forEach(function(a){if(c.getSenders().find(function(b){return b.track===a}))throw new DOMException("Track already exists.","InvalidAccessError")}),!c._reverseStreams[b.id]){var d=new a.MediaStream(b.getTracks());c._streams[b.id]=d,c._reverseStreams[d.id]=b,b=d}g.apply(c,[b])};var h=a.RTCPeerConnection.prototype.removeStream;a.RTCPeerConnection.prototype.removeStream=function(a){var b=this;b._streams=b._streams||{},b._reverseStreams=b._reverseStreams||{},h.apply(b,[b._streams[a.id]||a]),delete b._reverseStreams[b._streams[a.id]?b._streams[a.id].id:a.id],delete b._streams[a.id]},a.RTCPeerConnection.prototype.addTrack=function(b,c){var d=this;if("closed"===d.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");var e=[].slice.call(arguments,1);if(1!==e.length||!e[0].getTracks().find(function(a){return a===b}))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(d.getSenders().find(function(a){return a.track===b}))throw new DOMException("Track already exists.","InvalidAccessError");d._streams=d._streams||{},d._reverseStreams=d._reverseStreams||{};var f=d._streams[c.id];if(f)f.addTrack(b),Promise.resolve().then(function(){d.dispatchEvent(new Event("negotiationneeded"))});else{var g=new a.MediaStream([b]);d._streams[c.id]=g,d._reverseStreams[g.id]=c,d.addStream(g)}return d.getSenders().find(function(a){return a.track===b})},["createOffer","createAnswer"].forEach(function(c){var d=a.RTCPeerConnection.prototype[c];a.RTCPeerConnection.prototype[c]=function(){var a=this,c=arguments;return arguments.length&&"function"==typeof arguments[0]?d.apply(a,[function(d){var e=b(a,d);c[0].apply(null,[e])},function(a){c[1]&&c[1].apply(null,a)},arguments[2]]):d.apply(a,arguments).then(function(c){return b(a,c)})}});var i=a.RTCPeerConnection.prototype.setLocalDescription;a.RTCPeerConnection.prototype.setLocalDescription=function(){var a=this;return arguments.length&&arguments[0].type?(arguments[0]=c(a,arguments[0]),i.apply(a,arguments)):i.apply(a,arguments)};var j=Object.getOwnPropertyDescriptor(a.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(a.RTCPeerConnection.prototype,"localDescription",{get:function(){var a=this,c=j.get.apply(this);return""===c.type?c:b(a,c)}}),a.RTCPeerConnection.prototype.removeTrack=function(a){var b=this;if("closed"===b.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!a._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(a._pc!==b)throw new DOMException("Sender was not created by this connection.","InvalidAccessError");b._streams=b._streams||{};var c;Object.keys(b._streams).forEach(function(d){b._streams[d].getTracks().find(function(b){return a.track===b})&&(c=b._streams[d])}),c&&(1===c.getTracks().length?b.removeStream(b._reverseStreams[c.id]):c.removeTrack(a.track),b.dispatchEvent(new Event("negotiationneeded")))}},shimPeerConnection:function(a){var b=f.detectBrowser(a);!a.RTCPeerConnection&&a.webkitRTCPeerConnection&&(a.RTCPeerConnection=function(b,c){return g("PeerConnection"),b&&b.iceTransportPolicy&&(b.iceTransports=b.iceTransportPolicy),new a.webkitRTCPeerConnection(b,c)},a.RTCPeerConnection.prototype=a.webkitRTCPeerConnection.prototype,a.webkitRTCPeerConnection.generateCertificate&&Object.defineProperty(a.RTCPeerConnection,"generateCertificate",{get:function(){return a.webkitRTCPeerConnection.generateCertificate}}));var c=a.RTCPeerConnection.prototype.getStats;a.RTCPeerConnection.prototype.getStats=function(a,b,d){var e=this,f=arguments;if(arguments.length>0&&"function"==typeof a)return c.apply(this,arguments);if(0===c.length&&(0===arguments.length||"function"!=typeof arguments[0]))return c.apply(this,[]);var g=function(a){var b={};return a.result().forEach(function(a){var c={id:a.id,timestamp:a.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[a.type]||a.type};a.names().forEach(function(b){c[b]=a.stat(b)}),b[c.id]=c}),b},h=function(a){return new Map(Object.keys(a).map(function(b){return[b,a[b]]}))};if(arguments.length>=2){var i=function(a){f[1](h(g(a)))};return c.apply(this,[i,arguments[0]])}return new Promise(function(a,b){c.apply(e,[function(b){a(h(g(b)))},b])}).then(b,d)},b.version<51&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(b){var c=a.RTCPeerConnection.prototype[b];a.RTCPeerConnection.prototype[b]=function(){var a=arguments,b=this,d=new Promise(function(d,e){c.apply(b,[a[0],d,e])});return a.length<2?d:d.then(function(){a[1].apply(null,[])},function(b){a.length>=3&&a[2].apply(null,[b])})}}),b.version<52&&["createOffer","createAnswer"].forEach(function(b){var c=a.RTCPeerConnection.prototype[b];a.RTCPeerConnection.prototype[b]=function(){var a=this;if(arguments.length<1||1===arguments.length&&"object"==typeof arguments[0]){var b=1===arguments.length?arguments[0]:void 0;return new Promise(function(d,e){c.apply(a,[d,e,b])})}return c.apply(this,arguments)}}),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(b){var c=a.RTCPeerConnection.prototype[b];a.RTCPeerConnection.prototype[b]=function(){return arguments[0]=new("addIceCandidate"===b?a.RTCIceCandidate:a.RTCSessionDescription)(arguments[0]),c.apply(this,arguments)}});var d=a.RTCPeerConnection.prototype.addIceCandidate;a.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?d.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())}},fixNegotiationNeeded:function(a){f.wrapPeerConnectionEvent(a,"negotiationneeded",function(a){if("stable"===a.target.signalingState)return a})},shimGetDisplayMedia:function(a,b){if(!("getDisplayMedia"in a.navigator))return"function"!=typeof b?void console.error("shimGetDisplayMedia: getSourceId argument is not a function"):void(navigator.getDisplayMedia=function(a){return b(a).then(function(b){var c=a.video&&a.video.width,d=a.video&&a.video.height,e=a.video&&a.video.frameRate;return a.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:b,maxFrameRate:e||3}},c&&(a.video.mandatory.maxWidth=c),d&&(a.video.mandatory.maxHeight=d),navigator.mediaDevices.getUserMedia(a)})})}}},{"../utils.js":27,"./getusermedia":19}],19:[function(a,b,c){"use strict";var d=a("../utils.js"),e=d.log;b.exports=function(a){var b=d.detectBrowser(a),c=a&&a.navigator,f=function(a){if("object"!=typeof a||a.mandatory||a.optional)return a;var b={};return Object.keys(a).forEach(function(c){if("require"!==c&&"advanced"!==c&&"mediaSource"!==c){var d="object"==typeof a[c]?a[c]:{ideal:a[c]};void 0!==d.exact&&"number"==typeof d.exact&&(d.min=d.max=d.exact);var e=function(a,b){return a?a+b.charAt(0).toUpperCase()+b.slice(1):"deviceId"===b?"sourceId":b};if(void 0!==d.ideal){b.optional=b.optional||[];var f={};"number"==typeof d.ideal?(f[e("min",c)]=d.ideal,b.optional.push(f),f={},f[e("max",c)]=d.ideal,b.optional.push(f)):(f[e("",c)]=d.ideal,b.optional.push(f))}void 0!==d.exact&&"number"!=typeof d.exact?(b.mandatory=b.mandatory||{},b.mandatory[e("",c)]=d.exact):["min","max"].forEach(function(a){void 0!==d[a]&&(b.mandatory=b.mandatory||{},b.mandatory[e(a,c)]=d[a])})}}),a.advanced&&(b.optional=(b.optional||[]).concat(a.advanced)),b},g=function(a,d){if(b.version>=61)return d(a);if((a=JSON.parse(JSON.stringify(a)))&&"object"==typeof a.audio){var g=function(a,b,c){b in a&&!(c in a)&&(a[c]=a[b],delete a[b])};a=JSON.parse(JSON.stringify(a)),g(a.audio,"autoGainControl","googAutoGainControl"),g(a.audio,"noiseSuppression","googNoiseSuppression"),a.audio=f(a.audio)}if(a&&"object"==typeof a.video){var h=a.video.facingMode;h=h&&("object"==typeof h?h:{ideal:h});var i=b.version<66;if(h&&("user"===h.exact||"environment"===h.exact||"user"===h.ideal||"environment"===h.ideal)&&(!c.mediaDevices.getSupportedConstraints||!c.mediaDevices.getSupportedConstraints().facingMode||i)){delete a.video.facingMode;var j;if("environment"===h.exact||"environment"===h.ideal?j=["back","rear"]:"user"!==h.exact&&"user"!==h.ideal||(j=["front"]),j)return c.mediaDevices.enumerateDevices().then(function(b){b=b.filter(function(a){return"videoinput"===a.kind});var c=b.find(function(a){return j.some(function(b){return-1!==a.label.toLowerCase().indexOf(b)})});return!c&&b.length&&-1!==j.indexOf("back")&&(c=b[b.length-1]),c&&(a.video.deviceId=h.exact?{exact:c.deviceId}:{ideal:c.deviceId}),a.video=f(a.video),e("chrome: "+JSON.stringify(a)),d(a)})}a.video=f(a.video)}return e("chrome: "+JSON.stringify(a)),d(a)},h=function(a){return b.version>=64?a:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[a.name]||a.name,message:a.message,constraint:a.constraint||a.constraintName,toString:function(){return this.name+(this.message&&": ")+this.message}}},i=function(a,b,d){g(a,function(a){c.webkitGetUserMedia(a,b,function(a){d&&d(h(a))})})};c.getUserMedia=i;var j=function(a){return new Promise(function(b,d){c.getUserMedia(a,b,d)})};if(c.mediaDevices||(c.mediaDevices={getUserMedia:j,enumerateDevices:function(){return new Promise(function(b){var c={audio:"audioinput",video:"videoinput"};return a.MediaStreamTrack.getSources(function(a){b(a.map(function(a){return{label:a.label,kind:c[a.kind],deviceId:a.id,groupId:""}}))})})},getSupportedConstraints:function(){return{deviceId:!0,echoCancellation:!0,facingMode:!0,frameRate:!0,height:!0,width:!0}}}),c.mediaDevices.getUserMedia){var k=c.mediaDevices.getUserMedia.bind(c.mediaDevices);c.mediaDevices.getUserMedia=function(a){return g(a,function(a){return k(a).then(function(b){if(a.audio&&!b.getAudioTracks().length||a.video&&!b.getVideoTracks().length)throw b.getTracks().forEach(function(a){a.stop()}),new DOMException("","NotFoundError");return b},function(a){return Promise.reject(h(a))})})}}else c.mediaDevices.getUserMedia=function(a){return j(a)};void 0===c.mediaDevices.addEventListener&&(c.mediaDevices.addEventListener=function(){e("Dummy mediaDevices.addEventListener called.")}),void 0===c.mediaDevices.removeEventListener&&(c.mediaDevices.removeEventListener=function(){e("Dummy mediaDevices.removeEventListener called.")})}},{"../utils.js":27}],20:[function(a,b,c){"use strict";var d=a("sdp"),e=a("./utils");b.exports={shimRTCIceCandidate:function(a){if(a.RTCIceCandidate&&!(a.RTCIceCandidate&&"foundation"in a.RTCIceCandidate.prototype)){var b=a.RTCIceCandidate;a.RTCIceCandidate=function(a){if("object"==typeof a&&a.candidate&&0===a.candidate.indexOf("a=")&&(a=JSON.parse(JSON.stringify(a)),a.candidate=a.candidate.substr(2)),a.candidate&&a.candidate.length){var c=new b(a),e=d.parseCandidate(a.candidate),f=Object.assign(c,e);return f.toJSON=function(){return{candidate:f.candidate,sdpMid:f.sdpMid,sdpMLineIndex:f.sdpMLineIndex,usernameFragment:f.usernameFragment}},f}return new b(a)},a.RTCIceCandidate.prototype=b.prototype,e.wrapPeerConnectionEvent(a,"icecandidate",function(b){return b.candidate&&Object.defineProperty(b,"candidate",{value:new a.RTCIceCandidate(b.candidate),writable:"false"}),b})}},shimCreateObjectURL:function(a){var b=a&&a.URL;if("object"==typeof a&&a.HTMLMediaElement&&"srcObject"in a.HTMLMediaElement.prototype&&b.createObjectURL&&b.revokeObjectURL){var c=b.createObjectURL.bind(b),d=b.revokeObjectURL.bind(b),f=new Map,g=0;b.createObjectURL=function(a){if("getTracks"in a){var b="polyblob:"+ ++g;return f.set(b,a),e.deprecated("URL.createObjectURL(stream)","elem.srcObject = stream"),b}return c(a)},b.revokeObjectURL=function(a){d(a),f.delete(a)};var h=Object.getOwnPropertyDescriptor(a.HTMLMediaElement.prototype,"src");Object.defineProperty(a.HTMLMediaElement.prototype,"src",{get:function(){return h.get.apply(this)},set:function(a){return this.srcObject=f.get(a)||null,h.set.apply(this,[a])}});var i=a.HTMLMediaElement.prototype.setAttribute;a.HTMLMediaElement.prototype.setAttribute=function(){return 2===arguments.length&&"src"===(""+arguments[0]).toLowerCase()&&(this.srcObject=f.get(arguments[1])||null),i.apply(this,arguments)}}},shimMaxMessageSize:function(a){if(!a.RTCSctpTransport&&a.RTCPeerConnection){var b=e.detectBrowser(a);"sctp"in a.RTCPeerConnection.prototype||Object.defineProperty(a.RTCPeerConnection.prototype,"sctp",{get:function(){return void 0===this._sctp?null:this._sctp}});var c=function(a){var b=d.splitSections(a.sdp);return b.shift(),b.some(function(a){var b=d.parseMLine(a);return b&&"application"===b.kind&&-1!==b.protocol.indexOf("SCTP")})},f=function(a){var b=a.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===b||b.length<2)return-1;var c=parseInt(b[1],10);return c!==c?-1:c},g=function(a){var c=65536;return"firefox"===b.browser&&(c=b.version<57?-1===a?16384:2147483637:b.version<60?57===b.version?65535:65536:2147483637),c},h=function(a,c){var e=65536;"firefox"===b.browser&&57===b.version&&(e=65535);var f=d.matchPrefix(a.sdp,"a=max-message-size:");return f.length>0?e=parseInt(f[0].substr(19),10):"firefox"===b.browser&&-1!==c&&(e=2147483637),e},i=a.RTCPeerConnection.prototype.setRemoteDescription;a.RTCPeerConnection.prototype.setRemoteDescription=function(){var a=this;if(a._sctp=null,c(arguments[0])){var b,d=f(arguments[0]),e=g(d),j=h(arguments[0],d);b=0===e&&0===j?Number.POSITIVE_INFINITY:0===e||0===j?Math.max(e,j):Math.min(e,j);var k={};Object.defineProperty(k,"maxMessageSize",{get:function(){return b}}),a._sctp=k}return i.apply(a,arguments)}}},shimSendThrowTypeError:function(a){function b(a,b){var c=a.send;a.send=function(){var d=arguments[0],e=d.length||d.size||d.byteLength;if("open"===a.readyState&&b.sctp&&e>b.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+b.sctp.maxMessageSize+" bytes)");return c.apply(a,arguments)}}if(a.RTCPeerConnection&&"createDataChannel"in a.RTCPeerConnection.prototype){var c=a.RTCPeerConnection.prototype.createDataChannel;a.RTCPeerConnection.prototype.createDataChannel=function(){var a=this,d=c.apply(a,arguments);return b(d,a),d},e.wrapPeerConnectionEvent(a,"datachannel",function(a){return b(a.channel,a.target),a})}}}},{"./utils":27,sdp:15}],21:[function(a,b,c){"use strict";var d=a("../utils"),e=a("./filtericeservers"),f=a("rtcpeerconnection-shim");b.exports={shimGetUserMedia:a("./getusermedia"),shimPeerConnection:function(a){var b=d.detectBrowser(a);if(a.RTCIceGatherer&&(a.RTCIceCandidate||(a.RTCIceCandidate=function(a){return a}),a.RTCSessionDescription||(a.RTCSessionDescription=function(a){return a}),b.version<15025)){var c=Object.getOwnPropertyDescriptor(a.MediaStreamTrack.prototype,"enabled");Object.defineProperty(a.MediaStreamTrack.prototype,"enabled",{set:function(a){c.set.call(this,a);var b=new Event("enabled");b.enabled=a,this.dispatchEvent(b)}})}!a.RTCRtpSender||"dtmf"in a.RTCRtpSender.prototype||Object.defineProperty(a.RTCRtpSender.prototype,"dtmf",{get:function(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=new a.RTCDtmfSender(this):"video"===this.track.kind&&(this._dtmf=null)),this._dtmf}}),a.RTCDtmfSender&&!a.RTCDTMFSender&&(a.RTCDTMFSender=a.RTCDtmfSender);var g=f(a,b.version);a.RTCPeerConnection=function(a){return a&&a.iceServers&&(a.iceServers=e(a.iceServers)),new g(a)},a.RTCPeerConnection.prototype=g.prototype},shimReplaceTrack:function(a){!a.RTCRtpSender||"replaceTrack"in a.RTCRtpSender.prototype||(a.RTCRtpSender.prototype.replaceTrack=a.RTCRtpSender.prototype.setTrack)}}},{"../utils":27,"./filtericeservers":22,"./getusermedia":23,"rtcpeerconnection-shim":14}],22:[function(a,b,c){"use strict";var d=a("../utils") ;b.exports=function(a,b){var c=!1;return a=JSON.parse(JSON.stringify(a)),a.filter(function(a){if(a&&(a.urls||a.url)){var e=a.urls||a.url;a.url&&!a.urls&&d.deprecated("RTCIceServer.url","RTCIceServer.urls");var f="string"==typeof e;return f&&(e=[e]),e=e.filter(function(a){return 0!==a.indexOf("turn:")||-1===a.indexOf("transport=udp")||-1!==a.indexOf("turn:[")||c?0===a.indexOf("stun:")&&b>=14393&&-1===a.indexOf("?transport=udp"):(c=!0,!0)}),delete a.url,a.urls=f?e[0]:e,!!e.length}})}},{"../utils":27}],23:[function(a,b,c){"use strict";b.exports=function(a){var b=a&&a.navigator,c=function(a){return{name:{PermissionDeniedError:"NotAllowedError"}[a.name]||a.name,message:a.message,constraint:a.constraint,toString:function(){return this.name}}},d=b.mediaDevices.getUserMedia.bind(b.mediaDevices);b.mediaDevices.getUserMedia=function(a){return d(a).catch(function(a){return Promise.reject(c(a))})}}},{}],24:[function(a,b,c){"use strict";var d=a("../utils");b.exports={shimGetUserMedia:a("./getusermedia"),shimOnTrack:function(a){"object"!=typeof a||!a.RTCPeerConnection||"ontrack"in a.RTCPeerConnection.prototype||Object.defineProperty(a.RTCPeerConnection.prototype,"ontrack",{get:function(){return this._ontrack},set:function(a){this._ontrack&&(this.removeEventListener("track",this._ontrack),this.removeEventListener("addstream",this._ontrackpoly)),this.addEventListener("track",this._ontrack=a),this.addEventListener("addstream",this._ontrackpoly=function(a){a.stream.getTracks().forEach(function(b){var c=new Event("track");c.track=b,c.receiver={track:b},c.transceiver={receiver:c.receiver},c.streams=[a.stream],this.dispatchEvent(c)}.bind(this))}.bind(this))},enumerable:!0,configurable:!0}),"object"==typeof a&&a.RTCTrackEvent&&"receiver"in a.RTCTrackEvent.prototype&&!("transceiver"in a.RTCTrackEvent.prototype)&&Object.defineProperty(a.RTCTrackEvent.prototype,"transceiver",{get:function(){return{receiver:this.receiver}}})},shimSourceObject:function(a){"object"==typeof a&&(!a.HTMLMediaElement||"srcObject"in a.HTMLMediaElement.prototype||Object.defineProperty(a.HTMLMediaElement.prototype,"srcObject",{get:function(){return this.mozSrcObject},set:function(a){this.mozSrcObject=a}}))},shimPeerConnection:function(a){var b=d.detectBrowser(a);if("object"==typeof a&&(a.RTCPeerConnection||a.mozRTCPeerConnection)){a.RTCPeerConnection||(a.RTCPeerConnection=function(c,d){if(b.version<38&&c&&c.iceServers){for(var e=[],f=0;f55&&"autoGainControl"in c.mediaDevices.getSupportedConstraints())){var l=function(a,b,c){b in a&&!(c in a)&&(a[c]=a[b],delete a[b])},m=c.mediaDevices.getUserMedia.bind(c.mediaDevices);if(c.mediaDevices.getUserMedia=function(a){return"object"==typeof a&&"object"==typeof a.audio&&(a=JSON.parse(JSON.stringify(a)),l(a.audio,"autoGainControl","mozAutoGainControl"),l(a.audio,"noiseSuppression","mozNoiseSuppression")),m(a)},f&&f.prototype.getSettings){var n=f.prototype.getSettings;f.prototype.getSettings=function(){var a=n.apply(this,arguments);return l(a,"mozAutoGainControl","autoGainControl"),l(a,"mozNoiseSuppression","noiseSuppression"),a}}if(f&&f.prototype.applyConstraints){var o=f.prototype.applyConstraints;f.prototype.applyConstraints=function(a){return"audio"===this.kind&&"object"==typeof a&&(a=JSON.parse(JSON.stringify(a)),l(a,"autoGainControl","mozAutoGainControl"),l(a,"noiseSuppression","mozNoiseSuppression")),o.apply(this,[a])}}}c.getUserMedia=function(a,e,f){if(b.version<44)return h(a,e,f);d.deprecated("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),c.mediaDevices.getUserMedia(a).then(e,f)}}},{"../utils":27}],26:[function(a,b,c){"use strict";var d=a("../utils");b.exports={shimLocalStreamsAPI:function(a){if("object"==typeof a&&a.RTCPeerConnection){if("getLocalStreams"in a.RTCPeerConnection.prototype||(a.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),"getStreamById"in a.RTCPeerConnection.prototype||(a.RTCPeerConnection.prototype.getStreamById=function(a){var b=null;return this._localStreams&&this._localStreams.forEach(function(c){c.id===a&&(b=c)}),this._remoteStreams&&this._remoteStreams.forEach(function(c){c.id===a&&(b=c)}),b}),!("addStream"in a.RTCPeerConnection.prototype)){var b=a.RTCPeerConnection.prototype.addTrack;a.RTCPeerConnection.prototype.addStream=function(a){this._localStreams||(this._localStreams=[]),-1===this._localStreams.indexOf(a)&&this._localStreams.push(a);var c=this;a.getTracks().forEach(function(d){b.call(c,d,a)})},a.RTCPeerConnection.prototype.addTrack=function(a,c){return c&&(this._localStreams?-1===this._localStreams.indexOf(c)&&this._localStreams.push(c):this._localStreams=[c]),b.call(this,a,c)}}"removeStream"in a.RTCPeerConnection.prototype||(a.RTCPeerConnection.prototype.removeStream=function(a){this._localStreams||(this._localStreams=[]);var b=this._localStreams.indexOf(a);if(-1!==b){this._localStreams.splice(b,1);var c=this,d=a.getTracks();this.getSenders().forEach(function(a){-1!==d.indexOf(a.track)&&c.removeTrack(a)})}})}},shimRemoteStreamsAPI:function(a){if("object"==typeof a&&a.RTCPeerConnection&&("getRemoteStreams"in a.RTCPeerConnection.prototype||(a.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in a.RTCPeerConnection.prototype))){Object.defineProperty(a.RTCPeerConnection.prototype,"onaddstream",{get:function(){return this._onaddstream},set:function(a){this._onaddstream&&this.removeEventListener("addstream",this._onaddstream),this.addEventListener("addstream",this._onaddstream=a)}});var b=a.RTCPeerConnection.prototype.setRemoteDescription;a.RTCPeerConnection.prototype.setRemoteDescription=function(){var a=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(b){b.streams.forEach(function(b){if(a._remoteStreams||(a._remoteStreams=[]),!(a._remoteStreams.indexOf(b)>=0)){a._remoteStreams.push(b);var c=new Event("addstream");c.stream=b,a.dispatchEvent(c)}})}),b.apply(a,arguments)}}},shimCallbacksAPI:function(a){if("object"==typeof a&&a.RTCPeerConnection){var b=a.RTCPeerConnection.prototype,c=b.createOffer,d=b.createAnswer,e=b.setLocalDescription,f=b.setRemoteDescription,g=b.addIceCandidate;b.createOffer=function(a,b){var d=arguments.length>=2?arguments[2]:arguments[0],e=c.apply(this,[d]);return b?(e.then(a,b),Promise.resolve()):e},b.createAnswer=function(a,b){var c=arguments.length>=2?arguments[2]:arguments[0],e=d.apply(this,[c]);return b?(e.then(a,b),Promise.resolve()):e};var h=function(a,b,c){var d=e.apply(this,[a]);return c?(d.then(b,c),Promise.resolve()):d};b.setLocalDescription=h,h=function(a,b,c){var d=f.apply(this,[a]);return c?(d.then(b,c),Promise.resolve()):d},b.setRemoteDescription=h,h=function(a,b,c){var d=g.apply(this,[a]);return c?(d.then(b,c),Promise.resolve()):d},b.addIceCandidate=h}},shimGetUserMedia:function(a){var b=a&&a.navigator;b.getUserMedia||(b.webkitGetUserMedia?b.getUserMedia=b.webkitGetUserMedia.bind(b):b.mediaDevices&&b.mediaDevices.getUserMedia&&(b.getUserMedia=function(a,c,d){b.mediaDevices.getUserMedia(a).then(c,d)}.bind(b)))},shimRTCIceServerUrls:function(a){var b=a.RTCPeerConnection;a.RTCPeerConnection=function(a,c){if(a&&a.iceServers){for(var e=[],f=0;f=c&&parseInt(d[c],10)}function e(a,b,c){if(a.RTCPeerConnection){var d=a.RTCPeerConnection.prototype,e=d.addEventListener;d.addEventListener=function(a,d){if(a!==b)return e.apply(this,arguments);var f=function(a){var b=c(a);b&&d(b)};return this._eventMap=this._eventMap||{},this._eventMap[d]=f,e.apply(this,[a,f])};var f=d.removeEventListener;d.removeEventListener=function(a,c){if(a!==b||!this._eventMap||!this._eventMap[c])return f.apply(this,arguments);var d=this._eventMap[c];return delete this._eventMap[c],f.apply(this,[a,d])},Object.defineProperty(d,"on"+b,{get:function(){return this["_on"+b]},set:function(a){this["_on"+b]&&(this.removeEventListener(b,this["_on"+b]),delete this["_on"+b]),a&&this.addEventListener(b,this["_on"+b]=a)},enumerable:!0,configurable:!0})}}var f=!0,g=!0;b.exports={extractVersion:d,wrapPeerConnectionEvent:e,disableLog:function(a){return"boolean"!=typeof a?new Error("Argument type: "+typeof a+". Please use a boolean."):(f=a,a?"adapter.js logging disabled":"adapter.js logging enabled")},disableWarnings:function(a){return"boolean"!=typeof a?new Error("Argument type: "+typeof a+". Please use a boolean."):(g=!a,"adapter.js deprecation warnings "+(a?"disabled":"enabled"))},log:function(){if("object"==typeof window){if(f)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}},deprecated:function(a,b){g&&console.warn(a+" is deprecated, please use "+b+" instead.")},detectBrowser:function(a){var b=a&&a.navigator,c={};if(c.browser=null,c.version=null,void 0===a||!a.navigator)return c.browser="Not a browser.",c;if(b.mozGetUserMedia)c.browser="firefox",c.version=d(b.userAgent,/Firefox\/(\d+)\./,1);else if(b.webkitGetUserMedia)c.browser="chrome",c.version=d(b.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(b.mediaDevices&&b.userAgent.match(/Edge\/(\d+).(\d+)$/))c.browser="edge",c.version=d(b.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!a.RTCPeerConnection||!b.userAgent.match(/AppleWebKit\/(\d+)\./))return c.browser="Not a supported browser.",c;c.browser="safari",c.version=d(b.userAgent,/AppleWebKit\/(\d+)\./,1)}return c}}},{}]},{},[3]);function Presenter(){var self=this;Object.getOwnPropertyNames(Object.getPrototypeOf(self)).filter(function(name){return typeof self[name]==="function"}).filter(function(name){return name!=="constructor"}).forEach(function(name){self[name]=self[name].bind(self)});self.appName=window.btoa(window.location.href.slice(0,window.location.href.indexOf(window.location.hash)));self.namespace=self.appName.replace(/[^a-zA-Z0-9]+/g,"");self.peerId=self.namespace+" "+Math.random().toString().slice(2);self.peers={};self.peer=null;self.touchCount=0;self.timeoutId=null;self.register();self.subscribe();document.addEventListener("keypress",self.onKeyPress);document.addEventListener("mousedown",self.onTouchStart);document.addEventListener("touchstart",self.onTouchStart)}Presenter.prototype.register=function(){var self=this;self.peer=new Peer(self.peerId,{host:"peerjs.now.sh",port:443,secure:true});self.peer.on("connection",function(conn){self.peers[conn.peer]=conn;conn.on("data",self.onDatahandler)})};Presenter.prototype.publish=function(){window.alert("publish mode on");window.onhashchange=this.onHashChange};Presenter.prototype.subscribe=function(){var self=this;this.peer.listAllPeers(function(peers){peers.filter(function(id){return id!==self.peerId&&id.split(" ")[0]===self.namespace}).forEach(function(id){if(!self.peers[id]){var conn=self.peer.connect(id);conn.on("data",self.onDatahandler);self.peers[id]=conn}})})};Presenter.prototype.onTouchStart=function(event){var self=this;if(self.timeoutId){clearTimeout(self.timeoutId);self.timeoutId=null}self.touchCount=self.touchCount+1;if(self.touchCount===6){document.removeEventListener("mousedown",self.onTouchStart);document.removeEventListener("touchstart",self.onTouchStart);self.publish()}else{self.timeoutId=setTimeout(function(){self.touchCount=0},500)}};Presenter.prototype.onKeyPress=function(event){if(event.key==="q"){this.toggleQRCode()}};Presenter.prototype.onHashChange=function(){var self=this;Object.keys(self.peers).filter(function(id){return self.peers[id].open}).forEach(function(id){self.peers[id].send(window.location.href)})};Presenter.prototype.onDatahandler=function(data){window.location.href=data};Presenter.prototype.toggleQRCode=function(){if(!this.elCode){this.elCode=document.createElement("div");this.elCode.style.display="none";this.elCode.style.position="absolute";this.elCode.style.top="0";this.elCode.style.right="0";this.elCode.style.zIndex="1000";document.body.appendChild(this.elCode);new QRCode(this.elCode,window.location.href)}if(this.elCode.style.display==="none"){this.elCode.style.display="block"}else{this.elCode.style.display="none"}};new Presenter;