UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 4.76 kB
!function(){function e(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}var t=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;t.register("aYnRb",(function(n,r){e(n.exports,"Sync",(function(){return v}));var i=t("f1evb"),u=t("hnmIs"),o=t("9Klpk"),s=t("3bWnf"),a=t("eT7f3"),c=t("9WzNc"),l=t("div3d"),f=t("kb0qF"),b=t("5ENmm"),d=t("bWNdT"),h=t("32Euv"),p=t("auvHb"),y=t("frnPj"),v=function(e){"use strict";(0,f.default)(n,e);var t=(0,d.default)(n);function n(){var e;return(0,o.default)(this,n),e=t.apply(this,arguments),(0,a.default)((0,i.default)(e),"channel",""),e}return(0,s.default)(n,[{key:"destroy",value:function(){this.pubnub&&(this.pubnub.unsubscribeAll(),this.pubnub.stop()),(0,c.default)((0,l.default)(n.prototype),"destroy",this).call(this)}},{key:"connect",value:function(e){var t=this,r=this;return(0,u.default)((function(){return(0,h.__generator)(this,(function(i){return(0,c.default)((0,l.default)(n.prototype),"connect",t).call(r,e),r.publishKey=e.config.publishKey,r.subscribeKey=e.config.subscribeKey,window.PubNub?r.init(!0):r.load(["//cdn.pubnub.com/sdk/javascript/pubnub.4.33.1.min.js"],r),[2]}))}))()}},{key:"init",value:function(e,t){if(!this.publishKey||!this.subscribeKey)return this.sendDisconnectError("You have to provide a valid pair of keys");var 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});var r=this;this.pubnub.addListener({status:function(e){y.default.info("PUBNUB status:",e),"PNConnectedCategory"===e.category?r.sendConnect():"PNBadRequestCategory"===e.category&&r.sendDisconnectError(e.errorData.message)},message:function(e){if(e.publisher!==r.token){var t=(0,b.default)(e.message,3),n=t[0],i=t[1],u=t[2];n?u==r.db.timestamp?r.applyUpdate(p.base64_to_unit8(i)):u>r.db.timestamp?r.broadcast(!0,r.db.encode()):(r.db.timestamp=u,r.applyUpdate(p.base64_to_unit8(i),!0)):r.pubsubReceive(p.base64_to_unit8(i))}},presence:function(e){"leave"===e.action&&r.db.removePeer(e.uuid)}})}}},{key:"broadcast",value:function(e,t){this.pubnub&&this.pubnub.publish({channel:this.channel,message:[e,p.uint8_to_base64(t),this.db.timestamp],storeInHistory:!1},(function(e,t){}))}}]),n}(p.Sync)})),t.register("9WzNc",(function(n,r){e(n.exports,"default",(function(){return o}));var i=t("jwduU");function u(e,t,n){return u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=(0,i.default)(e,t);if(r){var u=Object.getOwnPropertyDescriptor(r,t);return u.get?u.get.call(n||e):u.value}},u(e,t,n)}function o(e,t,n){return u(e,t,n)}})),t.register("jwduU",(function(n,r){e(n.exports,"default",(function(){return u}));var i=t("div3d");function u(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=(0,i.default)(e)););return e}})),t.register("84cK9",(function(e,t){var n,r,i=e.exports={};function u(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function s(e){if(n===setTimeout)return setTimeout(e,0);if((n===u||!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:u}catch(e){n=u}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var a,c=[],l=!1,f=-1;function b(){l&&a&&(l=!1,a.length?c=a.concat(c):f=-1,c.length&&d())}function d(){if(!l){var e=s(b);l=!0;for(var t=c.length;t;){for(a=c,c=[];++f<t;)a&&a[f].run();f=-1,t=c.length}a=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===o||!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 h(e,t){this.fun=e,this.array=t}function p(){}i.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];c.push(new h(e,t)),1!==c.length||l||s(d)},h.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=p,i.addListener=p,i.once=p,i.off=p,i.removeListener=p,i.removeAllListeners=p,i.emit=p,i.prependListener=p,i.prependOnceListener=p,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}))}();