UNPKG

@liascript/exporter

Version:
1 lines 8.96 kB
!function(){function e(e,n,t,o){Object.defineProperty(e,n,{get:t,set:o,enumerable:!0,configurable:!0})}var n=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;n.register("lCGwp",(function(t,o){e(t.exports,"Sync",(function(){return m}));var r=n("f1evb"),i=n("hnmIs"),s=n("9Klpk"),c=n("3bWnf"),a=n("eT7f3"),u=n("9WzNc"),l=n("div3d"),d=n("kb0qF"),f=n("bgoEC"),p=n("bWNdT"),h=n("32Euv"),g=n("auvHb"),b=n("cT1vB"),v=n("733OA"),y={nostr:null,mqtt:null,torrent:null,ipfs:null},m=function(e){"use strict";(0,d.default)(o,e);var t=(0,p.default)(o);function o(e,n,i,c,u){var l,d=arguments.length>5&&void 0!==arguments[5]&&arguments[5],f=!(arguments.length>6&&void 0!==arguments[6])||arguments[6];return(0,s.default)(this,o),l=t.call(this,n,i,c,u,d,f),(0,a.default)((0,r.default)(l),"syncFallbackTimer",null),l.backend=e,l}return(0,c.default)(o,[{key:"destroy",value:function(){var e;null!==this.syncFallbackTimer&&(clearTimeout(this.syncFallbackTimer),this.syncFallbackTimer=null),(0,u.default)((0,l.default)(o.prototype),"destroy",this).call(this),null===(e=this.provider)||void 0===e||e.disconnect()}},{key:"connect",value:function(e){var t=this,r=this;return(0,i.default)((function(){var i;return(0,h.__generator)(this,(function(s){if((0,u.default)((0,l.default)(o.prototype),"connect",t).call(r,e),y[r.backend])return r.init(!0),[2];switch(i=function(e){e.then((function(e){y[r.backend]=e.joinRoom,r.init(!0)})).catch((function(e){return r.init(!1,e.message)}))},r.backend){case"nostr":i(n("5ZdQa"));break;case"mqtt":i(n("8G6Vu"));break;case"torrent":i(n("kEbLv"));break;case"ipfs":i(n("gVJuk"))}return[2]}))}))()}},{key:"init",value:function(e,n){var t=this,o=this.uniqueID();if(e&&o){var r=JSON.parse("null");this.transport=new(0,b.TrysteroTransport)((0,f.default)({joinRoom:y[this.backend],appId:"liascript",password:this.password},r?{rtcConfig:r}:{})),this.provider=new(0,v.GenericProvider)(this.db.doc,this.transport),this.db.setAwareness(this.provider.awareness);var i=!1,s=function(){i||(i=!0,null!==t.syncFallbackTimer&&(clearTimeout(t.syncFallbackTimer),t.syncFallbackTimer=null),t.sendConnect())};this.provider.on("synced",(function(e){console.log("Trystero: document synchronized",e.synced),s()})),this.provider.on("status",(function(e){var n=e.state;console.log("Trystero status: ".concat(n)),"connected"===n?t.syncFallbackTimer=setTimeout((function(){console.log("Trystero: sync fallback, proceeding as first peer"),s()}),2e3):"disconnected"===n&&console.warn("Trystero: disconnected")})),this.provider.pubsub.subscribe("*",(function(e,n){var o,r;null===(r=(o=t).onReceive)||void 0===r||r.call(o,n,e)})),this.provider.connect({room:o})}else{var c=this.backend+" unknown error";n&&(c="Could not load resource: "+n),this.sendDisconnectError(c)}}},{key:"pubsubSend",value:function(e,n){var t;this.provider&&(this.provider.pubsub.publish(e,n),this.replyOnReceive&&(null===(t=this.onReceive)||void 0===t||t.call(this,e,n)))}}]),o}(g.Sync)})),n.register("cT1vB",(function(t,o){e(t.exports,"TrysteroTransport",(function(){return l}));var r=n("hnmIs"),i=n("9Klpk"),s=n("3bWnf"),c=n("bgoEC"),a=n("5ENmm"),u=n("32Euv"),l=function(){"use strict";function e(n){(0,i.default)(this,e),this._connected=!1,this._room="",this.room=null,this.sendUpdate=null,this.peers=new Set,this.options=(0,c.default)({debug:!1},n)}return(0,s.default)(e,[{key:"log",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info";if(this.options.debug){var t="[TrysteroTransport]";switch(n){case"error":console.error(t,e);break;case"warn":console.warn(t,e);break;default:console.log(t,e)}}}},{key:"isConnected",get:function(){return this._connected}},{key:"connect",value:function(e){var n=this;return(0,r.default)((function(){var t,o,r,i,s;return(0,u.__generator)(this,(function(c){if(n._connected&&(n.log("Already connected, disconnecting first..."),n.disconnect()),!(t=e.room))throw new Error("Room ID is required");return n._room=t,n.log("Connecting to room: ".concat(t)),o={appId:n.options.appId},n.options.password&&(o.password=n.options.password),n.options.relayUrls&&(o.relayUrls=n.options.relayUrls),n.options.relayRedundancy&&(o.relayRedundancy=n.options.relayRedundancy),n.options.rtcConfig&&(o.rtcConfig=n.options.rtcConfig),n.options.turnConfig&&(o.turnConfig=n.options.turnConfig),n.options.rtcPolyfill&&(o.rtcPolyfill=n.options.rtcPolyfill),n.options.supabaseKey&&(o.supabaseKey=n.options.supabaseKey),n.options.firebaseApp&&(o.firebaseApp=n.options.firebaseApp),n.options.rootPath&&(o.rootPath=n.options.rootPath),void 0!==n.options.manualRelayReconnection&&(o.manualRelayReconnection=n.options.manualRelayReconnection),n.room=n.options.joinRoom(o,t,(function(e){n.log("Join error: ".concat(e.error),"error"),n.onJoinErrorCallback&&n.onJoinErrorCallback(e)})),r=(0,a.default)(n.room.makeAction("yjs-update"),2),i=r[0],s=r[1],n.sendUpdate=i,s((function(e,t){n.log("Received update from ".concat(t," (").concat(e.byteLength," bytes)")),n._callback&&n._callback(new Uint8Array(e))})),n.room.onPeerJoin((function(e){n.peers.add(e),n.log("Peer joined: ".concat(e," (").concat(n.peers.size," total)"))})),n.room.onPeerLeave((function(e){n.peers.delete(e),n.log("Peer left: ".concat(e," (").concat(n.peers.size," remaining)"))})),n._connected=!0,n.log("✅ Connected to room: ".concat(t)),[2]}))}))()}},{key:"disconnect",value:function(){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"))}},{key:"send",value:function(e){var n=this;return(0,r.default)((function(){return(0,u.__generator)(this,(function(t){switch(t.label){case 0:return n._connected&&n.sendUpdate?(n.log("Sending update (".concat(e.byteLength," bytes) to ").concat(n.peers.size," peers")),[4,n.sendUpdate(e,null)]):(n.log("⚠️ Not connected, cannot send","warn"),[2]);case 1:return t.sent(),[2]}}))}))()}},{key:"onMessage",value:function(e){var n=this;return this._callback=e,this.log("Message callback registered"),function(){n._callback=void 0,n.log("Message callback unregistered")}}},{key:"onJoinError",value:function(e){this.onJoinErrorCallback=e}},{key:"getPeers",value:function(){return new Set(this.peers)}},{key:"ping",value:function(e){var n=this;return(0,r.default)((function(){return(0,u.__generator)(this,(function(t){switch(t.label){case 0:if(!n.room)throw new Error("Not connected to a room");return[4,n.room.ping(e)];case 1:return[2,t.sent()]}}))}))()}}]),e}()})),n.register("5ZdQa",(function(e,t){e.exports=n("3OMJO")(n("5B9gS").getBundleURL("bFNS0")+n("b9xd4").resolve("6gAOH")).then((function(){return n("1UDrq")}))})),n.register("8G6Vu",(function(e,t){e.exports=n("3OMJO")(n("5B9gS").getBundleURL("bFNS0")+n("b9xd4").resolve("7U1md")).then((function(){return n("aB40U")}))})),n.register("kEbLv",(function(e,t){e.exports=n("3OMJO")(n("5B9gS").getBundleURL("bFNS0")+n("b9xd4").resolve("jnhCd")).then((function(){return n("E0fFs")}))})),n.register("gVJuk",(function(e,t){e.exports=n("3OMJO")(n("5B9gS").getBundleURL("bFNS0")+n("b9xd4").resolve("6eocP")).then((function(){return n("eB8Zt")}))})),n.register("84cK9",(function(e,n){var t,o,r=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(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i}catch(e){t=i}try{o="function"==typeof clearTimeout?clearTimeout:s}catch(e){o=s}}();var a,u=[],l=!1,d=-1;function f(){l&&a&&(l=!1,a.length?u=a.concat(u):d=-1,u.length&&p())}function p(){if(!l){var e=c(f);l=!0;for(var n=u.length;n;){for(a=u,u=[];++d<n;)a&&a[d].run();d=-1,n=u.length}a=null,l=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===s||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{return o(e)}catch(n){try{return o.call(null,e)}catch(n){return o.call(this,e)}}}(e)}}function h(e,n){this.fun=e,this.array=n}function g(){}r.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)n[t-1]=arguments[t];u.push(new h(e,n)),1!==u.length||l||c(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=g,r.addListener=g,r.once=g,r.off=g,r.removeListener=g,r.removeAllListeners=g,r.emit=g,r.prependListener=g,r.prependOnceListener=g,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}}))}();