!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.zaplink=t():e.zaplink=t()}(global,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=29)}([function(e,t){e.exports=require("events")},function(e,t){e.exports=require("core-js/modules/es6.promise")},function(e,t,r){"use strict";r(1),r(3),r(4),r(7),r(6),r(24),r(35),r(36),r(37),r(38),r(17),r(18),r(23),r(8);var n=r(5),o=r.n(n);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function a(e){var t="function"==typeof Map?new Map:void 0;return(a=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return f(e,arguments,l(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),p(n,e)})(e)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function f(e,t,r){return(f=s()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&p(o,r.prototype),o}).apply(null,arguments)}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var d=function(e){function t(){return c(this,t),i(this,l(t).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}(t,e),t}(a(Error));d.prototype.name="TimeoutError";var y=function(e){var t={},r=void 0!==e.timeout?e.timeout:1e3;return{createRequest:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r,n=arguments.length>1?arguments[1]:void 0,u=n||o()(8),c=null,i=new Promise((function(r,n){t[u]={resolve:function(e){delete t[u],c&&clearTimeout(c),r(e)},reject:function(e){delete t[u],c&&clearTimeout(c),n(e)}},e&&(c=setTimeout((function(){t[u]&&(delete t[u],n(new d("Request timed out")))}),e))}));return{reqId:u,promise:i}},handleResolve:function(e,r){return t[e]&&t[e].resolve(r)},handleReject:function(e,r){return t[e]&&t[e].reject(r)}}};y.TimeoutError=d,t.a=y},function(e,t){e.exports=require("core-js/modules/es7.symbol.async-iterator")},function(e,t){e.exports=require("core-js/modules/es6.symbol")},function(e,t){e.exports=require("randombytes")},function(e,t){e.exports=require("core-js/modules/web.dom.iterable")},function(e,t){e.exports=require("core-js/modules/es6.object.create")},function(e,t){e.exports=require("core-js/modules/es6.object.set-prototype-of")},function(e,t){e.exports=require("regenerator-runtime/runtime")},function(e,t){e.exports=require("debug")},function(e,t){e.exports=require("async-unwrap")},function(e,t,r){"use strict";r(32),r(33);var n=r(25),o=r.n(n),u=r(5),c=r.n(u),i=r(26),a=r.n(i),s=function(e){return o()("sha256","correct horse battery staple").update(e).digest()},f=[25,105,190,89,74,170,170,202,107,159,162,222,13,211,209,197,230,165,49,202,239,176,141,79,97,88,65,184,99,115,112,23],p=function(e){for(var t=new Uint8Array(32),r=0;r<32;r++)t[r]=f[r]^e[r];return t},l=function(){try{var e=window.localStorage.getItem("__zaplink-secret");return e&&/^\d+(?::\d+){31}$/.test(e)||window.localStorage.setItem("__zaplink-secret",c()(32).join(":")),p(new Uint8Array(window.localStorage.getItem("__zaplink-secret").split(":")))}catch(e){return null}};t.a={create:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.useLocalSecret?l():null,r=e.useLocalSecret&&t?t:c()(32),n=s(r);return{id:n,secret:r}},verify:function(e,t){try{return a()(e,s(t))}catch(e){return!1}},pad:p}},function(e,t,r){"use strict";r.d(t,"a",(function(){return y}));r(20),r(7),r(8),r(15),r(3),r(4),r(6),r(22),r(9),r(1),r(16),r(23),r(34),r(21);var n=r(0),o=r(11),u=r.n(o),c=r(2);function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var c,i=e[Symbol.iterator]();!(n=(c=i.next()).done)&&(r.push(c.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function s(e,t,r,n,o,u,c){try{var i=e[u](c),a=i.value}catch(e){return void r(e)}i.done?t(a):Promise.resolve(a).then(n,o)}function f(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var u=e.apply(t,r);function c(e){s(u,n,o,c,i,"next",e)}function i(e){s(u,n,o,c,i,"throw",e)}c(void 0)}))}}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return(d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var y=function(e){function t(e){var r,n,o;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),n=this,o=p(t).call(this),r=!o||"object"!==i(o)&&"function"!=typeof o?l(n):o;var s=Object(c.a)(e);r.id=e.peerId||null,r.key=e.peerKey||null,r.retryCount=Number(e.retryCount)||5;var d=[],y={},m=!1;r.socketCount=function(){return d.length};r.addHandler=function(e,t){y[e]||(y[e]=[]),y[e].push(t)},r.removeHandler=function(e,t){y[e]&&(y[e]=y[e].filter((function(e){return e!==t})))};var b=null;r.addSocket=function(t){m?t.disconnect():(d.push(t),b&&(clearTimeout(b),b=null),t.on("message",(function(e){return j(e)})),t.on("disconnect",(function(){for(var n;~(n=d.indexOf(t));)d.splice(n,1);r.emit("socket-lost"),r.emit("socket-count",d.length),d.length||(b=setTimeout((function(){return r.emit("disconnect")}),e.timeout||1e3))})),r.emit("socket-added"),r.emit("socket-count",d.length))};r.disconnect=function(){m=!0,d.map((function(e){return setImmediate((function(){return e.disconnect()}))}))};var v=function(){if(!d.length)return new Promise((function(t,n){r.once("socket-added",(function(){return t()}));var o=e.timeout||1e3;o&&setTimeout((function(){return n(new c.a.TimeoutError("Connection timed out"))}),o)}))},h=function(e){var t=d.shift();d.push(t),t&&t.send(e)},x=e.timeout,w=function(){var e=f(regeneratorRuntime.mark((function e(t,r){var n,o,u,c,i,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a.length>2&&void 0!==a[2]?a[2]:{},d.length){e.next=4;break}return e.next=4,v();case 4:return o=s.createRequest(null!=n.timeout?n.timeout:x),u=o.reqId,c=o.promise,i={type:"request",reqId:u,name:t,data:r},n.broadcast?d.map((function(e){return e.send(i)})):h(i),e.abrupt("return",c);case 8:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),g=function(){var e=f(regeneratorRuntime.mark((function e(t,n){var o,i,s,f,p,l,d=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=d.length>2&&void 0!==d[2]?d[2]:{},i=null,s=null,f=0;case 4:if(!(f<(o.retryCount||r.retryCount))){e.next=17;break}return e.next=8,w(t,n,o)[u.a];case 8:if(p=e.sent,l=a(p,2),s=l[0],i=l[1],s&&s instanceof c.a.TimeoutError){e.next=14;break}return e.abrupt("break",17);case 14:f++,e.next=4;break;case 17:if(!s){e.next=19;break}throw s;case 19:return e.abrupt("return",i);case 20:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}();r.send=g;var j=function(){var e=f(regeneratorRuntime.mark((function e(t){var r,n,o,u,c,i,a,f,p;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("response"===t.type&&s.handleResolve(t.reqId,t.data),"error"===t.type&&s.handleReject(t.reqId,t.data),"request"!==t.type){e.next=42;break}if(r=y[t.name]||[],n=t.reqId,r.length){e.next=7;break}return e.abrupt("return",h({type:"error",reqId:n,data:"No handler for call '".concat(t.name,"'")}));case 7:o=t.data,u=!0,c=!1,i=void 0,e.prev=11,a=r[Symbol.iterator]();case 13:if(u=(f=a.next()).done){e.next=27;break}return p=f.value,e.prev=15,e.next=18,p(t.data);case 18:o=e.sent,e.next=24;break;case 21:return e.prev=21,e.t0=e.catch(15),e.abrupt("return",h({type:"error",reqId:n,data:e.t0.message}));case 24:u=!0,e.next=13;break;case 27:e.next=33;break;case 29:e.prev=29,e.t1=e.catch(11),c=!0,i=e.t1;case 33:e.prev=33,e.prev=34,u||null==a.return||a.return();case 36:if(e.prev=36,!c){e.next=39;break}throw i;case 39:return e.finish(36);case 40:return e.finish(33);case 41:h({type:"response",reqId:n,data:o});case 42:case"end":return e.stop()}}),e,null,[[11,29,33,41],[15,21],[34,,36,40]])})));return function(t){return e.apply(this,arguments)}}(),k=!1;return r.on("socket-count",(function(e){e&&!k&&(k=!0,r.emit("ready")),!e&&k&&(k=!1,r.emit("pause"))})),Object.defineProperty(l(r),"ready",{get:function(){return k}}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t)}(t,e),t}(n.EventEmitter)},function(e,t,r){"use strict";r(1),r(9),r(3),r(4);var n=r(10),o=r.n(n),u=r(0),c=r(12),i=(r(22),r(6),r(24),r(39),r(16),r(19)),a=r.n(i),s={request:"R",response:"r",error:"e",ping:"P",pong:"p",connect:"C",connected:"c",disconnected:"d"},f={};Object.keys(s).map((function(e){return f[s[e]]=e}));var p=function(e){var t=e.type,r=e.name,n=e.reqId,o=e.data;return a.a.encode({t:s[t],n:r,r:n,d:o})},l=function(e){var t=a.a.decode(e);return{type:f[t.t],name:t.n,reqId:t.r,data:t.d}},d=r(2);function y(e,t,r,n,o,u,c){try{var i=e[u](c),a=i.value}catch(e){return void r(e)}i.done?t(a):Promise.resolve(a).then(n,o)}function m(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var u=e.apply(t,r);function c(e){y(u,n,o,c,i,"next",e)}function i(e){y(u,n,o,c,i,"throw",e)}c(void 0)}))}}var b=o()("zaplink:rpc-layer"),v=p,h=l,x=Symbol("connect"),w=function(){var e=m(regeneratorRuntime.mark((function e(t){var r,n,o,i,a,s,f,p,l,y=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=y.length>1&&void 0!==y[1]?y[1]:{},n=Object(d.a)(r),(o=new u.EventEmitter).peerId=r.peerId||null,o.disconnected=!1,i=function(e){if(1===t.readyState)return t.send(v(e))},o.send=i,a=n.createRequest(r.timeout,x),t.on("message",function(){var e=m(regeneratorRuntime.mark((function e(r){var u,p,l,d;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("request"!==(u=h(r)).type){e.next=3;break}return e.abrupt("return",s(u));case 3:if("response"!==u.type){e.next=5;break}return e.abrupt("return",s(u));case 5:if("error"!==u.type){e.next=7;break}return e.abrupt("return",s(u));case 7:if("ping"!==u.type){e.next=9;break}return e.abrupt("return",i({type:"pong",reqId:u.reqId}));case 9:if("pong"!==u.type){e.next=11;break}return e.abrupt("return",n.handleResolve(u.reqId));case 11:if("connected"!==u.type){e.next=13;break}return e.abrupt("return",n.handleResolve(a.reqId));case 13:if("disconnected"!==u.type){e.next=16;break}try{t.close()}catch(e){}return e.abrupt("return",f());case 16:"connect"===u.type&&(p=u.data||{},l=p.id,d=p.secret,c.a.verify(l,d)?(o.peerId=l,i({type:"connected"}),n.handleResolve(a.reqId)):i({type:"disconnected"}));case 17:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),s=function(){var e=m(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o.emit("message",t);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),f=function(){n.handleResolve(a.reqId),o.disconnected||(o.disconnected=!0,o.emit("disconnect"))},r.peerId&&i({type:"connect",data:{id:r.peerId,secret:r.peerSecret}}),p=function(){b("disconnecting socket");try{i({type:"disconnect"}),t.close()}catch(e){}f()},o.disconnect=p,t.on("close",p),l=function(){var e=m(regeneratorRuntime.mark((function e(){var t,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!o.disconnected){e.next=2;break}return e.abrupt("return");case 2:setTimeout(l,1e3),t=n.createRequest(r.timeout),u=t.reqId,c=t.promise,i({type:"ping",reqId:u}),c.catch((function(){return p()}));case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e.next=18,a.promise.catch((function(){f()}));case 18:return l(),e.abrupt("return",o);case 20:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();t.a=w},function(e,t){e.exports=require("core-js/modules/es6.object.define-property")},function(e,t){e.exports=require("core-js/modules/es6.array.map")},function(e,t){e.exports=require("core-js/modules/es6.regexp.to-string")},function(e,t){e.exports=require("core-js/modules/es6.date.to-string")},function(e,t){e.exports=require("msgpack-lite")},function(e,t){e.exports=require("core-js/modules/es6.array.is-array")},function(e,t){e.exports=require("core-js/modules/es6.number.constructor")},function(e,t){e.exports=require("core-js/modules/es6.function.name")},function(e,t){e.exports=require("core-js/modules/es6.array.index-of")},function(e,t){e.exports=require("core-js/modules/es6.array.iterator")},function(e,t){e.exports=require("create-hmac")},function(e,t){e.exports=require("scmp")},function(e,t){e.exports=require("blob-to-buffer")},function(e,t){e.exports=require("ws")},function(e,t,r){e.exports=r(30)},function(e,t,r){var n=r(41).default,o=r(40).default;e.exports={Client:n,Server:o}},function(e,t){e.exports=require("core-js/modules/es6.array.fill")},function(e,t){e.exports=require("core-js/modules/es6.regexp.split")},function(e,t){e.exports=require("core-js/modules/es6.typed.uint8-array")},function(e,t){e.exports=require("core-js/modules/es6.array.filter")},function(e,t){e.exports=require("core-js/modules/es6.string.iterator")},function(e,t){e.exports=require("core-js/modules/es6.map")},function(e,t){e.exports=require("core-js/modules/es6.function.bind")},function(e,t){e.exports=require("core-js/modules/es6.reflect.construct")},function(e,t){e.exports=require("core-js/modules/es6.object.keys")},function(e,t,r){"use strict";r.r(t),r.d(t,"default",(function(){return y}));r(3),r(4),r(1),r(7),r(8),r(17),r(18),r(9);var n=r(0),o=r.n(n),u=r(14),c=r(13);function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t,r,n,o,u,c){try{var i=e[u](c),a=i.value}catch(e){return void r(e)}i.done?t(a):Promise.resolve(a).then(n,o)}function s(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var u=e.apply(t,r);function c(e){a(u,n,o,c,i,"next",e)}function i(e){a(u,n,o,c,i,"throw",e)}c(void 0)}))}}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){return!t||"object"!==i(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function d(e,t){return(d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var y=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};f(this,t),e=p(this,l(t).call(this));var n={};return e.addSocket=function(){var t=s(regeneratorRuntime.mark((function t(o){var i,a,s,f;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Object(u.a)(o,r);case 2:if(!(i=t.sent).disconnected){t.next=5;break}return t.abrupt("return");case 5:a=i.peerId.toString("base64"),(s=!n[a])&&(n[a]=new c.a({peerId:i.peerId,peerKey:a,timeout:r.timeout,retryCount:r.retryCount})),(f=n[a]).addSocket(i),s&&(f.on("disconnect",(function(){e.emit("disconnect",f),delete n[a]})),e.emit("connect",f));case 11:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t)}(t,e),t}(o.a)},function(e,t,r){"use strict";r.r(t),r.d(t,"default",(function(){return _}));r(3),r(4),r(6),r(20),r(1),r(7),r(8),r(15),r(31),r(16),r(9),r(21),r(17),r(18);var n=r(10),o=r.n(n),u=r(0),c=r(11),i=r.n(c),a=r(12),s=r(27),f=r.n(s),p=r(28),l=r.n(p),d=global.WebSocket||null,y=function(e){return d?function(e){return new Promise((function(t,r){var n=new u.EventEmitter,o=new d(e);o.onmessage=function(e){return f()(e.data,(function(e,t){if(e)throw e;n.emit("message",t)}))},n.send=function(e){return o.send(e)},n.close=function(){return o.close()},Object.defineProperty(n,"readyState",{get:function(){return o.readyState}}),o.onopen=function(){return t(n)},o.onerror=function(e){return r(e)}}))}(e):new Promise((function(t,r){var n=new l.a(e);n.on("open",(function(){return t(n)})),n.on("error",(function(e){return r(e)}))}))},m=r(13),b=r(14);function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var c,i=e[Symbol.iterator]();!(n=(c=i.next()).done)&&(r.push(c.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function x(e,t,r,n,o,u,c){try{var i=e[u](c),a=i.value}catch(e){return void r(e)}i.done?t(a):Promise.resolve(a).then(n,o)}function w(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var u=e.apply(t,r);function c(e){x(u,n,o,c,i,"next",e)}function i(e){x(u,n,o,c,i,"throw",e)}c(void 0)}))}}function g(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function j(e,t){return!t||"object"!==v(t)&&"function"!=typeof t?q(e):t}function k(e){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function q(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function S(e,t){return(S=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var O=o()("zaplink:client"),_=function(e){function t(e){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};g(this,t),r=j(this,k(t).call(this));var o=a.a.create({useLocalSecret:!0}),u=o.id,c=o.secret;r.peerId=u,r.peerKey=u.toString("base64");var s=new m.a({peerId:u,peerKey:r.peerKey,timeout:n.timeout,retryCount:n.retryCount});r.peerKey=s.key,O("Client created with key %s",r.peerKey),r.concurrency=Number(n.concurrency)||8;var f=0,p=function(){var t=w(regeneratorRuntime.mark((function t(){var r,o,a,p,d;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return f++,t.next=3,y(e)[i.a];case 3:if(r=t.sent,o=h(r,2),a=o[0],p=o[1],!a){t.next=9;break}return t.abrupt("return",setTimeout(l,n.timeout||1e3));case 9:return t.next=11,Object(b.a)(p,{peerId:u,peerSecret:c,timeout:n.timeout});case 11:if(!(d=t.sent).disconnected){t.next=14;break}return t.abrupt("return",l());case 14:d.once("disconnect",l),s.addSocket(d);case 16:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),l=function(){f--,d()},d=function(){var e=r.concurrency,t=s.socketCount()+f,n=Math.max(e-t,0);O("Creating %d sockets (client %s)",n,r.peerKey),new Array(n).fill().map((function(){return p()}))};s.on("socket-lost",d),d();var v=!1;return s.on("socket-count",(function(e){r.emit("socket-count",e),O("concurrent sockets: %d (client %s)",e,r.peerKey),e&&!v&&(v=!0,r.emit("ready"),O("connection ready (client %s)",r.peerKey)),!e&&v&&(v=!1,r.emit("pause"),O("connection paused (client %s)",r.peerKey))})),r.addHandler=s.addHandler,r.removeHandler=s.removeHandler,r.send=s.send,r.disconnect=function(){r.concurrency=0,s.disconnect()},r.close=r.disconnect,Object.defineProperty(q(r),"ready",{get:function(){return v}}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&S(e,t)}(t,e),t}(u.EventEmitter)}])}));