UNPKG

@liascript/exporter

Version:
1 lines 9.05 kB
!function(e,t,n,o,r){var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},i="function"==typeof s[o]&&s[o],c=i.cache||{},a="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function l(t,n){if(!c[t]){if(!e[t]){var r="function"==typeof s[o]&&s[o];if(!n&&r)return r(t,!0);if(i)return i(t,!0);if(a&&"string"==typeof t)return a(t);var d=new Error("Cannot find module '"+t+"'");throw d.code="MODULE_NOT_FOUND",d}h.resolve=function(n){var o=e[t][1][n];return null!=o?o:n},h.cache={};var u=c[t]=new l.Module(t);e[t][0].call(u.exports,h,u,u.exports,this)}return c[t].exports;function h(e){var t=h.resolve(e);return!1===t?{}:l(t)}}l.isParcelRequire=!0,l.Module=function(e){this.id=e,this.bundle=l,this.exports={}},l.modules=e,l.cache=c,l.parent=i,l.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(l,"root",{get:function(){return s[o]}}),s[o]=l;for(var d=0;d<t.length;d++)l(t[d])}({"6dvMz":[function(e,t,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(n),o.export(n,"Sync",(()=>a));var r=e("../Base/index"),s=e("../../../../node_modules/y-generic/dist/providers/trystero/index"),i=e("y-generic");const c={nostr:null,mqtt:null,torrent:null,ipfs:null};class a extends r.Sync{syncFallbackTimer=null;constructor(e,t,n,o,r,s=!1,i=!0){super(t,n,o,r,s,i),this.backend=e}destroy(){null!==this.syncFallbackTimer&&(clearTimeout(this.syncFallbackTimer),this.syncFallbackTimer=null),super.destroy(),this.provider?.disconnect()}async connect(t){if(super.connect(t),c[this.backend])return void this.init(!0);const n=e=>{e.then((e=>{c[this.backend]=e.joinRoom,this.init(!0)})).catch((e=>this.init(!1,e.message)))};switch(this.backend){case"nostr":n(e("700482134916955a"));break;case"mqtt":n(e("add5f98263416a08"));break;case"torrent":n(e("1252a34ff5e347dc"));break;case"ipfs":n(e("eacdf1cfd1800d24"))}}init(e,t){const n=this.uniqueID();if(e&&n){const e=JSON.parse("null");this.transport=new(0,s.TrysteroTransport)({joinRoom:c[this.backend],appId:"liascript",password:this.password,...e?{rtcConfig:e}:{}}),this.provider=new(0,i.GenericProvider)(this.db.doc,this.transport),this.db.setAwareness(this.provider.awareness);let t=!1;const o=()=>{t||(t=!0,null!==this.syncFallbackTimer&&(clearTimeout(this.syncFallbackTimer),this.syncFallbackTimer=null),this.sendConnect())};this.provider.on("synced",(e=>{console.log("Trystero: document synchronized",e.synced),o()})),this.provider.on("status",(e=>{const t=e.state;console.log(`Trystero status: ${t}`),"connected"===t?this.syncFallbackTimer=setTimeout((()=>{console.log("Trystero: sync fallback, proceeding as first peer"),o()}),2e3):"disconnected"===t&&console.warn("Trystero: disconnected")})),this.provider.pubsub.subscribe("*",((e,t)=>{this.onReceive?.(t,e)})),this.provider.connect({room:n})}else{let e=this.backend+" unknown error";t&&(e="Could not load resource: "+t),this.sendDisconnectError(e)}}pubsubSend(e,t){this.provider&&(this.provider.pubsub.publish(e,t),this.replyOnReceive&&this.onReceive?.(e,t))}}},{"../Base/index":"2cTju","../../../../node_modules/y-generic/dist/providers/trystero/index":"aRtYt","y-generic":"3M9RT","700482134916955a":"8YwXP",add5f98263416a08:"flwd2","1252a34ff5e347dc":"j6lII",eacdf1cfd1800d24:"8mRBb","@parcel/transformer-js/src/esmodule-helpers.js":"XTfsy"}],aRtYt:[function(e,t,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(n),o.export(n,"TrysteroTransport",(()=>r));class r{constructor(e){this._connected=!1,this._room="",this.room=null,this.sendUpdate=null,this.peers=new Set,this.options={debug:!1,...e}}log(e,t="info"){if(this.options.debug){const n="[TrysteroTransport]";switch(t){case"error":console.error(n,e);break;case"warn":console.warn(n,e);break;default:console.log(n,e)}}}get isConnected(){return this._connected}async connect(e){this._connected&&(this.log("Already connected, disconnecting first..."),this.disconnect());const t=e.room;if(!t)throw new Error("Room ID is required");this._room=t,this.log(`Connecting to room: ${t}`);const n={appId:this.options.appId};this.options.password&&(n.password=this.options.password),this.options.relayUrls&&(n.relayUrls=this.options.relayUrls),this.options.relayRedundancy&&(n.relayRedundancy=this.options.relayRedundancy),this.options.rtcConfig&&(n.rtcConfig=this.options.rtcConfig),this.options.turnConfig&&(n.turnConfig=this.options.turnConfig),this.options.rtcPolyfill&&(n.rtcPolyfill=this.options.rtcPolyfill),this.options.supabaseKey&&(n.supabaseKey=this.options.supabaseKey),this.options.firebaseApp&&(n.firebaseApp=this.options.firebaseApp),this.options.rootPath&&(n.rootPath=this.options.rootPath),void 0!==this.options.manualRelayReconnection&&(n.manualRelayReconnection=this.options.manualRelayReconnection),this.room=this.options.joinRoom(n,t,(e=>{this.log(`Join error: ${e.error}`,"error"),this.onJoinErrorCallback&&this.onJoinErrorCallback(e)}));const[o,r]=this.room.makeAction("yjs-update");this.sendUpdate=o,r(((e,t)=>{this.log(`Received update from ${t} (${e.byteLength} bytes)`),this._callback&&this._callback(new Uint8Array(e))})),this.room.onPeerJoin((e=>{this.peers.add(e),this.log(`Peer joined: ${e} (${this.peers.size} total)`)})),this.room.onPeerLeave((e=>{this.peers.delete(e),this.log(`Peer left: ${e} (${this.peers.size} remaining)`)})),this._connected=!0,this.log(`✅ Connected to room: ${t}`)}disconnect(){this._connected&&(this.log("Disconnecting..."),this.room&&(this.room.leave(),this.room=null),this.sendUpdate=null,this._callback=void 0,this._connected=!1,this.peers.clear(),this.log("✅ Disconnected"))}async send(e){this._connected&&this.sendUpdate?(this.log(`Sending update (${e.byteLength} bytes) to ${this.peers.size} peers`),await this.sendUpdate(e,null)):this.log("⚠️ Not connected, cannot send","warn")}onMessage(e){return this._callback=e,this.log("Message callback registered"),()=>{this._callback=void 0,this.log("Message callback unregistered")}}onJoinError(e){this.onJoinErrorCallback=e}getPeers(){return new Set(this.peers)}async ping(e){if(!this.room)throw new Error("Not connected to a room");return await this.room.ping(e)}}},{"@parcel/transformer-js/src/esmodule-helpers.js":"XTfsy"}],"8YwXP":[function(e,t,n){t.exports=e("36a774a7f994d681")(e("db60da5ac0754d7").getBundleURL("dfDj8")+e("4f5cb48773fc5b10").resolve("llW5T")).then((()=>t.bundle.root("bQe85")))},{"36a774a7f994d681":"dBBqP",db60da5ac0754d7:"gEpYW","4f5cb48773fc5b10":"2ncQC"}],flwd2:[function(e,t,n){t.exports=e("4efca8dd431d3cf0")(e("c9029ef3fd2b6706").getBundleURL("dfDj8")+e("72538ba101415b2c").resolve("d7nlq")).then((()=>t.bundle.root("5IiuB")))},{"4efca8dd431d3cf0":"dBBqP",c9029ef3fd2b6706:"gEpYW","72538ba101415b2c":"2ncQC"}],j6lII:[function(e,t,n){t.exports=e("73b7fbbd5472d697")(e("ffda6f4dea05de4a").getBundleURL("dfDj8")+e("fa46c4185f8a443c").resolve("gINQj")).then((()=>t.bundle.root("biIhW")))},{"73b7fbbd5472d697":"dBBqP",ffda6f4dea05de4a:"gEpYW",fa46c4185f8a443c:"2ncQC"}],"8mRBb":[function(e,t,n){t.exports=e("38369b39f3dd71cf")(e("803a638febd9d174").getBundleURL("dfDj8")+e("60aacb078b79f8ab").resolve("ap0a8")).then((()=>t.bundle.root("aZqqK")))},{"38369b39f3dd71cf":"dBBqP","803a638febd9d174":"gEpYW","60aacb078b79f8ab":"2ncQC"}],fDdlt:[function(e,t,n){var o,r,s=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function c(){throw new Error("clearTimeout has not been defined")}function a(e){if(o===setTimeout)return setTimeout(e,0);if((o===i||!o)&&setTimeout)return o=setTimeout,setTimeout(e,0);try{return o(e,0)}catch(t){try{return o.call(null,e,0)}catch(t){return o.call(this,e,0)}}}!function(){try{o="function"==typeof setTimeout?setTimeout:i}catch(e){o=i}try{r="function"==typeof clearTimeout?clearTimeout:c}catch(e){r=c}}();var l,d=[],u=!1,h=-1;function f(){u&&l&&(u=!1,l.length?d=l.concat(d):h=-1,d.length&&p())}function p(){if(!u){var e=a(f);u=!0;for(var t=d.length;t;){for(l=d,d=[];++h<t;)l&&l[h].run();h=-1,t=d.length}l=null,u=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===c||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{return r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function b(e,t){this.fun=e,this.array=t}function y(){}s.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];d.push(new b(e,t)),1!==d.length||u||a(p)},b.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=y,s.addListener=y,s.once=y,s.off=y,s.removeListener=y,s.removeAllListeners=y,s.emit=y,s.prependListener=y,s.prependOnceListener=y,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},{}]},[],0,"parcelRequire55a5");