forked from muaz-khan/RTCMultiConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmc.min.js
More file actions
3 lines (3 loc) · 54.2 KB
/
rmc.min.js
File metadata and controls
3 lines (3 loc) · 54.2 KB
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":63}],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.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){return Object.keys(n[0]).map(function(e){return n.map(function(n){return n[e]})})}function r(n,e,t){this._task=n,this._args=e,this._done=t}function o(n,e,t,o){var i=n.names,c=n.args,a=(n.fn,[]);if(c)for(var s=0;s<c.length;s++){var f=c[s],l=f.match(u);if(l&&(f=f.slice(1)),!(f in e))return;l||a.push(e[f])}var d=new r(n,a,function(n,e){o(i,n,e)});t(i),d.run()}function i(n,e,t){var r;for(var c in n)r=n[c],o(r,e,function(e){delete n[e]},function(r,o,c){if(o)return void t.emit("error",o,r);for(var u=0;u<r.length;u++)e[r[u]]=c[u];i(n,e,t)})}function c(n,e,t){var r={};for(var o in n)r[o]=n[o];i(r,e,t)}var u=/^\!.+/;r.prototype._count=1,r.prototype._runs=0,r.prototype.run=function(){var n,e=this,t=[];this._task.fn.apply(this,this._args.concat([function(r){var o=Array.prototype.slice.call(arguments,1);t.push(o),e._runs++,r?(n=!0,e.done(r)):n||e._runs!==e._count||e.done(null,t)}]))},r.prototype.count=function(n){this._parallel=!0,this._count=n},r.prototype.done=function(n,e){return n?this._done(n):void this._done(null,this._parallel?t(e):e[0])},e.exports=c},{}],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){(function(t){"use strict";var r=n("rtc-tools"),o=n("mbus"),i=n("rtc-tools/cleanup"),c=n("rtc-core/plugin"),u=r.logger("rtc-quickconnect"),a=(n("cog/defaults"),n("cog/extend")),s=n("cog/getable"),f=n("./messenger");e.exports=function(e,l){function d(n,e){B.set(n,{active:!1,pc:e,channels:s({}),streams:[],lastping:Date.now()})}function p(n){var e=B.get(n);e&&(u("ending call to: "+n),e.channels.keys().forEach(function(t){var r=e.channels.get(t),o=[n,r,t];U.apply(U,["channel:closed"].concat(o)),U.apply(U,["channel:closed:"+t].concat(o)),r.onopen=null}),e.streams.forEach(function(e){U("stream:removed",n,e)}),B.delete(n),0===B.keys().length&&S(),U("call:ended",n,e.pc),i(e.pc))}function v(n,e,r){var o=B.get(n),i=[].concat(e.getRemoteStreams());o.active=!0,o.streams=[].concat(e.getRemoteStreams()),e.onaddstream=m(n),e.onremovestream=y(n),u(U.id+" - "+n+" call start: "+i.length+" streams"),U("call:started",n,e,r),x(),t.nextTick(function(){i.forEach(O(n))})}function h(){clearTimeout(K),z||$&&(!G||j)&&M&&(J&&V.length<J||(K=setTimeout(function(){var n=a({room:I},N);U.announce(n),z=!0},0)))}function g(n){var e,t,i=b(n);i.room===I&&(p(n),e=r.createConnection(a({},l,{iceServers:M}),(l||{}).constraints),U("peer:connect",i.id,e,i),d(i.id,e),V.forEach(function(n){e.addStream(n)}),U.isMaster(i.id)?(u("is master, creating data channels: ",Object.keys(W)),Object.keys(W).forEach(function(n){_(e.createDataChannel(n,W[n]),e,i)})):e.ondatachannel=function(t){var r=t&&t.channel;r&&void 0!==W[r.label]&&_(r,e,b(n))},u("coupling "+U.id+" to "+i.id),t=r.couple(e,n,U,a({},l,{logger:o("pc."+n,U)})),U("peer:couple",n,e,i,t),t.once("connected",v.bind(null,n,e,i)),t.once("closed",p.bind(null,n)),U.isMaster(n)&&t.createOffer())}function m(n){return function(e){u("peer "+n+" added stream"),D(n),O(n)(e.stream)}}function y(n){return function(e){u("peer "+n+" removed stream"),D(n),U("stream:removed",n,e.stream)}}function w(n){var e=B.get(n);if(!e)throw new Error("No active call for peer: "+n);return e}function b(n){var e=U.peers.get(n);return e&&e.data}function _(n,e,t){function r(){var r=B.get(t.id),i=[t.id,n,t,e];u('reporting channel "'+n.label+'" ready, have call: '+!!r),clearInterval(o),n.onopen=null,r&&r.channels.set(n.label,n),u("triggering channel:opened events for channel: "+n.label),U.apply(U,["channel:opened"].concat(i)),U.apply(U,["channel:opened:"+n.label].concat(i))}var o;return u("channel "+n.label+" discovered for peer: "+t.id),"open"===n.readyState?r():(u("channel not ready, current state = "+n.readyState),n.onopen=r,void(o=setInterval(function(){u("checking channel state, current state = "+n.readyState),"open"===n.readyState&&r()},500)))}function x(){!Q&&F&&(Q=setInterval(k,F))}function k(){var n=Date.now()-4*F;B.keys().forEach(function(e){var t=B.get(e);return t.lastping<n?p(e):void U.to(e).send("/ping")})}function S(){clearInterval(Q),Q=0}function E(){return G&&G.init(l,function(n){return n?console.error("Could not initialize plugin: ",n):(j=!0,void h())})}function L(n){n&&"undefined"!=typeof n.room&&(I=n.room)}function T(n,e){e.allow=e.allow&&V.length>=J}function C(n){var e=n&&n.id,t=e&&B.get(e);return e&&!t?(u("received peer update from peer "+e+", no active calls"),U.to(e).send("/reconnect"),g(e)):void 0}function A(n){var e=B.get(n&&n.id);e&&(e.lastping=Date.now())}function O(n){B.get(n);return function(e){U("stream:added",n,e,b(n))}}function D(n){var e=B.get(n);e&&e.pc&&(e.streams=[].concat(e.pc.getRemoteStreams()))}var M,j,R="undefined"!=typeof location&&location.hash.slice(1),U=n("rtc-signaller")(f(e),l),q=(l||{}).ns||"",I=(l||{}).room,P=(l||{}).debug,$=!(l||{}).manualJoin,F=(l||{}).heartbeat||2500,N={},z=!1,V=[],B=U.calls=s({}),W={},G=(U.plugins=(l||{}).plugins||[],c(U.plugins)),J=parseInt((l||{}).expectedLocalStreams,10)||0,K=0,Q=0,H=0;return I||("undefined"==typeof location||R||(R=location.hash=""+Math.pow(2,53)*Math.random()),I=q+"#"+R),P&&r.logger.enable.apply(r.logger,Array.isArray(u)?P:["*"]),U.on("peer:announce",function(n){g(n.id)}),U.on("peer:update",C),U.on("message:reconnect",function(n){g(n.id)}),U.broadcast=U.addStream=function(n){return V.push(n),B.values().forEach(function(e){e.pc.addStream(n)}),h(),U},U.endCalls=function(){B.keys().forEach(p)},U.close=function(){U.endCalls(),U.leave()},U.createDataChannel=function(n,e){return B.keys().forEach(function(t){var r,o=B.get(t);o&&o.pc&&U.isMaster(t)&&(r=o.pc.createDataChannel(n,e),_(r,o.pc,b(t)))}),W[n]=e||null,U},U.join=function(){$=!0,h()},U.get=function(n){return N[n]},U.getLocalStreams=function(){return[].concat(V)},U.reactive=function(){return l=l||{},l.reactive=!0,U},U.removeStream=function(n){var e=V.indexOf(n);return B.values().forEach(function(e){e.pc.removeStream(n)}),e>=0&&V.splice(e,1),U},U.requestChannel=function(n,e,t){var r=w(n),o=r&&r.channels.get(e);return o?(t(null,o),U):(U.once("channel:opened:"+e,function(n,e){t(null,e)}),U)},U.requestStream=function(n,e,t){function r(c){c===n&&(o=i.pc.getRemoteStreams()[e],o&&(U.removeListener("stream:added",r),t(null,o)))}var o,i=w(n);return(o=i.pc.getRemoteStreams()[e])?(t(null,o),U):(U.on("stream:added",r),U)},U.profile=function(n){return a(N,n),z&&(clearTimeout(H),H=setTimeout(function(){U.announce(N)},(l||{}).updateDelay||1e3)),U},U.waitForCall=function(n,e){var t=B.get(n);return t&&t.active?(e(null,t.pc),U):void U.on("call:started",function t(r){r===n&&(U.removeListener("call:started",t),e(null,B.get(r).pc))})},J&&U.on("peer:filter",T),U.on("local:announce",L),U.on("message:ping",A),n("rtc-core/genice")(l,function(n,e){return n?console.error("could not find iceServers: ",n):(M=e,void h())}),G&&E(),U}}).call(this,n("_process"))},{"./messenger":23,_process:4,"cog/defaults":5,"cog/extend":6,"cog/getable":7,mbus:24,"rtc-core/genice":19,"rtc-core/plugin":21,"rtc-signaller":28,"rtc-tools":57,"rtc-tools/cleanup":53}],23:[function(n,e){e.exports=function(e){return"function"==typeof e?e:n("rtc-switchboard-messenger")(e)}},{"rtc-switchboard-messenger":44}],24:[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}},{}],25:[function(n,e){e.exports={dataEvent:"data",openEvent:"open",closeEvent:"close",errorEvent:"error",writeMethod:"write",closeMethod:"close",leaveTimeout:3e3}},{}],26:[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}],27:[function(n,e){"use strict";e.exports=function(e,t){return{announce:n("./announce")(e,t)}}},{"./announce":26}],28:[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.3"};e.exports=function(e,v){function h(){L.announce()}function g(n){O.push(m(n)),M!==f||void 0!==k&&!k||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=(v||{}).autoreply,k=(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(_)),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 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===x||x,L.process=_=n("./processor")(L,v),(void 0===k||k)&&j(),L}},{"./defaults":25,"./processor":43,"cog/defaults":5,"cog/extend":6,"cog/getable":7,cuid:29,mbus:24,"pull-pushable":30,"pull-stream":37,"rtc-core/detect":18}],29:[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)},{}],30:[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":31}],31:[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":32,"./sinks":34,"./sources":35,"./throughs":36,"pull-core":33}],32:[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":33}],33:[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)}})()}},{}],34:[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)}}},{}],35:[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))})}}}},{}],36:[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":34,"./sources":35,_process:4,"pull-core":33}],37:[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":38,"./sinks":40,"./sources":41,"./throughs":42,"pull-core":39}],38:[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":39}],39:[function(n,e,t){arguments[4][33][0].apply(t,arguments)},{dup:33}],40:[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)}}},{}],41:[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))})}}}},{}],42:[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":40,"./sources":41,_process:4,"pull-core":39}],43:[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":27,"cog/jsonparse":8}],44:[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":45}],45:[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?void 0: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":46,ws:51,wsurl:52}],46:[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":49,"./source":50}],47:[function(n,e,t){function r(n){return"function"!=typeof n?n:(n.pipe=n.pipe||function(e){if("function"!=typeof e&&"function"!=typeof e.sink)throw new Error("must pipe to reader");var t=r(e.sink?e.sink(n):e(n));return e.source||t},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)}})()}},{}],48:[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))}},{}],49:[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":48,_process:4,"pull-core":47}],50:[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":48,"pull-core":47}],51:[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)},{}],52:[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")}},{}],53:[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}],54:[function(n,e){"use strict";function t(e,t,f,l){function d(){k("decoupling "+f.id+" from "+t),S.stop(),i(e),f.removeListener("sdp",v),f.removeListener("candidate",p),f.removeListener("negotiate",w),f.removeListener("message:sdp",v),f.removeListener("message:candidate",p),f.removeListener("message:negotiate",w)}function p(n){O.addIceCandidate(n)}function v(n,e){E("sdp.remote",n),e&&e.id===t&&O.setRemoteDescription(n)}function h(){k("captured pc close, iceConnectionState = "+e.iceConnectionState),d()}function g(){k("captured pc disconnect, monitoring connection status"),_=setTimeout(function(){k("manually closing connection after disconnect timeout"),i(e)},C),S.on("statechange",m)}function m(){return k("connection state changed to: "+e.iceConnectionState),s.indexOf(e.iceConnectionState)>=0?void 0:(b(),a.indexOf(e.iceConnectionState)>=0?S("closed"):void S.once("disconnect",g))}function y(n){var e;n.candidate?(b(),e={candidate:n.candidate.candidate,sdpMid:n.candidate.sdpMid,sdpMLineIndex:n.candidate.sdpMLineIndex},E("ice.local",e),f.to(t).send("/candidate",e),T=!1):T||(T=!0,E("ice.gathercomplete"),f.to(t).send("/endofcandidates",{}))}function w(n){n.id===t&&(E("negotiate.request",n.id),M())}function b(){S.off("statechange",m),k("reset disconnect timer, state: "+e.iceConnectionState),clearTimeout(_)}var _,x=(l||{}).debugLabel||"rtc",k=n("cog/logger")(x+"/couple"),S=c(e,t,f,(l||{}).logger),E=r("",S),L=(l||{}).reactive,T=!0,C=(l||{}).disconnectTimeout||1e4,A=f.isMaster(t),O=o(e,l),D=u(function(){return A?void O.createOffer():f.to(t).send("/negotiate")},100,{leading:!1}),M=u(O.createOffer,100,{leading:!1});return L&&(e.onnegotiationneeded=function(){E("negotiate.renegotiate"),D()}),e.onicecandidate=y,O.on("sdp.local",function(n){f.to(t).send("/sdp",n)}),f.on("sdp",v),f.on("candidate",p),f.on("message:sdp",v),f.on("message:candidate",p),A&&(f.on("negotiate",w),f.on("message:negotiate",w)),S.once("closed",h),S.once("disconnected",g),S.createOffer=D,S}var r=n("mbus"),o=n("rtc-taskqueue"),i=n("./cleanup"),c=n("./monitor"),u=n("cog/throttle"),a=["closed","failed"],s=["checking"];e.exports=t},{"./cleanup":53,"./monitor":58,"cog/logger":9,"cog/throttle":10,mbus:24,"rtc-taskqueue":59}],55:[function(n,e){"use strict";e.exports=n("rtc-core/detect")},{"rtc-core/detect":18}],56:[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":55,"cog/defaults":5,"cog/logger":9}],57:[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":54,"./detect":55,"./generators":56,"cog/logger":9,"rtc-core/plugin":21}],58:[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:24}],59:[function(n,e){var t=n("rtc-core/detect"),r=n("rtc-core/plugin"),o=n("priorityqueuejs"),i=n("rtc-validator/candidate"),c=n("rtc-sdpclean"),u=100,a=1e3,s=["candidate","setLocalDescription","setRemoteDescription","createAnswer","createOffer"],f={setLocalDescription:"setlocaldesc",setRemoteDescription:"setremotedesc",createOffer:"offer",createAnswer:"answer"},l=["have-remote-offer","have-local-pranswer"];e.exports=function(e,d){function p(n,t){function r(){j("ice.remote.applied",c),t()}function o(n){j("ice.remote.invalid",c),t(n)}var i=n.args[0],c=i&&i.candidate&&m(i);return c?void e.addIceCandidate(c,r,o):t()}function v(){var n=!M.isEmpty()&&!D&&M.peek(),t=n&&A(n),r=!M.isEmpty()&&L(e);return q=0,t?(D=M.deq(),void D.fn(D,function(n){var e=D.fail||I,t=D.pass,r=D.name;return n?(console.error(r+" task failed: ",n),e(n)):("function"==typeof t&&t.apply(D,[].slice.call(arguments,1)),void setTimeout(function(){D=null,O()},0))})):r&&O()}function h(n){var t=[],r=n&&c(n.sdp,{collector:t});return n&&r!==n.sdp&&(console.info("invalid lines removed from sdp: ",t),n.sdp=r),"function"==typeof P&&(n.sdp=P(n.sdp,e)),n}function g(){return l.indexOf(e.signalingState)>=0?j.createAnswer():void 0}function m(n){return U&&"function"==typeof U.createIceCandidate?U.createIceCandidate(n):new F(n)}function y(n){return U&&"function"==typeof U.createSessionDescription?U.createSessionDescription(n):new $(n)}function w(){j("sdp.local",this.args[0])}function b(n,e,t){return function(){var r=[].slice.call(arguments);t&&"function"==typeof t.processArgs&&(r=r.map(t.processArgs)),M.enq({args:r,name:n,fn:e,checks:[L].concat((t||{}).checks||[]),pass:(t||{}).pass,fail:(t||{}).fail}),O()}}function _(n,t){function r(e){j.apply(j,["negotiate.error",n.name,e].concat(n.args)),t(e)}function o(){j.apply(j,[["negotiate",c,"ok"],n.name].concat(n.args)),t.apply(null,[null].concat([].slice.call(arguments)))}var i=e[n.name],c=f[n.name]||(n.name||"").toLowerCase(),u=[o,r],a="createOffer"===n.name;return i?(j.apply(j,["negotiate."+c].concat(n.args)),void i.apply(e,n.args.concat(u).concat(a?k():[]))):t(new Error('cannot call "'+n.name+'" on RTCPeerConnection'))}function x(n){for(;n&&n.candidate&&n.candidate.candidate;)n=n.candidate;return n}function k(){var n={offertoreceivevideo:"OfferToReceiveVideo",offertoreceiveaudio:"OfferToReceiveAudio",icerestart:"IceRestart",voiceactivitydetection:"VoiceActivityDetection"},e={OfferToReceiveVideo:!0,OfferToReceiveAudio:!0};return Object.keys(d||{}).forEach(function(t){n[t.toLowerCase()]&&(e[n[t.toLowerCase()]]=d[t])}),{mandatory:e}}function S(n){return n.__hasDesc||(n.__hasDesc=!!n.remoteDescription)}function E(n){return"have-local-offer"!==n.signalingState}function L(n){return"closed"!==n.signalingState}function T(n,e){return e.__valid||(e.__valid=0===i(e.args[0]).length)}function C(n,e){var t=[n,e],r=t.map(A),o=t.map(function(n,e){var t=r[e],o=t&&R.indexOf(n.name);return t?o>=0?o:u:a});return o[1]-o[0]}function A(n){return(n.checks||[]).reduce(function(t,r){return t&&r(e,n)},!0)}function O(){q||(q=setTimeout(v,50))}var D,M=new o(C),j=n("mbus")("",(d||{}).logger),R=(d||{}).priorities||s,U=r((d||{}).plugins),q=0,I=j.bind(j,"fail"),P=(d||{}).sdpfilter||(d||{}).sdpFilter,$=(d||{}).RTCSessionDescription||t("RTCSessionDescription"),F=(d||{}).RTCIceCandidate||t("RTCIceCandidate");return j.addIceCandidate=b("addIceCandidate",p,{processArgs:x,checks:[S,T]}),j.setLocalDescription=b("setLocalDescription",_,{processArgs:h,pass:w}),j.setRemoteDescription=b("setRemoteDescription",_,{processArgs:y,pass:g}),j.createOffer=b("createOffer",_,{checks:[E],pass:j.setLocalDescription}),j.createAnswer=b("createAnswer",_,{pass:j.setLocalDescription}),j}},{mbus:24,priorityqueuejs:60,"rtc-core/detect":18,"rtc-core/plugin":21,"rtc-sdpclean":61,"rtc-validator/candidate":62}],60:[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}},{}],61:[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":62}],62:[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+$/,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}],63:[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)}}},{}]},{},[2])(2)});
//# sourceMappingURL=rtc.min.js.map