Guest User

Untitled

a guest
Feb 28th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 95.13 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6. /*
  7. FILE ARCHIVED ON 19:02:32 Feb 4, 2017 AND RETRIEVED FROM THE
  8. INTERNET ARCHIVE ON 19:03:55 Feb 28, 2017.
  9. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
  10.  
  11. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
  12. SECTION 108(a)(3)).
  13. */
  14. (function e$$0(m,k,a){function b(e,l){if(!k[e]){if(!m[e]){var n="function"==typeof require&&require;if(!l&&n)return n(e,!0);if(g)return g(e,!0);n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n;}n=k[e]={exports:{}};m[e][0].call(n.exports,function(d){var a=m[e][1][d];return b(a?a:d)},n,n.exports,e$$0,m,k,a)}return k[e].exports}for(var g="function"==typeof require&&require,e=0;e<a.length;e++)b(a[e]);return b})({1:[function(h,m,k){Twilio=function(a){var b=a||function(){};(function(a){for(var e in a)b[e]=
  15. a[e]})(function(){var a=h("./twilio/util"),e;if("undefined"==typeof e){e=location.protocol||"http:";for(var b="//media.twiliocdn.com/sdk/js/client/",l=document.getElementsByTagName("script"),n=RegExp("(\\w+:)?(//.*)v"+a.getPStreamVersion()+"/(twilio.min.js|twilio.js)"),d=0;d<l.length;d++){var t=l[d].src.match(n);if(t){e=t[1]||e;b=t[2];break}}e+=b}a.setTwilioRoot(e);return h("./twilio")}());return b}("undefined"!==typeof Twilio?Twilio:null)},{"./twilio":2,"./twilio/util":19}],2:[function(h,m,k){k.Device=
  16. h("./twilio/device").Device;k.PStream=h("./twilio/pstream").PStream;k.Connection=h("./twilio/connection").Connection},{"./twilio/connection":3,"./twilio/device":4,"./twilio/pstream":9}],3:[function(h,m,k){function a(c,p,w){function g(){}function u(){var p={call_sid:r.parameters.CallSid,client_name:c._clientName,sdk_version:d.getReleaseVersion(),selected_region:c.options.region};c.stream&&(c.stream.gateway&&(p.gateway=c.stream.gateway),c.stream.region&&(p.region=c.stream.region));r._direction&&(p.direction=
  17. r._direction);return p}function v(){0!==C.length&&m.postMetrics("quality-metrics-samples","metrics-sample",C.splice(0),u())}function B(c){var p={threshold:c.threshold.value};c.values?p.values=c.values.map(function(c){return"number"===typeof c?Math.round(100*c)/100:c}):c.value&&(p.value=c.value);return{data:p}}function h(c,p){var d=(/^audio/.test(p.name)?"audio-level-":"network-quality-")+"warning"+(c?"-cleared":"-raised"),a=q[p.threshold.name]+t[p.name];"constant-audio-input-level"===a&&r.isMuted()||
  18. m.post(c?"info":"warning",d,a,B(p))}if(!(this instanceof a))return new a(c,p,w);d.monitorEventEmitter("Twilio.Connection",this);this.device=c;this.message=p||{};w=w||{};p={logPrefix:"[Connection]",mediaStreamFactory:l.PeerConnection,offerSdp:null,callParameters:{},debug:!1,encrypt:!1,audioConstraints:c.options.audioConstraints,rtcConstraints:c.options.rtcConstraints,iceServers:c.options.iceServers};for(var k in p)k in w||(w[k]=p[k]);this.options=w;this.parameters=w.callParameters;this._status=this.options.offerSdp?
  19. "pending":"closed";this._direction=this.parameters.CallSid?"INCOMING":"OUTGOING";this.sendHangup=!0;e.mixinLog(this,this.options.logPrefix);this.log.enabled=this.options.debug;this.log.warnings=this.options.warnings;this._onHangup=this._onCancel=g;this._onAnswer=function(c){"undefined"!==typeof c.callsid&&(r.parameters.CallSid=c.callsid,r.mediaStream.callSid=c.callsid)};var r=this,m=this._publisher=new f("twilio-js-sdk",c.token,{host:c.options.eventgw,defaultPayload:function(){var p={client_name:c._clientName,
  20. platform:l.getMediaEngine(),sdk_version:d.getReleaseVersion(),selected_region:c.options.region};r.parameters.CallSid&&!/^TJ/.test(r.parameters.CallSid)&&(p.call_sid=r.parameters.CallSid);r.outboundConnectionId&&(p.temp_call_sid=r.outboundConnectionId);c.stream&&(c.stream.gateway&&(p.gateway=c.stream.gateway),c.stream.region&&(p.region=c.stream.region));r._direction&&(p.direction=r._direction);return p}});!1===w.publishEvents&&m.disable();"INCOMING"===this._direction&&m.info("connection","incoming");
  21. var z=this._monitor=new n;z.disableWarnings();var C=[],x=0;z.on("sample",function(c){20>x?x++:20===x&&z.enableWarnings();C.push(c);10<=C.length&&v()});z.on("warning-cleared",h.bind(null,!0));z.on("warning",h.bind(null,!1));this.mediaStream=new this.options.mediaStreamFactory(this.options.encrypt,this.device);this.mediaStream.oniceconnectionstatechange=function(c){m.post("failed"===c?"error":"debug","ice-connection-state",c)};this.mediaStream.onicegatheringstatechange=function(c){m.debug("signaling-state",
  22. c)};this.mediaStream.onsignalingstatechange=function(c){m.debug("signaling-state",c)};r=this;this.mediaStream.ondisconnect=function(c){r.log(c);m.warn("network-quality-warning-raised","ice-connectivity-lost",{message:c},r);r.emit("error",{code:31003,message:c,info:{code:31003,message:c},connection:r})};this.mediaStream.onreconnect=function(c){r.log(c);m.info("network-quality-warning-cleared","ice-connectivity-lost",{message:c},r)};this.mediaStream.onerror=function(c){!0===c.disconnect&&r._disconnect(c.info&&
  23. c.info.message);var p={code:c.info.code,message:c.info.message||"Error with mediastream",info:c.info,connection:r};r.log("Received an error from MediaStream:",c);r.emit("error",p)};this.mediaStream.onopen=function(){"open"!==r._status&&("connecting"===r._status?(r._status="open",r.mediaStream.attachAudio(),r.emit("accept",r)):r.mediaStream.close())};this.mediaStream.onclose=function(){r._status="closed";r.device.sounds.disconnect()&&r.device.soundcache.play("disconnect");z.disable();v();r.emit("disconnect",
  24. r)};this.outboundConnectionId=d.generateConnectionUUID();this.pstream=this.device.stream;this._onCancel=function(c){r.parameters.CallSid==c.callsid&&(r._status="closed",r.emit("cancel"),r.pstream.removeListener("cancel",r._onCancel))};this.pstream&&this.pstream.addListener("cancel",this._onCancel);this.on("error",function(c){m.error("connection","error",{code:c.code,message:c.message});r.pstream&&"disconnected"===r.pstream.status&&b(r)});this.on("disconnect",function(){b(r)});return this}function b(c){function p(){c.pstream.removeListener("answer",
  25. c._onAnswer);c.pstream.removeListener("cancel",c._onCancel);c.pstream.removeListener("hangup",c._onHangup)}p();setTimeout(p,0)}m=h("events").EventEmitter;var g=h("./util").Exception,e=h("./log"),f=h("./eventpublisher"),l=h("./rtc"),n=h("./rtc/monitor"),d=h("./util"),t={audioOutputLevel:"audio-output-level",audioInputLevel:"audio-input-level",packetsLostFraction:"packet-loss",jitter:"jitter",rtt:"rtt",mos:"mos"},q={min:"low-",max:"high-",maxDuration:"constant-"};h("util").inherits(a,m);a.toString=
  26. function(){return"[Twilio.Connection class]"};a.prototype.toString=function(){return"[Twilio.Connection instance]"};a.prototype.sendDigits=function(c){function p(c){if(c.length){var d=c.shift();d.length&&b.insertDTMF(d,160,70);setTimeout(p.bind(null,c),500)}}if(c.match(/[^0-9*#w]/))throw new g("Illegal character passed into sendDigits");for(var d=[],a=0;a<c.length;a++){var e="w"!=c[a]?"dtmf"+c[a]:"";"dtmf*"==e&&(e="dtmfs");"dtmf#"==e&&(e="dtmfh");d.push([e,200,20])}this.device.soundcache.playseq(d);
  27. var b=this.mediaStream.getOrCreateDTMFSender();if(b){if(b.canInsertDTMF)return this.log("Sending digits using RTCDTMFSender"),p(c.split("w"));this.log("RTCDTMFSender cannot insert DTMF")}this.log("Sending digits over PStream");null!=this.pstream&&"disconnected"!=this.pstream.status?(c={dtmf:c,callsid:this.parameters.CallSid},this.pstream.publish("dtmf",c)):(c={error:{}},this.emit("error",{code:c.error.code||31E3,message:c.error.message||"Could not send DTMF: Signaling channel is disconnected",connection:this}))};
  28. a.prototype.status=function(){return this._status};a.prototype.mute=function(c){0===arguments.length&&this.log.deprecated(".mute() is deprecated. Please use .mute(true) or .mute(false) to mute or unmute a call instead.");if("function"==typeof c)return this.addListener("mute",c);var p=this.isMuted(),d=this,a=function(){var c=d.isMuted();p!=c&&(d._publisher.info("connection",c?"muted":"unmuted"),d.emit("mute",c,d))};0==c?this.mediaStream.attachAudio(a):this.mediaStream.detachAudio(a)};a.prototype.isMuted=
  29. function(){return!this.mediaStream.isAudioAttached()};a.prototype.unmute=function(){this.log.deprecated(".unmute() is deprecated. Please use .mute(false) to unmute a call instead.");this.mute(!1)};a.prototype.accept=function(c){if("function"==typeof c)return this.addListener("accept",c);var p=c||this.options.audioConstraints,d=this;this._status="connecting";this.mediaStream.openHelper(function(c){function a(c){d._publisher.info("connection","accepted-by-local");d._monitor.enable(c)}function e(c){d._publisher.info("connection",
  30. "accepted-by-remote");d._monitor.enable(c)}if("connecting"!=d._status)b(d),d.mediaStream.close();else{if(c)return 31208===c.code?d._publisher.error("get-user-media","denied",{data:{audioConstraints:p,error:c.error}}):d._publisher.error("get-user-media","failed",{data:{audioConstraints:p,error:c.error}}),d._die(c.message,c.code);d._publisher.info("get-user-media","succeeded",{data:{audioConstraints:p}});c=[];for(var f in d.message)c.push(encodeURIComponent(f)+"="+encodeURIComponent(d.message[f]));
  31. f=c.join("&");"INCOMING"===d._direction?d.mediaStream.answerIncomingCall.call(d.mediaStream,d.parameters.CallSid,d.options.offerSdp,d.options.rtcConstraints,d.options.iceServers,a):(d.pstream.once("answer",d._onAnswer),d.mediaStream.makeOutgoingCall.call(d.mediaStream,f,d.outboundConnectionId,d.options.rtcConstraints,d.options.iceServers,e));d._onHangup=function(c){if(c.callsid&&(d.parameters.CallSid||d.outboundConnectionId)){if(c.callsid!=d.parameters.CallSid&&c.callsid!=d.outboundConnectionId)return}else if(c.callsid)return;
  32. d.log("Received HANGUP from gateway");c.error&&(c={code:c.error.code||31E3,message:c.error.message||"Error sent from gateway in HANGUP",connection:d},d.log("Received an error from the gateway:",c),d.emit("error",c));d.sendHangup=!1;d._publisher.info("connection","disconnected-by-remote");d._disconnect();b(d)};d.pstream.addListener("hangup",d._onHangup)}},p)};a.prototype.reject=function(c){if("function"==typeof c)return this.addListener("reject",c);"pending"==this._status&&(this.pstream.publish("reject",
  33. {callsid:this.parameters.CallSid}),this.emit("reject"),this.mediaStream.reject(this.parameters.CallSid),this._publisher.info("connection","rejected-by-local"))};a.prototype.ignore=function(c){if("function"==typeof c)return this.addListener("cancel",c);"pending"==this._status&&(this._status="closed",this.emit("cancel"),this.mediaStream.ignore(this.parameters.CallSid),this._publisher.info("connection","ignored-by-local"))};a.prototype.cancel=function(c){this.log.deprecated(".cancel() is deprecated. Please use .ignore() instead.");
  34. this.ignore(c)};a.prototype.disconnect=function(c){if("function"===typeof c)return this.addListener("disconnect",c);this._publisher.info("connection","disconnected-by-local");this._disconnect()};a.prototype._disconnect=function(c){c="string"===typeof c?c:null;if("open"==this._status||"connecting"==this._status){this.log("Disconnecting...");if(null!=this.pstream&&"disconnected"!=this.pstream.status&&this.sendHangup){var d=this.parameters.CallSid||this.outboundConnectionId;d&&(d={callsid:d},c&&(d.message=
  35. c),this.pstream.publish("hangup",d))}b(this);this.mediaStream.close()}};a.prototype.error=function(c){if("function"==typeof c)return this.addListener("error",c)};a.prototype._die=function(c,d){this.emit("error",{message:c,code:d});this._disconnect()};k.Connection=a},{"./eventpublisher":5,"./log":7,"./rtc":11,"./rtc/monitor":12,"./util":19,events:21,util:37}],4:[function(h,m,k){function a(p,b){if(!l.enabled())throw new f.Exception("twilio.js 1.3 requires WebRTC/ORTC browser support. For more information, see </web/20170204190232/https://www.twilio.com/docs/api/client/twilio-js>. If you have any questions about this announcement, please contact Twilio Support at <help@twilio.com>.");
  36. if(!(this instanceof a))return new a(p,b);f.monitorEventEmitter("Twilio.Device",this);if(!p)throw new f.Exception("Capability token is not valid or missing.");for(i in b);var g={logPrefix:"[Device]",chunderw:"chunderw-vpc-gll.twilio.com",eventgw:"eventgw.twilio.com",soundCacheFactory:t,soundFactory:d,connectionFactory:q,pStreamFactory:c,noRegister:!1,encrypt:!1,closeProtection:!1,secureSignaling:!0,warnings:!0,audioConstraints:!0,iceServers:[],region:"gll",dscp:!0,sounds:{}};b=b||{};var u=b.chunderw,
  37. v;for(v in g)v in b||(b[v]=g[v]);b.rtcConstraints=b.dscp?{optional:[{googDscp:!0}]}:{};this.options=b;this.token=p;this._region=this._status="offline";this.connections=[];this.sounds=new n({incoming:!0,outgoing:!0,disconnect:!0});e.mixinLog(this,this.options.logPrefix);this.log.enabled=this.options.debug;g={gll:"chunderw-vpc-gll.twilio.com",au1:"chunderw-vpc-gll-au1.twilio.com",br1:"chunderw-vpc-gll-br1.twilio.com",ie1:"chunderw-vpc-gll-ie1.twilio.com",jp1:"chunderw-vpc-gll-jp1.twilio.com",sg1:"chunderw-vpc-gll-sg1.twilio.com",
  38. us1:"chunderw-vpc-gll-us1.twilio.com"};v={au:"au1",br:"br1",ie:"ie1",jp:"jp1",sg:"sg1","us-va":"us1","us-or":"us1"};var h=b.region.toLowerCase();h in v&&(this.log.deprecated("Region "+h+" is deprecated, please use "+v[h]+"."),h=v[h]);if(!(h in g))throw new f.Exception("Region "+b.region+" is invalid. Valid values are: "+Object.keys(g).join(", "));b.chunderw=u||g[h];this.soundcache=this.options.soundCacheFactory();u="undefined"===typeof document?{}:document.createElement("audio");canPlayMp3=!1;try{canPlayMp3=
  39. !(!u.canPlayType||!u.canPlayType("audio/mpeg").replace(/no/,""))}catch(k){}canPlayVorbis=!1;try{canPlayVorbis=!(!u.canPlayType||!u.canPlayType('audio/ogg;codecs="vorbis"').replace(/no/,""))}catch(k){}u="mp3";canPlayVorbis&&!canPlayMp3&&(u="ogg");g={incoming:{filename:"incoming",loop:!0},outgoing:{filename:"outgoing",maxDuration:3E3},disconnect:{filename:"disconnect",maxDuration:3E3},dtmf1:{filename:"dtmf-1",maxDuration:1E3},dtmf2:{filename:"dtmf-2",maxDuration:1E3},dtmf3:{filename:"dtmf-3",maxDuration:1E3},
  40. dtmf4:{filename:"dtmf-4",maxDuration:1E3},dtmf5:{filename:"dtmf-5",maxDuration:1E3},dtmf6:{filename:"dtmf-6",maxDuration:1E3},dtmf7:{filename:"dtmf-7",maxDuration:1E3},dtmf8:{filename:"dtmf-8",maxDuration:1E3},dtmf9:{filename:"dtmf-9",maxDuration:1E3},dtmf0:{filename:"dtmf-0",maxDuration:1E3},dtmfs:{filename:"dtmf-star",maxDuration:1E3},dtmfh:{filename:"dtmf-hash",maxDuration:1E3}};v=f.getTwilioRoot()+"sounds/releases/"+f.getSoundVersion()+"/";for(var m in g){var h=g[m],A=this.options.soundFactory(h);
  41. A.load(v+h.filename+"."+u);this.soundcache.add(m,A)}this.soundcache.envelope("incoming",{release:2E3});var r=this;this.addListener("incoming",function(c){c.once("accept",function(){r.soundcache.stop("incoming")});c.once("cancel",function(){r.soundcache.stop("incoming")});c.once("error",function(){r.soundcache.stop("incoming")});c.once("reject",function(){r.soundcache.stop("incoming")});r.sounds.incoming()&&r.soundcache.play("incoming",0,1E3)});this.mediaPresence={audio:!this.options.noRegister};this.register(this.token);
  42. var E=this,z=this.options.closeProtection;z&&(m=function(c){if("busy"==r._status||E.connections[0]){var d=1==z?"A call is currently in-progress. Leaving or reloading this page will end the call.":z;return(c||window.event).returnValue=d}},"undefined"!==typeof window&&(window.addEventListener?window.addEventListener("beforeunload",m):window.attachEvent&&window.attachEvent("onbeforeunload",m)));m=function(){r.disconnectAll()};"undefined"!==typeof window&&(window.addEventListener?window.addEventListener("unload",
  43. m):window.attachEvent&&window.attachEvent("onunload",m));this.on("error",function(){});return this}function b(c,d,a){var b={publishEvents:c.options.publishEvents,debug:c.options.debug,encrypt:c.options.encrypt,warnings:c.options.warnings};a=a||{};for(var e in b)e in a||(a[e]=b[e]);var f=c.options.connectionFactory(c,d,a);f.once("accept",function(){c._status="busy";c.emit("connect",f)});f.addListener("error",function(d){c.emit("error",d);"pending"==f.status()&&"connecting"==f.status()&&c._removeConnection(f)});
  44. f.once("cancel",function(){c.log("Canceled: "+f.parameters.CallSid);c._removeConnection(f);c.emit("cancel",f)});f.once("disconnect",function(){"busy"==c._status&&(c._status="ready");c.emit("disconnect",f);c._removeConnection(f)});f.once("reject",function(){c.log("Rejected: "+f.parameters.CallSid);c._removeConnection(f)});return f}m=h("events").EventEmitter;var g=h("util"),e=h("./log"),f=h("./util"),l=h("./rtc"),n=h("./options").Options,d=h("./sound").Sound,t=h("./soundcache").SoundCache,q=h("./connection").Connection,
  45. c=h("./pstream").PStream;g.inherits(a,m);a.toString=function(){return"[Twilio.Device class]"};a.prototype.toString=function(){return"[Twilio.Device instance]"};a.prototype.register=function(c){var d=f.objectize(c);this._accountSid=d.iss;this._clientName=d.scope["client:incoming"]?d.scope["client:incoming"].params.clientName:null;this.stream&&"disconnected"!=this.stream.status?this.stream.setToken(c):this._setupStream()};a.prototype.registerPresence=function(){this.token&&(f.objectize(this.token).scope["client:incoming"]&&
  46. (this.mediaPresence.audio=!0),this._sendPresence())};a.prototype.unregisterPresence=function(){this.mediaPresence.audio=!1;this._sendPresence()};a.prototype.connect=function(c,d){if("function"==typeof c)return this.addListener("connect",c);c=c||{};d=d||this.options.audioConstraints;var a=b(this,c);this.connections.push(a);if(this.sounds.outgoing()){var e=this;a.accept(function(){e.soundcache.play("outgoing")})}a.accept(d);return a};a.prototype.disconnectAll=function(){for(var c=[].concat(this.connections),
  47. d=0;d<c.length;d++)c[d].disconnect();0<this.connections.length&&this.log("Connections left pending: "+this.connections.length)};a.prototype.destroy=function(){this._stopRegistrationTimer();this.stream&&(this.stream.destroy(),this.stream=null)};a.prototype.disconnect=function(c){this.addListener("disconnect",c)};a.prototype.incoming=function(c){this.addListener("incoming",c)};a.prototype.offline=function(c){this.addListener("offline",c)};a.prototype.ready=function(c){this.addListener("ready",c)};a.prototype.error=
  48. function(c){this.addListener("error",c)};a.prototype.status=function(){return this._status};a.prototype.activeConnection=function(){return this.connections[0]};a.prototype.region=function(){return this._region};a.prototype._sendPresence=function(){this.stream.register(this.mediaPresence);this.mediaPresence.audio?this._startRegistrationTimer():this._stopRegistrationTimer()};a.prototype._startRegistrationTimer=function(){clearTimeout(this.regTimer);var c=this;this.regTimer=setTimeout(function(){c._sendPresence()},
  49. 3E4)};a.prototype._stopRegistrationTimer=function(){clearTimeout(this.regTimer)};a.prototype._setupStream=function(){var c=this;this.log("Setting up PStream");this.stream=this.options.pStreamFactory(this.token,{chunderw:this.options.chunderw,debug:this.options.debug,secureSignaling:this.options.secureSignaling});this.stream.addListener("connected",function(d){c._region={US_EAST_VIRGINIA:"us1",US_WEST_OREGON:"us2",ASIAPAC_SYDNEY:"au1",SOUTH_AMERICA_SAO_PAULO:"br1",EU_IRELAND:"ie1",ASIAPAC_TOKYO:"jp1",
  50. ASIAPAC_SINGAPORE:"sg1"}[d.region]||d.region;c._sendPresence()});this.stream.addListener("ready",function(){c.log("Stream is ready");"offline"==c._status&&(c._status="ready");c.emit("ready",c)});this.stream.addListener("offline",function(){c.log("Stream is offline");c._status="offline";c._region="offline";c.emit("offline",c)});this.stream.addListener("error",function(d){var a=d.error;a&&(d.callsid&&(a.connection=c._findConnection(d.callsid)),31205===a.code&&c._stopRegistrationTimer(),c.log("Received error: ",
  51. a),c.emit("error",a))});this.stream.addListener("invite",function(d){if("busy"==c._status)c.log("Device busy; ignoring incoming invite");else if(d.callsid&&d.sdp){var a=d.parameters||{};a.CallSid=a.CallSid||d.callsid;d=b(c,{},{offerSdp:d.sdp,callParameters:a});c.connections.push(d);c.emit("incoming",d)}else c.emit("error",{message:"Malformed invite from gateway"})})};a.prototype._removeConnection=function(c){for(var d=this.connections.length-1;0<=d;d--)c==this.connections[d]&&this.connections.splice(d,
  52. 1)};a.prototype._findConnection=function(c){for(var d=0;d<this.connections.length;d++){var a=this.connections[d];if(a.parameters.CallSid==c||a.outboundConnectionId==c)return a}};a=function(c){var d=[],b=[],e=function(d){if(c.instance)return d();b.push(d)},t=function(d){d=(d.code?d.code+": ":"")+d.message;if(c.instance){for(var a=0,e=c.instance.listeners("error"),b=0;b<e.length;b++)e[b]!==t&&a++;if(1<a)return;c.instance.log(d)}throw new f.Exception(d);},g={instance:null,setup:function(e,f){if(c.instance)c.instance.log("Found existing Device; using new token but ignoring options"),
  53. c.instance.token=e,c.instance.register(e);else{c.instance=new a(e,f);c.error(t);c.sounds=c.instance.sounds;for(var g=0;g<b.length;g++)b[g]();b=[]}for(g=0;g<d.length;g++)d[g](e,f);d=[];return c},connect:function(d,a){if("function"==typeof d)e(function(){c.instance.addListener("connect",d)});else{if(!c.instance)throw new f.Exception("Run Twilio.Device.setup()");if(0<c.instance.connections.length)c.instance.emit("error",{message:"A connection is currently active"});else return c.instance.connect(d,a)}},
  54. disconnectAll:function(){e(function(){c.instance.disconnectAll()});return c},disconnect:function(d){e(function(){c.instance.addListener("disconnect",d)});return c},status:function(){if(!c.instance)throw new f.Exception("Run Twilio.Device.setup()");return c.instance.status()},region:function(){if(!c.instance)throw new f.Exception("Run Twilio.Device.setup()");return c.instance.region()},ready:function(d){e(function(){c.instance.addListener("ready",d)});return c},error:function(d){e(function(){d!=t&&
  55. c.instance.removeListener("error",t);c.instance.addListener("error",d)});return c},offline:function(d){e(function(){c.instance.addListener("offline",d)});return c},incoming:function(d){e(function(){c.instance.addListener("incoming",d)});return c},destroy:function(){c.instance&&c.instance.destroy();return c},cancel:function(d){e(function(){c.instance.addListener("cancel",d)});return c},activeConnection:function(){return c.instance?c.instance.activeConnection():null}},q;for(q in g)c[q]=g[q];return c}(a);
  56. k.Device=a},{"./connection":3,"./log":7,"./options":8,"./pstream":9,"./rtc":11,"./sound":16,"./soundcache":17,"./util":19,events:21,util:37}],5:[function(h,m,k){function a(e,b,g){if(!(this instanceof a))return new a(e,b,g);g=Object.assign({defaultPayload:function(){return{}},host:"eventgw.twilio.com"},g);var n=g.defaultPayload;"function"!==typeof n&&(n=function(){return Object.assign({},g.defaultPayload)});var d=!0;Object.defineProperties(this,{_defaultPayload:{value:n},_isEnabled:{get:function(){return d},
  57. set:function(a){d=a}},_host:{value:g.host},isEnabled:{enumerable:!0,get:function(){return d}},productName:{enumerable:!0,value:e},token:{enumerable:!0,value:b}})}function b(a){return{timestamp:(new Date(a.timestamp)).toISOString(),total_packets_received:a.totals.packetsReceived,total_packets_lost:a.totals.packetsLost,total_packets_sent:a.totals.packetsSent,total_bytes_received:a.totals.bytesReceived,total_bytes_sent:a.totals.bytesSent,packets_received:a.packetsReceived,packets_lost:a.packetsLost,
  58. packets_lost_fraction:a.packetsLostFraction&&Math.round(100*a.packetsLostFraction)/100,audio_level_in:a.audioInputLevel,audio_level_out:a.audioOutputLevel,codec_name:a.codecName,local_candidate_address:a.candidatePair.localAddress,local_candidate_id:a.candidatePair.localCandidateId,local_candidate_type:a.candidatePair.localCandidateType,remote_candidate_address:a.candidatePair.remoteAddress,remote_candidate_id:a.candidatePair.remoteCandidateId,remote_candidate_type:a.candidatePair.remoteCandidateType,
  59. candidate_transport_type:a.candidatePair.transportType,jitter:a.jitter,rtt:a.rtt,mos:a.mos&&Math.round(100*a.mos)/100}}var g=h("./request");a.prototype._post=function(a,b,l,n,d,t){if(!this.isEnabled&&!t)return Promise.resolve();b={publisher:this.productName,group:l,name:n,timestamp:(new Date).toISOString(),level:b.toUpperCase(),payload_type:"application/json","private":!1,payload:d&&d.forEach?d.slice(0):Object.assign(this._defaultPayload(),d)};var q={url:"https://"+this._host+"/v2/"+a,body:b,headers:{"Content-Type":"application/json",
  60. "X-Twilio-Token":this.token}};return new Promise(function(c,d){g.post(q,function(a){a?d(a):c()})})};a.prototype.post=function(a,b,g,n,d){return this._post("EndpointEvents",a,b,g,n,d)};a.prototype.debug=function(a,b,g){return this.post("debug",a,b,g)};a.prototype.info=function(a,b,g){return this.post("info",a,b,g)};a.prototype.warn=function(a,b,g){return this.post("warning",a,b,g)};a.prototype.error=function(a,b,g){return this.post("error",a,b,g)};a.prototype.postMetrics=function(a,f,g,n){g=g.map(b).map(function(d){return Object.assign(d,
  61. n)});return this._post("EndpointMetrics","info",a,f,g)};a.prototype.enable=function(){this._isEnabled=!0};a.prototype.disable=function(){this._isEnabled=!1};m.exports=a},{"./request":10}],6:[function(h,m,k){function a(b){if(!(this instanceof a))return new a(b);b=b||{};var g=function(){},g={interval:10,now:function(){return(new Date).getTime()},repeat:function(a,b){return setInterval(a,b)},stop:function(a,b){return clearInterval(a,b)},onsleep:g,onwakeup:g},e;for(e in g)e in b||(b[e]=g[e]);this.interval=
  62. b.interval;this.lastbeat=0;this.pintvl=null;this.onsleep=b.onsleep;this.onwakeup=b.onwakeup;this.repeat=b.repeat;this.stop=b.stop;this.now=b.now}a.toString=function(){return"[Twilio.Heartbeat class]"};a.prototype.toString=function(){return"[Twilio.Heartbeat instance]"};a.prototype.beat=function(){this.lastbeat=this.now();if(this.sleeping()){if(this.onwakeup)this.onwakeup();var a=this;this.pintvl=this.repeat.call(null,function(){a.check()},1E3*this.interval)}};a.prototype.check=function(){var a=this.now()-
  63. this.lastbeat;if(!this.sleeping()&&a>=1E3*this.interval){if(this.onsleep)this.onsleep();this.stop.call(null,this.pintvl);this.pintvl=null}};a.prototype.sleeping=function(){return null==this.pintvl};k.Heartbeat=a},{}],7:[function(h,m,k){k.mixinLog=function(a,b){function g(){if(g.enabled)for(var a=g.prefix?g.prefix+" ":"",b=0;b<arguments.length;b++){var l=arguments[b];g.handler("string"==typeof l?a+l:l)}}g.enabled=!0;g.prefix=b||"";g.defaultHandler=function(a){"undefined"!==typeof console&&console.log(a)};
  64. g.handler=g.defaultHandler;g.warnings=!0;g.defaultWarnHandler=function(a){"undefined"!==typeof console&&("function"===typeof console.warn?console.warn(a):"function"===typeof console.log&&console.log(a))};g.warnHandler=g.defaultWarnHandler;g.deprecated=function(){if(g.warnings)for(var a=0;a<arguments.length;a++)g.warnHandler(arguments[a])};a.log=g}},{}],8:[function(h,m,k){h=function(){function a(g,e){if(!(this instanceof a))return new a(g);this.__dict__={};g=g||{};e=e||{};for(var f in g)this[f]=b(this.__dict__,
  65. f),this[f](g[f]);for(f in e)this[f](e[f])}function b(a,b){return function(f){return"undefined"==typeof f?a[b]:a[b]=f}}return a}();k.Options=h},{}],9:[function(h,m,k){function a(b,n){if(!(this instanceof a))return new a(b,n);e.monitorEventEmitter("Twilio.PStream",this);var d={logPrefix:"[PStream]",chunderw:"chunderw-vpc-gll.twilio.com",secureSignaling:!0,transportFactory:f,debug:!1};n=n||{};for(var t in d)t in n||(n[t]=d[t]);this.options=n;this.token=b||"";this.status="disconnected";this.host=this.options.chunderw;
  66. this.region=this.gateway=null;g.mixinLog(this,this.options.logPrefix);this.log.enabled=this.options.debug;this.on("error",function(){});var q=this;this.addListener("ready",function(){q.status="ready"});this.addListener("offline",function(){q.status="offline"});this.addListener("close",function(){q.destroy()});this.transport=this.options.transportFactory({host:this.host,debug:this.options.debug,secureSignaling:this.options.secureSignaling});this.transport.onopen=function(){q.status="connected";q.setToken(q.token)};
  67. this.transport.onclose=function(){"disconnected"!=q.status&&("offline"!=q.status&&q.emit("offline",q),q.status="disconnected")};this.transport.onerror=function(c){q.emit("error",c)};this.transport.onmessage=function(c){c=e.splitObjects(c.data);for(var d=0;d<c.length;d++){var a=JSON.parse(c[d]),b=a.type,a=a.payload||{};a.gateway&&(q.gateway=a.gateway);a.region&&(q.region=a.region);q.emit(b,a)}};this.transport.open();return this}m=h("events").EventEmitter;var b=h("util"),g=h("./log"),e=h("./util");
  68. h("./rtc");h("./heartbeat");var f=h("./wstransport").WSTransport;b.inherits(a,m);a.toString=function(){return"[Twilio.PStream class]"};a.prototype.toString=function(){return"[Twilio.PStream instance]"};a.prototype.setToken=function(a){this.log("Setting token and publishing listen");this.token=a;a={token:a,browserinfo:e.getSystemInfo()};this.publish("listen",a)};a.prototype.register=function(a){this.publish("register",{media:a})};a.prototype.destroy=function(){this.log("Closing PStream");this.transport.close();
  69. return this};a.prototype.publish=function(a,b){var d=JSON.stringify({type:a,version:e.getPStreamVersion(),payload:b});this.transport.send(d)};k.PStream=a},{"./heartbeat":6,"./log":7,"./rtc":11,"./util":19,"./wstransport":20,events:21,util:37}],10:[function(h,m,k){var a="undefined"===typeof XMLHttpRequest?h("xmlhttprequest").XMLHttpRequest:XMLHttpRequest;h=function(b,g,e){var f;f=f||a;var l=new f;l.open(b,g.url,!0);l.onreadystatechange=function(){4===l.readyState&&(200<=l.status&&300>l.status?e(null,
  70. l.responseText):e(Error(l.responseText)))};for(var n in g.headers)l.setRequestHeader(n,g.headers[n]);l.send(JSON.stringify(g.body))};h.get=function(a,g){return new this("GET",a,g)};h.post=function(a,g){return new this("POST",a,g)};m.exports=h},{xmlhttprequest:39}],11:[function(h,m,k){var a=h("./peerconnection");m.exports={enabled:function(b){"undefined"!==typeof b&&(a.enabled=b);return a.enabled},getMediaEngine:function(){return"undefined"!==typeof RTCIceGatherer?"ORTC":"WebRTC"},PeerConnection:a}},
  71. {"./peerconnection":14}],12:[function(h,m,k){function a(d){if(!(this instanceof a))return new a(d);d=d||{};var b=Object.assign({},n,d.thresholds);Object.defineProperties(this,{_activeWarnings:{value:new Map},_currentStreaks:{value:new Map},_peerConnection:{value:d.peerConnection,writable:!0},_sampleBuffer:{value:[]},_sampleInterval:{value:null,writable:!0},_thresholds:{value:b},_warningsEnabled:{value:!0,writable:!0}});d.peerConnection&&this.enable();e.call(this)}function b(d,a){return a.reduce(function(a,
  72. c){return a+(c<d?1:0)},0)}function g(d,a){return a.reduce(function(a,c){return a+(c>d?1:0)},0)}var e=h("events").EventEmitter,f=h("./stats");k=h("util").inherits;var l=h("./mos"),n={audioInputLevel:{maxDuration:10},audioOutputLevel:{maxDuration:10},packetsLostFraction:{max:1},jitter:{max:30},rtt:{max:400},mos:{min:3}};k(a,e);a.createSample=function(d,a){var b=d.packetsReceived-(a&&a.totals.packetsReceived||0),c=d.packetsLost-(a&&a.totals.packetsLost||0),e=b+c,e=0<e?c/e*100:100,g=d.packetsReceived+
  73. d.packetsLost;return{timestamp:d.timestamp,totals:{packetsReceived:d.packetsReceived,packetsLost:d.packetsLost,packetsSent:d.packetsSent,packetsLostFraction:0<g?d.packetsLost/g*100:100,bytesReceived:d.bytesReceived,bytesSent:d.bytesSent},candidatePair:{localAddress:d.localAddress,localCandidateId:d.localCandidateId,localCandidateType:d.localCandidateType,remoteAddress:d.remoteAddress,remoteCandidateId:d.remoteCandidateId,remoteCandidateType:d.remoteCandidateType,transportType:d.transportType},packetsSent:d.packetsSent-
  74. (a&&a.totals.packetsSent||0),packetsReceived:b,packetsLost:c,packetsLostFraction:e,audioInputLevel:d.audioInputLevel,audioOutputLevel:d.audioOutputLevel,codecName:d.codecName,jitter:d.jitter,rtt:d.rtt,mos:l.calculate(d,a&&e)}};a.prototype.enable=function(d){if(d){if(this._peerConnection&&d!==this._peerConnection)throw Error("Attempted to replace an existing PeerConnection in RTCMonitor.enable");this._peerConnection=d}if(!this._peerConnection)throw Error("Can not enable RTCMonitor without a PeerConnection");
  75. this._sampleInterval=this._sampleInterval||setInterval(this._fetchSample.bind(this),1E3);return this};a.prototype.disable=function(){clearInterval(this._sampleInterval);this._sampleInterval=null;return this};a.prototype.getSample=function(){var d=this._peerConnection,b=this;return new Promise(function(e,c){f(d,function(d,g){d?c(d):e(a.createSample(g,b._sampleBuffer.length&&b._sampleBuffer[b._sampleBuffer.length-1]))})})};a.prototype._fetchSample=function(d){var a=this;return this.getSample().then(function(d){a._addSample(d);
  76. a._raiseWarnings();a.emit("sample",d);return d},function(d){a.disable();a.emit("error",d)})};a.prototype._addSample=function(d){var a=this._sampleBuffer;a.push(d);5<a.length&&a.splice(0,a.length-5)};a.prototype._raiseWarnings=function(){if(this._warningsEnabled)for(var d in this._thresholds)this._raiseWarningsForStat(d)};a.prototype.enableWarnings=function(){this._warningsEnabled=!0;return this};a.prototype.disableWarnings=function(){this._warningsEnabled&&this._activeWarnings.clear();this._warningsEnabled=
  77. !1;return this};a.prototype._raiseWarningsForStat=function(d){var a=this._sampleBuffer,e=this._thresholds[d],c=a.slice(-5),c=c.map(function(c){return c[d]});if(!c.some(function(c){return"undefined"===typeof c||null===c})){if("number"===typeof e.max){var f=g(e.max,c);3<=f?this._raiseWarning(d,"max",{values:c}):0>=f&&this._clearWarning(d,"max",{values:c})}"number"===typeof e.min&&(f=b(e.min,c),3<=f?this._raiseWarning(d,"min",{values:c}):0>=f&&this._clearWarning(d,"min",{values:c}));"number"===typeof e.maxDuration&&
  78. 1<a.length&&(c=a.slice(-2),a=c[0][d],f=c[1][d],c=this._currentStreaks.get(d)||0,a=a===f?c+1:0,this._currentStreaks.set(d,a),a>=e.maxDuration?this._raiseWarning(d,"maxDuration",{value:a}):0===a&&this._clearWarning(d,"maxDuration",{value:c}))}};a.prototype._clearWarning=function(a,b,e){var c=a+":"+b,f=this._activeWarnings.get(c);!f||5E3>Date.now()-f.timeRaised||(this._activeWarnings["delete"](c),this.emit("warning-cleared",Object.assign({name:a,threshold:{name:b,value:this._thresholds[a][b]}},e)))};
  79. a.prototype._raiseWarning=function(a,b,e){var c=a+":"+b;this._activeWarnings.has(c)||(this._activeWarnings.set(c,{timeRaised:Date.now()}),this.emit("warning",Object.assign({name:a,threshold:{name:b,value:this._thresholds[a][b]}},e)))};m.exports=a},{"./mos":13,"./stats":15,events:21,util:37}],13:[function(h,m,k){m.exports={calculate:function(a,b){if(!a||"number"!==typeof a.rtt||"number"!==typeof a.jitter||"number"!==typeof a.packetsLost||"number"!==typeof b)return null;var g,e=a.rtt+2*a.jitter+10;
  80. g=0;switch(!0){case 160>e:g=94.768-e/40;break;case 1E3>e:g=94.768-(e-120)/10;break;case 1E3<=e:g=94.768-e/100}e=.01;switch(!0){case -1===b:g=e=0;break;case b<=g/2.5:e=2.5;break;case b>g/2.5&&100>b:e=.25}g-=b*e;g=1+.035*g+7E-6*g*(g-60)*(100-g);return 1<=g&&4.6>g?g:null}}},{}],14:[function(h,m,k){function a(d,b){if(!(this instanceof a))return new a(d,b);var e=function(){};this.onicecandidate=this.oniceconnectionstatechange=this.onsignalingstatechange=this.onreconnect=this.ondisconnect=this.onclose=
  81. this.onerror=this.onopen=e;this.version=null;this.pstream=b.stream;this.stream=null;this.video="undefined"!==typeof document&&document.createElement("video");this.video.autoplay="autoplay";this.device=b;this.status="connecting";this._dtmfSender=this.callSid=null;this._dtmfSenderUnsupported=!1;this._callEvents=[];this._nextTimeToPublish=Date.now();this._onAnswer=e;g.mixinLog(this,"[Twilio.PeerConnection]");this.log.enabled=this.device.options.debug;this.log.warnings=this.device.options.warnings;this._iceConnectionStateMachine=
  82. new f(l,"new");this._signalingStateMachine=new f(n,"stable");return this}function b(a){"function"===typeof MediaStreamTrack.prototype.stop?("function"===typeof a.getAudioTracks?a.getAudioTracks():a.audioTracks).forEach(function(a){a.stop()}):a.stop()}var g=h("../log"),e=h("ortc-adapter");h("stacktrace-js");var f=h("../statemachine");h("../util");var l={"new":["checking","closed"],checking:["new","connected","failed","closed","completed"],connected:["new","disconnected","completed","closed"],completed:["new",
  83. "disconnected","closed","completed"],failed:["new","disconnected","closed"],disconnected:["connected","completed","failed","closed"],closed:[]},n={stable:["have-local-offer","have-remote-offer","closed"],"have-local-offer":["stable","closed"],"have-remote-offer":["stable","closed"],closed:[]};a.prototype.uri=function(){return this._uri};a.prototype.openHelper=function(d,b){var e=this;a.getUserMedia({audio:b},function(c){e.stream=c;d()},function(c){c.code&&c.code===c.PERMISSION_DENIED||c.name&&"PermissionDeniedError"===
  84. c.name?d({error:c,message:"User denied access to microphone, or the web browser did not allow microphone access at this address.",code:31208}):d({error:c,message:"Error occurred while accessing microphone: "+c.name+(c.message?" ("+c.message+")":""),code:31201})})};a.prototype._setupPeerConnection=function(d,b){var e=a.protocol;e.create(this.log,d,b);e.pc.addStream(this.stream);var c=this;e.pc.onaddstream=function(a){"undefined"!==typeof c.video.srcObject?c.video.srcObject=a.stream:"undefined"!==typeof c.video.mozSrcObject?
  85. c.video.mozSrcObject=a.stream:"undefined"!==typeof c.video.src?c.video.src=(window.URL||window.webkitURL).createObjectURL(a.stream):c.log("Error attaching stream to element.")};return e};a.prototype._setupChannel=function(){var a=this,b=this.version.pc;a.version.pc.onopen=function(){a.status="open";a.onopen()};a.version.pc.onstatechange=function(b){a.version.pc&&"stable"==a.version.pc.readyState&&(a.status="open",a.onopen())};a.version.pc.onsignalingstatechange=function(e){e=b.signalingState;a.log('signalingState is "'+
  86. e+'"');try{a._signalingStateMachine.transition(e)}catch(c){}a.version.pc&&"stable"==a.version.pc.signalingState&&(a.status="open",a.onopen());a.onsignalingstatechange(b.signalingState)};b.onicecandidate=function(b){a.onicecandidate(b.candidate)};b.oniceconnectionstatechange=function(){var e=b.iceConnectionState,c=a._iceConnectionStateMachine.currentState;try{a._iceConnectionStateMachine.transition(e)}catch(f){}switch(e){case "connected":"disconnected"===c&&(c="ICE liveliness check succeeded. Connection with Twilio restored",
  87. a.log(c),a.onreconnect(c));break;case "disconnected":c="ICE liveliness check failed. May be having trouble connecting to Twilio";a.log(c);a.ondisconnect(c);break;case "failed":c=("checking"===c?"ICE negotiation with Twilio failed.":"Connection with Twilio was interrupted.")+" Call will terminate.";a.log(c);a.onerror({info:{code:31003,message:c},disconnect:!0});break;default:a.log('iceConnectionState is "'+e+'"')}a.oniceconnectionstatechange(e)}};a.prototype._initializeMediaStream=function(a,b){if("open"==
  88. this.status)return!1;if("disconnected"==this.pstream.status)return this.onerror({info:{code:31E3,message:"Cannot establish connection. Client is disconnected"}}),this.close(),!1;this.version=this._setupPeerConnection(a,b);this._setupChannel();return!0};a.prototype.makeOutgoingCall=function(a,b,e,c,f){if(this._initializeMediaStream(e,c)){var g=this;this.callSid=b;var l=function(){f(g.version.pc)},u=function(c){g.onerror({info:{code:31E3,message:"Error processing answer: "+(c.message||c)}})};this._onAnswer=
  89. function(c){"closed"!=g.status&&g.version.processAnswer(c.sdp,l,u)};this.pstream.once("answer",this._onAnswer);this.version.createOffer({audio:!0},function(){"closed"!=g.status&&g.pstream.publish("invite",{sdp:g.version.getSDP(),callsid:g.callSid,twilio:{params:a}})},function(c){g.onerror({info:{code:31E3,message:"Error creating the offer: "+(c.message||c)}})})}};a.prototype.answerIncomingCall=function(a,b,e,c,g){if(this._initializeMediaStream(e,c)){this.callSid=a;var f=this;this.version.processSDP(b,
  90. {audio:!0},function(){"closed"!=f.status&&(f.pstream.publish("answer",{callsid:a,sdp:f.version.getSDP()}),g(f.version.pc))},function(c){f.onerror({info:{code:31E3,message:"Error creating the answer: "+(c.message||c)}})})}};a.prototype.close=function(){this.version&&this.version.pc&&("closed"!==this.version.pc.signalingState&&this.version.pc.close(),this.version.pc=null);this.stream&&(b(this.stream),this.stream=null);this.pstream&&this.pstream.removeListener("answer",this._onAnswer);this.video.src=
  91. "";this.status="closed";this.onclose()};a.prototype.reject=function(a){this.callSid=a};a.prototype.ignore=function(a){this.callSid=a};a.prototype.attachAudio=function(a){this.stream&&(("function"===typeof this.stream.getAudioTracks?this.stream.getAudioTracks():this.stream.audioTracks)[0].enabled=!0);a&&"function"==typeof a&&a()};a.prototype.detachAudio=function(a){this.stream&&(("function"===typeof this.stream.getAudioTracks?this.stream.getAudioTracks():this.stream.audioTracks)[0].enabled=!1);a&&
  92. "function"==typeof a&&a()};a.prototype.isAudioAttached=function(){return this.stream?("function"===typeof this.stream.getAudioTracks?this.stream.getAudioTracks():this.stream.audioTracks)[0].enabled:!1};a.getUserMedia=function(a,b,e){"undefined"!=typeof navigator&&("function"==typeof navigator.webkitGetUserMedia?navigator.webkitGetUserMedia(a,b,e):"function"==typeof navigator.mozGetUserMedia?navigator.mozGetUserMedia(a,b,e):"function"===typeof navigator.getUserMedia?navigator.getUserMedia(a,b,e):this.log("No getUserMedia() implementation available"))};
  93. a.prototype.getOrCreateDTMFSender=function(){if(this._dtmfSender)return this._dtmfSender;if(this._dtmfSenderUnsupported)return null;var a=this.version.pc;if(!a)return this.log("No RTCPeerConnection available to call createDTMFSender on"),null;if("function"!==typeof a.createDTMFSender)return this.log("RTCPeerConnection does not support createDTMFSender"),this._dtmfSenderUnsupported=!0,null;for(var b=a.getLocalStreams(),e,c,f=0;f<b.length;f++)if(e=b[f],e="function"===typeof e.getAudioTracks?e.getAudioTracks():
  94. e.audioTracks,e.length){c=e[0];break}if(!c)return this.log("No local audio MediaStreamTrack available on the RTCPeerConnection to pass to createDTMFSender"),null;this.log("Creating RTCDTMFSender");return this._dtmfSender=a=a.createDTMFSender(c)};h=function(){"undefined"!=typeof window&&("function"==typeof window.webkitRTCPeerConnection?this.RTCPeerConnection=webkitRTCPeerConnection:"function"==typeof window.mozRTCPeerConnection?(this.RTCPeerConnection=mozRTCPeerConnection,RTCSessionDescription=mozRTCSessionDescription,
  95. RTCIceCandidate=mozRTCIceCandidate):"undefined"!==typeof RTCIceGatherer?(this.RTCPeerConnection=e.RTCPeerConnection,RTCSessionDescription=e.RTCSessionDescription,RTCIceCandidate=e.RTCIceCandidate):this.log("No RTCPeerConnection implementation available"))};h.prototype.create=function(a,b,e){this.log=a;this.pc=new this.RTCPeerConnection({iceServers:e},b)};h.prototype.createModernConstraints=function(a){if("undefined"===typeof a)return null;var b={};"undefined"!==typeof webkitRTCPeerConnection?(b.mandatory=
  96. {},"undefined"!==typeof a.audio&&(b.mandatory.OfferToReceiveAudio=a.audio),"undefined"!==typeof a.video&&(b.mandatory.OfferToReceiveVideo=a.video)):("undefined"!==typeof a.audio&&(b.offerToReceiveAudio=a.audio),"undefined"!==typeof a.video&&(b.offerToReceiveVideo=a.video));return b};h.prototype.createOffer=function(a,b,e){var c=this;this.pc.createOffer(function(a){c.pc&&c.pc.setLocalDescription(new RTCSessionDescription(a),b,e)},e,this.createModernConstraints(a))};h.prototype.createAnswer=function(a,
  97. b,e){var c=this;this.pc.createAnswer(function(a){c.pc&&c.pc.setLocalDescription(new RTCSessionDescription(a),b,e)},e,this.createModernConstraints(a))};h.prototype.processSDP=function(a,b,e,c){var f=this;this.pc.setRemoteDescription(new RTCSessionDescription({sdp:a,type:"offer"}),function(){f.createAnswer(b,e,c)},c)};h.prototype.getSDP=function(){return this.pc.localDescription.sdp};h.prototype.processAnswer=function(a,b,e){this.pc&&this.pc.setRemoteDescription(new RTCSessionDescription({sdp:a,type:"answer"}),
  98. b,e)};h.test=function(){if("object"==typeof navigator){if(navigator.webkitGetUserMedia&&"function"==typeof window.webkitRTCPeerConnection)return!0;if(navigator.mozGetUserMedia&&"function"==typeof window.mozRTCPeerConnection){try{if("function"!==typeof(new window.mozRTCPeerConnection).getLocalStreams)return!1}catch(a){return!1}return!0}if("undefined"!==typeof RTCIceGatherer)return!0}};h=h.test()?new h:null;a.protocol=h;a.enabled=!!a.protocol;m.exports=a},{"../log":7,"../statemachine":18,"../util":19,
  99. "ortc-adapter":22,"stacktrace-js":34}],15:[function(h,m,k){function a(a,g){var l=[],c=[];a.result().forEach(function(a){var d=null;switch(a.type){case "googCandidatePair":a:{for(var d={},f={},g=a.names(),n=a.timestamp?Number(a.timestamp):null,p=0;p<g.length;p++){var t=g[p],h=a.stat(t);switch(t){case "googActiveConnection":if("true"!==h){d=null;break a}break;case "googLocalAddress":d.localAddress=h;break;case "googRemoteAddress":d.remoteAddress=h;break;case "googLocalCandidateType":d.localCandidateType=
  100. h;break;case "googRemoteCandidateType":d.remoteCandidateType=h;break;case "googTransportType":d.transportType=h;break;case "localCandidateId":d.localCandidateId=h;break;case "remoteCandidateId":d.remoteCandidateId=h;break;case "googRtt":d.rtt=Number(h);break;case "":break;default:f[t]=h}}d.timestamp=n;d=e(d,f)}break;case "ssrc":d=b(a);break;default:c.push(a)}d&&l.push(d)});if(0===l.length||0===(l=f(l)).length)return g(null,{});var n=l.reduceRight(function(a,c){for(var b in c)a[b]=c[b];return a},{});
  101. g(null,n)}function b(a){var b={},f={},c=a.names(),g=a.timestamp?Number(a.timestamp):null;c.forEach(function(c){var e=a.stat(c);switch(c){case "googCodecName":""!==e&&(b.codecName=e);break;case "googJitterBufferMs":b.googJitterBufferMs=Number(e);break;case "googJitterReceived":c=Number(e);-1!==c&&(b.jitter=c);break;case "bytesReceived":case "bytesSent":case "packetsReceived":case "packetsSent":case "timestamp":case "audioInputLevel":case "audioOutputLevel":b[c]=Number(e);break;case "packetsLost":e=
  102. Number(e);-1!==e&&(b[c]=e);break;default:f[c]=e}});b.timestamp=g;return e(b,f)}function g(a,b){var g=[],c=[];a.forEach(function(a){var b=null;switch(a.type){case "inboundrtp":var d={},b={},f;for(f in a){var l=a[f];switch(f){case "mozRtt":d.rtt=l;break;case "timestamp":d.timestamp=l?Number(l):null;break;case "jitter":d[f]=1E3*l;break;case "bytesReceived":case "packetsLost":case "packetsReceived":d[f]=l;break;default:b[f]=l}}b=e(d,b);break;case "outboundrtp":if(!1===a.isRemote){f={};b={};for(d in a)switch(l=
  103. a[d],d){case "timestamp":f.timestamp=l?Number(l):null;case "bytesSent":case "packetsSent":f[d]=l;break;default:b[d]=l}b=e(f,b)}break;default:c.push(a)}b&&g.push(b)});if(0===g.length||0===(g=f(g)).length)return b(null,{});var l=g.reduceRight(function(a,c){for(var b in c)a[b]=c[b];return a},{});b(null,l)}function e(a,b){var e=null;l(a)||(e=e||{},e.known=a);l(b)||(e=e||{},e.unknown=b);return e}function f(a){for(var b=[],e=0;e<a.length;e++){var c=a[e];c.known&&b.push(c.known)}return b}function l(a){if(!a)return!0;
  104. for(var b in a)return!1;return!0}function n(a,b){return function(){var e=Array.prototype.slice.call(arguments);e.push(b);return a.apply(null,e)}}m.exports=function(b,e){var f=Error("WebRTC statistics are unsupported");b?"undefined"===typeof navigator||"function"!==typeof b.getStats?e(f):navigator.webkitGetUserMedia?b.getStats(n(a,e),e):navigator.mozGetUserMedia?b.getStats(null,n(g,e),e):e(f):e(Error("PeerConnection is null"))}},{}],16:[function(h,m,k){function a(b){if(!(this instanceof a))return new a(b);
  105. this.id=a.nextId++;this.maxDuration=b.maxDuration;a.items[this.id]=this;this.create(!!b.loop);return this}h={create:function(a){this.audio=document.createElement("audio");this.audio.loop=a;this.playing=!1;var b=this;this.audio.addEventListener("ended",function(){b.playing=!1})},buffer:function(){},play:function(){if(!this.playing){var a=this.audio;this.rewind();var b=this,f=this.maxDuration;f&&f<1E3*a.duration&&setTimeout(function(){a.pause();b.playing=!1},f);this.playing=!0;a.play()}},load:function(a){this.audio.src=
  106. a},stop:function(){this.playing=!1;this.audio.pause();this.rewind()},destroy:function(){this.audio.src="";delete this.audio},rewind:function(){this.audio.currentTime=0;this.audio.currentTime&&this.audio.load()}};m={create:function(){},buffer:function(a){},play:function(){},load:function(a){},stop:function(){},destroy:function(){}};if("undefined"===typeof window)for(var b in m)a.prototype[b]=m[b];else a.prototype=h;a.nextId=0;a.debug=!1;a.tasks=[];a.items={};k.Sound=a},{}],17:[function(h,m,k){function a(a,
  107. b){return function(){var f=Array.prototype.slice(arguments);b.apply(a,f)}}function b(){if(!(this instanceof b))return new b;this.cache={}}b.prototype.add=function(a,b,f){f=f||{};if(!(f instanceof Object))throw new TypeError("Bad envelope type; expected Object");b instanceof Array||(b=[b]);this.cache[a]={starttime:null,sounds:b,envelope:f}};b.prototype.play=function(a,b,f){b=b||0;f=f||1;if(a in this.cache){a=this.cache[a];for(var l=0;l<a.sounds.length;l++)a.sounds[l].play(b,f);a.starttime=(new Date).getTime()}};
  108. b.prototype.stop=function(a){if(a in this.cache){var b=this.cache[a];a=b.envelope.release||0;var f=function(){for(var a=0;a<b.sounds.length;a++)b.sounds[a].stop()},l=(new Date).getTime(),l=Math.max(0,a-(l-b.starttime));0==a?f():setTimeout(f,l)}};b.prototype.envelope=function(a,b){if(a in this.cache){var f=this.cache[a],l;for(l in b)f.envelope[l]=b[l]}};b.prototype.playseq=function(){var b=null,e=[],f=function(){var l=e.shift();if(l){var n=l[0],d=l[1]||0,l=l[2]||0;n in this.cache&&this.play(n);b=setTimeout(a(this,
  109. f),d+l)}else b=null};return function(l){for(var n=0;n<l.length;n++)e.push(l[n]);null==b&&(b=setTimeout(a(this,f),0))}}();k.SoundCache=b},{}],18:[function(h,m,k){function a(b,f){if(!(this instanceof a))return new a(b,f);var g=f;Object.defineProperties(this,{_currentState:{get:function(){return g},set:function(a){g=a}},currentState:{enumerable:!0,get:function(){return g}},states:{enumerable:!0,value:b},transitions:{enumerable:!0,value:[]}});Object.freeze(this)}function b(a,b){Object.defineProperties(this,
  110. {from:{enumerable:!0,value:a},to:{enumerable:!0,value:b}})}function g(a,f){if(!(this instanceof g))return new g(a,f);Error.call(this);b.call(this,a,f);Object.defineProperties(this,{message:{enumerable:!0,value:"Invalid transition from "+("string"===typeof a?'"'+a+'"':"null")+' to "'+f+'"'}});Object.freeze(this)}h=h("util").inherits;a.prototype.transition=function(a){var f=this.currentState,l=this.states[f],f=l&&-1!==l.indexOf(a)?new b(f,a):new g(f,a);this.transitions.push(f);this._currentState=a;
  111. if(f instanceof g)throw f;return this};h(g,Error);m.exports=a},{util:37}],19:[function(h,m,k){function a(c){if(!(this instanceof a))return new a(c);this.message=c}function b(a){return function(){var c=Array.prototype.slice.call(arguments,0);a.memo=a.memo||{};return a.memo[c]?a.memo[c]:a.memo[c]=a.apply(null,c)}}function g(b){b=b.split(".");if(3!=b.length)throw new a("Wrong number of segments");return c(b[1])}function e(a){if(""==a)return{};if(-1==a.indexOf("&")&&-1==a.indexOf("="))return a;a=a.split("&");
  112. for(var c={},b=0;b<a.length;b++){var d=a[b].split("=");c[decodeURIComponent(d[0])]=e(decodeURIComponent(d[1]))}return c}function f(a){try{return btoa(a)}catch(c){return(new Buffer(a)).toString("base64")}}function l(a){try{return atob(a)}catch(c){try{return(new Buffer(a,"base64")).toString("ascii")}catch(b){return base64.decode(a)}}}function n(a){var c=[],b;for(b in a){var d="object"==typeof a[b]?n(a[b]):a[b];c.push(encodeURIComponent(b)+"="+encodeURIComponent(d))}return c.join("&")}function d(a,c){return a===
  113. c?!0:typeof a!==typeof c?!1:a instanceof Date&&c instanceof Date?a.getTime()===c.getTime():"object"!==typeof a&&"object"!==typeof c?a==c:t(a,c)}function t(a,c){if(void 0===a||null===a||void 0===c||null===c||a.prototype!==c.prototype)return!1;try{var b=y(a),e=y(c)}catch(f){return!1}if(b.length!==e.length)return!1;b.sort();e.sort();for(e=b.length-1;0<=e;e--){var g=b[e];if(!d(a[g],c[g]))return!1}return!0}var q=h("events").EventEmitter;a.prototype.toString=function(){return"Twilio.Exception: "+this.message};
  114. var c=b(function(a){var c=a.length%4;0<c&&(a+=Array(4-c+1).join("="));a=a.replace(/-/g,"+").replace(/_/g,"/");a=l(a);return JSON.parse(a)});m=b(function(c){c=g(c);for(var b=0===c.scope.length?[]:c.scope.split(" "),d={},f=0;f<b.length;f++){var l;l=b[f].match(/^scope:(\w+):(\w+)\??(.*)$/);if(!l||4!=l.length)throw new a("Bad scope URI");l={service:l[1],privilege:l[2],params:e(l[3])};d[l.service+":"+l.privilege]=l}c.scope=d;return c});var p=function(){function a(){this.set={}}a.prototype.clear=function(){this.set=
  115. {}};a.prototype.put=function(c){return this.set[c]=a.DUMMY};a.prototype.del=function(a){return delete this.set[a]};a.prototype.map=function(a,c){var b=[],d;for(d in this.set)b.push(a.call(c,d));return b};a.DUMMY={};return a}(),w="",y="function"===typeof Object.keys?Object.keys:function(a){var c=[],b;for(b in a)c.push(b);return c};k.getPStreamVersion=function(){return"1.3"};k.getReleaseVersion=function(){return"1.3.16"};k.getSoundVersion=function(){return"1.0.0"};k.encodescope=function(a,c,b){a=["scope",
  116. a,c].join(":");c=!0;for(var d in b){c=!1;break}return c?a:a+"?"+n(b)};k.dummyToken=function(a){var c={iss:"AC1111111111111111111111111111111",exp:14E8},b;for(b in c)a[b]=a[b]||c[b];a=f(JSON.stringify(a));a=a.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");return["*",a,"*"].join(".")};k.Exception=a;k.decode=g;k.btoa=f;k.atob=l;k.objectize=m;k.urlencode=function(a,c){var b=[];c=c||!1;for(var d in a)if(c&&a[d]instanceof Array)for(var e in a[d]){var f=a[d][e];b.push(encodeURIComponent(d)+"="+encodeURIComponent(f))}else f=
  117. a[d],b.push(encodeURIComponent(d)+"="+encodeURIComponent(f));return b.join("&")};k.Set=p;k.bind=function(a,c){var b=Array.prototype.slice.call(arguments,2);return function(){var d=Array.prototype.slice.call(arguments);return a.apply(c,b.concat(d))}};k.getSystemInfo=function(){h("./rtc");var a="undefined"!=typeof navigator?navigator:{};return{p:"browser",v:"1.3",h:"a95f379",browser:{userAgent:a.userAgent||"unknown",platform:a.platform||"unknown"},plugin:"rtc"}};k.splitObjects=function(a,c){var b;b=
  118. "string"!=typeof a?"":a.trim?a.trim():a.replace(/^\s+|\s+$/g,"");return 0==b.length?[]:b.split("\n")};k.generateConnectionUUID=function(){return"TJSxxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)})};k.getTwilioRoot=function(){return w};k.setTwilioRoot=function(a){w=a};k.monitorEventEmitter=function(a,c){function b(d){var e=q.listenerCount(c,d);d="The number of "+d+" listeners on "+a+" exceeds the recommended number of 10. While twilio.js will continue to function normally, this may be indicative of an application error. Note that "+
  119. d+" listeners exist for the lifetime of the "+a+".";10<=e&&("undefined"!==typeof console&&(console.warn?console.warn(d):console.log&&console.log(d)),c.removeListener("newListener",b))}c.setMaxListeners(0);c.on("newListener",b)};k.deepEqual=d},{"./rtc":11,events:21}],20:[function(h,m,k){function a(b){var e=this instanceof a?this:new a(b);e.sock=null;var n=function(){};e.onopen=n;e.onclose=n;e.onmessage=n;e.onerror=n;n={logPrefix:"[WSTransport]",chunderw:"chunderw-vpc-gll.twilio.com",reconnect:!0,debug:!1,
  120. secureSignaling:!0};b=b||{};for(var d in n)d in b||(b[d]=n[d]);e.options=b;g.mixinLog(e,e.options.logPrefix);e.log.enabled=e.options.debug;e.defaultReconnect=e.options.reconnect;e.uri=(e.options.secureSignaling?"wss://":"ws://")+e.options.host+"/signal";return e}var b=h("./heartbeat").Heartbeat,g=h("./log"),e=h("ws");a.prototype.msgQueue=[];a.prototype.open=function(a){this.log("Opening socket");this.sock&&2>this.sock.readyState?this.log("Socket already open."):(this.options.reconnect=this.defaultReconnect,
  121. this.heartbeat&&(this.heartbeat.onsleep=function(){}),this.heartbeat=new b({interval:15}),this.sock=this._connect(a))};a.prototype.send=function(a){if(this.sock)if(0==this.sock.readyState)this.msgQueue.push(a);else try{this.sock.send(a)}catch(b){this.log("Error while sending. Closing socket: "+b.message),this.sock.close()}};a.prototype.close=function(){this.log("Closing socket");this.options.reconnect=!1;this.sock&&(this.sock.close(),this.sock=null);this.heartbeat.onsleep=function(){}};a.prototype._cleanupSocket=
  122. function(a){if(a){this.log("Cleaning up socket");var b=function(){};a.onopen=function(){a.close()};a.onmessage=b;a.onerror=b;a.onclose=b;2>a.readyState&&a.close()}};a.prototype._connect=function(a){var b=++a||1;this.log("attempting to connect");var g=null;try{g=new e(this.uri)}catch(p){this.onerror({code:31E3,message:p.message||"Could not connect to "+this.uri});this.close();return}var d=this,h=this.sock,q=null,c=setTimeout(function(){d.log("connection attempt timed out");g.onclose=function(){};g.close();
  123. d.onclose();d._tryReconnect(b)},5E3);g.onopen=function(){clearTimeout(c);d._cleanupSocket(h);q=(new Date).getTime();d.log("Socket opened");d.heartbeat.onsleep=function(){d.log("Heartbeat timed out. closing socket");d.sock.onclose=function(){};d.sock.close();d.onclose();d._tryReconnect(b)};d.heartbeat.beat();d.onopen();for(var a=0;a<d.msgQueue.length;a++)d.sock.send(d.msgQueue[a]);d.msgQueue=[]};g.onclose=function(){clearTimeout(c);d._cleanupSocket(h);d.heartbeat.onsleep=function(){};q&&10<((new Date).getTime()-
  124. q)/1E3&&(b=1);d.log("Socket closed");d.onclose();d._tryReconnect(b)};g.onerror=function(a){d.log("Socket received error: "+a.message);d.onerror({code:31E3,message:a.message||"WSTransport socket error"})};g.onmessage=function(a){d.heartbeat.beat();if("\n"==a.data)d.send("\n");else d.onmessage(a)};return g};a.prototype._tryReconnect=function(a){a=a||0;if(this.options.reconnect){this.log("Attempting to reconnect.");var b=this,e=0,e=5>a?30+Math.round(50*Math.random()*Math.pow(2,a)):3E3;setTimeout(function(){b.open(a)},
  125. e)}};k.WSTransport=a},{"./heartbeat":6,"./log":7,ws:38}],21:[function(h,m,k){function a(){this._events=this._events||{};this._maxListeners=this._maxListeners||void 0}function b(a){return"function"===typeof a}function g(a){return"object"===typeof a&&null!==a}m.exports=a;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._maxListeners=void 0;a.defaultMaxListeners=10;a.prototype.setMaxListeners=function(a){if("number"!==typeof a||0>a||isNaN(a))throw TypeError("n must be a positive number");this._maxListeners=
  126. a;return this};a.prototype.emit=function(a){var f,l,n,d;this._events||(this._events={});if("error"===a&&(!this._events.error||g(this._events.error)&&!this._events.error.length)){f=arguments[1];if(f instanceof Error)throw f;l=Error('Uncaught, unspecified "error" event. ('+f+")");l.context=f;throw l;}l=this._events[a];if(void 0===l)return!1;if(b(l))switch(arguments.length){case 1:l.call(this);break;case 2:l.call(this,arguments[1]);break;case 3:l.call(this,arguments[1],arguments[2]);break;default:f=
  127. Array.prototype.slice.call(arguments,1),l.apply(this,f)}else if(g(l))for(f=Array.prototype.slice.call(arguments,1),d=l.slice(),l=d.length,n=0;n<l;n++)d[n].apply(this,f);return!0};a.prototype.addListener=function(e,f){var l;if(!b(f))throw TypeError("listener must be a function");this._events||(this._events={});this._events.newListener&&this.emit("newListener",e,b(f.listener)?f.listener:f);this._events[e]?g(this._events[e])?this._events[e].push(f):this._events[e]=[this._events[e],f]:this._events[e]=
  128. f;g(this._events[e])&&!this._events[e].warned&&(l=void 0!==this._maxListeners?this._maxListeners:a.defaultMaxListeners)&&0<l&&this._events[e].length>l&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"===typeof console.trace&&console.trace());return this};a.prototype.on=a.prototype.addListener;a.prototype.once=function(a,f){function g(){this.removeListener(a,
  129. g);n||(n=!0,f.apply(this,arguments))}if(!b(f))throw TypeError("listener must be a function");var n=!1;g.listener=f;this.on(a,g);return this};a.prototype.removeListener=function(a,f){var l,n,d;if(!b(f))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;l=this._events[a];d=l.length;n=-1;if(l===f||b(l.listener)&&l.listener===f)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,f);else if(g(l)){for(;0<d--;)if(l[d]===f||l[d].listener&&
  130. l[d].listener===f){n=d;break}if(0>n)return this;1===l.length?(l.length=0,delete this._events[a]):l.splice(n,1);this._events.removeListener&&this.emit("removeListener",a,f)}return this};a.prototype.removeAllListeners=function(a){var f;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[a]&&delete this._events[a],this;if(0===arguments.length){for(f in this._events)"removeListener"!==f&&this.removeAllListeners(f);this.removeAllListeners("removeListener");
  131. this._events={};return this}f=this._events[a];if(b(f))this.removeListener(a,f);else if(f)for(;f.length;)this.removeListener(a,f[f.length-1]);delete this._events[a];return this};a.prototype.listeners=function(a){return this._events&&this._events[a]?b(this._events[a])?[this._events[a]]:this._events[a].slice():[]};a.prototype.listenerCount=function(a){if(this._events){a=this._events[a];if(b(a))return 1;if(a)return a.length}return 0};a.listenerCount=function(a,b){return a.listenerCount(b)}},{}],22:[function(h,
  132. m,k){m.exports.RTCIceCandidate=h("./rtcicecandidate");m.exports.RTCPeerConnection=h("./rtcpeerconnection");m.exports.RTCSessionDescription=h("./rtcsessiondescription")},{"./rtcicecandidate":25,"./rtcpeerconnection":26,"./rtcsessiondescription":28}],23:[function(h,m,k){function a(b,g,e,f,l,n,d,h,q,c){if(!(this instanceof a))return new a(b,g,e,f,l,n,d,h,q,c);var p=!1;b=b||"0.0.0.0";d="number"===typeof d?d:9;h="boolean"===typeof h?h:!0;q=q||null;c=c||null;Object.defineProperties(this,{_address:{get:function(){return b},
  133. set:function(a){b=a}},_candidates:{value:[]},_port:{get:function(){return d},set:function(a){d=a}},_rejected:{get:function(){return p},set:function(a){p=a}},_streamId:{get:function(){return q},set:function(a){q=a}},_track:{get:function(){return c},set:function(a){c=a}},_triples:{value:new Set},candidates:{enumerable:!0,get:function(){return this._candidates.slice()}},capabilities:{enumerable:!0,value:e},defaultCandidate:{enumerable:!0,get:function(){return this._candidates.length?this._candidates[0]:
  134. null}},direction:{enumerable:!0,value:f},kind:{enumerable:!0,value:l},port:{enumerable:!0,get:function(){return d}},rtcpMux:{enumerable:!0,value:h},streamId:{enumerable:!0,get:function(){return q}},track:{enumerable:!0,get:function(){return c}}});g&&g.forEach(this.addCandidate,this)}a.prototype.addCandidate=function(a){var g=[a.ip,a.port,a.protocol].join(" ");return this._triples.has(g)?!1:(this._triples.add(g),this._candidates.push(a),!0)};a.prototype.copy=function(b,g,e,f,l,n,d){return new a(this.address,
  135. g,e||this.capabilities,f||this.direction,this.kind,this.mid,l,this.rtcpMux,n,d)};a.prototype.copyAndReject=function(){return(new a(null,this.candidates,this.capabilities,this.direction,this.kind,this.mid,null,this.rtcpMux)).reject()};a.prototype.reject=function(){this.setPort(0);return this};a.prototype.setAddress=function(a){this._address=a;return this};a.prototype.setPort=function(a){this._port=a;return this};m.exports=a},{}],24:[function(h,m,k){function a(b,g){if(!(this instanceof a))return new a(b,
  136. g);Event.call(this,b,g);Object.defineProperties(this,{stream:{enumerable:!0,value:g.stream}})}m.exports=a},{}],25:[function(h,m,k){function a(b){if(!(this instanceof a))return new a(b);Object.defineProperties(this,{candidate:{enumerable:!0,value:b.candidate},sdpMLineIndex:{enumerable:!0,value:b.sdpMLineIndex}})}m.exports=a},{}],26:[function(h,m,k){function a(c){if(!(this instanceof a))return new a(c);c={gatherPolicy:c.gatherPolicy||"all",iceServers:[]};var b=new RTCIceGatherer(c),d=!1;b.onlocalcandidate=
  137. this._onlocalcandidate.bind(this);var e=null,f=!1,g=0,l=new RTCIceTransport,n=null;l.onicestatechange=this._onicestatechange.bind(this);var h=new RTCDtlsTransport(l);h.ondtlsstatechange=this._ondtlsstatechange.bind(this);var t="stable",q=null,k=null,m=null,x=null;Object.defineProperties(this,{_dtlsTransport:{value:h},_dtmfSenders:{value:new Map},_gatherOptions:{value:c},_iceCandidatesAdded:{get:function(){return g},set:function(a){g=a}},_iceGatherer:{value:b},_iceGatheringCompleted:{get:function(){return d},
  138. set:function(a){d=a}},_iceTransport:{value:l},_localCandidates:{value:new Set},_localDescription:{get:function(){return k},set:function(a){k=a}},_localStreams:{value:[]},_midCounters:{value:{audio:0,video:0}},_remoteCandidates:{value:new Set},_remoteDescription:{get:function(){return m},set:function(a){m=a}},_remoteStreams:{value:[]},_rtpReceivers:{value:new Map},_rtpSenders:{value:new Map},_signalingState:{get:function(){return t},set:function(a){t=a;if(this.onsignalingstatechange)this.onsignalingstatechange()}},
  139. _streamIds:{value:new Map},iceConnectionState:{enumerable:!0,get:function(){return l.state}},iceGatheringState:{enumerable:!0,get:function(){return d?"gathering":"complete"}},localDescription:{enumerable:!0,get:function(){return k}},onaddstream:{enumerable:!0,get:function(){return x},set:function(a){x=a}},onicecandidate:{enumerable:!0,get:function(){return e},set:function(a){e=a;if(!f)try{b.getLocalCandidates().forEach(b.onlocalcandidate)}catch(c){}f=!0}},oniceconnectionstatechange:{enumerable:!0,
  140. get:function(){return n},set:function(a){n=a}},onsignalingstatechange:{enumerable:!0,get:function(){return q},set:function(a){q=a}},remoteDescription:{enumerable:!0,get:function(){return m}},signalingState:{enumerable:!0,get:function(){return t}}})}function b(a){return Error("Invalid signaling state: "+a)}function g(a,b){var d=[];a.forEach(function(a){b.forEach(function(c){a.name===c.name&&a.clockRate===c.clockRate&&a.numChannels===c.numChannels&&d.push(c)})});return d}var e=h("./mediasection"),f=
  141. h("./mediastreamevent"),l=h("./rtcicecandidate"),n=h("./rtcpeerconnectioniceevent"),d=h("./rtcsessiondescription"),t=h("sdp-transform"),q=h("./sdp-utils");a.prototype._makeMid=function(a){return a+ ++this._midCounters[a]};a.prototype._ondtlsstatechange=function(a){void 0};a.prototype._onicestatechange=function(a){if(this.oniceconnectionstatechange)this.oniceconnectionstatechange(a)};a.prototype._onlocalcandidate=function(a){Object.keys(a.candidate).length||(this._iceGatheringCompleted=!0);this._localCandidates.add(a.candidate);
  142. if(this.onicecandidate){a=a.candidate;if(Object.keys(a).length){var b=["a=candidate",a.foundation,1,a.protocol,a.priority,a.ip,a.port,a.type];a.relatedAddress&&(b=b.concat(["raddr",a.relatedAddress,"rport",a.relatedPort]));b.push("generation 0");a=new l({candidate:b.join(" "),sdpMLineIndex:0})}else a=null;this.onicecandidate(new n("icecandidate",{candidate:a}))}};a.prototype._sendRtp=function(a){var b=a.kind;this._rtpSenders.forEach(function(d){d.track.kind===b&&d.send(a.capabilities)},this);return this};
  143. a.prototype._sendAndReceiveRtp=function(a){a.forEach(function(a){"sendrecv"!==a.direction&&"sendonly"!==a.direction||this._sendRtp(a);"sendrecv"!==a.direction&&"recvonly"!==a.direction||this._receiveRtp(a)},this);return this};a.prototype._receiveRtp=function(a){var b=new RTCRtpReceiver(this._dtlsTransport,a.capabilities.type);b.receive(a.capabilities);a=b.track;this._rtpReceivers.set(a,b);b=new MediaStream;b.addTrack(a);this._remoteStreams.push(b);if(this.onaddstream)this.onaddstream(new f("addstream",
  144. {stream:b}));return this};a.prototype._startDtlsTransport=function(a){this._dtlsTransport.start(a);return this};a.prototype._startIceTransport=function(a){this._iceTransport.start(this._iceGatherer,a,"have-local-offer"===this.signalingState?"controlling":"controlled");return this};a.prototype.addIceCandidate=function(a,b,d){void 0;this._iceCandidatesAdded++;a?(d=a.candidate.indexOf("candidate:"),a=a.candidate.slice(d+10).replace(/ +/g," ").split(" "),d={foundation:a[0],protocol:a[2],priority:parseInt(a[3]),
  145. ip:a[4],port:parseInt(a[5]),type:a[7],relatedAddress:null,relatedPort:0,tcpType:"active"},"host"!==d.type&&(d.relatedAddress=a[9],d.relatedPort=parseInt(a[11])),a=d):a={};d=[a.ip,a.port,a.transport].join(" ");this._remoteCandidates.has(d)||(this._remoteCandidates.add(d),this._iceTransport.addRemoteCandidate(a));b&&b()};a.prototype.addStream=function(a){this._localStreams.push(a);a.getTracks().forEach(function(b){var d=new RTCRtpSender(b,this._dtlsTransport);this._rtpSenders.set(b,d);this._streamIds.set(b,
  146. a.id)},this)};a.prototype.close=function(){this._signalingState="closed";this._rtpReceivers.forEach(function(a){a.stop()});this._dtlsTransport.stop();this._iceTransport.stop()};a.prototype.createAnswer=function(a,e){if("have-remote-offer"!==this.signalingState)return void e(b(this.signalingState));var f=q.parseDescription(this.remoteDescription),l={audio:[],video:[]};this.getLocalStreams().forEach(function(a){l.audio=l.audio.concat(a.getAudioTracks());l.video=l.video.concat(a.getVideoTracks())});
  147. f=f.mediaSections.map(function(a){var c=a.kind,b=a.direction,d=a.capabilities,e=RTCRtpSender.getCapabilities(c),e=g(d.codecs,e.codecs),d={codecs:e},f;if(!e.length)return a.copyAndReject();"inactive"===b||"recvonly"===b&&!l[c].length?c="inactive":"recvonly"===b?(f=l[c].shift(),c="sendonly"):c="sendrecv"===b?(f=l[c].shift())?"sendrecv":"recvonly":"recvonly";b=this._streamIds.get(f);return a.copy(null,null,d,c,null,b,f)},this);f.forEach(function(a){this._localCandidates.forEach(a.addCandidate,a)},this);
  148. var n=q.makeInitialSDPBlob();q.addMediaSectionsToSDPBlob(n,f);q.addIceParametersToSDPBlob(n,this._iceGatherer.getLocalParameters());q.addDtlsParametersToSDPBlob(n,this._dtlsTransport.getLocalParameters());f=new d({sdp:t.write(n),type:"answer"});a(f)};a.prototype.createDTMFSender=function(a){if(!this._dtmfSenders.has(a)){var b=this._rtpSenders.get(a),b=new RTCDtmfSender(b);this._dtmfSenders.set(a,b)}return this._dtmfSenders.get(a)};a.prototype.createOffer=function(a,b,f){var g={audio:null,video:null},
  149. l={audio:0,video:0};f=f||{};["optional","mandatory"].forEach(function(a){a in f&&("OfferToReceiveAudio"in f[a]&&(g.audio=Number(f[a].OfferToReceiveAudio)),"OfferToReceiveVideo"in f[a]&&(g.video=Number(f[a].OfferToReceiveVideo)))});var n=[],h={audio:g.audio,video:g.video};this.getLocalStreams().forEach(function(a){var b=a.getAudioTracks(),c=a.getVideoTracks();l.audio+=b.length;l.video+=c.length;b.concat(c).forEach(function(b){var c=b.kind,d=RTCRtpSender.getCapabilities(c),f,g=this._makeMid(c);null===
  150. h.audio?f="sendrecv":h[c]?(h[c]--,f="sendrecv"):f="sendonly";b=new e(null,null,d,f,c,g,null,null,a.id,b);n.push(b)},this)},this);["audio","video"].forEach(function(a){var b=Math.max(g[a]-l[a],0);if(b)for(var c=RTCRtpSender.getCapabilities(a),d;b--;)d=this._makeMid(a),d=new e(null,null,c,"recvonly",a,d),n.push(d)},this);n.forEach(function(a){this._localCandidates.forEach(a.addCandidate,a)},this);b=q.makeInitialSDPBlob();q.addMediaSectionsToSDPBlob(b,n);q.addIceParametersToSDPBlob(b,this._iceGatherer.getLocalParameters());
  151. q.addDtlsParametersToSDPBlob(b,this._dtlsTransport.getLocalParameters());b=new d({sdp:t.write(b),type:"offer"});a(b)};a.prototype.getLocalStreams=function(){return this._localStreams.slice()};a.prototype.getRemoteStreams=function(){return this._remoteStreams.slice()};a.prototype.setLocalDescription=function(a,d,e){switch(this.signalingState){case "stable":e="have-local-offer";break;case "have-remote-offer":case "have-local=offer":e="stable";break;default:return void e(b(this.signalingState))}var f=
  152. q.parseDescription(a);if("have-remote-offer"===this.signalingState){f.mediaSections.forEach(this._sendRtp,this);var g=q.parseDescription(this.remoteDescription).mediaSections[0].capabilities.encodings[0].ssrc;f.mediaSections.forEach(function(a){a.capabilities.encodings.forEach(function(a){a.ssrc=g});a.capabilities.rtcp.ssrc=g});f.mediaSections.forEach(this._receiveRtp,this)}this._localDescription=a;this._signalingState=e;d()};a.prototype.setRemoteDescription=function(a,d,e){console.info(this.signalingState,
  153. "have-local-offer"===this.signalingState);switch(this.signalingState){case "stable":e="have-remote-offer";break;case "have-local-offer":e="stable";break;default:return console.info("WUT",this.signalingState),void e(b(this.signalingState))}var f=q.parseDescription(a);f.mediaSections.forEach(function(a){a.candidates.forEach(this._iceTransport.addRemoteCandidate,this._iceTransport)},this);this._startIceTransport(f.iceParameters[0]);this._startDtlsTransport(f.dtlsParameters[0]);"have-local-offer"===this.signalingState&&
  154. (f.mediaSections.forEach(this._receiveRtp,this),f.mediaSections.forEach(this._sendRtp,this));this._remoteDescription=a;this._signalingState=e;d()};m.exports=a},{"./mediasection":23,"./mediastreamevent":24,"./rtcicecandidate":25,"./rtcpeerconnectioniceevent":27,"./rtcsessiondescription":28,"./sdp-utils":29,"sdp-transform":31}],27:[function(h,m,k){function a(b,g){if(!(this instanceof a))return new a(b,g);Event.call(this,b,g);Object.defineProperties(this,{candidate:{enumerable:!0,value:g.candidate}})}
  155. m.exports=a},{}],28:[function(h,m,k){function a(b){if(!(this instanceof a))return new a(b);Object.defineProperties(this,{sdp:{enumerable:!0,value:b.sdp},type:{enumerable:!0,value:b.type}})}m.exports=a},{}],29:[function(h,m,k){function a(a,b,c){a=a||{};a.candidates=a.candidates||[];if(!b)return a;b.forEach(function(b){if(b.foundation){var d={foundation:b.foundation,transport:b.protocol,priority:b.priority,ip:b.ip,port:b.port,type:b.type,generation:0};b.relatedAddress&&(d.raddr=b.relatedAddress,d.rport=
  156. b.relatedPort);if("number"===typeof c)d.component=c,a.candidates.push(d);else{d.component=1;a.candidates.push(d);b={};for(var e in d)b[e]=d[e];b.component=2;a.candidates.push(b)}}else a.endOfCandidates="end-of-candidates"});return a}function b(b,d,c){b=b||{};if(!b.media)return b;b.media.forEach(function(b){a(b,d,c)});return b}function g(a,b){a=a||{};if(!a.media)return a;a.media.forEach(function(a){a=a||{};var d=b.fingerprints;d.length&&(a.fingerprint={type:d[0].algorithm,hash:d[0].value})});return a}
  157. function e(a,b){a=a||{};if(!a.media)return a;a.media.forEach(function(a){a=a||{};a.iceUfrag=b.usernameFragment;a.icePwd=b.password});return a}function f(b,d){var c=d.streamId;c&&(b.msidSemantic=b.msidSemantic||{semantic:"WMS",token:[]},b.msidSemantic.token.push(c));var e=d.mid;if(e){b.groups=b.groups||[];var f=!1;b.groups.forEach(function(a){"BUNDLE"===a.type&&(a.mids.push(e),f=!0)});f||b.groups.push({type:"BUNDLE",mids:[e]})}var g=[],n=[],h=[];d.capabilities.codecs.forEach(function(a){var b=a.preferredPayloadType;
  158. g.push(b);var c={payload:b,codec:a.name,rate:a.clockRate};1<a.numChannels&&(c.encoding=a.numChannels);n.push(c);switch(a.name){case "telephone-event":a.parameters&&a.parameters.events&&h.push({payload:b,config:a.parameters.events})}});var k=[];if(c&&d.track)var c=Math.floor(4294967296*Math.random()),m=l(),A=d.track.id,k=k.concat([{id:c,attribute:"cname",value:m},{id:c,attribute:"msid",value:d.streamId+" "+A},{id:c,attribute:"mslabel",value:A},{id:c,attribute:"label",value:A}]);c=d.defaultCandidate;
  159. k={rtp:n,fmtp:h,type:d.kind,port:c?c.port:9,payloads:g.join(" "),protocol:"RTP/SAVPF",direction:d.direction,connection:{version:4,ip:c?c.ip:"0.0.0.0"},rtcp:{port:c?c.port:9,netType:"IN",ipVer:4,address:c?c.ip:"0.0.0.0"},ssrcs:k};e&&(k.mid=e);d.rtcpMux&&(k.rtcpMux="rtcp-mux");a(k,d.candidates);b.media.push(k);return b}function l(){for(var a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/".split(""),b=16,c="";b--;)c+=a[Math.floor(Math.random()*a.length)];return c}var n=h("./mediasection"),
  160. d=h("sdp-transform");m.exports.addCandidatesToSDPBlob=function(a,d,c){a=a||{};b(a,d,c);return a};m.exports.addDtlsParametersToSDPBlob=function(a,b){a=a||{};g(a,b);return a};m.exports.addIceParametersToSDPBlob=function(a,b){a=a||{};e(a,b);return a};m.exports.addMediaSectionsToSDPBlob=function(a,b){b.forEach(f.bind(null,a));return a};m.exports.makeInitialSDPBlob=function(a){a=a||Math.floor(4294967296*Math.random());return{version:0,origin:{username:"-",sessionId:a,sessionVersion:0,netType:"IN",ipVer:4,
  161. address:"127.0.0.1"},name:"-",timing:{start:0,stop:0},connection:{version:4,ip:"0.0.0.0"},media:[]}};m.exports.parseDescription=function(a){a=d.parse(a.sdp);var b=[],c=[],e=[],f=[],g=[a];a.media&&(g=g.concat(a.media));g.forEach(function(a){a.iceUfrag&&a.icePwd&&a.fingerprint&&(b.push({usernameFragment:a.iceUfrag,password:a.icePwd}),c.push({fingerprints:[{algorithm:a.fingerprint.type,value:a.fingerprint.hash}]}));if(a.rtp&&"video"!==a.type){var d=a.connection?a.connection.ip:null,g=a.direction,l=a.type,
  162. h=a.mid,k=a.port||null,m="rtcp-mux"===a.rtcpMux,t,y,x;(a.ssrcs||[]).forEach(function(a){switch(a.attribute){case "cname":y=a.id;t=a.value;break;case "label":case "mslabel":y=a.id;break;case "msid":y=a.id,x=a.value.split(" ")[0]}});var D={type:l,muxId:h,codecs:a.rtp.map(function(a){var b={name:a.codec,payloadType:parseInt(a.payload),clockRate:parseInt(a.rate),numChannels:a.encoding||1,rtcpFeedback:[],parameters:{}};switch(a.codec){case "telephone-event":b.parameters.events="0-16"}return b}),headerExtensions:[],
  163. encodings:a.rtp.map(function(a){return{ssrc:y,codecPayloadType:parseInt(a.payload),active:!0}}),rtcp:{ssrc:y,cname:t,mux:m}},F=new n(d,e,D,g,l,h,k,m,x);(a.candidates||[]).forEach(function(a){a={foundation:String(a.foundation),protocol:a.transport,priority:a.priority,ip:a.ip,port:a.port,type:a.type,relatedAddress:a.raddr,relatedPort:a.rport};e.push(a);F.addCandidate(a)});void 0;"end-of-candidates"===a.endOfCandidates&&F.addCandidate({});f.push(F)}});return{iceParameters:b,dtlsParameters:c,mediaSections:f}}},
  164. {"./mediasection":23,"sdp-transform":31}],30:[function(h,m,k){var a=m.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:"username sessionId sessionVersion netType ipVer address".split(" "),format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],
  165. c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(a){return a.encoding?"rtpmap:%d %s/%s/%s":a.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},
  166. {push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(a){return null!=a.address?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%d trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload",
  167. "type","subtype"],format:function(a){return null!=a.subtype?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:([\w_\/]*) (\S*)(?: (\S*))?/,names:["value","uri","config"],format:function(a){return null!=a.config?"extmap:%s %s %s":"extmap:%s %s"}},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(a){return null!=a.sessionConfig?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},
  168. {name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],
  169. format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?/,names:"foundation component transport priority ip port type raddr rport tcptype generation".split(" "),format:function(a){var g;g="candidate:%s %d %s %d %s %d typ %s"+(null!=a.raddr?" raddr %s rport %d":"%v%v");g+=null!=a.tcptype?" tcptype %s":"%v";null!=a.generation&&(g+=" generation %d");return g}},{name:"endOfCandidates",
  170. reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_]*):(.*)/,names:["id","attribute","value"],format:"ssrc:%d %s:%s"},{push:"ssrcGroups",reg:/^ssrc-group:(\w*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},
  171. {push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(a){return null!=a.maxMessageSize?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{push:"invalid",names:["value"]}]};Object.keys(a).forEach(function(b){a[b].forEach(function(a){a.reg||(a.reg=/(.*)/);a.format||(a.format="%s")})})},{}],
  172. 31:[function(h,m,k){m=h("./parser");h=h("./writer");k.write=h;k.parse=m.parse;k.parseFmtpConfig=m.parseFmtpConfig;k.parsePayloads=m.parsePayloads;k.parseRemoteCandidates=m.parseRemoteCandidates},{"./parser":32,"./writer":33}],32:[function(h,m,k){var a=function(a){return String(Number(a))===a?Number(a):a},b=h("./grammar"),g=RegExp.prototype.test.bind(/^([a-z])=(.*)/);k.parse=function(e){var l={},n=[],d=l;e.split(/(\r\n|\r|\n)/).filter(g).forEach(function(e){var f=e[0],c=e.slice(2);"m"===f&&(n.push({rtp:[],
  173. fmtp:[]}),d=n[n.length-1]);for(e=0;e<(b[f]||[]).length;e+=1){var g=b[f][e];if(g.reg.test(c)){f=g;e=d;g=c;c=f.name&&f.names;f.push&&!e[f.push]?e[f.push]=[]:c&&!e[f.name]&&(e[f.name]={});var c=f.push?{}:c?e[f.name]:e,g=g.match(f.reg),l=c,h=f.names,k=f.name;if(k&&!h)l[k]=a(g[1]);else for(k=0;k<h.length;k+=1)null!=g[k+1]&&(l[h[k]]=a(g[k+1]));f.push&&e[f.push].push(c);break}}});l.media=n;return l};var e=function(b,e){var g=e.split(/=(.+)/,2);2===g.length&&(b[g[0]]=a(g[1]));return b};k.parseFmtpConfig=
  174. function(a){return a.split(/\;\s?/).reduce(e,{})};k.parsePayloads=function(a){return a.split(" ").map(Number)};k.parseRemoteCandidates=function(b){var e=[];b=b.split(" ").map(a);for(var g=0;g<b.length;g+=3)e.push({component:b[g],ip:b[g+1],port:b[g+2]});return e}},{"./grammar":30}],33:[function(h,m,k){var a=h("./grammar"),b=/%[sdv%]/g,g=function(a){var d=1,e=arguments,f=e.length;return a.replace(b,function(a){if(d>=f)return a;var b=e[d];d+=1;switch(a){case "%%":return"%";case "%s":return String(b);
  175. case "%d":return Number(b);case "%v":return""}})},e=function(a,b,e){var f=b.format instanceof Function?b.format(b.push?e:e[b.name]):b.format;a=[a+"="+f];if(b.names)for(f=0;f<b.names.length;f+=1){var c=b.names[f];b.name?a.push(e[b.name][c]):a.push(e[b.names[f]])}else a.push(e[b.name]);return g.apply(null,a)},f="vosiuepcbtrza".split(""),l=["i","c","b","a"];m.exports=function(b,d){d=d||{};null==b.version&&(b.version=0);null==b.name&&(b.name=" ");b.media.forEach(function(a){null==a.payloads&&(a.payloads=
  176. "")});var g=d.innerOrder||l,h=[];(d.outerOrder||f).forEach(function(c){a[c].forEach(function(a){a.name in b&&null!=b[a.name]?h.push(e(c,a,b)):a.push in b&&null!=b[a.push]&&b[a.push].forEach(function(b){h.push(e(c,a,b))})})});b.media.forEach(function(b){h.push(e("m",a.m[0],b));g.forEach(function(d){a[d].forEach(function(a){a.name in b&&null!=b[a.name]?h.push(e(d,a,b)):a.push in b&&null!=b[a.push]&&b[a.push].forEach(function(b){h.push(e(d,a,b))})})})});return h.join("\r\n")+"\r\n"}},{"./grammar":30}],
  177. 34:[function(h,m,k){(function(a,b){"object"===typeof k?m.exports=b():"function"===typeof define&&define.amd?define(b):a.printStackTrace=b()})(this,function(){function a(b){b=b||{guess:!0};var g=b.e||null,e=!!b.guess,f=b.mode||null;b=new a.implementation;g=b.run(g,f);return e?b.guessAnonymousFunctions(g):g}a.implementation=function(){};a.implementation.prototype={run:function(a,g){a=a||this.createException();g=g||this.mode(a);return"other"===g?this.other(arguments.callee):this[g](a)},createException:function(){try{this.undef()}catch(a){return a}},
  178. mode:function(a){return"undefined"!==typeof window&&-1<window.navigator.userAgent.indexOf("PhantomJS")?"phantomjs":a.arguments&&a.stack?"chrome":a.stack&&a.sourceURL?"safari":a.stack&&a.number?"ie":a.stack&&a.fileName?"firefox":a.message&&a["opera#sourceloc"]?!a.stacktrace||-1<a.message.indexOf("\n")&&a.message.split("\n").length>a.stacktrace.split("\n").length?"opera9":"opera10a":a.message&&a.stack&&a.stacktrace?0>a.stacktrace.indexOf("called from line")?"opera10b":"opera11":a.stack&&!a.fileName?
  179. "chrome":"other"},instrumentFunction:function(b,g,e){b=b||window;var f=b[g];b[g]=function(){e.call(this,a().slice(4));return b[g]._instrumented.apply(this,arguments)};b[g]._instrumented=f},deinstrumentFunction:function(a,g){a[g].constructor===Function&&a[g]._instrumented&&a[g]._instrumented.constructor===Function&&(a[g]=a[g]._instrumented)},chrome:function(a){return(a.stack+"\n").replace(/^[\s\S]+?\s+at\s+/," at ").replace(/^\s+(at eval )?at\s+/gm,"").replace(/^([^\(]+?)([\n$])/gm,"{anonymous}() ($1)$2").replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm,
  180. "{anonymous}() ($1)").replace(/^(.+) \((.+)\)$/gm,"$1@$2").split("\n").slice(0,-1)},safari:function(a){return a.stack.replace(/\[native code\]\n/m,"").replace(/^(?=\w+Error\:).*$\n/m,"").replace(/^@/gm,"{anonymous}()@").split("\n")},ie:function(a){return a.stack.replace(/^\s*at\s+(.*)$/gm,"$1").replace(/^Anonymous function\s+/gm,"{anonymous}() ").replace(/^(.+)\s+\((.+)\)$/gm,"$1@$2").split("\n").slice(1)},firefox:function(a){return a.stack.replace(/(?:\n@:0)?\s+$/m,"").replace(/^(?:\((\S*)\))?@/gm,
  181. "{anonymous}($1)@").split("\n")},opera11:function(a){var g=/^.*line (\d+), column (\d+)(?: in (.+))? in (\S+):$/;a=a.stacktrace.split("\n");for(var e=[],f=0,l=a.length;f<l;f+=2){var h=g.exec(a[f]);if(h){var d=h[4]+":"+h[1]+":"+h[2],h=h[3]||"global code",h=h.replace(/<anonymous function: (\S+)>/,"$1").replace(/<anonymous function>/,"{anonymous}");e.push(h+"@"+d+" -- "+a[f+1].replace(/^\s+/,""))}}return e},opera10b:function(a){var g=/^(.*)@(.+):(\d+)$/;a=a.stacktrace.split("\n");for(var e=[],f=0,l=
  182. a.length;f<l;f++){var h=g.exec(a[f]);h&&e.push((h[1]?h[1]+"()":"global code")+"@"+h[2]+":"+h[3])}return e},opera10a:function(a){var g=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;a=a.stacktrace.split("\n");for(var e=[],f=0,h=a.length;f<h;f+=2){var k=g.exec(a[f]);k&&e.push((k[3]||"{anonymous}")+"()@"+k[2]+":"+k[1]+" -- "+a[f+1].replace(/^\s+/,""))}return e},opera9:function(a){var g=/Line (\d+).*script (?:in )?(\S+)/i;a=a.message.split("\n");for(var e=[],f=2,h=a.length;f<h;f+=2){var k=
  183. g.exec(a[f]);k&&e.push("{anonymous}()@"+k[2]+":"+k[1]+" -- "+a[f+1].replace(/^\s+/,""))}return e},phantomjs:function(a){var g=/(\S+) \((\S+)\)/i;a=a.stack.split("\n");for(var e=[],f=1,h=a.length;f<h;f++){a[f]=a[f].replace(/^\s+at\s+/gm,"");var k=g.exec(a[f]);k?e.push(k[1]+"()@"+k[2]):e.push("{anonymous}()@"+a[f])}return e},other:function(a){for(var g=/function(?:\s+([\w$]+))?\s*\(/,e=[],f,h,k=Array.prototype.slice;a&&10>e.length;){f=g.test(a.toString())?RegExp.$1||"{anonymous}":"{anonymous}";try{h=
  184. k.call(a.arguments||[])}catch(d){h=["Cannot access arguments: "+d]}e[e.length]=f+"("+this.stringifyArguments(h)+")";try{a=a.caller}catch(d){e[e.length]="Cannot access caller: "+d;break}}return e},stringifyArguments:function(a){for(var g=[],e=Array.prototype.slice,f=0;f<a.length;++f){var h=a[f];void 0===h?g[f]="undefined":null===h?g[f]="null":h.constructor&&(g[f]=h.constructor===Array?3>h.length?"["+this.stringifyArguments(h)+"]":"["+this.stringifyArguments(e.call(h,0,1))+"..."+this.stringifyArguments(e.call(h,
  185. -1))+"]":h.constructor===Object?"#object":h.constructor===Function?"#function":h.constructor===String?'"'+h+'"':h.constructor===Number?h:"?")}return g.join(",")},sourceCache:{},ajax:function(a){var g=this.createXMLHTTPObject();if(g)try{return g.open("GET",a,!1),g.send(null),g.responseText}catch(e){}return""},createXMLHTTPObject:function(){for(var a,g=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},
  186. function(){return new ActiveXObject("Microsoft.XMLHTTP")}],e=0;e<g.length;e++)try{return a=g[e](),this.createXMLHTTPObject=g[e],a}catch(f){}},isSameDomain:function(a){return"undefined"!==typeof location&&-1!==a.indexOf(location.hostname)},getSource:function(a){a in this.sourceCache||(this.sourceCache[a]=this.ajax(a).split("\n"));return this.sourceCache[a]},guessAnonymousFunctions:function(a){for(var g=0;g<a.length;++g){var e=/^(.*?)(?::(\d+))(?::(\d+))?(?: -- .+)?$/,f=a[g],h=/\{anonymous\}\(.*\)@(.*)/.exec(f);
  187. if(h){var k=e.exec(h[1]);k&&(e=k[1],h=k[2],k=k[3]||0,e&&this.isSameDomain(e)&&h&&(e=this.guessAnonymousFunction(e,h,k),a[g]=f.replace("{anonymous}",e)))}}return a},guessAnonymousFunction:function(a,g,e){var f;try{f=this.findFunctionName(this.getSource(a),g)}catch(h){f="getSource failed with url: "+a+", exception: "+h.toString()}return f},findFunctionName:function(a,g){for(var e=/function\s+([^(]*?)\s*\(([^)]*)\)/,f=/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*function\b/,h=/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*(?:eval|new Function)\b/,
  188. k="",d,m=Math.min(g,20),q,c=0;c<m;++c)if(d=a[g-c-1],q=d.indexOf("//"),0<=q&&(d=d.substr(0,q)),d)if(k=d+k,(d=f.exec(k))&&d[1]||(d=e.exec(k))&&d[1]||(d=h.exec(k))&&d[1])return d[1];return"(?)"}};return a})},{}],35:[function(h,m,k){m.exports="function"===typeof Object.create?function(a,b){a.super_=b;a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})}:function(a,b){a.super_=b;var g=function(){};g.prototype=b.prototype;a.prototype=new g;a.prototype.constructor=
  189. a}},{}],36:[function(h,m,k){m.exports=function(a){return a&&"object"===typeof a&&"function"===typeof a.copy&&"function"===typeof a.fill&&"function"===typeof a.readUInt8}},{}],37:[function(h,m,k){function a(a,c){var d={seen:[],stylize:g};3<=arguments.length&&(d.depth=arguments[2]);4<=arguments.length&&(d.colors=arguments[3]);p(c)?d.showHidden=c:c&&k._extend(d,c);u(d.showHidden)&&(d.showHidden=!1);u(d.depth)&&(d.depth=2);u(d.colors)&&(d.colors=!1);u(d.customInspect)&&(d.customInspect=!0);d.colors&&
  190. (d.stylize=b);return f(d,a,d.depth)}function b(b,c){var d=a.styles[c];return d?"\u001b["+a.colors[d][0]+"m"+b+"\u001b["+a.colors[d][1]+"m":b}function g(a,b){return a}function e(a){var b={};a.forEach(function(a,c){b[a]=!0});return b}function f(a,b,g){if(a.customInspect&&b&&r(b.inspect)&&b.inspect!==k.inspect&&(!b.constructor||b.constructor.prototype!==b)){var h=b.inspect(g,a);y(h)||(h=f(a,h,g));return h}if(h=l(a,b))return h;var m=Object.keys(b),p=e(m);a.showHidden&&(m=Object.getOwnPropertyNames(b));
  191. if(A(b)&&(0<=m.indexOf("message")||0<=m.indexOf("description")))return n(b);if(0===m.length){if(r(b))return a.stylize("[Function"+(b.name?": "+b.name:"")+"]","special");if(v(b))return a.stylize(RegExp.prototype.toString.call(b),"regexp");if(H(b))return a.stylize(Date.prototype.toString.call(b),"date");if(A(b))return n(b)}var h="",G=!1,u=["{","}"];c(b)&&(G=!0,u=["[","]"]);r(b)&&(h=" [Function"+(b.name?": "+b.name:"")+"]");v(b)&&(h=" "+RegExp.prototype.toString.call(b));H(b)&&(h=" "+Date.prototype.toUTCString.call(b));
  192. A(b)&&(h=" "+n(b));if(0===m.length&&(!G||0==b.length))return u[0]+h+u[1];if(0>g)return v(b)?a.stylize(RegExp.prototype.toString.call(b),"regexp"):a.stylize("[Object]","special");a.seen.push(b);m=G?d(a,b,g,p,m):m.map(function(c){return t(a,b,g,p,c,G)});a.seen.pop();return q(m,h,u)}function l(a,b){if(u(b))return a.stylize("undefined","undefined");if(y(b)){var c="'"+JSON.stringify(b).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return a.stylize(c,"string")}if(w(b))return a.stylize(""+
  193. b,"number");if(p(b))return a.stylize(""+b,"boolean");if(null===b)return a.stylize("null","null")}function n(a){return"["+Error.prototype.toString.call(a)+"]"}function d(a,b,c,d,e){for(var f=[],g=0,h=b.length;g<h;++g)Object.prototype.hasOwnProperty.call(b,String(g))?f.push(t(a,b,c,d,String(g),!0)):f.push("");e.forEach(function(e){e.match(/^\d+$/)||f.push(t(a,b,c,d,e,!0))});return f}function t(a,b,c,d,e,g){var h,k;b=Object.getOwnPropertyDescriptor(b,e)||{value:b[e]};b.get?k=b.set?a.stylize("[Getter/Setter]",
  194. "special"):a.stylize("[Getter]","special"):b.set&&(k=a.stylize("[Setter]","special"));Object.prototype.hasOwnProperty.call(d,e)||(h="["+e+"]");k||(0>a.seen.indexOf(b.value)?(k=null===c?f(a,b.value,null):f(a,b.value,c-1),-1<k.indexOf("\n")&&(k=g?k.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+k.split("\n").map(function(a){return" "+a}).join("\n"))):k=a.stylize("[Circular]","special"));if(u(h)){if(g&&e.match(/^\d+$/))return k;h=JSON.stringify(""+e);h.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?
  195. (h=h.substr(1,h.length-2),h=a.stylize(h,"name")):(h=h.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),h=a.stylize(h,"string"))}return h+": "+k}function q(a,b,c){var d=0;return 60<a.reduce(function(a,b){d++;0<=b.indexOf("\n")&&d++;return a+b.replace(/\u001b\[\d\d?m/g,"").length+1},0)?c[0]+(""===b?"":b+"\n ")+" "+a.join(",\n ")+" "+c[1]:c[0]+b+" "+a.join(", ")+" "+c[1]}function c(a){return Array.isArray(a)}function p(a){return"boolean"===typeof a}function w(a){return"number"===typeof a}
  196. function y(a){return"string"===typeof a}function u(a){return void 0===a}function v(a){return B(a)&&"[object RegExp]"===Object.prototype.toString.call(a)}function B(a){return"object"===typeof a&&null!==a}function H(a){return B(a)&&"[object Date]"===Object.prototype.toString.call(a)}function A(a){return B(a)&&("[object Error]"===Object.prototype.toString.call(a)||a instanceof Error)}function r(a){return"function"===typeof a}function E(a){return 10>a?"0"+a.toString(10):a.toString(10)}function z(){var a=
  197. new Date,b=[E(a.getHours()),E(a.getMinutes()),E(a.getSeconds())].join(":");return[a.getDate(),F[a.getMonth()],b].join(" ")}var C=/%[sdj%]/g;k.format=function(b){if(!y(b)){for(var c=[],d=0;d<arguments.length;d++)c.push(a(arguments[d]));return c.join(" ")}for(var d=1,e=arguments,f=e.length,c=String(b).replace(C,function(a){if("%%"===a)return"%";if(d>=f)return a;switch(a){case "%s":return String(e[d++]);case "%d":return Number(e[d++]);case "%j":try{return JSON.stringify(e[d++])}catch(b){return"[Circular]"}default:return a}}),
  198. g=e[d];d<f;g=e[++d])c=null!==g&&B(g)?c+(" "+a(g)):c+(" "+g);return c};k.deprecate=function(a,b){if(u(global.process))return function(){return k.deprecate(a,b).apply(this,arguments)};if(!0===process.noDeprecation)return a;var c=!1;return function(){if(!c){if(process.throwDeprecation)throw Error(b);process.traceDeprecation?console.trace(b):console.error(b);c=!0}return a.apply(this,arguments)}};var x={},D;k.debuglog=function(a){u(D)&&(D=process.env.NODE_DEBUG||"");a=a.toUpperCase();if(!x[a])if((new RegExp("\\b"+
  199. a+"\\b","i")).test(D)){var b=process.pid;x[a]=function(){var c=k.format.apply(k,arguments);console.error("%s %d: %s",a,b,c)}}else x[a]=function(){};return x[a]};k.inspect=a;a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};a.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};
  200. k.isArray=c;k.isBoolean=p;k.isNull=function(a){return null===a};k.isNullOrUndefined=function(a){return null==a};k.isNumber=w;k.isString=y;k.isSymbol=function(a){return"symbol"===typeof a};k.isUndefined=u;k.isRegExp=v;k.isObject=B;k.isDate=H;k.isError=A;k.isFunction=r;k.isPrimitive=function(a){return null===a||"boolean"===typeof a||"number"===typeof a||"string"===typeof a||"symbol"===typeof a||"undefined"===typeof a};k.isBuffer=h("./support/isBuffer");var F="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
  201. k.log=function(){console.log("%s - %s",z(),k.format.apply(k,arguments))};k.inherits=h("inherits");k._extend=function(a,b){if(!b||!B(b))return a;for(var c=Object.keys(b),d=c.length;d--;)a[c[d]]=b[c[d]];return a}},{"./support/isBuffer":36,inherits:35}],38:[function(h,m,k){function a(a,e,f){return e?new b(a,e):new b(a)}h=function(){return this}();var b=h.WebSocket||h.MozWebSocket;m.exports=b?a:null;b&&(a.prototype=b.prototype)},{}],39:[function(h,m,k){k.XMLHttpRequest=XMLHttpRequest},{}]},{},[1]);
Add Comment
Please, Sign In to add comment