UNPKG

rtc-quickconnect

Version:

Create a WebRTC connection in record time

2 lines 51.1 kB
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.quickconnect=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d=a("rtc-tools"),e=a("mbus"),f=a("rtc-core/plugin"),g=d.logger("rtc-quickconnect"),h=a("cog/extend");b.exports=function(b,c){function i(){clearTimeout(H),A||y&&(!F||r)&&q&&(G&&B.length<G||(H=setTimeout(function(){var a=h({room:w},z);t.announce(a),A=!0},0)))}function j(a){var b,f,i=u(a);i.room===w&&(C.end(a),b=d.createConnection(h({},c,{iceServers:q}),(c||{}).constraints),t("peer:connect",i.id,b,i),C.create(i.id,b),B.forEach(function(a){b.addStream(a)}),t.isMaster(i.id)?(g("is master, creating data channels: ",Object.keys(D)),Object.keys(D).forEach(function(a){l(b.createDataChannel(a,D[a]),b,i)})):b.ondatachannel=function(c){var d=c&&c.channel;d&&void 0!==D[d.label]&&l(d,b,u(a))},g("coupling "+t.id+" to "+i.id),f=d.couple(b,a,t,h({},c,{logger:e("pc."+a,t)})),t("peer:couple",a,b,i,f),f.once("connected",C.start.bind(null,a,b,i)),f.once("closed",C.end.bind(null,a)),t.isMaster(a)&&f.createOffer())}function k(a){var b=C.get(a);if(!b)throw new Error("No active call for peer: "+a);return b}function l(a,b,c){function d(){var d=C.get(c.id),f=[c.id,a,c,b];g('reporting channel "'+a.label+'" ready, have call: '+!!d),clearInterval(e),a.onopen=null,d&&d.channels.set(a.label,a),g("triggering channel:opened events for channel: "+a.label),t.apply(t,["channel:opened"].concat(f)),t.apply(t,["channel:opened:"+a.label].concat(f))}var e;return g("channel "+a.label+" discovered for peer: "+c.id),"open"===a.readyState?d():(g("channel not ready, current state = "+a.readyState),a.onopen=d,void(e=setInterval(function(){g("checking channel state, current state = "+a.readyState),"open"===a.readyState&&d()},500)))}function m(){return F&&F.init(c,function(a){return a?console.error("Could not initialize plugin: ",a):(r=!0,void i())})}function n(a){a&&"undefined"!=typeof a.room&&(w=a.room)}function o(a,b){b.allow=b.allow&&B.length>=G}function p(a){var b=a&&a.id,c=b&&C.get(b);return b&&!c?(g("received peer update from peer "+b+", no active calls"),t.to(b).send("/reconnect"),j(b)):void 0}var q,r,s="undefined"!=typeof location&&location.hash.slice(1),t=a("rtc-pluggable-signaller")(h({signaller:b,endpoints:["/","/primus"]},c)),u=a("./lib/getpeerdata")(t.peers),v=(c||{}).ns||"",w=(c||{}).room,x=(c||{}).debug,y=!(c||{}).manualJoin,z={},A=!1,B=[],C=t.calls=a("./lib/calls")(t,c),D={},E=t.plugins=(c||{}).plugins||[],F=f(E),G=parseInt((c||{}).expectedLocalStreams,10)||0,H=0,I=0;return w||("undefined"==typeof location||s||(s=location.hash=""+Math.pow(2,53)*Math.random()),w=v+"#"+s),x&&d.logger.enable.apply(d.logger,Array.isArray(g)?x:["*"]),t.on("peer:announce",function(a){j(a.id)}),t.on("peer:update",p),t.on("message:reconnect",function(a){j(a.id)}),t.broadcast=t.addStream=function(a){return B.push(a),C.values().forEach(function(b){b.pc.addStream(a)}),i(),t},t.endCalls=function(){C.keys().forEach(C.end)},t.close=function(){t.endCalls(),t.leave()},t.createDataChannel=function(a,b){return C.keys().forEach(function(c){var d,e=C.get(c);e&&e.pc&&t.isMaster(c)&&(d=e.pc.createDataChannel(a,b),l(d,e.pc,u(c)))}),D[a]=b||null,t},t.join=function(){y=!0,i()},t.get=function(a){return z[a]},t.getLocalStreams=function(){return[].concat(B)},t.reactive=function(){return c=c||{},c.reactive=!0,t},t.removeStream=function(a){var b=B.indexOf(a);return C.values().forEach(function(b){b.pc.removeStream(a)}),b>=0&&B.splice(b,1),t},t.requestChannel=function(a,b,c){var d=k(a),e=d&&d.channels.get(b);return e?(c(null,e),t):(t.once("channel:opened:"+b,function(a,b){c(null,b)}),t)},t.requestStream=function(a,b,c){function d(g){g===a&&(e=f.pc.getRemoteStreams()[b],e&&(t.removeListener("stream:added",d),c(null,e)))}var e,f=k(a);return(e=f.pc.getRemoteStreams()[b])?(c(null,e),t):(t.on("stream:added",d),t)},t.profile=function(a){return h(z,a),A&&(clearTimeout(I),I=setTimeout(function(){t.announce(z)},(c||{}).updateDelay||1e3)),t},t.waitForCall=function(a,b){var c=C.get(a);return c&&c.active?(b(null,c.pc),t):void t.on("call:started",function d(c){c===a&&(t.removeListener("call:started",d),b(null,C.get(c).pc))})},G&&t.on("peer:filter",o),t.on("local:announce",n),t.on("message:ping",C.ping),a("rtc-core/genice")(c,function(a,b){return a?console.error("could not find iceServers: ",a):(q=b,void i())}),F&&m(),t}},{"./lib/calls":2,"./lib/getpeerdata":3,"cog/extend":6,mbus:12,"rtc-core/genice":14,"rtc-core/plugin":16,"rtc-pluggable-signaller":17,"rtc-tools":50}],2:[function(a,b,c){(function(c){var d=a("rtc-tools"),e=d.logger("rtc-quickconnect"),f=a("rtc-tools/cleanup"),g=a("cog/getable");b.exports=function(b,d){function h(a,b){r.set(a,{active:!1,pc:b,channels:g({}),streams:[],lastping:Date.now()})}function i(a){return function(b){e("peer "+a+" added stream"),p(a),m(a)(b.stream)}}function j(a){return function(c){e("peer "+a+" removed stream"),p(a),b("stream:removed",a,c.stream)}}function k(a){var c=r.get(a);c&&(c.channels.keys().forEach(function(d){var e=c.channels.get(d),f=[a,e,d];b.apply(b,["channel:closed"].concat(f)),b.apply(b,["channel:closed:"+d].concat(f)),e.onopen=null}),c.streams.forEach(function(c){b("stream:removed",a,c)}),r["delete"](a),0===r.keys().length&&n(),b("call:ended",a,c.pc),f(c.pc))}function l(a){var b=r.get(a&&a.id);b&&(b.lastping=Date.now())}function m(a){return function(c){b("stream:added",a,c,s(a))}}function n(){clearInterval(q),q=0}function o(f,g,h){var k=r.get(f),l=[].concat(g.getRemoteStreams());k.active=!0,k.streams=[].concat(g.getRemoteStreams()),g.onaddstream=i(f),g.onremovestream=j(f),e(b.id+" - "+f+" call start: "+l.length+" streams"),b("call:started",f,g,h),q=q||a("./heartbeat")(b,r,d),c.nextTick(function(){l.forEach(m(f))})}function p(a){var b=r.get(a);b&&b.pc&&(b.streams=[].concat(b.pc.getRemoteStreams()))}var q,r=g({}),s=a("./getpeerdata")(b.peers);return r.create=h,r.end=k,r.ping=l,r.start=o,r}}).call(this,a("_process"))},{"./getpeerdata":3,"./heartbeat":4,_process:11,"cog/getable":7,"rtc-tools":50,"rtc-tools/cleanup":46}],3:[function(a,b,c){b.exports=function(a){return function(b){var c=a.get(b);return c&&c.data}}},{}],4:[function(a,b,c){b.exports=function(a,b,c){function d(){var c=Date.now()-4*e;b.keys().forEach(function(d){var e=b.get(d);return e.lastping<c?b.end(d):void a.to(d).send("/ping")})}var e=(c||{}).heartbeat||2500;return e?setInterval(d,e):void 0}},{}],5:[function(a,b,c){"use strict";b.exports=function(a){return a=a||{},[].slice.call(arguments,1).forEach(function(b){if(b)for(var c in b)void 0===a[c]&&(a[c]=b[c])}),a}},{}],6:[function(a,b,c){"use strict";b.exports=function(a){return[].slice.call(arguments,1).forEach(function(b){if(b)for(var c in b)a[c]=b[c]}),a}},{}],7:[function(a,b,c){b.exports=function(a){function b(b){return a[b]}function c(b,c){a[b]=c}function d(b){return delete a[b]}function e(){return Object.keys(a)}function f(){return Object.keys(a).map(function(b){return a[b]})}return"object"!=typeof a?a:{get:b,set:c,remove:d,"delete":d,keys:e,values:f}}},{}],8:[function(a,b,c){"use strict";b.exports=function(a){var b,c,d,e="string"==typeof a||a instanceof String,f=/^\-?\d+\.?\d*$/;if(!e||a.length<2)return e&&f.test(a)?parseFloat(a):a;if("true"===a||"false"===a)return"true"===a;if("null"===a)return null;if(c=a.charAt(0),d=a.charAt(a.length-1),b="{"==c&&"}"==d||"["==c&&"]"==d||'"'==c&&'"'==d)try{return JSON.parse(a)}catch(g){}return f.test(a)?parseFloat(a):a}},{}],9:[function(a,b,c){"use strict";var d=[],e=[],f=[console],g=b.exports=function(a){function b(){return c=d.indexOf("*")>=0||d.indexOf(a)>=0}var c=b();return e[e.length]=b,function(){var b=[].slice.call(arguments);("string"==typeof b[0]||b[0]instanceof String)&&(b[0]=a+": "+b[0]),c&&f.forEach(function(a){a.log.apply(a,b)})}};g.reset=function(){return f=[],d=[],g.enable()},g.to=function(a){return f=f.concat(a||[]),g},g.enable=function(){return d=d.concat([].slice.call(arguments)),e.forEach(function(a){a()}),g}},{}],10:[function(a,b,c){"use strict";b.exports=function(a,b,c){function d(){a.apply(g,f||[]),h=Date.now()}var e,f,g,h=(c||{}).leading!==!1?0:Date.now(),i=(c||{}).trailing;return i=i||void 0===i,function(){var c=Date.now(),j=c-h;return clearTimeout(e),b>j?(f=[].slice.call(arguments,0),g=this,i&&(e=setTimeout(d,b-j))):(h=c,void a.apply(this,arguments))}}},{}],11:[function(a,b,c){function d(){k=!1,h.length?j=h.concat(j):l=-1,j.length&&e()}function e(){if(!k){var a=setTimeout(d);k=!0;for(var b=j.length;b;){for(h=j,j=[];++l<b;)h[l].run();l=-1,b=j.length}h=null,k=!1,clearTimeout(a)}}function f(a,b){this.fun=a,this.array=b}function g(){}var h,i=b.exports={},j=[],k=!1,l=-1;i.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];j.push(new f(a,b)),1!==j.length||k||setTimeout(e,0)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=g,i.addListener=g,i.once=g,i.off=g,i.removeListener=g,i.removeAllListeners=g,i.emit=g,i.binding=function(a){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(a){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],12:[function(a,b,c){var d=/[\.\:]/,e=b.exports=function(a,b,c){function f(b){var d,e=[].slice.call(arguments,1),g=i(b),h=m[g]||[];return n.forEach(function(a){a({name:g,args:e})}),d=[].concat(h).map(function(a){return a.apply(c||this,e)}),f.parent&&(d=d.concat(f.parent.apply(c||this,[(a?a+".":"")+g].concat(e)))),d}function g(a){a?delete m[i(a)]:m={}}function h(a){function b(){n.splice(n.indexOf(a),1)}return n.push(a),b}function i(a){return(Array.isArray(a)?a:a.split(d)).join(".")}function j(a,b){var c=m[i(a)]||[],d=c?c.indexOf(b._actual||b):-1;d>=0&&c.splice(d,1)}function k(a,b){var c;return a=i(a),c=m[a],c?c.push(b):m[a]=[b],f}function l(a,b){function c(){var d=b.apply(this,arguments);return f.off(a,c),d}return b._actual=c,k(a,c)}var m={},n=[];return"function"==typeof a&&(b=a,a=""),a=i(a||""),f.clear=f.removeAllListeners=g,f.feed=h,f.on=f.addListener=k,f.once=l,f.off=f.removeListener=j,f.parent=b||a&&e(),f}},{}],13:[function(a,b,c){"use strict";var d=a("detect-browser"),e=b.exports=function(a,b){var c,d,f,g=(b||{}).attach,h=this||("undefined"!=typeof window?window:void 0),i=((b||{}).prefixes||["ms","o","moz","webkit"]).concat("");if(h)for(c=i.length;c--;)if(d=i[c],f=d+(d?a.charAt(0).toUpperCase()+a.slice(1):a),"undefined"!=typeof h[f])return e.browser=e.browser||d.toLowerCase(),g&&(h[a]=h[f]),h[f]};e.moz="undefined"!=typeof navigator&&!!navigator.mozGetUserMedia,e.browser=d.name,e.browserVersion=e.version=d.version},{"detect-browser":15}],14:[function(a,b,c){b.exports=function(a,b){var c=(a||{}).ice,d=(a||{}).iceServers;return"function"==typeof c?c(a,b):Array.isArray(c)?b(null,[].concat(c)):void b(null,[].concat(d||[]))}},{}],15:[function(a,b,c){function d(a){return a.concat(a[1].exec(navigator.userAgent))}function e(a){return!!a[2]}for(var f=[["chrome",/Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/iPad\;\sCPU\sOS\s([0-9\._]+)/],["ios",/iPhone\;\sCPU\siPhone\sOS\s([0-9\._]+)/],["safari",/Safari\/([0-9\._]+)/]],d=f.map(d).filter(e)[0],g=d&&d[3].split(/[._]/).slice(0,3);g&&g.length<3;)g.push("0");c.name=d&&d[0],c.version=g&&g.join(".")},{}],16:[function(a,b,c){function d(a){return a&&"function"==typeof a.supported&&a.supported(f)}function e(a){var b=g.filter(function(b){return"function"==typeof a[b]});return b.length===g.length}var f=a("./detect"),g=["init"];b.exports=function(a){return[].concat(a||[]).filter(d).filter(e)[0]}},{"./detect":13}],17:[function(a,b,c){b.exports=function(b){var c=(b||{}).signaller,d=(b||{}).messenger||a("rtc-switchboard-messenger");return"string"==typeof c||c instanceof String?a("rtc-signaller")(d(c,b),b):c}},{"rtc-signaller":18,"rtc-switchboard-messenger":37}],18:[function(a,b,c){"use strict";var d=(a("rtc-core/detect"),a("cog/extend"),a("mbus"),a("cog/getable"),a("cuid"),a("pull-stream")),e=(a("pull-pushable"),a("rtc-signal/prepare"),a("pull-pushable")),f=0,g=1,h=2,i={version:"6.2.1"};b.exports=function(b,c){function j(a){n.push(a),s!==f||void 0!==l&&!l||t()}function k(){(void 0===m||m)&&setTimeout(t,50)}var l=(c||{}).autoconnect,m=(c||{}).reconnect,n=e(),o=0,p=a("rtc-signal/signaller")(c,j),q=!1,r=0,s=f,t=p.connect=function(){s!==g&&(s=g,b(function(a,b,c){return a?(s=f,p("error",a)):(o+=1,s=h,d(b,d.through(null,function(){n=e(),s=f,p("disconnected")}),d.drain(p._process)),d(n,c),p.removeListener("disconnected",k),p.on("disconnected",k),p("connected"),void(q&&o>1&&p._announce()))}))};return p.announce=function(a){return q=!0,p._update(a),clearTimeout(r),r=setTimeout(p._announce,(c||{}).announceDelay||10)},p.leave=p.close=function(){p.send("/leave",{id:p.id}),p.removeListener("disconnected",k),p.removeListener("connected",p._announce),n.end(),s=f},p._update({agent:"signaller@"+i.version}),(void 0===l||l)&&t(),p}},{"cog/extend":6,"cog/getable":7,cuid:19,mbus:12,"pull-pushable":20,"pull-stream":27,"rtc-core/detect":13,"rtc-signal/prepare":34,"rtc-signal/signaller":36}],19:[function(a,b,c){!function(a){"use strict";var c="cuid",d=0,e=4,f=36,g=Math.pow(f,e),h=function(a,b){var c="000000000"+a;return c.substr(c.length-b)},i=function(){return h((Math.random()*g<<0).toString(f),e)},j=function(){return d=g>d?d:0,d++,d-1},k=function(){var a,b="c",c=(new Date).getTime().toString(f),d=k.fingerprint(),g=i()+i();return a=h(j().toString(f),e),b+c+a+d+g};k.slug=function(){var a,b=(new Date).getTime().toString(36),c=k.fingerprint().slice(0,1)+k.fingerprint().slice(-1),d=i().slice(-2);return a=j().toString(36).slice(-4),b.slice(-2)+a+c+d},k.globalCount=function(){var a=function(){var a,b=0;for(a in window)b++;return b}();return k.globalCount=function(){return a},a},k.fingerprint=function(){return h((navigator.mimeTypes.length+navigator.userAgent.length).toString(36)+k.globalCount().toString(36),4)},a.register?a.register(c,k):"undefined"!=typeof b?b.exports=k:a[c]=k}(this.applitude||this)},{}],20:[function(a,b,c){var d=a("pull-stream");b.exports=d.Source(function(a){function b(){for(var a;g.length&&((a=e.length)||d);){var b=e.shift(),c=f.shift();g.shift()(a?null:d,b),c&&c(d===!0?null:d)}}function c(c,e){d=d||c,g.push(e),b(),d&&a&&a(d===!0?null:d)}var d,e=[],f=[],g=[];return c.push=function(a,c){return d?c&&c(d===!0?null:d):(e.push(a),f.push(c),void b())},c.end=function(c,e){"function"==typeof c&&(e=c,c=!0),d=d||c||!0,e&&f.push(e),b(),d&&a&&a(d===!0?null:d)},c})},{"pull-stream":21}],21:[function(a,b,c){var d=a("./sources"),e=a("./sinks"),f=a("./throughs"),g=a("pull-core");for(var h in d)c[h]=g.Source(d[h]);for(var h in f)c[h]=g.Through(f[h]);for(var h in e)c[h]=g.Sink(e[h]);var i=a("./maybe")(c);for(var h in i)c[h]=i[h];c.Duplex=c.Through=c.pipeable=g.Through,c.Source=c.pipeableSource=g.Source,c.Sink=c.pipeableSink=g.Sink},{"./maybe":22,"./sinks":24,"./sources":25,"./throughs":26,"pull-core":23}],22:[function(a,b,c){var d=a("pull-core"),e=d.prop,f=d.id,g=d.maybeSink;b.exports=function(a){var b={},c=a.drain,d=(b.find=function(a,b){return g(function(b){var d=!1;return b?a=e(a)||f:(b=a,a=f),c(function(c){return a(c)?(d=!0,b(null,c),!1):void 0},function(a){d||b(a===!0?null:a,null)})},b)},b.reduce=function(a,b,d){return g(function(d){return c(function(c){b=a(b,c)},function(a){d(a,b)})},d)});b.collect=b.writeArray=function(a){return d(function(a,b){return a.push(b),a},[],a)};return b}},{"pull-core":23}],23:[function(a,b,c){function d(a){return"function"!=typeof a?a:(a.pipe=a.pipe||function(b){if("function"!=typeof b)throw new Error("must pipe to reader");return d(b(a))},a.type="Source",a)}c.id=function(a){return a},c.prop=function(a){if("string"==typeof a){var b=a;return function(a){return a[b]}}return a},c.tester=function(a){return a?"object"==typeof a&&"function"==typeof a.test?a.test.bind(a):c.prop(a)||c.id:c.id},c.addPipe=d;var e=(c.Source=function(a){function b(){var b=[].slice.call(arguments);return d(a.apply(null,b))}return b.type="Source",b},c.Through=function(a){return function(){function b(b){for(c.unshift(b),b=a.apply(null,c);d.length;)b=d.shift()(b);return b}var c=[].slice.call(arguments),d=[];return b.pipe=function(a){if(d.push(a),"Source"===a.type)throw new Error("cannot pipe "+b.type+" to Source");return b.type="Sink"===a.type?"Sink":"Through",b},b.type="Through",b}}),f=c.Sink=function(a){return function(){function b(b){return c.unshift(b),a.apply(null,c)}var c=[].slice.call(arguments);if(!a)throw new Error("must be createReader function");return b.type="Sink",b}};c.maybeSink=c.maybeDrain=function(a,b){return b?f(function(c){return a(b)(c)})():e(function(b){var c;return function(d,e){return d?b(d,e):c?e(c):void a(function(a,b){c=a||!0,a?e(c):e(null,b)})(b)}})()}},{}],24:[function(a,b,c){var d=c.drain=function(a,b,c){!function d(){for(var e=!0,f=!1;e;)if(f=!1,a(null,function(g,h){f=!0,g?(e=!1,c&&c(g===!0?null:g)):b&&!1===b(h)?(e=!1,a(!0,c||function(){})):e||d()}),!f)return void(e=!1)}()};c.onEnd=function(a,b){return d(a,null,b)},c.log=function(a,b){return d(a,function(a){console.log(a)},b)}},{}],25:[function(a,b,c){var d=(c.keys=function(a){return e(Object.keys(a))},c.once=function(a){return function(b,c){if(b)return c(b);if(null!=a){var d=a;a=null,c(null,d)}else c(!0)}}),e=c.values=c.readArray=function(a){Array.isArray(a)||(a=Object.keys(a).map(function(b){return a[b]}));var b=0;return function(c,d){return c?d&&d(c):void d(b>=a.length||null,a[b++])}};c.count=function(a){var b=0;return a=a||1/0,function(c,d){return c?d&&d(c):b>a?d(!0):void d(null,b++)}},c.infinite=function(a){return a=a||Math.random,function(b,c){return b?c&&c(b):c(null,a())}},c.defer=function(){var a,b,c=[],d=function(d,e){a?a(d,e):(b=d,c.push(e))};return d.resolve=function(d){if(a)throw new Error("already resolved");if(a=d,!a)throw new Error("no read cannot resolve!"+a);for(;c.length;)a(b,c.shift())},d.abort=function(a){d.resolve(function(b,c){c(a||!0)})},d},c.empty=function(){return function(a,b){b(!0)}},c.depthFirst=function(a,b){var c=[];return c.unshift(d(a)),function e(a,d){return c.length?void c[0](a,function(a,f){return a?(c.shift(),e(null,d)):(c.unshift(b(f)),void d(a,f))}):d(!0)}},c.widthFirst=function(a,b){var c=[];return c.push(d(a)),function e(a,d){return c.length?void c[0](a,function(a,f){return a?(c.shift(),e(null,d)):(c.push(b(f)),void d(a,f))}):d(!0)}},c.leafFirst=function(a,b){var c=[],e=[];return c.push(d(a)),function f(a,d){c[0](a,function(a,g){return a?(c.shift(),e.length?d(null,e.shift()):d(!0)):(c.unshift(b(g)),e.unshift(g),void f(null,d))})}}},{}],26:[function(a,b,c){(function(b){var d=a("pull-core"),e=a("./sources"),f=a("./sinks"),g=d.prop,h=d.id,i=d.tester,j=(c.map=function(a,b){return b=g(b)||h,function(c,d){a(c,function(a,c){var c=a?null:b(c);d(a,c)})}},c.asyncMap=function(a,b){return b?function(c,d){return c?a(c,d):void a(null,function(a,c){return a?d(a,c):void b(c,d)})}:a},c.paraMap=function(a,b,c){function d(){if(f){var a=f;return f=null,h.length?a(null,h.shift()):g&&!i?a(g):void(f=a)}}function e(){a(null,function(a,f){return a?(g=a,d()):(i++,b(f,function(a,b){i--,h.push(b),d()}),void(c>i&&!g&&e()))})}if(!b)return a;var f,g=!1,h=[],i=0;return function(b,c){return b?a(b,c):(f=c,void(h.length||g?(e(),d()):e()))}},c.filter=function(a,b){return b=i(b),function c(d,e){a(d,function(a,d){return a||b(d)?void e(a,d):c(a,e)})}}),k=(c.filterNot=function(a,b){return b=i(b),j(a,function(a){return!b(a)})},c.through=function(a,b,c){function d(a){!e&&c&&(e=!0,c(a===!0?null:a))}var e=!1;return function(c,e){return c&&d(c),a(c,function(a,c){a?d(a):b&&b(c),e(a,c)})}},c.take=function(a,b){var c=!1;if("number"==typeof b){var d=b;b=function(){return d--}}return function(d,e){return c?e(c):(c=d)?a(c,e):void a(null,function(d,f){return(c=c||d)?e(c):void(b(f)?e(null,f):(c=!0,a(!0,function(a,b){e(c,b)})))})}},c.unique=function(a,b,c){b=g(b)||h;var d={};return j(a,function(a){var e=b(a);return d[e]?!!c:(d[e]=!0,!c)})}),l=(c.nonUnique=function(a,b){return k(a,b,!0)},c.group=function(a,b){var c;b=b||5;var d=[];return function(e,f){return e?a(c=e,f):c?f(c):void a(null,function g(e,h){if(c=c||e){if(!d.length)return f(c);var i=d;return d=[],f(null,i)}if(d.push(h),d.length<b)return a(null,g);var i=d;d=[],f(null,i)})}},c.flatten=function(a){var b;return function(c,d){function f(){b(null,function(a,b){a?g():d(null,b)})}function g(){a(null,function(a,c){if(a)return d(a);if(Array.isArray(c))c=e.values(c);else if("function"!=typeof c)throw new Error("expected stream of streams");b=c,f()})}b?f():g()}},c.prepend=function(a,b){return function(c,d){if(null!==b){if(c)return a(c,d);var e=b;b=null,d(null,e)}else a(c,d)}},c._reduce=function(a,b,c){return function(d,e){return d?a(d,e):ended?e(ended):void f.drain(function(a){c=b(c,a)},function(a,b){ended=a||!0,a?e(ended):e(null,c)})(a)}},b.nextTick);c.highWaterMark=function(a,b){function c(){for(;g.length&&(f.length||e);)g.shift()(e,e?null:f.shift())}function d(){return e||h||f.length>=b?void 0:(h=!0,a(e,function(a,b){h=!1,e=e||a,null!=b&&f.push(b),d(),c()}))}var e,f=[],g=[],h=!1;return b=b||10,l(d),function(a,b){e=e||a,g.push(b),d(),c()}}}).call(this,a("_process"))},{"./sinks":24,"./sources":25,_process:11,"pull-core":23}],27:[function(a,b,c){function d(a){return"function"==typeof a}function e(a){return a&&("Through"===a.type||1===a.length)}var f=a("./sources"),g=a("./sinks"),h=a("./throughs"),i=a("pull-core"),c=b.exports=function l(){function a(){var c=b.shift();return null==c?a():d(c)?c:function(a){return c.sink(a),c.source}}var b=[].slice.call(arguments);if(e(b[0]))return function(a){return b.unshift(a),l.apply(null,b)};var c=b.shift();for(d(c.source)&&(c=c.source);b.length;)c=a()(c);return c};for(var j in f)c[j]=i.Source(f[j]);for(var j in h)c[j]=i.Through(h[j]);for(var j in g)c[j]=i.Sink(g[j]);var k=a("./maybe")(c);for(var j in k)c[j]=k[j];c.Duplex=c.Through=c.pipeable=i.Through,c.Source=c.pipeableSource=i.Source,c.Sink=c.pipeableSink=i.Sink},{"./maybe":28,"./sinks":30,"./sources":31,"./throughs":32,"pull-core":29}],28:[function(a,b,c){var d=a("pull-core"),e=d.prop,f=d.id,g=d.maybeSink;b.exports=function(a){var b={},c=a.drain,d=(b.find=function(a,b){return g(function(b){var d=!1;return b?a=e(a)||f:(b=a,a=f),c(function(c){return a(c)?(d=!0,b(null,c),!1):void 0},function(a){d||b(a===!0?null:a,null)})},b)},b.reduce=function(a,b,d){return g(function(d){return c(function(c){b=a(b,c)},function(a){d(a,b)})},d)});b.collect=b.writeArray=function(a){return d(function(a,b){return a.push(b),a},[],a)},b.concat=function(a){return d(function(a,b){return a+b},"",a)};return b}},{"pull-core":29}],29:[function(a,b,c){function d(a){return"function"!=typeof a?a:(a.pipe=a.pipe||function(b){if("function"!=typeof b&&"function"!=typeof b.sink)throw new Error("must pipe to reader");var c=d(b.sink?b.sink(a):b(a));return b.source||c},a.type="Source",a)}c.id=function(a){return a},c.prop=function(a){if("string"==typeof a){var b=a;return function(a){return a[b]}}return a},c.tester=function(a){return a?"object"==typeof a&&"function"==typeof a.test?a.test.bind(a):c.prop(a)||c.id:c.id},c.addPipe=d;var e=(c.Source=function(a){function b(){var b=[].slice.call(arguments);return d(a.apply(null,b))}return b.type="Source",b},c.Through=function(a){return function(){function b(b){for(c.unshift(b),b=a.apply(null,c);d.length;)b=d.shift()(b);return b}var c=[].slice.call(arguments),d=[];return b.pipe=function(a){if(d.push(a),"Source"===a.type)throw new Error("cannot pipe "+b.type+" to Source");return b.type="Sink"===a.type?"Sink":"Through",b},b.type="Through",b}}),f=c.Sink=function(a){return function(){function b(b){return c.unshift(b),a.apply(null,c)}var c=[].slice.call(arguments);if(!a)throw new Error("must be createReader function");return b.type="Sink",b}};c.maybeSink=c.maybeDrain=function(a,b){return b?f(function(c){return a(b)(c)})():e(function(b){var c;return function(d,e){return d?b(d,e):c?e(c):void a(function(a,b){c=a||!0,a?e(c):e(null,b)})(b)}})()}},{}],30:[function(a,b,c){var d=c.drain=function(a,b,c){!function d(){for(var e=!0,f=!1;e;)if(f=!1,a(null,function(g,h){if(f=!0,g){if(e=!1,c)c(g===!0?null:g);else if(g&&g!==!0)throw g}else b&&!1===b(h)?(e=!1,a(!0,c||function(){})):e||d()}),!f)return void(e=!1)}()};c.onEnd=function(a,b){return d(a,null,b)},c.log=function(a,b){return d(a,function(a){console.log(a)},b)}},{}],31:[function(a,b,c){function d(a,b,c){a(b),c&&c(b===!0?null:b)}var e=(c.keys=function(a){return f(Object.keys(a))},c.once=function(a,b){return function(c,e){if(c)return d(e,c,b);if(null!=a){var f=a;a=null,e(null,f)}else e(!0)}}),f=c.values=c.readArray=function(a,b){if(!a)return function(a,c){return a?d(c,a,b):c(!0)};Array.isArray(a)||(a=Object.keys(a).map(function(b){return a[b]}));var c=0;return function(e,f){return e?d(f,e,b):void f(c>=a.length||null,a[c++])}};c.count=function(a){var b=0;return a=a||1/0,function(c,d){return c?d&&d(c):b>a?d(!0):void d(null,b++)}},c.infinite=function(a){return a=a||Math.random,function(b,c){return b?c&&c(b):c(null,a())}},c.defer=function(){var a,b,c=[],d=function(d,e){a?a(d,e):(b=d,c.push(e))};return d.resolve=function(d){if(a)throw new Error("already resolved");if(a=d,!a)throw new Error("no read cannot resolve!"+a);for(;c.length;)a(b,c.shift())},d.abort=function(a){d.resolve(function(b,c){c(a||!0)})},d},c.empty=function(){return function(a,b){b(!0)}},c.error=function(a){return function(b,c){c(a)}},c.depthFirst=function(a,b){var c=[];return c.unshift(e(a)),function d(a,e){return c.length?void c[0](a,function(a,f){return a?(c.shift(),d(null,e)):(c.unshift(b(f)),void e(a,f))}):e(!0)}},c.widthFirst=function(a,b){var c=[];return c.push(e(a)),function d(a,e){return c.length?void c[0](a,function(a,f){return a?(c.shift(),d(null,e)):(c.push(b(f)),void e(a,f))}):e(!0)}},c.leafFirst=function(a,b){var c=[],d=[];return c.push(e(a)),function f(a,e){c[0](a,function(a,g){return a?(c.shift(),d.length?e(null,d.shift()):e(!0)):(c.unshift(b(g)),d.unshift(g),void f(null,e))})}}},{}],32:[function(a,b,c){(function(b){var d=a("pull-core"),e=a("./sources"),f=a("./sinks"),g=d.prop,h=d.id,i=d.tester,j=(c.map=function(a,b){return b=g(b)||h,function(c,d){a(c,function(c,e){try{e=c?null:b(e)}catch(f){return a(f,function(){return d(f)})}d(c,e)})}},c.asyncMap=function(a,b){return b?function(c,d){return c?a(c,d):void a(null,function(a,c){return a?d(a,c):void b(c,d)})}:a},c.paraMap=function(a,b,c){function d(){if(f){var a=f;return f=null,h.length?a(null,h.shift()):g&&!i?a(g):void(f=a)}}function e(){a(null,function(a,f){return a?(g=a,d()):(i++,b(f,function(a,b){i--,h.push(b),d()}),void(c>i&&!g&&e()))})}if(!b)return a;var f,g=!1,h=[],i=0;return function(b,c){return b?a(b,c):(f=c,void(h.length||g?(e(),d()):e()))}},c.filter=function(a,b){return b=i(b),function c(d,e){for(var f,g=!0;g;)g=!1,f=!0,a(d,function(a,d){return a||b(d)?void e(a,d):f?g=!0:c(a,e)}),f=!1}}),k=(c.filterNot=function(a,b){return b=i(b),j(a,function(a){return!b(a)})},c.through=function(a,b,c){function d(a){!e&&c&&(e=!0,c(a===!0?null:a))}var e=!1;return function(c,e){return c&&d(c),a(c,function(a,c){a?d(a):b&&b(c),e(a,c)})}},c.take=function(a,b){var c=!1;if("number"==typeof b){var d=b;b=function(){return d--}}return function(d,e){return c?e(c):(c=d)?a(c,e):void a(null,function(d,f){return(c=c||d)?e(c):void(b(f)?e(null,f):(c=!0,a(!0,function(a,b){e(c,b)})))})}},c.unique=function(a,b,c){b=g(b)||h;var d={};return j(a,function(a){var e=b(a);return d[e]?!!c:(d[e]=!0,!c)})});c.nonUnique=function(a,b){return k(a,b,!0)},c.group=function(a,b){var c;b=b||5;var d=[];return function(e,f){return e?a(c=e,f):c?f(c):void a(null,function g(e,h){if(c=c||e){if(!d.length)return f(c);var i=d;return d=[],f(null,i)}if(d.push(h),d.length<b)return a(null,g);var i=d;d=[],f(null,i)})}},c.flatten=function(a){var b;return function(c,d){function f(){b(null,function(a,b){a?g():d(null,b)})}function g(){a(null,function(a,c){if(a)return d(a);if(Array.isArray(c)||c&&"object"==typeof c)c=e.values(c);else if("function"!=typeof c)throw new Error("expected stream of streams");b=c,f()})}b?f():g()}},c.prepend=function(a,b){return function(c,d){if(null!==b){if(c)return a(c,d);var e=b;b=null,d(null,e)}else a(c,d)}},c._reduce=function(a,b,c){return function(d,e){return d?a(d,e):ended?e(ended):void f.drain(function(a){c=b(c,a)},function(a,b){ended=a||!0,a?e(ended):e(null,c)})(a)}},b.nextTick,c.highWaterMark=function(a,c){function d(){for(;i.length&&(h.length||f);)i.shift()(f,f?null:h.shift());!h.length&&g&&(f=g)}function e(){return f||g||j||h.length>=c?void 0:(j=!0,a(f||g,function(a,b){j=!1,g=g||a,null!=b&&h.push(b),e(),d()}))}var f,g,h=[],i=[],j=!1;return c=c||10,b.nextTick(e),function(a,b){f=f||a,i.push(b),e(),d()}},c.flatMap=function(a,b){b=b||h;var c,d=[];return function(e,f){return d.length?f(null,d.shift()):c?f(c):void a(e,function g(e,h){if(e)c=e;else for(var i=b(h);i&&i.length;)d.push(i.shift());d.length?f(null,d.shift()):c?f(c):a(null,g)})}}}).call(this,a("_process"))},{"./sinks":30,"./sources":31,_process:11,"pull-core":29}],33:[function(a,b,c){var d=a("cog/extend");b.exports=function(a){function b(b){var c=d({allow:!0},b);return a("peer:filter",b.id,c),c.allow}return function(c,e,f,g,h){var i,j=c[0];if(j&&j.id&&j.id!==a.id){if(!b(j))return;return i=a.peers.get(j.id),a("peer:connected",j.id,j),i?(d(i.data,j),a("peer:update",j,f)):(i={id:j.id,roleIdx:[j.id,a.id].sort().indexOf(j.id),data:{}},d(i.data,j),a.peers.set(j.id,i),a.autoreply&&!h&&a.to(j.id).send("/announce",a.attributes),a("peer:announce",j,i))}}}},{"cog/extend":6}],34:[function(a,b,c){function d(a){return"object"!=typeof a||a instanceof String?"function"==typeof a?null:a:JSON.stringify(a)}b.exports=function(a){return a.map(d).join("|")}},{}],35:[function(a,b,c){var d=a("cog/jsonparse");b.exports=function(b,c){function e(a,c,e){var f="message:"+a[0].slice(1),g=a.slice(2).map(d);b.apply(b,[f].concat(g).concat([c,e]))}var f={announce:a("./handlers/announce")(b,c)};return function(a){var c,g,h,i,j=a,k=!0,l=!1;if(!j||"primus"!==j.slice(0,6)){var m=b.id+"";if("/to"===j.slice(0,3)&&(k=j.slice(4,m.length+4)===m,k&&(c=j.slice(5+m.length).split("|").map(d),l=!0,c=c.map(d))),k&&(b("rawdata",j),c=c||j.split("|").map(d),"string"==typeof c[0])){if(h=c[1],h===b.id)return console.warn("got data from ourself, discarding");i=b.peers.get(h)||h,"/"===c[0].charAt(0)?(g=f[c[0].slice(1)],"function"==typeof g?g(c.slice(2),c[0].slice(1),h,i,l):e(c,i,a)):b("data",c.slice(0,1).concat(c.slice(2)),h,i,l)}}}}},{"./handlers/announce":33,"cog/jsonparse":8}],36:[function(a,b,c){var d=a("rtc-core/detect"),e=a("cog/extend"),f=a("cog/getable"),g=a("cuid"),h=a("mbus"),i=a("./prepare");b.exports=function(b,c){function j(a){return function(){var b=a.concat([].slice.call(arguments));b.splice(3,0,l.id),c(i(b))}}var k=(b||{}).autoreply,l=h("",(b||{}).logger),m=l.peers=f({}),n=l.attributes={browser:d.browser,browserVersion:d.browserVersion,agent:"unknown"};return l.id=(b||{}).id||g(),l.isMaster=function(a){var b=m.get(a);return b&&0!==b.roleIdx},l.send=function(){var a=[].slice.call(arguments);a.splice(1,0,l.id),c(i(a))},l.to=function(a){return{send:j(["/to",a])}},l._announce=function(){l.send("/announce",n), l("local:announce",n)},l._process=a("./process")(l),l._update=function(a){e(n,a,{id:l.id})},l.autoreply=void 0===k||k,l}},{"./prepare":34,"./process":35,"cog/extend":6,"cog/getable":7,cuid:19,mbus:12,"rtc-core/detect":13}],37:[function(a,b,c){var d=a("cog/extend");b.exports=function(b,c){return a("messenger-ws")(b,d({endpoints:(c||{}).endpoints||["/"]},c))}},{"cog/extend":6,"messenger-ws":38}],38:[function(a,b,c){var d=a("ws"),e=a("wsurl"),f=a("pull-ws"),g=(a("cog/defaults"),/\/$/),h=[];b.exports=function(a,b){function c(c){function g(){if(!u){if(0===t.length)return c(new Error("Unable to connect to url: "+a));o=new d(e(t.shift())),o.addEventListener("message",h),o.addEventListener("error",m),o.addEventListener("close",l),o.addEventListener("open",n),r=o.removeEventListener||o.removeListener,p=setTimeout(g,i)}}function h(){u||(clearTimeout(p),clearTimeout(q),r.call(o,"open",n),r.call(o,"close",l),r.call(o,"error",m),r.call(o,"message",h),u=!0,c(null,s,f.sink(o,b)))}function l(a){var b=a.wasClean&&(void 0===a.code||j.indexOf(a.code)<0);return b?(clearTimeout(q),void clearTimeout(p)):m()}function m(){clearTimeout(q),clearTimeout(p),g()}function n(){s=f.source(o,b),q=setTimeout(h,100)}var o,p,q,r,s,t=[].concat(k),u=!1;g()}var i=(b||{}).timeout||1e3,j=(b||{}).failcodes||h,k=((b||{}).endpoints||["/"]).map(function(b){return a.replace(g,"")+b});return c}},{"cog/defaults":5,"pull-ws":39,ws:44,wsurl:45}],39:[function(a,b,c){function d(a,b){return{source:c.source(a),sink:c.sink(a,b)}}c=b.exports=d,c.source=a("./source"),c.sink=a("./sink")},{"./sink":42,"./source":43}],40:[function(a,b,c){arguments[4][29][0].apply(c,arguments)},{dup:29}],41:[function(a,b,c){b.exports=function(a,b){function c(){"function"==typeof f&&(f.call(a,"open",d),f.call(a,"error",e))}function d(a){c(),b()}function e(a){c(),b(a)}var f=a&&(a.removeEventListener||a.removeListener);return a.readyState>=2?b(!0):1===a.readyState?b():(a.addEventListener("open",d),void a.addEventListener("error",e))}},{}],42:[function(a,b,c){(function(c){var d=a("pull-core"),e=a("./ready");b.exports=d.Sink(function(a,b,d){function f(d,i){return d?void(g&&b.readyState<=1&&(h&&b.addEventListener("close",function(a){if(a.wasClean)h();else{var b=new Error("ws error");b.event=a,h(b)}}),b.close())):void e(b,function(d){return d?a(d,function(){}):(b.send(i),void c.nextTick(function(){a(null,f)}))})}d=d||{};var g=d.closeOnEnd!==!1,h="function"==typeof d?d:d.onClose;a(null,f)})}).call(this,a("_process"))},{"./ready":41,_process:11,"pull-core":40}],43:[function(a,b,c){var d=a("pull-core"),e=a("./ready");b.exports=d.Source(function(a){function b(b,g){return c=null,d?g(d):b?(c=g,a.close()):void e(a,function(a){return a?g(d=a):d&&d!==!0?g(d):f.length>0?g(null,f.shift()):d?g(!0):void(c=g)})}var c,d,f=[];return a.addEventListener("message",function(a){return c?c(null,a.data):void f.push(a.data)}),a.addEventListener("close",function(a){return d?void 0:c?c(d=!0):void 0}),a.addEventListener("error",function(a){d||(d=a,c&&c(d))}),b})},{"./ready":41,"pull-core":40}],44:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],45:[function(a,b,c){var d=/^http(.*)$/;b.exports=function(a,b){var c=(b||{}).current||"undefined"!=typeof location&&location.href,e=c&&c.slice(0,c.indexOf(":")),f=(b||{}).insecure,g="//"==a.slice(0,2),h=!e||"file:"===e;return g?h?(f?"ws:":"wss:")+a:e.replace(d,"ws$1")+":"+a:a.replace(d,"ws$1")}},{}],46:[function(a,b,c){"use strict";var d=a("cog/logger")("rtc/cleanup"),e=["closed"],f=["addstream","datachannel","icecandidate","negotiationneeded","removestream","signalingstatechange"],g=["iceconnectionstatechange"];b.exports=function(a){function b(b){b.forEach(function(b){a["on"+b]&&(a["on"+b]=null)})}var c=a.iceConnectionState,h=e.indexOf(c)<0;b(f),h&&(d("attempting connection close, current state: "+a.iceConnectionState),a.close()),setTimeout(function(){b(g)},100)}},{"cog/logger":9}],47:[function(a,b,c){"use strict";function d(b,c,d,j){function n(){y("decoupling "+d.id+" from "+c),z.stop(),g(b),d.removeListener("sdp",p),d.removeListener("candidate",o),d.removeListener("negotiate",u),d.removeListener("message:sdp",p),d.removeListener("message:candidate",o),d.removeListener("message:negotiate",u)}function o(a){F.addIceCandidate(a)}function p(a,b){A("sdp.remote",a),b&&b.id===c&&F.setRemoteDescription(a)}function q(){y("captured pc close, iceConnectionState = "+b.iceConnectionState),n()}function r(){y("captured pc disconnect, monitoring connection status"),w=setTimeout(function(){y("manually closing connection after disconnect timeout"),g(b)},D),z.on("statechange",s)}function s(){return y("connection state changed to: "+b.iceConnectionState),m.indexOf(b.iceConnectionState)>=0?void 0:(v(),l.indexOf(b.iceConnectionState)>=0?z("closed"):void z.once("disconnect",r))}function t(a){var b=a.candidate&&k(a.candidate);a.candidate?(v(),A("ice.local",b),d.to(c).send("/candidate",b),C=!1):C||(C=!0,A("ice.gathercomplete"),d.to(c).send("/endofcandidates",{}))}function u(a){a.id===c&&(A("negotiate.request",a.id),H())}function v(){z.off("statechange",s),y("reset disconnect timer, state: "+b.iceConnectionState),clearTimeout(w)}var w,x=(j||{}).debugLabel||"rtc",y=a("cog/logger")(x+"/couple"),z=h(b,c,d,(j||{}).logger),A=e("",z),B=(j||{}).reactive,C=!0,D=(j||{}).disconnectTimeout||1e4,E=d.isMaster(c),F=f(b,j),G=i(function(){return E?void F.createOffer():d.to(c).send("/negotiate")},100,{leading:!1}),H=i(F.createOffer,100,{leading:!1});return B&&(b.onnegotiationneeded=function(){A("negotiate.renegotiate"),G()}),b.onicecandidate=t,F.on("sdp.local",function(a){d.to(c).send("/sdp",a)}),d.on("sdp",p),d.on("candidate",o),d.on("message:sdp",p),d.on("message:candidate",o),E&&(d.on("negotiate",u),d.on("message:negotiate",u)),z.once("closed",q),z.once("disconnected",r),z.createOffer=G,z}var e=a("mbus"),f=a("rtc-taskqueue"),g=a("./cleanup"),h=a("./monitor"),i=a("cog/throttle"),j=a("whisk/pluck"),k=j("candidate","sdpMid","sdpMLineIndex"),l=["closed","failed"],m=["checking"];b.exports=d},{"./cleanup":46,"./monitor":51,"cog/logger":9,"cog/throttle":10,mbus:12,"rtc-taskqueue":52,"whisk/pluck":63}],48:[function(a,b,c){"use strict";b.exports=a("rtc-core/detect")},{"rtc-core/detect":13}],49:[function(a,b,c){"use strict";var d=a("cog/logger")("generators"),e=a("./detect"),f=a("cog/defaults"),g={create:{dtls:function(a){e.moz||(a.optional=(a.optional||[]).concat({DtlsSrtpKeyAgreement:!0}))}}};c.config=function(a){var b=(a||{}).iceServerGenerator;return f({},a,{iceServers:"function"==typeof b?b():[]})},c.connectionConstraints=function(a,b){var c,e={},h=g.create;return Object.keys(a||{}).forEach(function(a){h[a]&&h[a](e)}),c=f({},b,e),d("generated connection constraints: ",c),c}},{"./detect":48,"cog/defaults":5,"cog/logger":9}],50:[function(a,b,c){"use strict";var d=a("./generators"),e=c.detect=a("./detect"),f=a("rtc-core/plugin");c.logger=a("cog/logger");var g=c.RTCPeerConnection=e("RTCPeerConnection");c.couple=a("./couple"),c.createConnection=function(a,b){var c=f((a||{}).plugins),e=(a||{}).RTCPeerConnection||g,h=d.config(a);return b=d.connectionConstraints(a,b),c&&"function"==typeof c.createConnection?c.createConnection(h,b):new e(h,b)}},{"./couple":47,"./detect":48,"./generators":49,"cog/logger":9,"rtc-core/plugin":16}],51:[function(a,b,c){"use strict";function d(a){return f[a]||a}var e=a("mbus"),f={completed:"connected"},g=["signalingstatechange","iceconnectionstatechange"];b.exports=function(a,b,c,f){function h(){var b=d(a.iceConnectionState);k("statechange",a,b),j!==b&&(k(b),j=b)}function i(){k("closed")}var j,k=e("",f);return a.onclose=i,g.forEach(function(b){a["on"+b]=h}),k.stop=function(){a.onclose=null,g.forEach(function(b){a["on"+b]=null})},k.checkState=h,a?(j=d(a.iceConnectionState),k):k}},{mbus:12}],52:[function(a,b,c){var d=a("rtc-core/detect"),e=a("rtc-core/plugin"),f=a("priorityqueuejs"),g=a("whisk/pluck"),h=g("sdp","type"),i=a("rtc-validator/candidate"),j=a("rtc-sdpclean"),k=a("rtc-sdp"),l=100,m=1e3,n=["addIceCandidate","setLocalDescription","setRemoteDescription","createAnswer","createOffer"],o={setLocalDescription:"setlocaldesc",setRemoteDescription:"setremotedesc",createOffer:"offer",createAnswer:"answer"},p={data:"application"},q=["have-remote-offer","have-local-pranswer"];b.exports=function(b,c){function g(a,d){function e(){L("ice.remote.applied",h),d()}function f(a){L("ice.remote.invalid",h),d(a)}var g=a.args[0];if(c&&c.filterCandidate&&!c.filterCandidate(g))return L("ice.remote.filtered",h),d();var h=g&&g.candidate&&u(g);return h?void b.addIceCandidate(h,e,f):d()}function r(){var a=!K.isEmpty()&&K.peek(),c=a&&I(a);return P=0,c?(a=K.deq(),void a.fn(a,function(b){var c=a.fail||Q,d=a.pass,e=a.name;return b?(console.error(e+" task failed: ",b),c(b)):("function"==typeof d&&d.apply(a,[].slice.call(arguments,1)),void J())})):(a&&z(a)&&(L("task.expire",a),K.deq()),!K.isEmpty()&&E(b)&&J())}function s(a){var c=[],d=a&&j(a.sdp,{collector:c});return a&&d!==a.sdp&&(console.info("invalid lines removed from sdp: ",c),a.sdp=d),"function"==typeof R&&(a.sdp=R(a.sdp,b)),a}function t(){return q.indexOf(b.signalingState)>=0?L.createAnswer():void 0}function u(a){return O&&"function"==typeof O.createIceCandidate?O.createIceCandidate(a):new T(a)}function v(a){return O&&"function"==typeof O.createSessionDescription?O.createSessionDescription(a):new S(a)}function w(){L("sdp.local",h(this.args[0]))}function x(a,b,c){return function(){var d=[].slice.call(arguments);c&&"function"==typeof c.processArgs&&(d=d.map(c.processArgs));var e=M.indexOf(a);K.enq({args:d,name:a,fn:b,priority:e>=0?e:l,start:Date.now(),checks:[E].concat((c||{}).checks||[]),pass:(c||{}).pass,fail:(c||{}).fail}),J()}}function y(a,c){function d(b){L.apply(L,["negotiate.error",a.name,b].concat(a.args)),c(b)}function e(){L.apply(L,[["negotiate",g,"ok"],a.name].concat(a.args)),c.apply(null,[null].concat([].slice.call(arguments)))}var f=b[a.name],g=o[a.name]||(a.name||"").toLowerCase(),h=[e,d],i="createOffer"===a.name;return f?(L.apply(L,["negotiate."+g].concat(a.args)),void f.apply(b,a.args.concat(h).concat(i?B():[]))):c(new Error('cannot call "'+a.name+'" on RTCPeerConnection'))}function z(a){return"number"==typeof a.ttl&&a.start+a.ttl<Date.now()}function A(a){for(;a&&a.candidate&&a.candidate.candidate;)a=a.candidate;return a}function B(){var a={offertoreceivevideo:"OfferToReceiveVideo",offertoreceiveaudio:"OfferToReceiveAudio",icerestart:"IceRestart",voiceactivitydetection:"VoiceActivityDetection"},b={OfferToReceiveVideo:!0,OfferToReceiveAudio:!0};return Object.keys(c||{}).forEach(function(d){a[d.toLowerCase()]&&(b[a[d.toLowerCase()]]=c[d])}),{mandatory:b}}function C(a,b){return a.__hasDesc||(a.__hasDesc=!!a.remoteDescription)}function D(a){return"have-local-offer"!==a.signalingState}function E(a){return"closed"!==a.signalingState}function F(a,b){return b.__valid||(b.__valid=0===i(b.args[0]).length)}function G(a,b){var c=b.args[0]&&b.args[0].sdpMid;if(c=p[c]||c,""===c)return!0;if(!a.__mediaTypes){var d=k(a.remoteDescription&&a.remoteDescription.sdp);a.__mediaTypes=d.getMediaTypes()}return a.__mediaTypes.indexOf(c)>=0}function H(a,b){var c=[a,b],d=c.map(I),e=c.map(function(a,b){var c=d[b];return c?a.priority:m});return e[1]-e[0]}function I(a){return(a.checks||[]).reduce(function(c,d){return c&&d(b,a)},!0)}function J(){P||(P=setTimeout(r,N))}var K=new f(H),L=a("mbus")("",(c||{}).logger),M=(c||{}).priorities||n,N=(c||{}).interval||50,O=e((c||{}).plugins),P=0,Q=L.bind(L,"fail"),R=(c||{}).sdpfilter||(c||{}).sdpFilter,S=(c||{}).RTCSessionDescription||d("RTCSessionDescription"),T=(c||{}).RTCIceCandidate||d("RTCIceCandidate");return L.addIceCandidate=x("addIceCandidate",g,{processArgs:A,checks:[C,F,G],ttl:5e3}),L.setLocalDescription=x("setLocalDescription",y,{processArgs:s,pass:w}),L.setRemoteDescription=x("setRemoteDescription",y,{processArgs:v,pass:t}),L.createOffer=x("createOffer",y,{checks:[D],pass:L.setLocalDescription}),L.createAnswer=x("createAnswer",y,{pass:L.setLocalDescription}),L}},{mbus:12,priorityqueuejs:53,"rtc-core/detect":13,"rtc-core/plugin":16,"rtc-sdp":54,"rtc-sdpclean":56,"rtc-validator/candidate":57,"whisk/pluck":63}],53:[function(a,b,c){function d(a){this._comparator=a||d.DEFAULT_COMPARATOR,this._elements=[]}b.exports=d,d.DEFAULT_COMPARATOR=function(a,b){return"number"==typeof a&&"number"==typeof b?a-b:(a=a.toString(),b=b.toString(),a==b?0:a>b?1:-1)},d.prototype.isEmpty=function(){return 0===this.size()},d.prototype.peek=function(){if(this.isEmpty())throw new Error("PriorityQueue is empty");return this._elements[0]},d.prototype.deq=function(){var a=this.peek(),b=this._elements.pop(),c=this.size();if(0===c)return a;this._elements[0]=b;for(var d=0;c>d;){var e=d,f=2*d+1,g=2*d+2;if(c>f&&this._compare(f,e)>=0&&(e=f),c>g&&this._compare(g,e)>=0&&(e=g),e===d)break;this._swap(e,d),d=e}return a},d.prototype.enq=function(a){for(var b=this._elements.push(a),c=b-1;c>0;){var d=Math.floor((c-1)/2);if(this._compare(c,d)<=0)break;this._swap(d,c),c=d}return b},d.prototype.size=function(){return this._elements.length},d.prototype.forEach=function(a){return this._elements.forEach(a)},d.prototype._compare=function(a,b){return this._comparator(this._elements[a],this._elements[b])},d.prototype._swap=function(a,b){var c=this._elements[a];this._elements[a]=this._elements[b],this._elements[b]=c}},{}],54:[function(a,b,c){"use strict";var d=a("whisk/nub"),e=a("whisk/pluck"),f=a("whisk/flatten"),g=/\r?\n/,h=/\r?\n$/,i=["a","c","b","k"],j=a("./parsers");b.exports=function(a){var b,c={},k=[],l=a.split(g).filter(Boolean).map(function(a){return a.split("=")}),m=(d(l.filter(function(a){return a[0]&&i.indexOf(a[0])<0}).map(e(0))),c.findLine=function(a,b){var c=k.filter(function(b){return b[0]===a})[b||0];return c&&c[1]});return l.forEach(function(a){var c=j[a[0]];c?b=c(k,a):b?b=b(a):k.push(a)}),c.addIceCandidate=function(a){var b=(a||{}).lineIndex||(a||{}).sdpMLineIndex,c="undefined"!=typeof b&&m("m",b),d=(a||{}).candidate;c&&d&&c.childlines.push(d.replace(h,"").split("="))},c.getMediaTypes=function(){function a(a){return a[1].def.split(/\s/)[0]}return k.filter(function(a){return"m"===a[0]&&a[1]&&a[1].def}).map(a)},c.toString=function(){return k.map(function(a){return"function"==typeof a[1].toArray?a[1].toArray():[a]}).reduce(f).map(function(a){return a.join("=")}).join("\n")},c}},{"./parsers":55,"whisk/flatten":60,"whisk/nub":62,"whisk/pluck":63}],55:[function(a,b,c){"use strict";c.m=function(a,b){function c(a){return d.childlines.push(a),c}var d={def:b[1],childlines:[],toArray:function(){return[["m",d.def]].concat(d.childlines)}};return a.push(["m",d]),c}},{}],56:[function(a,b,c){function d(a){var b=f.exec(a);return b&&b[0]}var e=[[/^(a\=candidate.*)$/,a("rtc-validator/candidate")]],f=/(\r?\n|\\r\\n)/;b.exports=function(a,b){var c=d(a),f=a.split(c),g=(b||{}).collector;return f=f.filter(function(a){var b=e.reduce(function(b,c,d){return"undefined"!=typeof b?b:c[0].exec(a)&&{line:a.replace(c[0],"$1"),fn:c[1]}},void 0),c=b?b.fn(b.line):[];return g&&c.forEach(function(a){g.push(a)}),0===c.length}),f.join(c)}},{"rtc-validator/candidate":57}],57:[function(a,b,c){function d(a,b){var c=g[b];return c&&!c[0].test(a)?(e(c[2]+" part failed validation: "+a),new Error(c[1])):void 0}var e=a("cog/logger")("rtc-validator"),f=/^(?:a=)?candidate:/,g=[[/.+/,"invalid foundation component","foundation"],[/\d+/,"invalid component id","component-id"],[/(UDP|TCP)/i,"transport must be TCP or UDP","transport"],[/\d+/,"numeric priority expected","priority"],[a("reu/ip"),"invalid connection address","connection-address"],[/\d+/,"invalid connection port","connection-port"],[/typ/,'Expected "typ" identifier',"type classifier"],[/.+/,"Invalid candidate type specified","candidate-type"]];b.exports=function(a){var b=[],c=a&&(a.candidate||a),e=c&&f.exec(c),g=e&&c.slice(e[0].length).split(/\s/);return c?e?b=b.concat(g.map(d)).filter(Boolean):[new Error("candidate did not match expected sdp line format")]:[new Error("empty candidate")]}},{"cog/logger":9,"reu/ip":58}],58:[function(a,b,c){b.exports=/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?: