UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 5.46 kB
!function(){function t(t,e,n,r){Object.defineProperty(t,e,{get:n,set:r,enumerable:!0,configurable:!0})}var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("lCGwp",(function(n,r){t(n.exports,"Sync",(function(){return b}));var i=e("hnmIs"),o=e("9Klpk"),u=e("3bWnf"),c=e("9WzNc"),s=e("div3d"),a=e("kb0qF"),l=e("5ENmm"),f=e("bWNdT"),d=e("32Euv"),h=e("auvHb"),p={nostr:null,mqtt:null,torrent:null},b=function(t){"use strict";(0,a.default)(r,t);var n=(0,f.default)(r);function r(t,e,i,u,c){var s,a=arguments.length>5&&void 0!==arguments[5]&&arguments[5],l=!(arguments.length>6&&void 0!==arguments[6])||arguments[6];return(0,o.default)(this,r),(s=n.call(this,e,i,u,c,a,l)).backend=t,s}return(0,u.default)(r,[{key:"destroy",value:function(){this.connection&&this.connection.leave(),(0,c.default)((0,s.default)(r.prototype),"destroy",this).call(this)}},{key:"connect",value:function(t){var n=this,o=this;return(0,i.default)((function(){return(0,d.__generator)(this,(function(i){if((0,c.default)((0,s.default)(r.prototype),"connect",n).call(o,t),p[o.backend])return o.init(!0),[2];switch(o.backend){case"nostr":e("5ZdQa").then((function(t){p.nostr=t.joinRoom,o.init(!0)})).catch((function(t){o.init(!1,t.message)}));break;case"mqtt":e("8G6Vu").then((function(t){p.mqtt=t.joinRoom,o.init(!0)})).catch((function(t){o.init(!1,t.message)}));break;case"torrent":e("kEbLv").then((function(t){p.torrent=t.joinRoom,o.init(!0)})).catch((function(t){o.init(!1,t.message)}))}return[2]}))}))()}},{key:"init",value:function(t,e){var n=this.uniqueID();if(t&&n){var r={appId:"liascript"};this.password&&(r.password=this.password);var i=JSON.parse("null");i&&(r.rtcConfig=i),this.connection=p[this.backend](r,n),this.connection.onPeerJoin((function(t){return console.log("".concat(t," joined"))})),this.connection.onPeerLeave((function(t){return console.log("".concat(t," left"))}));var o=(0,l.default)(this.connection.makeAction("message"),2),u=o[0],c=o[1];this.pub=u,this.sub=c;var s=this;this.sub((function(t,e){if(t)try{var n=(0,l.default)(t,3),r=n[0],i=n[1],o=n[2];if(r){if(null===i)return;o==s.db.timestamp?s.applyUpdate(h.base64_to_unit8(i)):o>s.db.timestamp?s.broadcast(!0,s.db.encode()):(s.db.timestamp=o,s.applyUpdate(h.base64_to_unit8(i),!0))}else s.pubsubReceive(h.base64_to_unit8(i))}catch(t){console.warn(s.backend,t.message)}})),this.sendConnect()}else{var a=this.backend+" unknown error";e&&(a="Could not load resource: "+e),this.sendDisconnectError(a)}}},{key:"broadcast",value:function(t,e){if(this.publish){var n=null==e?null:h.uint8_to_base64(e);this.pub([t,n,this.db.timestamp])}}}]),r}(h.Sync)})),e.register("9WzNc",(function(n,r){t(n.exports,"default",(function(){return u}));var i=e("jwduU");function o(t,e,n){return o="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=(0,i.default)(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n||t):o.value}},o(t,e,n)}function u(t,e,n){return o(t,e,n)}})),e.register("jwduU",(function(n,r){t(n.exports,"default",(function(){return o}));var i=e("div3d");function o(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=(0,i.default)(t)););return t}})),e.register("5ZdQa",(function(t,n){t.exports=e("3OMJO")(e("5B9gS").getBundleURL("bFNS0")+e("b9xd4").resolve("6gAOH")).then((function(){return e("1UDrq")}))})),e.register("8G6Vu",(function(t,n){t.exports=e("3OMJO")(e("5B9gS").getBundleURL("bFNS0")+e("b9xd4").resolve("7U1md")).then((function(){return e("aB40U")}))})),e.register("kEbLv",(function(t,n){t.exports=e("3OMJO")(e("5B9gS").getBundleURL("bFNS0")+e("b9xd4").resolve("jnhCd")).then((function(){return e("E0fFs")}))})),e.register("84cK9",(function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function c(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:u}catch(t){r=u}}();var s,a=[],l=!1,f=-1;function d(){l&&s&&(l=!1,s.length?a=s.concat(a):f=-1,a.length&&h())}function h(){if(!l){var t=c(d);l=!0;for(var e=a.length;e;){for(s=a,a=[];++f<e;)s&&s[f].run();f=-1,e=a.length}s=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===u||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function b(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];a.push(new p(t,e)),1!==a.length||l||c(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=b,i.addListener=b,i.once=b,i.off=b,i.removeListener=b,i.removeAllListeners=b,i.emit=b,i.prependListener=b,i.prependOnceListener=b,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}))}();