-
Notifications
You must be signed in to change notification settings - Fork 9
/
rtc.min.js
3 lines (3 loc) · 55.7 KB
/
rtc.min.js
1
2
3
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.RTC=n()}}(function(){return function n(e,t,r){function o(c,u){if(!t[c]){if(!e[c]){var a="function"==typeof require&&require;if(!u&&a)return a(c,!0);if(i)return i(c,!0);var s=new Error("Cannot find module '"+c+"'");throw s.code="MODULE_NOT_FOUND",s}var f=t[c]={exports:{}};e[c][0].call(f.exports,function(n){var t=e[c][1][n];return o(t?t:n)},f,f.exports,n,e,t,r)}return t[c].exports}for(var i="function"==typeof require&&require,c=0;c<r.length;c++)o(r[c]);return o}({1:[function(n,e){e.exports={constraints:{video:!0,audio:!0},signaller:"https://switchboard.rtc.io/",room:void 0,ice:[],channels:{},localContainer:"#l-video",remoteContainer:"#r-video",plugins:[],options:{}}},{}],2:[function(n,e){function t(n){return function(e){e.dataset.peer=n}}function r(n,e){g(e)("capture",["constraints","options"],f)("attach",["capture","options"],s.local)("render-local",["attach"],d([v("+rtc"),v("+localvideo"),p.to((e||{}).localContainer||"#l-video")]))("start-conference",["capture"],n.addStream).on("error",c(n,e))}function o(n,e){return function(r,o){g(a({stream:o},e))("attach",["stream","options"],s)("render-remote",["attach"],d([v("+rtc"),v("+remotevideo"),t(r),p.to((e||{}).remoteContainer||"#r-video")])).on("error",c(n,e))}}function i(n){h('[data-peer="'+n+'"]').forEach(function(n){n.parentNode.removeChild(n)})}function c(){return function(n){console.error(n)}}var u=n("cog/defaults"),a=n("cog/extend"),s=n("rtc-attach"),f=n("rtc-capture"),l=n("rtc-quickconnect"),d=n("whisk/chain"),p=n("fdom/append"),v=n("fdom/classtweak"),h=n("fdom/qsa"),g=n("kgo");e.exports=function(e){var t;return e=u({},e,n("./defaultconfig.js")),e.options=a({room:e.room,ice:e.ice,plugins:e.plugins,expectedLocalStreams:e.constraints?1:0},e.options),t=l(e.signaller,e.options),t.on("call:ended",i).on("stream:added",o(t,e)),Object.keys(e.channels||{}).forEach(function(n){var r=e.channels[n];t.createDataChannel(n,r===!0?null:r)}),e.constraints&&r(t,e),t}},{"./defaultconfig.js":1,"cog/defaults":5,"cog/extend":6,"fdom/append":11,"fdom/classtweak":12,"fdom/qsa":13,kgo:14,"rtc-attach":16,"rtc-capture":17,"rtc-quickconnect":22,"whisk/chain":66}],3:[function(n,e){function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(n){return"function"==typeof n}function o(n){return"number"==typeof n}function i(n){return"object"==typeof n&&null!==n}function c(n){return void 0===n}e.exports=t,t.EventEmitter=t,t.prototype._events=void 0,t.prototype._maxListeners=void 0,t.defaultMaxListeners=10,t.prototype.setMaxListeners=function(n){if(!o(n)||0>n||isNaN(n))throw TypeError("n must be a positive number");return this._maxListeners=n,this},t.prototype.emit=function(n){var e,t,o,u,a,s;if(this._events||(this._events={}),"error"===n&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(t=this._events[n],c(t))return!1;if(r(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:for(o=arguments.length,u=new Array(o-1),a=1;o>a;a++)u[a-1]=arguments[a];t.apply(this,u)}else if(i(t)){for(o=arguments.length,u=new Array(o-1),a=1;o>a;a++)u[a-1]=arguments[a];for(s=t.slice(),o=s.length,a=0;o>a;a++)s[a].apply(this,u)}return!0},t.prototype.addListener=function(n,e){var o;if(!r(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",n,r(e.listener)?e.listener:e),this._events[n]?i(this._events[n])?this._events[n].push(e):this._events[n]=[this._events[n],e]:this._events[n]=e,i(this._events[n])&&!this._events[n].warned){var o;o=c(this._maxListeners)?t.defaultMaxListeners:this._maxListeners,o&&o>0&&this._events[n].length>o&&(this._events[n].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[n].length),"function"==typeof console.trace&&console.trace())}return this},t.prototype.on=t.prototype.addListener,t.prototype.once=function(n,e){function t(){this.removeListener(n,t),o||(o=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var o=!1;return t.listener=e,this.on(n,t),this},t.prototype.removeListener=function(n,e){var t,o,c,u;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[n])return this;if(t=this._events[n],c=t.length,o=-1,t===e||r(t.listener)&&t.listener===e)delete this._events[n],this._events.removeListener&&this.emit("removeListener",n,e);else if(i(t)){for(u=c;u-->0;)if(t[u]===e||t[u].listener&&t[u].listener===e){o=u;break}if(0>o)return this;1===t.length?(t.length=0,delete this._events[n]):t.splice(o,1),this._events.removeListener&&this.emit("removeListener",n,e)}return this},t.prototype.removeAllListeners=function(n){var e,t;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[n]&&delete this._events[n],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(t=this._events[n],r(t))this.removeListener(n,t);else for(;t.length;)this.removeListener(n,t[t.length-1]);return delete this._events[n],this},t.prototype.listeners=function(n){var e;return e=this._events&&this._events[n]?r(this._events[n])?[this._events[n]]:this._events[n].slice():[]},t.listenerCount=function(n,e){var t;return t=n._events&&n._events[e]?r(n._events[e])?1:n._events[e].length:0}},{}],4:[function(n,e){function t(){if(!c){c=!0;for(var n,e=i.length;e;){n=i,i=[];for(var t=-1;++t<e;)n[t]();e=i.length}c=!1}}function r(){}var o=e.exports={},i=[],c=!1;o.nextTick=function(n){i.push(n),c||setTimeout(t,0)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=r,o.addListener=r,o.once=r,o.off=r,o.removeListener=r,o.removeAllListeners=r,o.emit=r,o.binding=function(){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],5:[function(n,e){"use strict";e.exports=function(n){return n=n||{},[].slice.call(arguments,1).forEach(function(e){if(e)for(var t in e)void 0===n[t]&&(n[t]=e[t])}),n}},{}],6:[function(n,e){"use strict";e.exports=function(n){return[].slice.call(arguments,1).forEach(function(e){if(e)for(var t in e)n[t]=e[t]}),n}},{}],7:[function(n,e){e.exports=function(n){function e(e){return n[e]}function t(e,t){n[e]=t}function r(e){return delete n[e]}function o(){return Object.keys(n)}function i(){return Object.keys(n).map(function(e){return n[e]})}return"object"!=typeof n?n:{get:e,set:t,remove:r,delete:r,keys:o,values:i}}},{}],8:[function(n,e){"use strict";e.exports=function(n){var e,t,r,o="string"==typeof n||n instanceof String,i=/^\-?\d+\.?\d*$/;if(!o||n.length<2)return o&&i.test(n)?parseFloat(n):n;if("true"===n||"false"===n)return"true"===n;if("null"===n)return null;if(t=n.charAt(0),r=n.charAt(n.length-1),e="{"==t&&"}"==r||"["==t&&"]"==r||'"'==t&&'"'==r)try{return JSON.parse(n)}catch(n){}return i.test(n)?parseFloat(n):n}},{}],9:[function(n,e){"use strict";var t=[],r=[],o=[console],i=e.exports=function(n){function e(){return i=t.indexOf("*")>=0||t.indexOf(n)>=0}var i=e();return r[r.length]=e,function(){var e=[].slice.call(arguments);("string"==typeof e[0]||e[0]instanceof String)&&(e[0]=n+": "+e[0]),i&&o.forEach(function(n){n.log.apply(n,e)})}};i.reset=function(){return o=[],t=[],i.enable()},i.to=function(n){return o=o.concat(n||[]),i},i.enable=function(){return t=t.concat([].slice.call(arguments)),r.forEach(function(n){n()}),i}},{}],10:[function(n,e){"use strict";e.exports=function(n,e,t){function r(){n.apply(c,i||[]),u=Date.now()}var o,i,c,u=(t||{}).leading!==!1?0:Date.now(),a=(t||{}).trailing;return a=a||void 0===a,function(){var t=Date.now(),s=t-u;return clearTimeout(o),e>s?(i=[].slice.call(arguments,0),c=this,a&&(o=setTimeout(r,e-s))):(u=t,void n.apply(this,arguments))}}},{}],11:[function(n,e){"use strict";var t=e.exports=function(){return console.log("not yet implemented"),!1};t.to=function(n,e){function t(e){var t=n;return("string"==typeof t||t instanceof String)&&(t=document.querySelector(t)),t&&"function"==typeof t.appendChild?(t.appendChild(e),e):void 0}return e?t(e):t}},{}],12:[function(n,e){"use strict";var t=/[\s\,]\s*/,r={"+":"add","-":"remove","~":"toggle","!":"toggle"};e.exports=function(n,e){function o(n){return n.classList?(i.forEach(function(e){n.classList[e.op](e.cls)}),n):n}var i=n.trim().split(t).map(function(n){return{op:r[n.charAt(0)],cls:n.slice(1)}}).filter(function(n){return n.op});return e?o(e):o}},{}],13:[function(n,e){"use strict";var t=/^\.([\w\-]+)$/,r=/^#([\w\-]+)$/,o=/^[\w\-]+$/;e.exports=function(n,e){var i;return e=e||document,i=e===document&&r.test(n),i?[e.getElementById(RegExp.$1)]:Array.prototype.slice.call(t.test(n)?e.getElementsByClassName(RegExp.$1):o.test(n)?e.getElementsByTagName(n):e.querySelectorAll(n))}},{}],14:[function(n,e){function t(){function n(){if(e)throw"No tasks or defaults may be set after kgo is in flight";for(var r=0;"string"==typeof arguments[r];)r++;var o,i,s=Array.prototype.slice.call(arguments,0,r);if(s.length||s.push((c++).toString()+"__returnless"),"object"==typeof arguments[r]&&!Array.isArray(arguments[r])){var f=arguments[r];if(t)throw"Defaults may be defined only once per kgo";for(var l in f){if(l in u)throw"A task is already defined for "+l;a[l]=f[l]}return t=!0,n}if(Array.isArray(arguments[r])&&(o=arguments[r],r++),"function"==typeof arguments[r]&&(i=arguments[r]),"function"!=typeof i)throw new Error("No function provided for task number "+Object.keys(u).length+" ("+s+")");for(var d=0;d<s.length;d++)if(s[d]in a)throw"A default with the same name as this task ("+s[d]+") has already been set";return u[s]={names:s,args:o||[],fn:i},n}var e,t,c=0,u={},a={};for(var s in o.prototype)n[s]=o.prototype[s];return n.apply(null,arguments),i(function(){e=!0,r(u,a,n)}),n}var r=n("./run"),o=n("events").EventEmitter,i="function"==typeof setImmediate?setImmediate:setTimeout;e.exports=t},{"./run":15,events:3}],15:[function(n,e){function t(n,e,t){this._task=n,this._args=e,this._done=t}function r(n,e,r,o){var i=n.names,u=n.args,a=(n.fn,[]);if(u)for(var s=0;s<u.length;s++){var f=u[s],l=f.match(c);if(l&&(f=f.slice(1)),!(f in e))return;l||a.push(e[f])}var d=new t(n,a,function(n,e){o(i,n,e)});r(i),d.run()}function o(n,e,t){var i,c=!0;if(!t._complete){for(var u in n)c=!1,i=n[u],r(i,e,function(e){delete n[e]},function(r,i,c){if(!t._complete){if(i)return t._complete=!0,t.emit("error",i,r),void t.emit("complete");for(var u=0;u<r.length;u++)e[r[u]]=c[u];o(n,e,t)}});c&&(t._complete=!0,t.emit("complete"))}}function i(n,e,t){var r={};for(var i in n)r[i]=n[i];o(r,e,t)}var c=/^\!.+/;t.prototype.run=function(){var n,e=this;this._task.fn.apply(this,this._args.concat([function(t){var r=Array.prototype.slice.call(arguments,1);t?(n=!0,e.done(t)):n||e.done(null,r)}]))},t.prototype.done=function(n,e){return n?this._done(n):void this._done(null,e)},e.exports=i},{}],16:[function(n,e){var t=n("rtc-core/plugin"),r=n("cog/extend"),o=e.exports=function(n,e,r){function o(n,e){return(e||{}).muted&&(n.muted=!0,n.setAttribute("muted","")),(e||{}).mirror&&n.setAttribute("data-mirrored",!0),n}function i(e,t){var r=(t||{}).autoplay,i="audio",c=(t||{}).el||(t||{}).target,a=e&&"function"==typeof e.getVideoTracks;return a&&e.getVideoTracks().length>0&&(i="video"),c&&"function"!=typeof c.play&&(c=null),c=c||document.createElement(i),u&&u.createObjectURL?c.src=u.createObjectURL(n):c.srcObject?c.srcObject=n:c.mozSrcObject&&(c.mozSrcObject=n),(void 0===r||r)&&(c.setAttribute("autoplay",""),c.play()),o(c,t)}var c,u="undefined"!=typeof window&&window.URL;return"function"==typeof e&&(r=e,e={}),(c=t((e||{}).plugins))?c.init(e,function(t){return t?r(t):"function"!=typeof c.attach?r(new Error("plugin must support the attach function")):void r(null,o(c.attach(n,e),e))}):void r(null,i(n,e))};o.local=function(n,e,t){"function"==typeof e&&(t=e,e={}),o(n,r({muted:!0,mirror:!0},e),t)}},{"cog/extend":6,"rtc-core/plugin":21}],17:[function(n,e){var t=n("rtc-core/plugin"),r=n("rtc-core/detect");navigator.getUserMedia=navigator.getUserMedia||r.call(navigator,"getUserMedia"),e.exports=function(n,e,r){function o(n){r(null,n)}var i;return"function"==typeof e&&(r=e,e={}),(i=t((e||{}).plugins))?i.init(e,function(e){return e?r(e):"function"!=typeof navigator.getUserMedia?r(new Error("plugin does not support media capture")):void navigator.getUserMedia(n,o,r)}):"function"!=typeof navigator.getUserMedia?r(new Error("getUserMedia not supported")):void navigator.getUserMedia(n,o,r)}},{"rtc-core/detect":18,"rtc-core/plugin":21}],18:[function(n,e){"use strict";var t=n("detect-browser"),r=e.exports=function(n,e){var t,o,i,c=(e||{}).attach,u=this||("undefined"!=typeof window?window:void 0),a=((e||{}).prefixes||["ms","o","moz","webkit"]).concat("");if(u)for(t=a.length;t--;)if(o=a[t],i=o+(o?n.charAt(0).toUpperCase()+n.slice(1):n),"undefined"!=typeof u[i])return r.browser=r.browser||o.toLowerCase(),c&&(u[n]=u[i]),u[i]};r.moz="undefined"!=typeof navigator&&!!navigator.mozGetUserMedia,r.browser=t.name,r.browserVersion=r.version=t.version},{"detect-browser":20}],19:[function(n,e){e.exports=function(n,e){var t=(n||{}).ice,r=(n||{}).iceServers;return"function"==typeof t?t(n,e):Array.isArray(t)?e(null,[].concat(t)):void e(null,[].concat(r||[]))}},{}],20:[function(n,e,t){function r(n){return n.concat(n[1].exec(navigator.userAgent))}function o(n){return!!n[2]}for(var i=[["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\._]+)/]],r=i.map(r).filter(o)[0],c=r&&r[3].split(/[._]/).slice(0,3);c&&c.length<3;)c.push("0");t.name=r&&r[0],t.version=c&&c.join(".")},{}],21:[function(n,e){function t(n){return n&&"function"==typeof n.supported&&n.supported(o)}function r(n){var e=i.filter(function(e){return"function"==typeof n[e]});return e.length===i.length}var o=n("./detect"),i=["init"];e.exports=function(n){return[].concat(n||[]).filter(t).filter(r)[0]}},{"./detect":18}],22:[function(n,e){"use strict";var t=n("rtc-tools"),r=n("mbus"),o=n("rtc-core/plugin"),i=t.logger("rtc-quickconnect"),c=n("cog/extend");e.exports=function(e,u){function a(){clearTimeout(j),L||S&&(!D||m)&&g&&(M&&T.length<M||(j=setTimeout(function(){var n=c({room:k},E);w.announce(n),L=!0},0)))}function s(n){var e,o,a=b(n);a.room===k&&(C.end(n),e=t.createConnection(c({},u,{iceServers:g}),(u||{}).constraints),w("peer:connect",a.id,e,a),C.create(a.id,e),T.forEach(function(n){e.addStream(n)}),w.isMaster(a.id)?(i("is master, creating data channels: ",Object.keys(A)),Object.keys(A).forEach(function(n){l(e.createDataChannel(n,A[n]),e,a)})):e.ondatachannel=function(t){var r=t&&t.channel;r&&void 0!==A[r.label]&&l(r,e,b(n))},i("coupling "+w.id+" to "+a.id),o=t.couple(e,n,w,c({},u,{logger:r("pc."+n,w)})),w("peer:couple",n,e,a,o),o.once("connected",C.start.bind(null,n,e,a)),o.once("closed",C.end.bind(null,n)),w.isMaster(n)&&o.createOffer())}function f(n){var e=C.get(n);if(!e)throw new Error("No active call for peer: "+n);return e}function l(n,e,t){function r(){var r=C.get(t.id),c=[t.id,n,t,e];i('reporting channel "'+n.label+'" ready, have call: '+!!r),clearInterval(o),n.onopen=null,r&&r.channels.set(n.label,n),i("triggering channel:opened events for channel: "+n.label),w.apply(w,["channel:opened"].concat(c)),w.apply(w,["channel:opened:"+n.label].concat(c))}var o;return i("channel "+n.label+" discovered for peer: "+t.id),"open"===n.readyState?r():(i("channel not ready, current state = "+n.readyState),n.onopen=r,void(o=setInterval(function(){i("checking channel state, current state = "+n.readyState),"open"===n.readyState&&r()},500)))}function d(){return D&&D.init(u,function(n){return n?console.error("Could not initialize plugin: ",n):(m=!0,void a())})}function p(n){n&&"undefined"!=typeof n.room&&(k=n.room)}function v(n,e){e.allow=e.allow&&T.length>=M}function h(n){var e=n&&n.id,t=e&&C.get(e);return e&&!t?(i("received peer update from peer "+e+", no active calls"),w.to(e).send("/reconnect"),s(e)):void 0}var g,m,y="undefined"!=typeof location&&location.hash.slice(1),w=n("rtc-pluggable-signaller")(c({signaller:e},u)),b=n("./lib/getpeerdata")(w.peers),x=(u||{}).ns||"",k=(u||{}).room,_=(u||{}).debug,S=!(u||{}).manualJoin,E={},L=!1,T=[],C=w.calls=n("./lib/calls")(w,u),A={},O=w.plugins=(u||{}).plugins||[],D=o(O),M=parseInt((u||{}).expectedLocalStreams,10)||0,j=0,R=0;return k||("undefined"==typeof location||y||(y=location.hash=""+Math.pow(2,53)*Math.random()),k=x+"#"+y),_&&t.logger.enable.apply(t.logger,Array.isArray(i)?_:["*"]),w.on("peer:announce",function(n){s(n.id)}),w.on("peer:update",h),w.on("message:reconnect",function(n){s(n.id)}),w.broadcast=w.addStream=function(n){return T.push(n),C.values().forEach(function(e){e.pc.addStream(n)}),a(),w},w.endCalls=function(){C.keys().forEach(C.end)},w.close=function(){w.endCalls(),w.leave()},w.createDataChannel=function(n,e){return C.keys().forEach(function(t){var r,o=C.get(t);o&&o.pc&&w.isMaster(t)&&(r=o.pc.createDataChannel(n,e),l(r,o.pc,b(t)))}),A[n]=e||null,w},w.join=function(){S=!0,a()},w.get=function(n){return E[n]},w.getLocalStreams=function(){return[].concat(T)},w.reactive=function(){return u=u||{},u.reactive=!0,w},w.removeStream=function(n){var e=T.indexOf(n);return C.values().forEach(function(e){e.pc.removeStream(n)}),e>=0&&T.splice(e,1),w},w.requestChannel=function(n,e,t){var r=f(n),o=r&&r.channels.get(e);return o?(t(null,o),w):(w.once("channel:opened:"+e,function(n,e){t(null,e)}),w)},w.requestStream=function(n,e,t){function r(c){c===n&&(o=i.pc.getRemoteStreams()[e],o&&(w.removeListener("stream:added",r),t(null,o)))}var o,i=f(n);return(o=i.pc.getRemoteStreams()[e])?(t(null,o),w):(w.on("stream:added",r),w)},w.profile=function(n){return c(E,n),L&&(clearTimeout(R),R=setTimeout(function(){w.announce(E)},(u||{}).updateDelay||1e3)),w},w.waitForCall=function(n,e){var t=C.get(n);return t&&t.active?(e(null,t.pc),w):void w.on("call:started",function t(r){r===n&&(w.removeListener("call:started",t),e(null,C.get(r).pc))})},M&&w.on("peer:filter",v),w.on("local:announce",p),w.on("message:ping",C.ping),n("rtc-core/genice")(u,function(n,e){return n?console.error("could not find iceServers: ",n):(g=e,void a())}),D&&d(),w}},{"./lib/calls":23,"./lib/getpeerdata":24,"cog/extend":6,mbus:26,"rtc-core/genice":19,"rtc-core/plugin":21,"rtc-pluggable-signaller":28,"rtc-tools":58}],23:[function(n,e){(function(t){var r=n("rtc-tools"),o=r.logger("rtc-quickconnect"),i=n("rtc-tools/cleanup"),c=n("cog/getable");e.exports=function(e,r){function u(n,e){m.set(n,{active:!1,pc:e,channels:c({}),streams:[],lastping:Date.now()})}function a(n){return function(e){o("peer "+n+" added stream"),h(n),d(n)(e.stream)}}function s(n){return function(t){o("peer "+n+" removed stream"),h(n),e("stream:removed",n,t.stream)}}function f(n){var t=m.get(n);t&&(t.channels.keys().forEach(function(r){var o=t.channels.get(r),i=[n,o,r];e.apply(e,["channel:closed"].concat(i)),e.apply(e,["channel:closed:"+r].concat(i)),o.onopen=null}),t.streams.forEach(function(t){e("stream:removed",n,t)}),m.delete(n),0===m.keys().length&&p(),e("call:ended",n,t.pc),i(t.pc))}function l(n){var e=m.get(n&&n.id);e&&(e.lastping=Date.now())}function d(n){return function(t){e("stream:added",n,t,y(n))}}function p(){clearInterval(g),g=0}function v(i,c,u){var f=m.get(i),l=[].concat(c.getRemoteStreams());f.active=!0,f.streams=[].concat(c.getRemoteStreams()),c.onaddstream=a(i),c.onremovestream=s(i),o(e.id+" - "+i+" call start: "+l.length+" streams"),e("call:started",i,c,u),g=g||n("./heartbeat")(e,m,r),t.nextTick(function(){l.forEach(d(i))})}function h(n){var e=m.get(n);e&&e.pc&&(e.streams=[].concat(e.pc.getRemoteStreams()))}var g,m=c({}),y=n("./getpeerdata")(e.peers);return m.create=u,m.end=f,m.ping=l,m.start=v,m}}).call(this,n("_process"))},{"./getpeerdata":24,"./heartbeat":25,_process:4,"cog/getable":7,"rtc-tools":58,"rtc-tools/cleanup":54}],24:[function(n,e){e.exports=function(n){return function(e){var t=n.get(e);return t&&t.data}}},{}],25:[function(n,e){e.exports=function(n,e,t){function r(){var t=Date.now()-4*o;e.keys().forEach(function(r){var o=e.get(r);return o.lastping<t?e.end(r):void n.to(r).send("/ping")})}var o=(t||{}).heartbeat||2500;return o?setInterval(r,o):void 0}},{}],26:[function(n,e){var t=/[\.\:]/,r=e.exports=function(n,e,o){function i(e){var t,r=[].slice.call(arguments,1),c=a(e),u=d[c]||[];return p.forEach(function(n){n({name:c,args:r})}),t=[].concat(u).map(function(n){return n.apply(o||this,r)}),i.parent&&(t=t.concat(i.parent.apply(o||this,[(n?n+".":"")+c].concat(r)))),t}function c(n){n?delete d[a(n)]:d={}}function u(n){function e(){p.splice(p.indexOf(n),1)}return p.push(n),e}function a(n){return(Array.isArray(n)?n:n.split(t)).join(".")}function s(n,e){var t=d[a(n)]||[],r=t?t.indexOf(e._actual||e):-1;r>=0&&t.splice(r,1)}function f(n,e){var t;return n=a(n),t=d[n],t?t.push(e):d[n]=[e],i}function l(n,e){function t(){var r=e.apply(this,arguments);return i.off(n,t),r}return e._actual=t,f(n,t)}var d={},p=[];return"function"==typeof n&&(e=n,n=""),n=a(n||""),i.clear=i.removeAllListeners=c,i.feed=u,i.on=i.addListener=f,i.once=l,i.off=i.removeListener=s,i.parent=e||n&&r(),i}},{}],27:[function(n,e,t){function r(n){return"function"!=typeof n?n:(n.pipe=n.pipe||function(e){if("function"!=typeof e)throw new Error("must pipe to reader");return r(e(n))},n.type="Source",n)}t.id=function(n){return n},t.prop=function(n){if("string"==typeof n){var e=n;return function(n){return n[e]}}return n},t.tester=function(n){return n?"object"==typeof n&&"function"==typeof n.test?n.test.bind(n):t.prop(n)||t.id:t.id},t.addPipe=r;var o=(t.Source=function(n){function e(){var e=[].slice.call(arguments);return r(n.apply(null,e))}return e.type="Source",e},t.Through=function(n){return function(){function e(e){for(t.unshift(e),e=n.apply(null,t);r.length;)e=r.shift()(e);return e}var t=[].slice.call(arguments),r=[];return e.pipe=function(n){if(r.push(n),"Source"===n.type)throw new Error("cannot pipe "+e.type+" to Source");return e.type="Sink"===n.type?"Sink":"Through",e},e.type="Through",e}}),i=t.Sink=function(n){return function(){function e(e){return t.unshift(e),n.apply(null,t)}var t=[].slice.call(arguments);if(!n)throw new Error("must be createReader function");return e.type="Sink",e}};t.maybeSink=t.maybeDrain=function(n,e){return e?i(function(t){return n(e)(t)})():o(function(e){var t;return function(r,o){return r?e(r,o):t?o(t):void n(function(n,e){t=n||!0,n?o(t):o(null,e)})(e)}})()}},{}],28:[function(n,e){e.exports=function(e){var t=(e||{}).signaller,r=(e||{}).messenger||n("rtc-switchboard-messenger");return"string"==typeof t||t instanceof String?n("rtc-signaller")(r(t),e):t}},{"rtc-signaller":40,"rtc-switchboard-messenger":29}],29:[function(n,e){var t=n("cog/extend");e.exports=function(e,r){return n("messenger-ws")(e,t({endpoints:["/primus","/"]},r))}},{"cog/extend":6,"messenger-ws":30}],30:[function(n,e){var t=n("ws"),r=n("wsurl"),o=n("pull-ws"),i=(n("cog/defaults"),/\/$/);e.exports=function(n,e){function c(i){function c(){function a(){h=!0,p.call(g,"message",a)}var g;return 0===v.length?i(new Error("Unable to connect to url: "+n)):(g=new t(r(v.shift())),g.addEventListener("error",f),g.addEventListener("close",s),g.addEventListener("open",function(){var n=o.source(g,e);g.addEventListener("message",a),d=setTimeout(function(){clearTimeout(l),i(null,n,o.sink(g,e))},100)}),p=g.removeEventListener||g.removeListener,void(l=setTimeout(c,u)))}function s(n){return n.wasClean||h||0===v.length?(clearTimeout(d),void clearTimeout(l)):f()}function f(){clearTimeout(d),clearTimeout(l),c()}var l,d,p,v=[].concat(a),h=!1;c()}var u=(e||{}).timeout||1e3,a=((e||{}).endpoints||["/"]).map(function(e){return n.replace(i,"")+e});return c}},{"cog/defaults":5,"pull-ws":31,ws:35,wsurl:36}],31:[function(n,e,t){function r(n,e){return{source:t.source(n),sink:t.sink(n,e)}}t=e.exports=r,t.source=n("./source"),t.sink=n("./sink")},{"./sink":33,"./source":34}],32:[function(n,e){e.exports=function(n,e){function t(){"function"==typeof i&&(i.call(n,"open",r),i.call(n,"error",o))}function r(){t(),e()}function o(n){t(),e(n)}var i=n&&(n.removeEventListener||n.removeListener);return n.readyState>=2?e(!0):1===n.readyState?e():(n.addEventListener("open",r),void n.addEventListener("error",o))}},{}],33:[function(n,e){(function(t){var r=n("pull-core"),o=n("./ready");e.exports=r.Sink(function(n,e,r){function i(r,a){return r?void(c&&e.readyState<=1&&(u&&e.addEventListener("close",function(n){if(n.wasClean)u();else{var e=new Error("ws error");e.event=n,u(e)}}),e.close())):void o(e,function(r){return r?n(r,function(){}):(e.send(a),void t.nextTick(function(){n(null,i)}))})}r=r||{};var c=r.closeOnEnd!==!1,u="function"==typeof r?r:r.onClose;n(null,i)})}).call(this,n("_process"))},{"./ready":32,_process:4,"pull-core":27}],34:[function(n,e){var t=n("pull-core"),r=n("./ready");e.exports=t.Source(function(n){function e(e,c){return t=null,o?c(o):e?(t=c,n.close()):void r(n,function(n){return n?c(o=n):o&&o!==!0?c(o):i.length>0?c(null,i.shift()):o?c(!0):void(t=c)})}var t,o,i=[];return n.addEventListener("message",function(n){return t?t(null,n.data):void i.push(n.data)}),n.addEventListener("close",function(){return o?void 0:t?t(o=!0):void 0}),n.addEventListener("error",function(n){o||(o=n,t&&t(o))}),e})},{"./ready":32,"pull-core":27}],35:[function(n,e){function t(n,e){var t;return t=e?new o(n,e):new o(n)}var r=function(){return this}(),o=r.WebSocket||r.MozWebSocket;e.exports=o?t:null,o&&(t.prototype=o.prototype)},{}],36:[function(n,e){var t=/^http(.*)$/;e.exports=function(n,e){var r=(e||{}).current||"undefined"!=typeof location&&location.href,o=r&&r.slice(0,r.indexOf(":")),i=(e||{}).insecure,c="//"==n.slice(0,2),u=!o||"file:"===o;return c?u?(i?"ws:":"wss:")+n:o.replace(t,"ws$1")+":"+n:n.replace(t,"ws$1")}},{}],37:[function(n,e){e.exports={dataEvent:"data",openEvent:"open",closeEvent:"close",errorEvent:"error",writeMethod:"write",closeMethod:"close",leaveTimeout:3e3}},{}],38:[function(n,e){"use strict";var t=n("cog/extend");e.exports=function(n){function e(e){var r=t({allow:!0},e);return n("peer:filter",e.id,r),r.allow}return function(r,o,i,c,u){var a,s=r[0];if(s&&s.id&&s.id!==n.id){if(!e(s))return;return a=n.peers.get(s.id),n("peer:connected",s.id,s),a&&!a.inactive?(t(a.data,s),n("peer:update",s,i)):(a={id:s.id,roleIdx:[s.id,n.id].sort().indexOf(s.id),data:{}},t(a.data,s),clearTimeout(a.leaveTimer),a.inactive=!1,n.peers.set(s.id,a),n.autoreply&&!u&&n.to(s.id).send("/announce",n.attributes),n("peer:announce",s,a))}}}},{"cog/extend":6}],39:[function(n,e){"use strict";e.exports=function(e,t){return{announce:n("./announce")(e,t)}}},{"./announce":38}],40:[function(n,e){"use strict";var t=n("rtc-core/detect"),r=n("cog/defaults"),o=n("cog/extend"),i=n("mbus"),c=n("cog/getable"),u=n("cuid"),a=n("pull-stream"),s=n("pull-pushable"),f=0,l=1,d=2,p={version:"5.2.4"};e.exports=function(e,v){function h(){L.announce()}function g(n){O.push(m(n)),M!==f||void 0!==_&&!_||j()}function m(n){return n.map(b).join("|")}function y(){return o({},E,{id:L.id})}function w(){(void 0===S||S)&&setTimeout(j,50)}function b(n){return"object"!=typeof n||n instanceof String?"function"==typeof n?null:n:JSON.stringify(n)}var x,k=(v||{}).autoreply,_=(v||{}).autoconnect,S=(v||{}).reconnect,E={},L=i("",(v||{}).logger),T=L.id=(v||{}).id||u(),C=L.attributes={browser:t.browser,browserVersion:t.browserVersion,id:T,agent:"signaller@"+p.version},A=L.peers=c({}),O=n("pull-pushable")(),D=0,M=f,j=L.connect=function(){M!==l&&(M=l,e(function(n,e,t){return n?(M=f,L("error",n)):(M=d,a(e,a.through(null,function(){M=f,L("disconnected")}),a.drain(x)),a(O,t),L.removeListener("disconnected",w),L.on("disconnected",w),void L("connected"))}))},R=L.send=function(){var n=[].slice.call(arguments);n.splice(1,0,y()),g(n)};return L.announce=function(n,e){function t(){(e||R)("/announce",C),L("local:announce",C)}return M===d&&(L.removeListener("connected",h),L.on("connected",h)),clearTimeout(D),o(C,n,{id:L.id}),D=setTimeout(t,(v||{}).announceDelay||10)},L.isMaster=function(n){var e=A.get(n);return e&&0!==e.roleIdx},L.leave=L.close=function(){R("/leave",{id:T}),L.removeListener("disconnected",w),L.removeListener("connected",h),O.end(),O=s(),M=f},L.metadata=function(n){return console.warn("metadata is deprecated, please do not use"),0===arguments.length?o({},E):void(E=o({},n))},L.to=function(n){var e=function(){var e,t=L.peers.get(n);if(!t)throw new Error("Unknown peer: "+n);t.inactive||(e=["/to",n].concat([].slice.call(arguments)),e.splice(3,0,y()),g(e))};return{announce:function(n){return L.announce(n,e)},send:e}},v=r({},v,n("./defaults")),L.autoreply=void 0===k||k,L.process=x=n("./processor")(L,v),(void 0===_||_)&&j(),L}},{"./defaults":37,"./processor":53,"cog/defaults":5,"cog/extend":6,"cog/getable":7,cuid:41,mbus:26,"pull-pushable":42,"pull-stream":48,"rtc-core/detect":18}],41:[function(n,e){!function(n){"use strict";var t="cuid",r=0,o=4,i=36,c=Math.pow(i,o),u=function(n,e){var t="000000000"+n;return t.substr(t.length-e)},a=function(){return u((Math.random()*c<<0).toString(i),o)},s=function(){return r=c>r?r:0,r++,r-1},f=function(){var n,e="c",t=(new Date).getTime().toString(i),r=f.fingerprint(),c=a()+a();return n=u(s().toString(i),o),e+t+n+r+c};f.slug=function(){var n,e=(new Date).getTime().toString(36),t=f.fingerprint().slice(0,1)+f.fingerprint().slice(-1),r=a().slice(-2);return n=s().toString(36).slice(-4),e.slice(-2)+n+t+r},f.globalCount=function(){var n=function(){var n,e=0;for(n in window)e++;return e}();return f.globalCount=function(){return n},n},f.fingerprint=function(){return u((navigator.mimeTypes.length+navigator.userAgent.length).toString(36)+f.globalCount().toString(36),4)},n.register?n.register(t,f):"undefined"!=typeof e?e.exports=f:n[t]=f}(this.applitude||this)},{}],42:[function(n,e){var t=n("pull-stream");e.exports=t.Source(function(n){function e(){for(var n;c.length&&((n=o.length)||r);){var e=o.shift(),t=i.shift();c.shift()(n?null:r,e),t&&t(r===!0?null:r)}}function t(t,o){r=r||t,c.push(o),e(),r&&n&&n(r===!0?null:r)}var r,o=[],i=[],c=[];return t.push=function(n,t){return r?t&&t(r===!0?null:r):(o.push(n),i.push(t),void e())},t.end=function(t,o){"function"==typeof t&&(o=t,t=!0),r=r||t||!0,o&&i.push(o),e(),r&&n&&n(r===!0?null:r)},t})},{"pull-stream":43}],43:[function(n,e,t){var r=n("./sources"),o=n("./sinks"),i=n("./throughs"),c=n("pull-core");for(var u in r)t[u]=c.Source(r[u]);for(var u in i)t[u]=c.Through(i[u]);for(var u in o)t[u]=c.Sink(o[u]);var a=n("./maybe")(t);for(var u in a)t[u]=a[u];t.Duplex=t.Through=t.pipeable=c.Through,t.Source=t.pipeableSource=c.Source,t.Sink=t.pipeableSink=c.Sink},{"./maybe":44,"./sinks":45,"./sources":46,"./throughs":47,"pull-core":27}],44:[function(n,e){var t=n("pull-core"),r=t.prop,o=t.id,i=t.maybeSink;e.exports=function(n){{var e={},t=n.drain,c=(e.find=function(n,e){return i(function(e){var i=!1;return e?n=r(n)||o:(e=n,n=o),t(function(t){return n(t)?(i=!0,e(null,t),!1):void 0},function(n){i||e(n===!0?null:n,null)})},e)},e.reduce=function(n,e,r){return i(function(r){return t(function(t){e=n(e,t)},function(n){r(n,e)})},r)});e.collect=e.writeArray=function(n){return c(function(n,e){
return n.push(e),n},[],n)}}return e}},{"pull-core":27}],45:[function(n,e,t){{var r=t.drain=function(n,e,t){!function r(){for(var o=!0,i=!1;o;)if(i=!1,n(null,function(c,u){i=!0,c?(o=!1,t&&t(c===!0?null:c)):e&&!1===e(u)?(o=!1,n(!0,t||function(){})):o||r()}),!i)return void(o=!1)}()};t.onEnd=function(n,e){return r(n,null,e)},t.log=function(n,e){return r(n,function(n){console.log(n)},e)}}},{}],46:[function(n,e,t){{var r=(t.keys=function(n){return o(Object.keys(n))},t.once=function(n){return function(e,t){if(e)return t(e);if(null!=n){var r=n;n=null,t(null,r)}else t(!0)}}),o=t.values=t.readArray=function(n){Array.isArray(n)||(n=Object.keys(n).map(function(e){return n[e]}));var e=0;return function(t,r){return t?r&&r(t):void r(e>=n.length||null,n[e++])}};t.count=function(n){var e=0;return n=n||1/0,function(t,r){return t?r&&r(t):e>n?r(!0):void r(null,e++)}},t.infinite=function(n){return n=n||Math.random,function(e,t){return e?t&&t(e):t(null,n())}},t.defer=function(){var n,e,t=[],r=function(r,o){n?n(r,o):(e=r,t.push(o))};return r.resolve=function(r){if(n)throw new Error("already resolved");if(n=r,!n)throw new Error("no read cannot resolve!"+n);for(;t.length;)n(e,t.shift())},r.abort=function(n){r.resolve(function(e,t){t(n||!0)})},r},t.empty=function(){return function(n,e){e(!0)}},t.depthFirst=function(n,e){var t=[];return t.unshift(r(n)),function n(r,o){return t.length?void t[0](r,function(r,i){return r?(t.shift(),n(null,o)):(t.unshift(e(i)),void o(r,i))}):o(!0)}},t.widthFirst=function(n,e){var t=[];return t.push(r(n)),function n(r,o){return t.length?void t[0](r,function(r,i){return r?(t.shift(),n(null,o)):(t.push(e(i)),void o(r,i))}):o(!0)}},t.leafFirst=function(n,e){var t=[],o=[];return t.push(r(n)),function n(r,i){t[0](r,function(r,c){return r?(t.shift(),o.length?i(null,o.shift()):i(!0)):(t.unshift(e(c)),o.unshift(c),void n(null,i))})}}}},{}],47:[function(n,e,t){(function(e){{var r=n("pull-core"),o=n("./sources"),i=n("./sinks"),c=r.prop,u=r.id,a=r.tester,s=(t.map=function(n,e){return e=c(e)||u,function(t,r){n(t,function(n,t){var t=n?null:e(t);r(n,t)})}},t.asyncMap=function(n,e){return e?function(t,r){return t?n(t,r):void n(null,function(n,t){return n?r(n,t):void e(t,r)})}:n},t.paraMap=function(n,e,t){function r(){if(i){var n=i;return i=null,u.length?n(null,u.shift()):c&&!a?n(c):void(i=n)}}function o(){n(null,function(n,i){return n?(c=n,r()):(a++,e(i,function(n,e){a--,u.push(e),r()}),void(t>a&&!c&&o()))})}if(!e)return n;var i,c=!1,u=[],a=0;return function(e,t){return e?n(e,t):(i=t,void(u.length||c?(o(),r()):o()))}},t.filter=function(n,e){return e=a(e),function t(r,o){n(r,function(n,r){return n||e(r)?void o(n,r):t(n,o)})}}),f=(t.filterNot=function(n,e){return e=a(e),s(n,function(n){return!e(n)})},t.through=function(n,e,t){function r(n){!o&&t&&(o=!0,t(n===!0?null:n))}var o=!1;return function(t,o){return t&&r(t),n(t,function(n,t){n?r(n):e&&e(t),o(n,t)})}},t.take=function(n,e){var t=!1;if("number"==typeof e){var r=e;e=function(){return r--}}return function(r,o){return t?o(t):(t=r)?n(t,o):void n(null,function(r,i){return(t=t||r)?o(t):void(e(i)?o(null,i):(t=!0,n(!0,function(n,e){o(t,e)})))})}},t.unique=function(n,e,t){e=c(e)||u;var r={};return s(n,function(n){var o=e(n);return r[o]?!!t:(r[o]=!0,!t)})}),l=(t.nonUnique=function(n,e){return f(n,e,!0)},t.group=function(n,e){var t;e=e||5;var r=[];return function(o,i){return o?n(t=o,i):t?i(t):void n(null,function o(c,u){if(t=t||c){if(!r.length)return i(t);var a=r;return r=[],i(null,a)}if(r.push(u),r.length<e)return n(null,o);var a=r;r=[],i(null,a)})}},t.flatten=function(n){var e;return function(t,r){function i(){e(null,function(n,e){n?c():r(null,e)})}function c(){n(null,function(n,t){if(n)return r(n);if(Array.isArray(t))t=o.values(t);else if("function"!=typeof t)throw new Error("expected stream of streams");e=t,i()})}e?i():c()}},t.prepend=function(n,e){return function(t,r){if(null!==e){if(t)return n(t,r);var o=e;e=null,r(null,o)}else n(t,r)}},t._reduce=function(n,e,t){return function(r,o){return r?n(r,o):ended?o(ended):void i.drain(function(n){t=e(t,n)},function(n){ended=n||!0,n?o(ended):o(null,t)})(n)}},e.nextTick);t.highWaterMark=function(n,e){function t(){for(;c.length&&(i.length||o);)c.shift()(o,o?null:i.shift())}function r(){return o||u||i.length>=e?void 0:(u=!0,n(o,function(n,e){u=!1,o=o||n,null!=e&&i.push(e),r(),t()}))}var o,i=[],c=[],u=!1;return e=e||10,l(r),function(n,e){o=o||n,c.push(e),r(),t()}}}}).call(this,n("_process"))},{"./sinks":45,"./sources":46,_process:4,"pull-core":27}],48:[function(n,e,t){function r(n){return"function"==typeof n}function o(n){return n&&("Through"===n.type||1===n.length)}var i=n("./sources"),c=n("./sinks"),u=n("./throughs"),a=n("pull-core"),t=e.exports=function n(){function e(){var n=t.shift();return null==n?e():r(n)?n:function(e){return n.sink(e),n.source}}var t=[].slice.call(arguments);if(o(t[0]))return function(e){return t.unshift(e),n.apply(null,t)};var i=t.shift();for(r(i.source)&&(i=i.source);t.length;)i=e()(i);return i};for(var s in i)t[s]=a.Source(i[s]);for(var s in u)t[s]=a.Through(u[s]);for(var s in c)t[s]=a.Sink(c[s]);var f=n("./maybe")(t);for(var s in f)t[s]=f[s];t.Duplex=t.Through=t.pipeable=a.Through,t.Source=t.pipeableSource=a.Source,t.Sink=t.pipeableSink=a.Sink},{"./maybe":49,"./sinks":50,"./sources":51,"./throughs":52,"pull-core":27}],49:[function(n,e){var t=n("pull-core"),r=t.prop,o=t.id,i=t.maybeSink;e.exports=function(n){{var e={},t=n.drain,c=(e.find=function(n,e){return i(function(e){var i=!1;return e?n=r(n)||o:(e=n,n=o),t(function(t){return n(t)?(i=!0,e(null,t),!1):void 0},function(n){i||e(n===!0?null:n,null)})},e)},e.reduce=function(n,e,r){return i(function(r){return t(function(t){e=n(e,t)},function(n){r(n,e)})},r)});e.collect=e.writeArray=function(n){return c(function(n,e){return n.push(e),n},[],n)},e.concat=function(n){return c(function(n,e){return n+e},"",n)}}return e}},{"pull-core":27}],50:[function(n,e,t){{var r=t.drain=function(n,e,t){!function r(){for(var o=!0,i=!1;o;)if(i=!1,n(null,function(c,u){if(i=!0,c){if(o=!1,t)t(c===!0?null:c);else if(c&&c!==!0)throw c}else e&&!1===e(u)?(o=!1,n(!0,t||function(){})):o||r()}),!i)return void(o=!1)}()};t.onEnd=function(n,e){return r(n,null,e)},t.log=function(n,e){return r(n,function(n){console.log(n)},e)}}},{}],51:[function(n,e,t){{var r=(t.keys=function(n){return o(Object.keys(n))},t.once=function(n){return function(e,t){if(e)return t(e);if(null!=n){var r=n;n=null,t(null,r)}else t(!0)}}),o=t.values=t.readArray=function(n){Array.isArray(n)||(n=Object.keys(n).map(function(e){return n[e]}));var e=0;return function(t,r){return t?r&&r(t):void r(e>=n.length||null,n[e++])}};t.count=function(n){var e=0;return n=n||1/0,function(t,r){return t?r&&r(t):e>n?r(!0):void r(null,e++)}},t.infinite=function(n){return n=n||Math.random,function(e,t){return e?t&&t(e):t(null,n())}},t.defer=function(){var n,e,t=[],r=function(r,o){n?n(r,o):(e=r,t.push(o))};return r.resolve=function(r){if(n)throw new Error("already resolved");if(n=r,!n)throw new Error("no read cannot resolve!"+n);for(;t.length;)n(e,t.shift())},r.abort=function(n){r.resolve(function(e,t){t(n||!0)})},r},t.empty=function(){return function(n,e){e(!0)}},t.error=function(n){return function(e,t){t(n)}},t.depthFirst=function(n,e){var t=[];return t.unshift(r(n)),function n(r,o){return t.length?void t[0](r,function(r,i){return r?(t.shift(),n(null,o)):(t.unshift(e(i)),void o(r,i))}):o(!0)}},t.widthFirst=function(n,e){var t=[];return t.push(r(n)),function n(r,o){return t.length?void t[0](r,function(r,i){return r?(t.shift(),n(null,o)):(t.push(e(i)),void o(r,i))}):o(!0)}},t.leafFirst=function(n,e){var t=[],o=[];return t.push(r(n)),function n(r,i){t[0](r,function(r,c){return r?(t.shift(),o.length?i(null,o.shift()):i(!0)):(t.unshift(e(c)),o.unshift(c),void n(null,i))})}}}},{}],52:[function(n,e,t){(function(e){{var r=n("pull-core"),o=n("./sources"),i=n("./sinks"),c=r.prop,u=r.id,a=r.tester,s=(t.map=function(n,e){return e=c(e)||u,function(t,r){n(t,function(t,o){try{o=t?null:e(o)}catch(e){return n(e,function(){return r(e)})}r(t,o)})}},t.asyncMap=function(n,e){return e?function(t,r){return t?n(t,r):void n(null,function(n,t){return n?r(n,t):void e(t,r)})}:n},t.paraMap=function(n,e,t){function r(){if(i){var n=i;return i=null,u.length?n(null,u.shift()):c&&!a?n(c):void(i=n)}}function o(){n(null,function(n,i){return n?(c=n,r()):(a++,e(i,function(n,e){a--,u.push(e),r()}),void(t>a&&!c&&o()))})}if(!e)return n;var i,c=!1,u=[],a=0;return function(e,t){return e?n(e,t):(i=t,void(u.length||c?(o(),r()):o()))}},t.filter=function(n,e){return e=a(e),function t(r,o){for(var i,c=!0;c;)c=!1,i=!0,n(r,function(n,r){return n||e(r)?void o(n,r):i?c=!0:t(n,o)}),i=!1}}),f=(t.filterNot=function(n,e){return e=a(e),s(n,function(n){return!e(n)})},t.through=function(n,e,t){function r(n){!o&&t&&(o=!0,t(n===!0?null:n))}var o=!1;return function(t,o){return t&&r(t),n(t,function(n,t){n?r(n):e&&e(t),o(n,t)})}},t.take=function(n,e){var t=!1;if("number"==typeof e){var r=e;e=function(){return r--}}return function(r,o){return t?o(t):(t=r)?n(t,o):void n(null,function(r,i){return(t=t||r)?o(t):void(e(i)?o(null,i):(t=!0,n(!0,function(n,e){o(t,e)})))})}},t.unique=function(n,e,t){e=c(e)||u;var r={};return s(n,function(n){var o=e(n);return r[o]?!!t:(r[o]=!0,!t)})});t.nonUnique=function(n,e){return f(n,e,!0)},t.group=function(n,e){var t;e=e||5;var r=[];return function(o,i){return o?n(t=o,i):t?i(t):void n(null,function o(c,u){if(t=t||c){if(!r.length)return i(t);var a=r;return r=[],i(null,a)}if(r.push(u),r.length<e)return n(null,o);var a=r;r=[],i(null,a)})}},t.flatten=function(n){var e;return function(t,r){function i(){e(null,function(n,e){n?c():r(null,e)})}function c(){n(null,function(n,t){if(n)return r(n);if(Array.isArray(t)||t&&"object"==typeof t)t=o.values(t);else if("function"!=typeof t)throw new Error("expected stream of streams");e=t,i()})}e?i():c()}},t.prepend=function(n,e){return function(t,r){if(null!==e){if(t)return n(t,r);var o=e;e=null,r(null,o)}else n(t,r)}},t._reduce=function(n,e,t){return function(r,o){return r?n(r,o):ended?o(ended):void i.drain(function(n){t=e(t,n)},function(n){ended=n||!0,n?o(ended):o(null,t)})(n)}},e.nextTick,t.highWaterMark=function(n,t){function r(){for(;a.length&&(u.length||i);)a.shift()(i,i?null:u.shift());!u.length&&c&&(i=c)}function o(){return i||c||s||u.length>=t?void 0:(s=!0,n(i||c,function(n,e){s=!1,c=c||n,null!=e&&u.push(e),o(),r()}))}var i,c,u=[],a=[],s=!1;return t=t||10,e.nextTick(o),function(n,e){i=i||n,a.push(e),o(),r()}},t.flatMap=function(n,e){e=e||u;var t,r=[];return function(o,i){return r.length?i(null,r.shift()):t?i(t):void n(o,function o(c,u){if(c)t=c;else for(var a=e(u);a&&a.length;)r.push(a.shift());r.length?i(null,r.shift()):t?i(t):n(null,o)})}}}}).call(this,n("_process"))},{"./sinks":50,"./sources":51,_process:4,"pull-core":27}],53:[function(n,e){"use strict";var t=n("cog/jsonparse");e.exports=function(e,r){function o(n,r,o){var i="message:"+n[0].slice(1),c=n.slice(2).map(t);e.apply(e,[i].concat(c).concat([r,o]))}var i=n("./handlers")(e,r);return function(n){var r,c,u,a,s=n,f=!0,l=!1;if(!s||"primus"!==s.slice(0,6)){var d=e.id+"";if("/to"===s.slice(0,3)&&(f=s.slice(4,d.length+4)===d,f&&(r=s.slice(5+d.length).split("|").map(t),l=!0,r=r.map(t))),f&&(e("rawdata",s),r=r||s.split("|").map(t),"string"==typeof r[0])){if(u=r[1],u&&u.id===e.id)return console.warn("got data from ourself, discarding");a=e.peers.get(u&&u.id)||u,"/"===r[0].charAt(0)?(c=i[r[0].slice(1)],"function"==typeof c?c(r.slice(2),r[0].slice(1),u,a,l):o(r,a,n)):e("data",r.slice(0,1).concat(r.slice(2)),u,a,l)}}}}},{"./handlers":39,"cog/jsonparse":8}],54:[function(n,e){"use strict";var t=n("cog/logger")("rtc/cleanup"),r=["closed"],o=["addstream","datachannel","icecandidate","negotiationneeded","removestream","signalingstatechange"],i=["iceconnectionstatechange"];e.exports=function(n){function e(e){e.forEach(function(e){n["on"+e]&&(n["on"+e]=null)})}var c=n.iceConnectionState,u=r.indexOf(c)<0;e(o),u&&(t("attempting connection close, current state: "+n.iceConnectionState),n.close()),setTimeout(function(){e(i)},100)}},{"cog/logger":9}],55:[function(n,e){"use strict";function t(e,t,a,d){function p(){S("decoupling "+a.id+" from "+t),E.stop(),i(e),a.removeListener("sdp",h),a.removeListener("candidate",v),a.removeListener("negotiate",b),a.removeListener("message:sdp",h),a.removeListener("message:candidate",v),a.removeListener("message:negotiate",b)}function v(n){D.addIceCandidate(n)}function h(n,e){L("sdp.remote",n),e&&e.id===t&&D.setRemoteDescription(n)}function g(){S("captured pc close, iceConnectionState = "+e.iceConnectionState),p()}function m(){S("captured pc disconnect, monitoring connection status"),k=setTimeout(function(){S("manually closing connection after disconnect timeout"),i(e)},A),E.on("statechange",y)}function y(){return S("connection state changed to: "+e.iceConnectionState),l.indexOf(e.iceConnectionState)>=0?void 0:(x(),f.indexOf(e.iceConnectionState)>=0?E("closed"):void E.once("disconnect",m))}function w(n){var e=n.candidate&&s(n.candidate);n.candidate?(x(),L("ice.local",e),a.to(t).send("/candidate",e),C=!1):C||(C=!0,L("ice.gathercomplete"),a.to(t).send("/endofcandidates",{}))}function b(n){n.id===t&&(L("negotiate.request",n.id),j())}function x(){E.off("statechange",y),S("reset disconnect timer, state: "+e.iceConnectionState),clearTimeout(k)}var k,_=(d||{}).debugLabel||"rtc",S=n("cog/logger")(_+"/couple"),E=c(e,t,a,(d||{}).logger),L=r("",E),T=(d||{}).reactive,C=!0,A=(d||{}).disconnectTimeout||1e4,O=a.isMaster(t),D=o(e,d),M=u(function(){return O?void D.createOffer():a.to(t).send("/negotiate")},100,{leading:!1}),j=u(D.createOffer,100,{leading:!1});return T&&(e.onnegotiationneeded=function(){L("negotiate.renegotiate"),M()}),e.onicecandidate=w,D.on("sdp.local",function(n){a.to(t).send("/sdp",n)}),a.on("sdp",h),a.on("candidate",v),a.on("message:sdp",h),a.on("message:candidate",v),O&&(a.on("negotiate",b),a.on("message:negotiate",b)),E.once("closed",g),E.once("disconnected",m),E.createOffer=M,E}var r=n("mbus"),o=n("rtc-taskqueue"),i=n("./cleanup"),c=n("./monitor"),u=n("cog/throttle"),a=n("whisk/pluck"),s=a("candidate","sdpMid","sdpMLineIndex"),f=["closed","failed"],l=["checking"];e.exports=t},{"./cleanup":54,"./monitor":59,"cog/logger":9,"cog/throttle":10,mbus:26,"rtc-taskqueue":60,"whisk/pluck":71}],56:[function(n,e){"use strict";e.exports=n("rtc-core/detect")},{"rtc-core/detect":18}],57:[function(n,e,t){"use strict";var r=n("cog/logger")("generators"),o=n("./detect"),i=n("cog/defaults"),c={create:{dtls:function(n){o.moz||(n.optional=(n.optional||[]).concat({DtlsSrtpKeyAgreement:!0}))}}};t.config=function(n){var e=(n||{}).iceServerGenerator;return i({},n,{iceServers:"function"==typeof e?e():[]})},t.connectionConstraints=function(n,e){var t,o={},u=c.create;return Object.keys(n||{}).forEach(function(n){u[n]&&u[n](o)}),t=i({},e,o),r("generated connection constraints: ",t),t}},{"./detect":56,"cog/defaults":5,"cog/logger":9}],58:[function(n,e,t){"use strict";var r=n("./generators"),o=t.detect=n("./detect"),i=n("rtc-core/plugin");t.logger=n("cog/logger");var c=t.RTCPeerConnection=o("RTCPeerConnection");t.couple=n("./couple"),t.createConnection=function(n,e){var t=i((n||{}).plugins),o=(n||{}).RTCPeerConnection||c,u=r.config(n);return e=r.connectionConstraints(n,e),t&&"function"==typeof t.createConnection?t.createConnection(u,e):new o(u,e)}},{"./couple":55,"./detect":56,"./generators":57,"cog/logger":9,"rtc-core/plugin":21}],59:[function(n,e){"use strict";function t(n){return o[n]||n}var r=n("mbus"),o={completed:"connected"},i=["signalingstatechange","iceconnectionstatechange"];e.exports=function(n,e,o,c){function u(){var e=t(n.iceConnectionState);f("statechange",n,e),s!==e&&(f(e),s=e)}function a(){f("closed")}var s,f=r("",c);return n.onclose=a,i.forEach(function(e){n["on"+e]=u}),f.stop=function(){n.onclose=null,i.forEach(function(e){n["on"+e]=null})},f.checkState=u,n?(s=t(n.iceConnectionState),f):f}},{mbus:26}],60:[function(n,e){var t=n("rtc-core/detect"),r=n("rtc-core/plugin"),o=n("priorityqueuejs"),i=n("whisk/pluck"),c=i("sdp","type"),u=n("rtc-validator/candidate"),a=n("rtc-sdpclean"),s=n("rtc-sdp"),f=100,l=1e3,d=["candidate","setLocalDescription","setRemoteDescription","createAnswer","createOffer"],p={setLocalDescription:"setlocaldesc",setRemoteDescription:"setremotedesc",createOffer:"offer",createAnswer:"answer"},v={data:"application"},h=["have-remote-offer","have-local-pranswer"];e.exports=function(e,i){function g(n,t){function r(){U("ice.remote.applied",c),t()}function o(n){U("ice.remote.invalid",c),t(n)}var i=n.args[0],c=i&&i.candidate&&b(i);return c?void e.addIceCandidate(c,r,o):t()}function m(){var n=!I.isEmpty()&&!q&&I.peek(),t=n&&j(n),r=!I.isEmpty()&&A(e);return F=0,t?(q=I.deq(),void q.fn(q,function(n){var e=q.fail||N,t=q.pass,r=q.name;return n?(console.error(r+" task failed: ",n),e(n)):("function"==typeof t&&t.apply(q,[].slice.call(arguments,1)),void setTimeout(function(){q=null,R()},0))})):r&&R()}function y(n){var t=[],r=n&&a(n.sdp,{collector:t});return n&&r!==n.sdp&&(console.info("invalid lines removed from sdp: ",t),n.sdp=r),"function"==typeof z&&(n.sdp=z(n.sdp,e)),n}function w(){return h.indexOf(e.signalingState)>=0?U.createAnswer():void 0}function b(n){return P&&"function"==typeof P.createIceCandidate?P.createIceCandidate(n):new B(n)}function x(n){return P&&"function"==typeof P.createSessionDescription?P.createSessionDescription(n):new V(n)}function k(){U("sdp.local",c(this.args[0]))}function _(n,e,t){return function(){var r=[].slice.call(arguments);t&&"function"==typeof t.processArgs&&(r=r.map(t.processArgs)),I.enq({args:r,name:n,fn:e,checks:[A].concat((t||{}).checks||[]),pass:(t||{}).pass,fail:(t||{}).fail}),R()}}function S(n,t){function r(e){U.apply(U,["negotiate.error",n.name,e].concat(n.args)),t(e)}function o(){U.apply(U,[["negotiate",c,"ok"],n.name].concat(n.args)),t.apply(null,[null].concat([].slice.call(arguments)))}var i=e[n.name],c=p[n.name]||(n.name||"").toLowerCase(),u=[o,r],a="createOffer"===n.name;return i?(U.apply(U,["negotiate."+c].concat(n.args)),void i.apply(e,n.args.concat(u).concat(a?L():[]))):t(new Error('cannot call "'+n.name+'" on RTCPeerConnection'))}function E(n){for(;n&&n.candidate&&n.candidate.candidate;)n=n.candidate;return n}function L(){var n={offertoreceivevideo:"OfferToReceiveVideo",offertoreceiveaudio:"OfferToReceiveAudio",icerestart:"IceRestart",voiceactivitydetection:"VoiceActivityDetection"},e={OfferToReceiveVideo:!0,OfferToReceiveAudio:!0};return Object.keys(i||{}).forEach(function(t){n[t.toLowerCase()]&&(e[n[t.toLowerCase()]]=i[t])}),{mandatory:e}}function T(n){return n.__hasDesc||(n.__hasDesc=!!n.remoteDescription)}function C(n){return"have-local-offer"!==n.signalingState}function A(n){return"closed"!==n.signalingState}function O(n,e){return e.__valid||(e.__valid=0===u(e.args[0]).length)}function D(n,e){var t=s(n.remoteDescription&&n.remoteDescription.sdp),r=t.getMediaTypes(),o=e.args[0]&&e.args[0].sdpMid;return o=v[o]||o,""===o||r.indexOf(o)>=0}function M(n,e){var t=[n,e],r=t.map(j),o=t.map(function(n,e){var t=r[e],o=t&&$.indexOf(n.name);return t?o>=0?o:f:l});return o[1]-o[0]}function j(n){return(n.checks||[]).reduce(function(t,r){return t&&r(e,n)},!0)}function R(){F||(F=setTimeout(m,50))}var q,I=new o(M),U=n("mbus")("",(i||{}).logger),$=(i||{}).priorities||d,P=r((i||{}).plugins),F=0,N=U.bind(U,"fail"),z=(i||{}).sdpfilter||(i||{}).sdpFilter,V=(i||{}).RTCSessionDescription||t("RTCSessionDescription"),B=(i||{}).RTCIceCandidate||t("RTCIceCandidate");return U.addIceCandidate=_("addIceCandidate",g,{processArgs:E,checks:[T,O,D]}),U.setLocalDescription=_("setLocalDescription",S,{processArgs:y,pass:k}),U.setRemoteDescription=_("setRemoteDescription",S,{processArgs:x,pass:w}),U.createOffer=_("createOffer",S,{checks:[C],pass:U.setLocalDescription}),U.createAnswer=_("createAnswer",S,{pass:U.setLocalDescription}),U}},{mbus:26,priorityqueuejs:61,"rtc-core/detect":18,"rtc-core/plugin":21,"rtc-sdp":62,"rtc-sdpclean":64,"rtc-validator/candidate":65,"whisk/pluck":71}],61:[function(n,e){function t(n){this._comparator=n||t.DEFAULT_COMPARATOR,this._elements=[]}e.exports=t,t.DEFAULT_COMPARATOR=function(n,e){return"number"==typeof n&&"number"==typeof e?n-e:(n=n.toString(),e=e.toString(),n==e?0:n>e?1:-1)},t.prototype.isEmpty=function(){return 0===this.size()},t.prototype.peek=function(){if(this.isEmpty())throw new Error("PriorityQueue is empty");return this._elements[0]},t.prototype.deq=function(){var n=this.peek(),e=this._elements.pop(),t=this.size();if(0===t)return n;this._elements[0]=e;for(var r=0;t>r;){var o=r,i=2*r+1,c=2*r+2;if(t>i&&this._compare(i,o)>=0&&(o=i),t>c&&this._compare(c,o)>=0&&(o=c),o===r)break;this._swap(o,r),r=o}return n},t.prototype.enq=function(n){for(var e=this._elements.push(n),t=e-1;t>0;){var r=Math.floor((t-1)/2);if(this._compare(t,r)<=0)break;this._swap(r,t),t=r}return e},t.prototype.size=function(){return this._elements.length},t.prototype.forEach=function(n){return this._elements.forEach(n)},t.prototype._compare=function(n,e){return this._comparator(this._elements[n],this._elements[e])},t.prototype._swap=function(n,e){var t=this._elements[n];this._elements[n]=this._elements[e],this._elements[e]=t}},{}],62:[function(n,e){"use strict";var t=n("whisk/nub"),r=n("whisk/pluck"),o=n("whisk/flatten"),i=/\r?\n/,c=/\r?\n$/,u=["a","c","b","k"],a=n("./parsers");e.exports=function(n){var e,s={},f=[],l=n.split(i).filter(Boolean).map(function(n){return n.split("=")}),d=(t(l.filter(function(n){return n[0]&&u.indexOf(n[0])<0}).map(r(0))),s.findLine=function(n,e){var t=f.filter(function(e){return e[0]===n})[e||0];return t&&t[1]});return l.forEach(function(n){var t=a[n[0]];t?e=t(f,n):e?e=e(n):f.push(n)}),s.addIceCandidate=function(n){var e=(n||{}).lineIndex||(n||{}).sdpMLineIndex,t="undefined"!=typeof e&&d("m",e),r=(n||{}).candidate;t&&r&&t.childlines.push(r.replace(c,"").split("="))},s.getMediaTypes=function(){function n(n){return n[1].def.split(/\s/)[0]}return f.filter(function(n){return"m"===n[0]&&n[1]&&n[1].def}).map(n)},s.toString=function(){return f.map(function(n){return"function"==typeof n[1].toArray?n[1].toArray():[n]}).reduce(o).map(function(n){return n.join("=")}).join("\n")},s}},{"./parsers":63,"whisk/flatten":68,"whisk/nub":70,"whisk/pluck":71}],63:[function(n,e,t){"use strict";t.m=function(n,e){function t(n){return r.childlines.push(n),t}var r={def:e[1],childlines:[],toArray:function(){return[["m",r.def]].concat(r.childlines)}};return n.push(["m",r]),t}},{}],64:[function(n,e){function t(n){var e=o.exec(n);return e&&e[0]}var r=[[/^(a\=candidate.*)$/,n("rtc-validator/candidate")]],o=/(\r?\n|\\r\\n)/;e.exports=function(n,e){var o=t(n),i=n.split(o),c=(e||{}).collector;return i=i.filter(function(n){var e=r.reduce(function(e,t){return"undefined"!=typeof e?e:t[0].exec(n)&&{line:n.replace(t[0],"$1"),fn:t[1]}},void 0),t=e?e.fn(e.line):[];return c&&t.forEach(function(n){c.push(n)}),0===t.length}),i.join(o)}},{"rtc-validator/candidate":65}],65:[function(n,e){function t(n,e){var t=c[e];return t&&!t[0].test(n)?(r(t[2]+" part failed validation: "+n),new Error(t[1])):void 0}var r=n("cog/logger")("rtc-validator"),o=/^(?:a=)?candidate:/,i=/^((\d+\.){3}\d+|([a-fA-F0-9]+\:){7}[a-fA-F0-9]+)$/,c=[[/.+/,"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"],[i,"invalid connection address","connection-address"],[/\d+/,"invalid connection port","connection-port"],[/typ/,'Expected "typ" identifier',"type classifier"],[/.+/,"Invalid candidate type specified","candidate-type"]];e.exports=function(n){var e=[],r=n&&(n.candidate||n),i=r&&o.exec(r),c=i&&r.slice(i[0].length).split(/\s/);return r?i?e=e.concat(c.map(t)).filter(Boolean):[new Error("candidate did not match expected sdp line format")]:[new Error("empty candidate")]}},{"cog/logger":9}],66:[function(n,e){e.exports=function(n){return n=[].concat(n||[]).concat([].slice.call(arguments,1)),function(e){return n.reduce(function(n,e){var t=e(n);return void 0!==t?t:n},e||0)}}},{}],67:[function(n,e){e.exports=function(n,e){return arguments.length>1?n===e:function(e){return n===e}}},{}],68:[function(n,e){e.exports=function(n,e){return n=Array.isArray(n)?n:[n],n.concat(e)}},{}],69:[function(n,e){e.exports=function(n){return function(e){for(var t=[],r=0,o=e.length;o>r;r++){for(var i=!1,c=t.length;c--;)i=i||n(e[r],t[c]);i||(t[t.length]=e[r])}return t}}},{}],70:[function(n,e){e.exports=n("./nub-by")(n("./equality"))},{"./equality":67,"./nub-by":69}],71:[function(n,e){e.exports=function(){function n(n,e){return function(t){var r=0,o=t;do o=o&&o[n[r++]];while(o&&e>=r);return o}}var e=[];return[].slice.call(arguments).forEach(function(n){var t="number"==typeof n?[n]:(n||"").split(".");e[e.length]={name:t[0],parts:t,maxIdx:t.length-1}}),e.length<=1?n(e[0].parts,e[0].maxIdx):function(t){for(var r={},o=0,i=e.length;i>o;o++)r[e[o].name]=n([e[o].parts[0]],0)(t);return r}}},{}]},{},[2])(2)});
//# sourceMappingURL=rtc.min.js.map