UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 3.6 kB
var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("hj5SX",(function(t,n){var i,r;i=t.exports,r=function(){return c},Object.defineProperty(i,"Sync",{get:r,set:undefined,enumerable:!0,configurable:!0});var s=e("2Xs1f"),u=e("5Owdb"),o=e("4ekS1");class c extends u.Sync{destroy(){this.pubnub&&(this.pubnub.unsubscribeAll(),this.pubnub.stop()),super.destroy()}async connect(e){super.connect(e),this.publishKey=e.config.publishKey,this.subscribeKey=e.config.subscribeKey,window.PubNub?this.init(!0):this.load(["//cdn.pubnub.com/sdk/javascript/pubnub.4.33.1.min.js"],this)}init(e,t){if(!this.publishKey||!this.subscribeKey)return this.sendDisconnectError("You have to provide a valid pair of keys");const n=this.uniqueID();if(e&&window.PubNub&&n){this.channel=btoa(n),this.pubnub=new PubNub({publishKey:this.publishKey,subscribeKey:this.subscribeKey,uuid:this.token,heartbeatInterval:30,cipherKey:this.password}),this.pubnub.subscribe({channels:[this.channel],withPresence:!0,restore:!1});let e=this;this.pubnub.addListener({status:function(t){o.default.info("PUBNUB status:",t),"PNConnectedCategory"===t.category?e.sendConnect():"PNBadRequestCategory"===t.category&&e.sendDisconnectError(t.errorData.message)},message:function(t){if(t.publisher!==e.token){const[n,i,r]=t.message;n?r==e.db.timestamp?e.applyUpdate(u.base64_to_unit8(i)):r>e.db.timestamp?e.broadcast(!0,e.db.encode()):(e.db.timestamp=r,e.applyUpdate(u.base64_to_unit8(i),!0)):e.pubsubReceive(u.base64_to_unit8(i))}},presence:function(t){"leave"===t.action&&e.db.removePeer(t.uuid)}})}}broadcast(e,t){this.pubnub&&this.pubnub.publish({channel:this.channel,message:[e,u.uint8_to_base64(t),this.db.timestamp],storeInHistory:!1},(function(e,t){}))}constructor(...e){super(...e),(0,s.default)(this,"channel","")}}})),e.register("jhEmn",(function(e,t){var n,i,r=e.exports={};function s(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function o(e){if(n===setTimeout)return setTimeout(e,0);if((n===s||!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:s}catch(e){n=s}try{i="function"==typeof clearTimeout?clearTimeout:u}catch(e){i=u}}();var c,a=[],b=!1,h=-1;function l(){b&&c&&(b=!1,c.length?a=c.concat(a):h=-1,a.length&&f())}function f(){if(!b){var e=o(l);b=!0;for(var t=a.length;t;){for(c=a,a=[];++h<t;)c&&c[h].run();h=-1,t=a.length}c=null,b=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===u||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function d(){}r.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 p(e,t)),1!==a.length||b||o(f)},p.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=d,r.addListener=d,r.once=d,r.off=d,r.removeListener=d,r.removeAllListeners=d,r.emit=d,r.prependListener=d,r.prependOnceListener=d,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}}));