@liascript/exporter
Version:
A generic exporter for LiaScript
2 lines (1 loc) • 4.89 kB
JavaScript
function t(e,t,n,r){Object.defineProperty(e,t,{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("iyAFm",(function(n,r){t(n.exports,"Sync",(function(){return c}));var o=e("2Xs1f"),i=e("5Owdb"),s=e("2O3kG");class c extends i.Sync{destroy(){var e;this.trackersAnnounceURLs=[],null===(e=this.p2pt)||void 0===e||e.destroy(),super.destroy()}async connect(t){super.connect(t),this.trackersAnnounceURLs=t.config||[],window.P2PT?this.init(!0):(window.P2PT=await e("21t9Q"),this.load([s.Crypto.url],this))}init(e,t){if(0==this.trackersAnnounceURLs.length)return this.sendDisconnectError("You have to provide at least one WebTorrent tracker.");const n=this.uniqueID();if(e&&window.P2PT&&n){this.p2pt=new window.P2PT(this.trackersAnnounceURLs,n),s.Crypto.init(this.password);const e=this;this.p2pt.on("trackerconnect",((t,n)=>{console.log("Connected to tracker : "+t.announceUrl),console.log("Tracker stats : "+JSON.stringify(n)),e.is_connected||(e.is_connected=!0,e.sendConnect())})),this.p2pt.on("trackerwarning",((e,t)=>{console.log("Connected to tracker : ",e),console.log("Tracker stats : "+JSON.stringify(t))})),this.p2pt.on("peerconnect",(t=>{console.warn("Peer connected : "+t.id,t),e.peers[t.id]=t})),this.p2pt.on("peerclose",(t=>{console.warn("Peer disconnected : "+t);const n=e.tokens[t.id];n&&(e.db.removePeer(n),delete e.tokens[t.id]),delete e.peers[t.id]})),this.p2pt.on("msg",((t,n)=>{if(n)try{const[r,o,c,u]=s.Crypto.decode(n);r!=e.token&&(o?u==e.db.timestamp?e.applyUpdate(i.base64_to_unit8(c)):u>e.db.timestamp?e.broadcast(!0,e.db.encode()):(e.db.timestamp=u,e.applyUpdate(i.base64_to_unit8(c),!0)):e.pubsubReceive(i.base64_to_unit8(c)),e.tokens[t.id]||(e.tokens[t.id]=r))}catch(e){console.warn("P2PT",e.message)}})),this.p2pt.start()}else{let e="P2PT unknown error";t?e="Could not load resource: "+t:window.P2PT||(e="Could not load P2PT interface"),this.sendDisconnectError(e)}}broadcast(e,t){if(!this.p2pt)return;const n=null==t?null:i.uint8_to_base64(t),r=s.Crypto.encode([this.token,e,n,this.db.timestamp]);for(const e in this.peers)this.p2pt.send(this.peers[e],r)}constructor(...e){super(...e),(0,o.default)(this,"trackersAnnounceURLs",[]),(0,o.default)(this,"peers",{}),(0,o.default)(this,"tokens",{}),(0,o.default)(this,"is_connected",!1)}}})),e.register("2O3kG",(function(e,n){t(e.exports,"Crypto",(function(){return r}));const r={url:"https://cdn.jsdelivr.net/npm/simple-crypto-js@2.5.0/dist/SimpleCrypto.min.js",crypt:null,check:function(){return!!window.SimpleCrypto},init:function(e){try{"string"==typeof e&&e.length>0?this.crypt=new SimpleCrypto(e):this.crypt=null}catch(e){console.warn("Crypto: ",e),this.crypt=null}},encode:function(e){return this.crypt?this.crypt.encrypt(btoa(encodeURIComponent(JSON.stringify(e)))):JSON.stringify(e)},decode:function(e){return this.crypt?JSON.parse(decodeURIComponent(atob(this.crypt.decrypt(e)))):JSON.parse(e)}}})),e.register("21t9Q",(function(t,n){t.exports=e("ebDiK")(e("ey3S0").getBundleURL("bPyXH")+e("abmWv").resolve("4lXxH")).then((()=>e("9P9uR")))})),e.register("jhEmn",(function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var u,a=[],l=!1,p=-1;function d(){l&&u&&(l=!1,u.length?a=u.concat(a):p=-1,a.length&&h())}function h(){if(!l){var e=c(d);l=!0;for(var t=a.length;t;){for(u=a,a=[];++p<t;)u&&u[p].run();p=-1,t=a.length}u=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function y(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];a.push(new f(e,t)),1!==a.length||l||c(h)},f.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}}));