1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="6266068d-d2f9-0fec-f2c8-6a6967196797")}catch(e){}}(); 2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,271734,996479,300433,407036,460069,e=>{"use strict";function t(e,t,s,i){return new(s||(s=Promise))(function(r,n){function o(e){try{h(i.next(e))}catch(e){n(e)}}function a(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?r(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(o,a)}h((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var s,i,r,n,o,a,h,l,c,u,d,_,p,f,b,g,m,v,S,y,T={exports:{}},P=(s=function(){if(d)return T.exports;d=1;var e,t="object"==typeof Reflect?Reflect:null,s=t&&"function"==typeof t.apply?t.apply:function(e,t,s){return Function.prototype.apply.call(e,t,s)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function r(){r.init.call(this)}T.exports=r,T.exports.once=function(e,t){return new Promise(function(s,i){var r,n,o;function a(s){e.removeListener(t,h),i(s)}function h(){"function"==typeof e.removeListener&&e.removeListener("error",a),s([].slice.call(arguments))}f(e,t,h,{once:!0}),"error"!==t&&(r=e,n=a,o={once:!0},"function"==typeof r.on&&f(r,"error",n,o))})},r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var n=10;function o(e){if("function"!=typeof e)throw TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function a(e){return void 0===e._maxListeners?r.defaultMaxListeners:e._maxListeners}function h(e,t,s,i){if(o(s),void 0===(n=e._events)?(n=e._events=Object.create(null),e._eventsCount=0):(void 0!==n.newListener&&(e.emit("newListener",t,s.listener?s.listener:s),n=e._events),h=n[t]),void 0===h)h=n[t]=s,++e._eventsCount;else if("function"==typeof h?h=n[t]=i?[s,h]:[h,s]:i?h.unshift(s):h.push(s),(r=a(e))>0&&h.length>r&&!h.warned){h.warned=!0;var r,n,h,l=Error("Possible EventEmitter memory leak detected. "+h.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=h.length,console&&console.warn&&console.warn(l)}return e}function l(){if(!this.fired)return(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0==arguments.length)?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function c(e,t,s){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:s},r=l.bind(i);return r.listener=s,i.wrapFn=r,r}function u(e,t,s){var i=e._events;if(void 0===i)return[];var r=i[t];return void 0===r?[]:"function"==typeof r?s?[r.listener||r]:[r]:s?function(e){for(var t=Array(e.length),s=0;s<t.length;++s)t[s]=e[s].listener||e[s];return t}(r):p(r,r.length)}function _(e){var t=this._events;if(void 0!==t){var s=t[e];if("function"==typeof s)return 1;if(void 0!==s)return s.length}return 0}function p(e,t){for(var s=Array(t),i=0;i<t;++i)s[i]=e[i];return s}function f(e,t,s,i){if("function"==typeof e.on)i.once?e.once(t,s):e.on(t,s);else if("function"==typeof e.addEventListener)e.addEventListener(t,function r(n){i.once&&e.removeEventListener(t,r),s(n)});else throw TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}return Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return n},set:function(e){if("number"!=typeof e||e<0||i(e))throw RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");n=e}}),r.init=function(){(void 0===this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},r.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},r.prototype.getMaxListeners=function(){return a(this)},r.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var r="error"===e,n=this._events;if(void 0!==n)r=r&&void 0===n.error;else if(!r)return!1;if(r){if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var o,a=Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=n[e];if(void 0===h)return!1;if("function"==typeof h)s(h,this,t);else for(var l=h.length,c=p(h,l),i=0;i<l;++i)s(c[i],this,t);return!0},r.prototype.addListener=function(e,t){return h(this,e,t,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(e,t){return h(this,e,t,!0)},r.prototype.once=function(e,t){return o(t),this.on(e,c(this,e,t)),this},r.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,c(this,e,t)),this},r.prototype.removeListener=function(e,t){var s,i,r,n,a;if(o(t),void 0===(i=this._events)||void 0===(s=i[e]))return this;if(s===t||s.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit
2("removeListener",e,s.listener||t));else if("function"!=typeof s){for(r=-1,n=s.length-1;n>=0;n--)if(s[n]===t||s[n].listener===t){a=s[n].listener,r=n;break}if(r<0)return this;0===r?s.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(s,r),1===s.length&&(i[e]=s[0]),void 0!==i.removeListener&&this.emit("removeListener",e,a||t)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(e){var t,s,i;if(void 0===(s=this._events))return this;if(void 0===s.removeListener)return 0==arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==s[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete s[e]),this;if(0==arguments.length){var r,n=Object.keys(s);for(i=0;i<n.length;++i)"removeListener"!==(r=n[i])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=s[e]))this.removeListener(e,t);else if(void 0!==t)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},r.prototype.listeners=function(e){return u(this,e,!0)},r.prototype.rawListeners=function(e){return u(this,e,!1)},r.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):_.call(e,t)},r.prototype.listenerCount=_,r.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},T.exports}())&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;function k(e){return null!=e&&"function"==typeof e}function R(e,t,s){e>31&&(e=31);let i=Math.floor(Math.random()*(Math.min(s,t*Math.pow(2,e))-0+1)+0);return Math.min(s,t+i)}function w(e){return Math.min(1e3*e,0x7fffffff)}(i=_||(_={}))[i.timeout=1]="timeout",i[i.transportClosed=2]="transportClosed",i[i.clientDisconnected=3]="clientDisconnected",i[i.clientClosed=4]="clientClosed",i[i.clientConnectToken=5]="clientConnectToken",i[i.clientRefreshToken=6]="clientRefreshToken",i[i.subscriptionUnsubscribed=7]="subscriptionUnsubscribed",i[i.subscriptionSubscribeToken=8]="subscriptionSubscribeToken",i[i.subscriptionRefreshToken=9]="subscriptionRefreshToken",i[i.transportWriteError=10]="transportWriteError",i[i.connectionClosed=11]="connectionClosed",i[i.badConfiguration=12]="badConfiguration",i[i.subscriptionGetState=13]="subscriptionGetState",i[i.sharedPollGetSignature=14]="sharedPollGetSignature",(r=p||(p={}))[r.connectCalled=0]="connectCalled",r[r.transportClosed=1]="transportClosed",r[r.noPing=2]="noPing",r[r.subscribeTimeout=3]="subscribeTimeout",r[r.unsubscribeError=4]="unsubscribeError",(n=f||(f={}))[n.disconnectCalled=0]="disconnectCalled",n[n.unauthorized=1]="unauthorized",n[n.badProtocol=2]="badProtocol",n[n.messageSizeLimit=3]="messageSizeLimit",n[n.stateInvalidated=3014]="stateInvalidated",(o=b||(b={}))[o.subscribeCalled=0]="subscribeCalled",o[o.transportClosed=1]="transportClosed",(a=g||(g={}))[a.unsubscribeCalled=0]="unsubscribeCalled",a[a.unauthorized=1]="unauthorized",a[a.clientClosed=2]="clientClosed",a[a.stateInvalidated=2502]="stateInvalidated",(h=m||(m={}))[h.channelCompaction=1]="channelCompaction",h[h.rejectUnrecovered=2]="rejectUnrecovered",(l=v||(v={})).Disconnected="disconnected",l.Connecting="connecting",l.Connected="connected",(c=S||(S={})).Unsubscribed="unsubscribed",c.Subscribing="subscribing",c.Subscribed="subscribed",(u=y||(y={}))[u.Live=0]="Live",u[u.Stream=1]="Stream",u[u.State=2]="State";class C extends P{constructor(e,t,s){super(),this._resubscribeTimeout=null,this._refreshTimeout=null,this._getState=null,this._map=!1,this._mapPresenceType=1,this._mapPhase=null,this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapCursor="",this._mapPageSize=0,this._mapUnrecoverableStrategy="from_scratch",this._debounceMs=0,this._debouncePending=new Map,this._sharedPoll=!1,this._sharedPollEpoch="",this._sharedPollTrackedItems=new Map,this._sharedPollGetSignature=null,this._sharedPollSignatureRefreshTimeout=null,this._sharedPollSignatureRefreshAttempts=0,this._sharedPollTrackRetryTimeout=null,this._sharedPollTrackRetryAttempts=0,this._sharedPollReplayRetryTimeout=null,this._sharedPollReplayRetryAttempts=0,this._sharedPollSignatures=[],this._sharedPollSignatureRefreshTargetMs=null,this._sharedPollSignatureRefresh
2InFlight=!1,this.channel=t,this.state=S.Unsubscribed,this._centrifuge=e,this._token="",this._getToken=null,this._data=null,this._getData=null,this._recover=!1,this._offset=null,this._epoch=null,this._id=0,this._recoverable=!1,this._positioned=!1,this._joinLeave=!1,this._minResubscribeDelay=500,this._maxResubscribeDelay=2e4,this._resubscribeTimeout=null,this._resubscribeAttempts=0,this._promises={},this._promiseId=0,this._inflight=!1,this._refreshTimeout=null,this._delta="",this._delta_negotiated=!1,this._tagsFilter=null,this._prevValueMap=new Map,this._unsubPromise=Promise.resolve(),this._deltaNumPubs=0,this._deltaNumFull=0,this._deltaNumDelta=0,this._deltaBytesReceived=0,this._deltaBytesDecoded=0,this._setOptions(s),this.type=this._sharedPoll?"shared_poll":this._map?"map":"stream",this._centrifuge._debugEnabled?(this.on("state",e=>{this._debug("subscription state",t,e.oldState,"->",e.newState)}),this.on("error",e=>{this._debug("subscription error",t,e)})):this.on("error",function(){Function.prototype()})}ready(e){return this.state===S.Unsubscribed?Promise.reject({code:_.subscriptionUnsubscribed,message:this.state}):this.state===S.Subscribed?Promise.resolve():new Promise((t,s)=>{let i={resolve:t,reject:s};e&&(i.timeout=setTimeout(function(){s({code:_.timeout,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=i})}subscribe(){this._isSubscribed()||(this._resubscribeAttempts=0,this._setSubscribing(b.subscribeCalled,"subscribe called"))}unsubscribe(){this._unsubPromise=this._setUnsubscribed(g.unsubscribeCalled,"unsubscribe called",!0)}_debouncedPublish(e,t,s){let i=this._debouncePending.get(e);if(i)return i.data=t,i.dirty=!0,Promise.resolve({});let r={data:t,dirty:!1,timer:null};return r.timer=setTimeout(()=>{let t=this._debouncePending.get(e);if(!t||!t.dirty)return void this._debouncePending.delete(e);t.dirty=!1;let i=t.data;(s?this._centrifuge.mapPublish(this.channel,e,i):this._centrifuge.publish(this.channel,i)).catch(()=>{}),t.timer=setTimeout(()=>{let t=this._debouncePending.get(e);t&&t.dirty?(this._debouncePending.delete(e),this._debouncedPublish(e,t.data,s)):this._debouncePending.delete(e)},this._debounceMs)},this._debounceMs),this._debouncePending.set(e,r),s?this._centrifuge.mapPublish(this.channel,e,t):this._centrifuge.publish(this.channel,t)}_cancelDebounce(e){let t=this._debouncePending.get(e);t&&(clearTimeout(t.timer),this._debouncePending.delete(e))}_cancelAllDebounce(){for(let[,e]of this._debouncePending)clearTimeout(e.timer);this._debouncePending.clear()}presence(){return t(this,void 0,void 0,function*(){return yield this._methodCall(),this._centrifuge.presence(this.channel)})}presenceStats(){return t(this,void 0,void 0,function*(){return yield this._methodCall(),this._centrifuge.presenceStats(this.channel)})}setTagsFilter(e){if(e&&this._delta)throw Error("cannot use delta and tagsFilter together");this._tagsFilter=e,this._map&&(this._recover=!1,this._offset=null,this._epoch=null)}setData(e){this._data=e}deltaStats(){let e=this._deltaBytesDecoded;return{numPublications:this._deltaNumPubs,numFullPayloads:this._deltaNumFull,numDeltaPayloads:this._deltaNumDelta,bytesReceived:this._deltaBytesReceived,bytesDecoded:e,compressionRatio:e>0?1-this._deltaBytesReceived/e:0}}_methodCall(){return this._isSubscribed()?Promise.resolve():this._isUnsubscribed()?Promise.reject({code:_.subscriptionUnsubscribed,message:this.state}):new Promise((e,t)=>{let s=setTimeout(()=>{t({code:_.timeout,message:"timeout"})},this._centrifuge._config.timeout);this._promises[this._nextPromiseId()]={timeout:s,resolve:e,reject:t}})}_nextPromiseId(){return++this._promiseId}_needRecover(){return!0===this._recover}_isUnsubscribed(){return this.state===S.Unsubscribed}_isSubscribing(){return this.state===S.Subscribing}_isSubscribed(){return this.state===S.Subscribed}_setState(e){if(this.state!==e){let t=this.state;return this.state=e,this.emit("state",{newState:e,oldState:t,channel:this.channel}),!0}return!1}_usesToken(){return""!==this._token||null!==this._getToken}_clearSubscribingState(){this._resubscribeAttempts=0,this._clearResubscribeTimeout()}_clearSubscribedState(){this._clearRefreshTimeout(),this._clearSharedPollSignatureRefresh(),this._clearSharedPollTrackRetry(),this._clearSharedPollReplayRetry(),this._sharedPollSignatureRefreshTargetMs=null,this._sharedPollSignatureRefresh
2InFlight=!1}_invalidateState(){this._token="",this._prevValueMap=new Map,this._map?(this._offset=null,this._epoch=null,this._recover=!1,this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapCursor="",this._mapPhase=null):(this._offset=0,this._epoch="_")}_setSubscribed(e){if(!this._isSubscribing())return;if(this._clearSubscribingState(),e.id&&(this._id=e.id),e.recoverable&&(this._recover=!0,this._offset=e.offset||0,this._epoch=e.epoch||""),e.delta?this._delta_negotiated=!0:this._delta_negotiated=!1,e.publish_debounce&&(this._debounceMs=e.publish_debounce),this._sharedPoll){let t=e.epoch||"";if(""!==this._sharedPollEpoch&&this._sharedPollEpoch!==t)for(let e of this._sharedPollTrackedItems.keys())this._sharedPollTrackedItems.set(e,0);this._sharedPollEpoch=t}this._setState(S.Subscribed);let t=this._centrifuge._getSubscribeContext(this.channel,e);this.emit("subscribed",t),this._resolvePromises();let s=e.publications;if(s&&s.length>0)for(let e in s)s.hasOwnProperty(e)&&this._handlePublication(s[e]);!0===e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),w(e.ttl)))}_setSubscribing(e,s){return t(this,void 0,void 0,function*(){this._isSubscribing()||(this._isSubscribed()&&this._clearSubscribedState(),this._id=0,this._setState(S.Subscribing)&&this.emit("subscribing",{channel:this.channel,code:e,reason:s}),this._centrifuge._transport&&this._centrifuge._transport.emulation()&&(yield this._unsubPromise),this._isSubscribing()&&this._subscribe())})}_subscribe(){return(this._debug("subscribing on",this.channel),this._isTransportOpen())?this._inflight?null:(this._inflight=!0,this._map)?(this._mapSubscribe(),null):this._getState&&null===this._offset?(this._loadStreamState(),null):this._canSubscribeWithoutGettingToken()?this._subscribeWithoutToken():(this._getSubscriptionToken().then(e=>this._handleTokenResponse(e)).catch(e=>this._handleTokenError(e)),null):(this._debug("delay subscribe on",this.channel,"till connected"),null)}_isTransportOpen(){return this._centrifuge._transportIsOpen}_canSubscribeWithoutGettingToken(){return!this._usesToken()||!!this._token}_subscribeWithoutToken(){return this._getData?(this._getDataAndSubscribe(this._token),null):this._sendSubscribe(this._token)}_loadStreamState(){if(!this._isSubscribing()){this._inflight=!1;return}this._getState().then(e=>{if(!this._isSubscribing()){this._inflight=!1;return}this._offset=e.offset,this._epoch=e.epoch,this._recover=!0,this._canSubscribeWithoutGettingToken()?this._subscribeWithoutToken():this._getSubscriptionToken().then(e=>this._handleTokenResponse(e)).catch(e=>this._handleTokenError(e))}).catch(e=>{if(!this._isSubscribing()){this._inflight=!1;return}this._inflight=!1,this._subscribeError({code:_.subscriptionGetState,message:(null==e?void 0:e.toString())||"getState failed",temporary:!0})})}_getDataAndSubscribe(e){if(!this._getData){this._inflight=!1;return}this._getData({channel:this.channel}).then(t=>{if(!this._isSubscribing()){this._inflight=!1;return}this._data=t,this._sendSubscribe(e)}).catch(e=>this._handleGetDataError(e))}_handleGetDataError(e){if(!this._isSubscribing()){this._inflight=!1;return}if(e instanceof F){this._inflight=!1,this._failUnauthorized();return}this.emit("error",{type:"subscribeData",channel:this.channel,error:{code:_.badConfiguration,message:(null==e?void 0:e.toString())||""}}),this._inflight=!1,this._scheduleResubscribe()}_handleTokenResponse(e){if(!this._isSubscribing()){this._inflight=!1;return}if(!e){this._inflight=!1,this._failUnauthorized();return}this._token=e,this._getData?this._getDataAndSubscribe(e):this._sendSubscribe(e)}_handleTokenError(e){if(!this._isSubscribing()){this._inflight=!1;return}if(e instanceof F){this._inflight=!1,this._failUnauthorized();return}this.emit("error",{type:"subscribeToken",channel:this.channel,error:{code:_.subscriptionSubscribeToken,message:(null==e?void 0:e.toString())||""}}),this._inflight=!1,this._scheduleResubscribe()}_sendSubscribe(e){if(!this._isTransportOpen())return this._inflight=!1,null;let t=this._buildSubscribeCommand(e);return this._centrifuge._call(t).then(e=>{this._inflight=!1;let t=e.reply.subscribe;this._handleSubscribeResponse(t),e.next&&e.next()},e=>{this._inflight=!1,this._handleSubscribeError(e.error),e.next&&e.next()}),t}_buildSubscribeCommand(e){let t={channel:this.channel};if(e&&(t.token=e),this._data&&(t.data=this._data),this._sharedPoll)return t.type=4,this._delta&&(t.delta=this._delta),{subscribe:t};
2if(this._positioned&&(t.positioned=!0),this._recoverable&&(t.recoverable=!0),this._joinLeave&&(t.join_leave=!0),t.flag=m.channelCompaction,this._getState&&(t.flag|=m.rejectUnrecovered),this._needRecover()){t.recover=!0;let e=this._getOffset();e&&(t.offset=e);let s=this._getEpoch();s&&(t.epoch=s)}return this._delta&&(t.delta=this._delta),this._tagsFilter&&(t.tf=this._tagsFilter),{subscribe:t}}_debug(...e){this._centrifuge._debug(...e)}_handleSubscribeError(e){if(this._isSubscribing()){if(e.code===_.timeout)return void this._centrifuge._disconnect(p.subscribeTimeout,"subscribe timeout",!0);if(112===e.code&&this._getState){this._offset=null,this._epoch=null,this._recover=!1,this._prevValueMap=new Map,this._scheduleResubscribe();return}this._subscribeError(e)}}_handleSubscribeResponse(e){this._isSubscribing()&&(this._setSubscribed(e),this._sharedPoll&&this._sharedPollReplayTrack())}_setUnsubscribed(e,t,s){if(this._isUnsubscribed())return Promise.resolve();let i=Promise.resolve();return this._isSubscribed()?(s&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribedState()):this._isSubscribing()&&(this._inflight&&s&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribingState()),this._inflight=!1,this._id=0,this._sharedPollEpoch="",this._sharedPollSignatures=[],this._sharedPollTrackedItems.clear(),this._sharedPollSignatureRefreshInFlight=!1,this._sharedPollSignatureRefreshTargetMs=null,this._cancelAllDebounce(),this._setState(S.Unsubscribed)&&this.emit("unsubscribed",{channel:this.channel,code:e,reason:t}),this._rejectPromises({code:_.subscriptionUnsubscribed,message:this.state}),i}_handlePublication(e){let t;if(this._delta&&this._delta_negotiated){let t=(this._map||this._sharedPoll)&&e.key||"",{newData:s,newPrevValue:i,isDelta:r,
2wireBytes:n,fullBytes:o}=this._centrifuge._codec.applyDeltaIfNeeded(e,this._prevValueMap.get(t));e.data=s,this._deltaNumPubs++,this._deltaBytesReceived+=n,this._deltaBytesDecoded+=o,r?this._deltaNumDelta++:this._deltaNumFull++,e.removed?this._prevValueMap.delete(t):this._prevValueMap.set(t,i)}if(this._sharedPoll){if(e.key&&!this._sharedPollTrackedItems.has(e.key))return;e.key&&(e.removed?this._sharedPollTrackedItems.delete(e.key):e.version&&this._sharedPollTrackedItems.set(e.key,e.version)),t=this._getSharedPollUpdateContext(e)}else t=this._map?this._getMapUpdateContext(e):this._centrifuge._getPublicationContext(this.channel,e);this.emit("publication",t),(this._map||this._sharedPoll)&&this.emit("update",t),e.offset&&(this._offset=e.offset),e.epoch&&(this._epoch=e.epoch)}_seedDeltaTracking(e){if(this._delta&&e.key){if("string"==typeof e.data){let t=e.data;e.removed?this._prevValueMap.delete(e.key):this._prevValueMap.set(e.key,new TextEncoder().encode(t));let s=t.length;this._deltaNumPubs++,this._deltaNumFull++,this._deltaBytesReceived+=s,this._deltaBytesDecoded+=s,e.data=JSON.parse(t)}else if(e.data instanceof Uint8Array){e.removed?this._prevValueMap.delete(e.key):this._prevValueMap.set(e.key,e.data);let t=e.data.length;this._deltaNumPubs++,this._deltaNumFull++,this._deltaBytesReceived+=t,this._deltaBytesDecoded+=t}}}_handleJoin(e){let t=this._centrifuge._getJoinLeaveContext(e.info);this.emit("join",{channel:this.channel,info:t})}_handleLeave(e){let t=this._centrifuge._getJoinLeaveContext(e.info);this.emit("leave",{channel:this.channel,info:t})}_resolvePromises(){for(let e in this._promises)this._promises.hasOwnProperty(e)&&(this._promises[e].timeout&&clearTimeout(this._promises[e].timeout),this._promises[e].resolve(),delete this._promises[e])}_rejectPromises(e){for(let t in this._promises)this._promises.hasOwnProperty(t)&&(this._promises[t].timeout&&clearTimeout(this._promises[t].timeout),this._promises[t].reject(e),delete this._promises[t])}_scheduleResubscribe(){if(!this._isSubscribing())return void this._debug("not in subscribing state, skip resubscribe scheduling",this.channel);let e=this,t=this._getResubscribeDelay();this._resubscribeTimeout=setTimeout(function(){e._isSubscribing()&&e._subscribe()},t),this._debug("resubscribe scheduled after "+t,this.channel)}_subscribeError(e){if(this._isSubscribing())if(e.code<100||109===e.code||!0===e.temporary){109===e.code&&(this._token="");let t={channel:this.channel,type:"subscribe",error:e};this._centrifuge.state===v.Connected&&this.emit("error",t),this._scheduleResubscribe()}else this._setUnsubscribed(e.code,e.message,!1)}_getResubscribeDelay(){let e=R(this._resubscribeAttempts,this._minResubscribeDelay,this._maxResubscribeDelay);return this._resubscribeAttempts++,e}_setOptions(e){if(e){if(e.since&&(this._offset=e.since.offset||0,this._epoch=e.since.epoch||"",this._recover=!0),e.data&&(this._data=e.data),e.getData&&(this._getData=e.getData),void 0!==e.minResubscribeDelay&&(this._minResubscribeDelay=e.minResubscribeDelay),void 0!==e.maxResubscribeDelay&&(this._maxResubscribeDelay=e.maxResubscribeDelay),e.token&&(this._token=e.token),e.getToken&&(this._getToken=e.getToken),!0===e.positioned&&(this._positioned=!0),!0===e.recoverable&&(this._recoverable=!0),!0===e.joinLeave&&(this._joinLeave=!0),e.delta){if("fossil"!==e.delta)throw Error("unsupported delta format");this._delta=e.delta}if(e.tagsFilter&&(this._tagsFilter=e.tagsFilter),this._tagsFilter&&this._delta)throw Error("cannot use delta and tagsFilter together");e.getState&&(this._getState=e.getState,this._recover=!0),!0===e.map&&(this._map=!0),void 0!==e.mapPageSize&&(this._mapPageSize=e.mapPageSize),void 0!==e.mapPresenceType&&(this._mapPresenceType=e.mapPresenceType,this._map=!0),e.mapUnrecoverableStrategy&&(this._mapUnrecoverableStrategy=e.mapUnrecoverableStrategy),!0===e.sharedPoll&&(this._sharedPoll=!0),e.sharedPollGetSignature&&(this._sharedPollGetSignature=e.sharedPollGetSignature)}}_getOffset(){let e=this._offset;return null!==e?e:0}_getEpoch(){let e=this._epoch;return null!==e?e:""}_clearRefreshTimeout(){null!==this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null)}_clearResubscribeTimeout(){null!==this._resubscribeTimeout&&(clearTimeout(this._resubscribeTimeout),this._resubscribeTimeout=null)}_getSubscriptionToken(){this._debug("get subscription token for channel",this.channel);let e={channel:this.channel},t=this._getToken;
2return null===t?(this.emit("error",{type:"configuration",channel:this.channel,error:{code:_.badConfiguration,message:"provide a function to get channel subscription token"}}),Promise.reject(new F(""))):t(e)}_refresh(){this._clearRefreshTimeout();let e=this;this._getSubscriptionToken().then(function(t){if(!e._isSubscribed())return;if(!t)return void e._failUnauthorized();e._token=t;let s={channel:e.channel,token:t};e._centrifuge._call({sub_refresh:s}).then(t=>{let s=t.reply.sub_refresh;e._refreshResponse(s),t.next&&t.next()},t=>{e._refreshError(t.error),t.next&&t.next()})}).catch(function(t){t instanceof F?e._failUnauthorized():(e.emit("error",{type:"refreshToken",channel:e.channel,error:{code:_.subscriptionRefreshToken,message:void 0!==t?t.toString():""}}),e._refreshTimeout=setTimeout(()=>e._refresh(),e._getRefreshRetryDelay()))})}_refreshResponse(e){this._isSubscribed()&&(this._debug("subscription token refreshed, channel",this.channel),this._clearRefreshTimeout(),!0===e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),w(e.ttl))))}_refreshError(e){this._isSubscribed()&&(e.code<100||!0===e.temporary?(this.emit("error",{type:"refresh",channel:this.channel,error:e}),this._refreshTimeout=setTimeout(()=>this._refresh(),this._getRefreshRetryDelay())):this._setUnsubscribed(e.code,e.message,!0))}_getRefreshRetryDelay(){return R(0,1e4,2e4)}_failUnauthorized(){this._setUnsubscribed(g.unauthorized,"unauthorized",!0)}_sendTrackRequest(e,t){if(0===e.length)return Promise.resolve();let s=[],i=[],r=100;if(t&&t.length>0)for(let e of t)r+=e.length+4;for(let t of e){let e=100;for(let s of t.items)e+=s.key.length+16;i.length>0&&r+e>6e4&&(s.push(i),i=[],r=100),i.push(t),r+=e}i.length>0&&s.push(i);let n=(e,t)=>new Promise((s,i)=>{let r={channel:this.channel,type:1,track:e.map(e=>({signature:e.signature,items:e.items.map(e=>e.version>0?e:{key:e.key})}))};t&&t.length>0&&(r.untrack=t),this._centrifuge._call({sub_refresh:r}).then(e=>{this._handleTrackResponse(e.reply.sub_refresh),e.next&&e.next(),s()},e=>{e.next&&e.next(),i(e.error)})});return s.reduce((e,s,i)=>e.then(()=>n(s,0===i?t:void 0)),Promise.resolve())}_sendUntrackRequest(e){return new Promise((t,s)=>{let i={channel:this.channel,type:2,untrack:e};this._centrifuge._call({sub_refresh:i}).then(e=>{e.next&&e.next(),t()},e=>{e.next&&e.next(),s(e.error)})})}_handleTrackResponse(e){if(this._clearSharedPollTrackRetry(),e&&e.items&&e.items.length>0)for(let t of e.items)this._handlePublication(t);if(e&&!0===e.expires&&e.ttl>0){let t=Date.now()+1e3*e.ttl;this._maybeScheduleSharedPollSignatureRefresh(t)}}_maybeScheduleSharedPollSignatureRefresh(e){if(null===e){this._sharedPollSignatureRefreshTargetMs=null,this._clearSharedPollSignatureRefresh();return}!this._isSubscribed()||null!==this._sharedPollSignatureRefreshTargetMs&&e>=this._sharedPollSignatureRefreshTargetMs||(this._sharedPollSignatureRefreshTargetMs=e,this._clearSharedPollSignatureRefresh(),this._sharedPollSignatureRefreshTimeout=setTimeout(()=>this._sharedPollRefreshSignature(),Math.max(0,e-Date.now())))}_clearSharedPollSignatureRefresh(){null!==this._sharedPollSignatureRefreshTimeout&&(clearTimeout(this._sharedPollSignatureRefreshTimeout),this._sharedPollSignatureRefreshTimeout=null),this._sharedPollSignatureRefreshAttempts=0}_clearSharedPollTrackRetry(){null!==this._sharedPollTrackRetryTimeout&&(clearTimeout(this._sharedPollTrackRetryTimeout),this._sharedPollTrackRetryTimeout=null),this._sharedPollTrackRetryAttempts=0}_clearSharedPollReplayRetry(){null!==this._sharedPollReplayRetryTimeout&&(clearTimeout(this._sharedPollReplayRetryTimeout),this._sharedPollReplayRetryTimeout=null),this._sharedPollReplayRetryAttempts=0}_handleTrackError(e){if(this._isSubscribed()){if(this.emit("error",{type:"track",channel:this.channel,error:e}),109===e.code)return void this._sharedPollRefreshSignature();(e.code<100||!0===e.temporary)&&(this._sharedPollTrackRetryTimeout=setTimeout(()=>this._sharedPollReplayTrack(),R(this._sharedPollTrackRetryAttempts++,1e3,15e3)))}}_sharedPollRefreshSignature(){if(this._clearSharedPollSignatureRefresh(),!this._isSubscribed()||!this._sharedPollGetSignature||0===this._sharedPollTrackedItems.size||this._sharedPollSignatureRefresh
2InFlight)return;this._sharedPollSignatureRefreshTargetMs=null,this._sharedPollSignatureRefreshInFlight=!0;let e=Array.from(this._sharedPollTrackedItems.keys()),t=this;this._sharedPollGetSignature({keys:e}).then(s=>{if(t._sharedPollSignatureRefreshInFlight=!1,!t._isSubscribed())return;t._sharedPollSignatureRefreshAttempts=0;let i=new Set(s.keys),r=[];for(let s of e)i.has(s)||(t._sharedPollTrackedItems.delete(s),r.push(s),t.emit("update",{channel:t.channel,key:s,data:null,removed:!0}));r.length>0&&t._sendUntrackRequest(r).catch(e=>{t.emit("error",{type:"untrack",channel:t.channel,error:e})});let n=[];for(let e of s.keys){let s=t._sharedPollTrackedItems.get(e);void 0!==s&&n.push({key:e,version:s})}let o=new Set(s.keys),a=t._sharedPollSignatures.filter(e=>e.keys.some(e=>t._sharedPollTrackedItems.has(e)&&!o.has(e)));t._sharedPollSignatures=n.length>0?[{keys:s.keys,signature:s.signature},...a]:a,0!==n.length&&t._sendTrackRequest([{items:n,signature:s.signature}]).catch(e=>{t._handleTrackError(e)})}).catch(e=>{t._sharedPollSignatureRefreshInFlight=!1,t.emit("error",{type:"signatureRefresh",channel:t.channel,error:{code:_.sharedPollGetSignature,message:void 0!==e?e.toString():""}}),t._sharedPollSignatureRefreshTimeout=setTimeout(()=>t._sharedPollRefreshSignature(),R(t._sharedPollSignatureRefreshAttempts++,5e3,3e4))})}_sharedPollReplayTrack(){if(!this._isSubscribed()||0===this._sharedPollTrackedItems.size&&0===this._sharedPollSignatures.length)return;let e=new Set,t=[],s=[];for(let i of this._sharedPollSignatures){let r=i.keys.map(e=>{var t;return{key:e,version:null!=(t=this._sharedPollTrackedItems.get(e))?t:0}});for(let n of(t.push({items:r,signature:i.signature}),i.keys))this._sharedPollTrackedItems.has(n)?e.add(n):s.push(n)}t.length>0&&this._sendTrackRequest(t,s).catch(e=>{this._handleTrackError(e)});let i=[];for(let t of this._sharedPollTrackedItems.keys())e.has(t)||i.push(t);if(0===i.length)return;if(!this._sharedPollGetSignature)return void this.emit("error",{type:"track",channel:this.channel,error:{code:_.sharedPollGetSignature,message:"getSignature callback required for tracked keys without an explicit signature"}});let r=this;this._sharedPollGetSignature({keys:i}).then(e=>{if(!r._isSubscribed())return;r._clearSharedPollReplayRetry();let t=new Set(e.keys),s=[];for(let e of i)t.has(e)||(r._sharedPollTrackedItems.delete(e),s.push(e),r.emit("update",{channel:r.channel,key:e,data:null,removed:!0}));s.length>0&&r._sendUntrackRequest(s).catch(e=>{r.emit("error",{type:"untrack",channel:r.channel,error:e})});let n=[];for(let t of e.keys){let e=r._sharedPollTrackedItems.get(t);void 0!==e&&n.push({key:t,version:e})}0!==n.length&&(r._sharedPollSignatures.push({keys:e.keys,signature:e.signature}),r._sendTrackRequest([{items:n,signature:e.signature}]).catch(e=>{r._handleTrackError(e)}))}).catch(e=>{r.emit("error",{type:"signatureRefresh",channel:r.channel,error:{code:_.sharedPollGetSignature,message:void 0!==e?e.toString():""}}),r._sharedPollReplayRetryTimeout=setTimeout(()=>r._sharedPollReplayTrack(),R(r._sharedPollReplayRetryAttempts++,5e3,3e4))})}_mapSubscribe(){if(this._debug("starting map subscribe on",this.channel),this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapCursor="",this._recover&&null!==this._offset&&null!==this._epoch||(this._prevValueMap=new Map),this._mapPhase=y.State,this._recover&&null!==this._offset&&null!==this._epoch){this._debug("map subscribe: recovering from position, skipping to stream phase"),this._mapPhase=y.Stream,this._fetchStream();return}this._canSubscribeWithoutGettingToken()?this._fetchSnapshot():this._getSubscriptionToken().then(e=>{if(!this._isSubscribing()){this._inflight=!1;return}if(!e){this._inflight=!1,this._failUnauthorized();return}this._token=e,this._fetchSnapshot()}).catch(e=>this._handleTokenError(e))}_fetchSnapshot(e){if(!this._isSubscribing()||!this._isTransportOpen()){this._inflight=!1;return}let t=this._buildMapSubscribeCommand(y.State,e);this._debug("map subscribe: fetching snapshot page",e?`cursor=${e}`:"initial"),this._centrifuge._call(t).then(e=>{let t=e.reply.subscribe;this._handleMapStateResponse(t),e.next&&e.next()},e=>
2{this._handleMapSubscribeError(e.error),e.next&&e.next()})}_handleMapStateResponse(e){if(!this._isSubscribing()){this._inflight=!1;return}if(!e.phase){this._debug("map subscribe: server forced LIVE transition during state pagination"),this._handleMapLiveResponse(e);return}if(!this._epoch&&e.epoch&&(this._epoch=e.epoch,this._offset=e.offset||0),this._epoch&&e.epoch&&this._epoch!==e.epoch){this._debug("map subscribe: epoch changed during snapshot pagination, restarting"),this._mapStateBuffer=[],this._mapCursor="",this._epoch=null,this._offset=null,this._prevValueMap=new Map,this._fetchSnapshot();return}if(e.state&&e.state.length>0)for(let t of e.state)this._seedDeltaTracking(t),this._mapStateBuffer.push(this._getMapUpdateContext(t));if(e.cursor){this._mapCursor=e.cursor,this._fetchSnapshot(this._mapCursor);return}this._transitionFromSnapshot()}_transitionFromSnapshot(){this._debug("map subscribe: snapshot complete, transitioning to stream phase"),this._mapPhase=y.Stream,this._fetchStream()}_fetchStream(){if(!this._isSubscribing()||!this._isTransportOpen()){this._inflight=!1;return}let e=this._buildMapSubscribeCommand(y.Stream);this._debug("map subscribe: fetching stream from offset",this._offset),this._centrifuge._call(e).then(e=>{let t=e.reply.subscribe;this._handleMapStreamResponse(t),e.next&&e.next()},e=>{this._handleMapSubscribeError(e.error),e.next&&e.next()})}_handleMapStreamResponse(e){if(!this._isSubscribing()){this._inflight=!1;return}if(!e.phase){this._debug("map subscribe: server forced LIVE transition during stream"),this._handleMapLiveResponse(e);return}if(this._epoch&&e.epoch&&this._epoch!==e.epoch){this._debug("map subscribe: epoch changed during stream, restarting"),this._mapStateBuffer=[],this._mapStreamBuffer=[],this._epoch=null,this._offset=null,this._prevValueMap=new Map,this._mapPhase=y.State,this._fetchSnapshot();return}if(e.publications&&e.publications.length>0)for(let t of e.publications)this._seedDeltaTracking(t),this._mapStreamBuffer.push(this._getMapUpdateContext(t));void 0!==e.offset&&(this._offset=e.offset),this._fetchStream()}_handleMapLiveResponse(e){if(!this._isSubscribing()){this._inflight=!1;return}if(this._inflight=!1,this._epoch&&e.epoch&&this._epoch!==e.epoch){this._debug("map subscribe: epoch changed during live transition, restarting"),this._mapStateBuffer=[],this._mapStreamBuffer=[],this._epoch=null,this._offset=null,this._prevValueMap=new Map,this._inflight=!0,this._mapPhase=y.State,this._fetchSnapshot();return}if(e.state&&e.state.length>0)for(let t of e.state)this._seedDeltaTracking(t),this._mapStateBuffer.push(this._getMapUpdateContext(t));if(e.publications&&e.publications.length>0)for(let t of e.publications){if(this._delta&&e.delta){let e=t.key||"",{newData:s,newPrevValue:i,isDelta:r,
2wireBytes:n,fullBytes:o}=this._centrifuge._codec.applyDeltaIfNeeded(t,this._prevValueMap.get(e));t.data=s,this._deltaNumPubs++,this._deltaBytesReceived+=n,this._deltaBytesDecoded+=o,r?this._deltaNumDelta++:this._deltaNumFull++,t.removed?this._prevValueMap.delete(e):this._prevValueMap.set(e,i)}else this._delta&&t.key&&(t.removed?this._prevValueMap.delete(t.key):this._prevValueMap.set(t.key,t.data));this._mapStreamBuffer.push(this._getMapUpdateContext(t))}this._offset=e.offset||0,this._epoch=e.epoch||"",this._clearSubscribingState(),e.id&&(this._id=e.id),this._recover=!0===e.recoverable,e.delta?this._delta_negotiated=!0:this._delta_negotiated=!1,e.publish_debounce&&(this._debounceMs=e.publish_debounce),this._setState(S.Subscribed);let t=this._centrifuge._getSubscribeContext(this.channel,e);if(t.state=this._mapStateBuffer,this.emit("subscribed",t),this._resolvePromises(),!t.recovered){if(this._mapStreamBuffer.length>0){let e=new Map;for(let t of this._mapStateBuffer)e.set(t.key,t);for(let t of this._mapStreamBuffer)t.removed?e.delete(t.key):e.set(t.key,t);this._mapStateBuffer=Array.from(e.values()),this._mapStreamBuffer=[]}
2this.emit("sync",{entries:this._mapStateBuffer})}for(let e of this._mapStreamBuffer)this.emit("publication",e),this.emit("update",e);this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapPhase=null,!0===e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),w(e.ttl)))}_handleMapSubscribeError(e){if(this._inflight=!1,this._isSubscribing()){if(e.code===_.timeout)return void this._centrifuge._disconnect(p.subscribeTimeout,"subscribe timeout",!0);if(this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapPhase=null,this._prevValueMap=new Map,112===e.code&&"from_scratch"===this._mapUnrecoverableStrategy){this._debug("map subscribe: unrecoverable position, restarting from scratch"),this._offset=null,this._epoch=null,this._recover=!1,this._scheduleResubscribe();return}this._subscribeError(e)}}_buildMapSubscribeCommand(e,t){let s={channel:this.channel,type:this._mapPresenceType||1,phase:e};return this._token&&(s.token=this._token),this._tagsFilter&&(s.tf=this._tagsFilter),this._delta&&(s.delta=this._delta),s.flag=m.channelCompaction,e===y.State&&(this._mapPageSize>0&&(s.limit=this._mapPageSize),t&&(s.cursor=t),this._epoch?(s.offset=this._offset,s.epoch=this._epoch):this._data&&(s.data=this._data)),e===y.Stream&&(this._mapPageSize>0&&(s.limit=this._mapPageSize),s.offset=this._offset,s.epoch=this._epoch,this._recover&&(s.recover=!0,0===this._mapStreamBuffer.length&&this._data&&(s.data=this._data))),{subscribe:s}}_getMapUpdateContext(e){let t={channel:this.channel,data:e.data,key:e.key||""};return!0===e.removed&&(t.removed=!0),void 0!==e.offset&&(t.offset=e.offset),e.info&&(t.info=this._centrifuge._getJoinLeaveContext(e.info)),e.tags&&(t.tags=e.tags),t}_getSharedPollUpdateContext(e){let t={channel:this.channel,key:e.key||"",data:e.data};return!0===e.removed&&(t.removed=!0),void 0!==e.version&&(t.version=e.version),t}}class E extends C{publish(e){return t(this,void 0,void 0,function*(){return(yield this._methodCall(),this._debounceMs>0)?this._debouncedPublish("",e,!1):this._centrifuge.publish(this.channel,e)})}history(e){return t(this,void 0,void 0,function*(){return yield this._methodCall(),this._centrifuge.history(this.channel,e)})}}class x extends C{publish(e,s){return t(this,void 0,void 0,function*(){return(yield this._methodCall(),this._debounceMs>0)?this._debouncedPublish(e,s,!0):this._centrifuge.mapPublish(this.channel,e,s)})}remove(e){return t(this,void 0,void 0,function*(){return yield this._methodCall(),this._cancelDebounce(e),this._centrifuge.mapRemove(this.channel,e)})}}class D extends C{track(e,t){let s;if(0===e.length)return;for(let t of s="string"==typeof e[0]?e.map(e=>({key:e,version:0})):e){let e=this._sharedPollTrackedItems.get(t.key);(void 0===e||t.version>e)&&this._sharedPollTrackedItems.set(t.key,t.version)}if(void 0!==t){this._sharedPollSignatures.push({keys:s.map(e=>e.key),signature:t}),this._isSubscribed()&&this._sendTrackRequest([{items:s,signature:t}]).catch(e=>{this._handleTrackError(e)});return}if(!this._sharedPollGetSignature)return void this.emit("error",{type:"track",channel:this.channel,error:{code:_.sharedPollGetSignature,message:"getSignature callback required for track(keys)"}});if(!this._isSubscribed())return;let i=s.map(e=>e.key);this._sharedPollGetSignature({keys:i}).then(e=>{if(!this._isSubscribed())return;let t=new Set(e.keys),s=[];for(let e of i)t.has(e)||(this._sharedPollTrackedItems.delete(e),s.push(e),this.emit("update",{channel:this.channel,key:e,data:null,removed:!0}));s.length>0&&this._sendUntrackRequest(s).catch(e=>{this.emit("error",{type:"untrack",channel:this.channel,error:e})});let r=[];for(let t of e.keys){let e=this._sharedPollTrackedItems.get(t);void 0!==e&&r.push({key:t,version:e})}0!==r.length&&(this._sharedPollSignatures.push({keys:e.keys,signature:e.signature}),this._sendTrackRequest([{items:r,signature:e.signature}]).catch(e=>{this._handleTrackError(e)}))}).catch(e=>{this.emit("error",{type:"track",channel:this.channel,error:{code:_.sharedPollGetSignature,message:void 0!==e?e.toString():"getSignature failed"}})})}untrack(e){for(let t of e)this._sharedPollTrackedItems.delete(t);this._sharedPollSignatures=this._sharedPollSignatures.filter(e=>e.keys.some(e=>this._sharedPollTrackedItems.has(e))),this._isSubscribed()&&this._sendUntrackRequest(e).catch(e=>
2{this.emit("error",{type:"untrack",channel:this.channel,error:e})})}trackedKeys(){return new Set(this._sharedPollTrackedItems.keys())}}class O{constructor(e,t){this.endpoint=e,this.options=t,this._transport=null}name(){return"sockjs"}subName(){return"sockjs-"+this._transport.transport}emulation(){return!1}supported(){return null!==this.options.sockjs}initialize(e,t){this._transport=new this.options.sockjs(this.endpoint,null,this.options.sockjsOptions),this._transport.onopen=()=>{t.onOpen()},this._transport.onerror=e=>{t.onError(e)},this._transport.onclose=e=>{t.onClose(e)},this._transport.onmessage=e=>{t.onMessage(e.data)}}close(){this._transport.close()}send(e){this._transport.send(e)}}class I{constructor(e,t){this.endpoint=e,this.options=t,this._transport=null}name(){return"websocket"}subName(){return"websocket"}emulation(){return!1}supported(){return void 0!==this.options.websocket&&null!==this.options.websocket}initialize(e,t){let s="";"protobuf"===e&&(s="centrifuge-protobuf"),""!==s?this._transport=new this.options.websocket(this.endpoint,s):this._transport=new this.options.websocket(this.endpoint),"protobuf"===e&&(this._transport.binaryType="arraybuffer"),this._transport.onopen=()=>{t.onOpen()},this._transport.onerror=e=>{t.onError(e)},this._transport.onclose=e=>{t.onClose(e)},this._transport.onmessage=e=>{t.onMessage(e.data)}}close(){this._transport.close()}send(e){this._transport.send(e)}}class M{constructor(e,t){this.endpoint=e,this.options=t,this._abortController=null,this._utf8decoder=new TextDecoder,this._protocol="json"}name(){return"http_stream"}subName(){return"http_stream"}emulation(){return!0}_handleErrors(e){if(!e.ok)throw Error(e.status);return e}_fetchEventTarget(e,t,s){let i=new EventTarget;return(0,e.options.fetch)(t,s).then(e._handleErrors).then(t=>{i.dispatchEvent(new Event("open"));let s="",r=0,n=new Uint8Array,o=t.body.getReader();return new e.options.readableStream({start:t=>(function a(){return o.read().then(({done:o,value:h})=>{if(o){i.dispatchEvent(new Event("close")),t.close();return}try{if("json"===e._protocol)for(s+=e._utf8decoder.decode(h);r<s.length;)if("\n"===s[r]){let e=s.substring(0,r);i.dispatchEvent(new MessageEvent("message",{data:e})),s=s.substring(r+1),r=0}else++r;else{let t=new Uint8Array(n.length+h.length);for(t.set(n),t.set(h,n.length),n=t;;){let t=e.options.decoder.decodeReply(n);if(t.ok){let e=n.slice(0,t.pos);i.dispatchEvent(new MessageEvent("message",{data:e})),n=n.slice(t.pos);continue}break}}}catch(e){i.dispatchEvent(new Event("error",{detail:e})),i.dispatchEvent(new Event("close")),t.close();return}a()}).catch(function(e){i.dispatchEvent(new Event("error",{detail:e})),i.dispatchEvent(new Event("close")),t.close()})})()})}).catch(e=>{i.dispatchEvent(new Event("error",{detail:e})),i.dispatchEvent(new Event("close"))}),i}supported(){return null!==this.options.fetch&&null!==this.options.readableStream&&"u">typeof TextDecoder&&"u">typeof AbortController&&"u">typeof EventTarget&&"u">typeof Event&&"u">typeof MessageEvent&&"u">typeof Error}initialize(e,t,s){let i;this._protocol=e,this._abortController=new AbortController;let r={method:"POST",headers:i="json"===e?{Accept:"application/json","Content-Type":"application/json"}:{Accept:"application/octet-stream","Content-Type":"application/octet-stream"},body:s,mode:"cors",credentials:"same-origin",signal:this._abortController.signal},n=this._fetchEventTarget(this,this.endpoint,r);n.addEventListener("open",()=>{t.onOpen()}),n.addEventListener("error",e=>{this._abortController.abort(),t.onError(e)}),n.addEventListener("close",()=>{this._abortController.abort(),t.onClose({code:4,reason:"connection closed"})}),n.addEventListener("message",e=>{t.onMessage(e.data)})}close(){this._abortController.abort()}send(e,t,s){let i,r,n={session:t,node:s,data:e};"json"===this._protocol?(i={"Content-Type":"application/json"},r=JSON.stringify(n)):(i={"Content-Type":"application/octet-stream"},r=this.options.encoder.encodeEmulationRequest(n));let o=this.options.fetch,a={method:"POST",headers:i,body:r,mode:"cors",credentials:"same-origin"};o(this.options.emulationEndpoint,a)}}class U{constructor(e,t){this.endpoint=e,this.options=t,this._protocol="json",this._transport=null,this._onClose=null}name(){return"sse"}subName(){return"sse"}emulation(){return!0}supported(){return null!==this.options.eventsource&&null!==this.options.fetch}
2initialize(e,t,s){let i;(i=globalThis&&globalThis.document&&globalThis.document.baseURI?new URL(this.endpoint,globalThis.document.baseURI):new URL(this.endpoint)).searchParams.append("cf_connect",s);let r=new this.options.eventsource(i.toString(),{});this._transport=r,r.onopen=function(){t.onOpen()},r.onerror=function(e){r.close(),t.onError(e),t.onClose({code:4,reason:"connection closed"})},r.onmessage=function(e){t.onMessage(e.data)},this._onClose=function(){t.onClose({code:4,reason:"connection closed"})}}close(){this._transport.close(),null!==this._onClose&&this._onClose()}send(e,t,s){let i=JSON.stringify({session:t,node:s,data:e});(0,this.options.fetch)(this.options.emulationEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:i,mode:"cors",credentials:"same-origin"})}}class j{constructor(e,t){this.endpoint=e,this.options=t,this._transport=null,this._stream=null,this._writer=null,this._utf8decoder=new TextDecoder,this._protocol="json"}name(){return"webtransport"}subName(){return"webtransport"}emulation(){return!1}supported(){return void 0!==this.options.webtransport&&null!==this.options.webtransport}initialize(e,s){return t(this,void 0,void 0,function*(){let t,i;t=globalThis&&globalThis.document&&globalThis.document.baseURI?new URL(this.endpoint,globalThis.document.baseURI):new URL(this.endpoint),"protobuf"===e&&t.searchParams.append("cf_protocol","protobuf"),this._protocol=e;let r=new EventTarget;this._transport=new this.options.webtransport(t.toString()),this._transport.closed.then(()=>{s.onClose({code:4,reason:"connection closed"})}).catch(()=>{s.onClose({code:4,reason:"connection closed"})});try{yield this._transport.ready}catch(e){this.close();return}try{i=yield this._transport.createBidirectionalStream()}catch(e){this.close();return}this._stream=i,this._writer=this._stream.writable.getWriter(),r.addEventListener("close",()=>{s.onClose({code:4,reason:"connection closed"})}),r.addEventListener("message",e=>{s.onMessage(e.data)}),this._startReading(r),s.onOpen()})}_startReading(e){return t(this,void 0,void 0,function*(){let t=this._stream.readable.getReader(),s="",i=0,r=new Uint8Array;try{for(;;){let{done:n,value:o}=yield t.read();if(o.length>0)if("json"===this._protocol)for(s+=this._utf8decoder.decode(o);i<s.length;)if("\n"===s[i]){let t=s.substring(0,i);e.dispatchEvent(new MessageEvent("message",{data:t})),s=s.substring(i+1),i=0}else++i;else{let t=new Uint8Array(r.length+o.length);for(t.set(r),t.set(o,r.length),r=t;;){let t=this.options.decoder.decodeReply(r);if(t.ok){let s=r.slice(0,t.pos);e.dispatchEvent(new MessageEvent("message",{data:s})),r=r.slice(t.pos);continue}break}}if(n)break}}catch(t){e.dispatchEvent(new Event("close"))}})}close(){return t(this,void 0,void 0,function*(){try{this._writer&&(yield this._writer.close()),this._transport.close()}catch(e){}})}send(e){return t(this,void 0,void 0,function*(){let t;t="json"===this._protocol?new TextEncoder().encode(e+"\n"):e;try{yield this._writer.write(t)}catch(e){this.close()}})}}let L=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,36,-1,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,-1,-1,-1,63,-1];class B{constructor(e){this.a=e,this.pos=0}haveBytes(){return this.pos<this.a.length}getByte(){let e=this.a[this.pos];if(this.pos++,this.pos>this.a.length)throw RangeError("out of bounds");return e}getChar(){return String.fromCharCode(this.getByte())}getInt(){let e,t=0;for(;this.haveBytes()&&(e=L[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0}}class z{constructor(){this.a=[]}toByteArray(e){return Array.isArray(e)?this.a:new Uint8Array(this.a)}putArray(e,t,s){for(let i=t;i<s;i++)this.a.push(e[i])}}class A{name(){return"json"}encodeCommands(e){return e.map(e=>JSON.stringify(e)).join("\n")}decodeReplies(e){return e.trim().split("\n").map(e=>JSON.parse(e))}applyDeltaIfNeeded(e,t){let s,i,r;if(e.delta){r=!0;let n=function(e,t){let s=0,i=new B(t),r=e.length,n=t.length,o=i.getInt();if("\n"!==i.getChar())throw Error("size integer not terminated by '\\n'");let a=new z;for(;i.haveBytes();){let t,h=i.getInt();switch(i.getChar()){case"@":if(t=i.getInt(),i.haveBytes()&&","!==i.getChar())throw Error("copy command not terminated by ','");if((s+=h)>o)throw Error("copy exceeds output file size");if(t+h>r)throw Error("copy extends past end of input");a.putArray(e,t,t+h);break;case":":if((s+=h)>o)throw Error("insert command gives an output larger than predicted");if(h>n)throw Error("insert count exceeds size of delta");a.putArray(i.a,i.pos,i.pos+h),i.pos+=h;break;case";":{let t=a.toByteArray(e);if(h!==function(e){let t=0,s=0,i=0,r=0,n=0,o=e.length;for(;o>=16;)t=t+e[n+0]|0,s=s+e[n+1]|0,i=i+e[n+2]|0,r=r+e[n+3]|0,t=t+e[n+4]|0,s=s+e[n+5]|0,i=i+e[n+6]|0,r=r+e[n+7]|0,t=t+e[n+8]|0,s=s+e[n+9]|0,i=i+e[n+10]|0,r=r+e[n+11]|0,t=t+e[n+12]|0,s=s+e[n+13]|0,i=i+e[n+14]|0,r=r+e[n+15]|0,n+=16,o-=16;for(;o>=4;
2)t=t+e[n+0]|0,s=s+e[n+1]|0,i=i+e[n+2]|0,r=r+e[n+3]|0,n+=4,o-=4;switch(r=((r+(i<<8)|0)+(s<<16)|0)+(t<<24)|0,o){case 3:r=r+(e[n+2]<<8)|0;case 2:r=r+(e[n+1]<<16)|0;case 1:r=r+(e[n+0]<<24)|0}return r>>>0}(t))throw Error("bad checksum");if(s!==o)throw Error("generated size does not match predicted size");return t}default:throw Error("unknown delta operator")}}throw Error("unterminated delta")}(t,new TextEncoder().encode(e.data));s=JSON.parse(new TextDecoder().decode(n)),i=n}else r=!1,s=JSON.parse(e.data),i=new TextEncoder().encode(e.data);return{newData:s,newPrevValue:i,isDelta:r,wireBytes:e.data.length,fullBytes:i.length}}}let N={headers:{},token:"",getToken:null,data:null,getData:null,debug:!1,name:"js",version:"",fetch:null,readableStream:null,websocket:null,eventsource:null,sockjs:null,sockjsOptions:{},emulationEndpoint:"/emulation",minReconnectDelay:500,maxReconnectDelay:2e4,timeout:5e3,maxServerPingDelay:1e4,networkEventTarget:null};class F extends Error{constructor(e){super(e),this.name=this.constructor.name}}class G extends P{constructor(e,t){super(),this._reconnectTimeout=null,this._refreshTimeout=null,this._serverPingTimeout=null,this.state=v.Disconnected,this._transportIsOpen=!1,this._endpoint=e,this._emulation=!1,this._transports=[],this._currentTransportIndex=0,this._triedAllTransports=!1,this._transportWasOpen=!1,this._transport=null,this._transportId=0,this._deviceWentOffline=!1,this._transportClosed=!0,this._codec=new A,this._reconnecting=!1,this._reconnectTimeout=null,this._reconnectAttempts=0,this._client=null,this._session="",this._node="",this._subs={},this._serverSubs={},this._commandId=0,this._commands=[],this._batching=!1,this._refreshRequired=!1,this._refreshTimeout=null,this._callbacks={},this._token="",this._data=null,this._dispatchPromise=Promise.resolve(),this._serverPing=0,this._serverPingTimeout=null,this._sendPong=!1,this._promises={},this._promiseId=0,this._debugEnabled=!1,this._networkEventsSet=!1,this._config=Object.assign(Object.assign({},N),t),this._configure(),this._debugEnabled?(this.on("state",e=>{this._debug("client state",e.oldState,"->",e.newState)}),this.on("error",e=>{this._debug("client error",e)})):this.on("error",function(){Function.prototype()})}newSubscription(e,t){if(null!==this.getSubscription(e))throw Error("Subscription to the channel "+e+" already exists");let s=new E(this,e,t);return this._subs[e]=s,s}newMapSubscription(e,t){if(null!==this.getSubscription(e))throw Error("Subscription to the channel "+e+" already exists");let s=new x(this,e,{token:null==t?void 0:t.token,getToken:null==t?void 0:t.getToken,data:null==t?void 0:t.data,minResubscribeDelay:null==t?void 0:t.minResubscribeDelay,maxResubscribeDelay:null==t?void 0:t.maxResubscribeDelay,delta:null==t?void 0:t.delta,tagsFilter:null==t?void 0:t.tagsFilter,map:!0,mapPageSize:null==t?void 0:t.pageSize,mapUnrecoverableStrategy:null==t?void 0:t.unrecoverableStrategy});return this._subs[e]=s,s}newMapClientsSubscription(e,t){if(null!==this.getSubscription(e))throw Error("Subscription to the channel "+e+" already exists");let s=new x(this,e,{token:null==t?void 0:t.token,getToken:null==t?void 0:t.getToken,data:null==t?void 0:t.data,minResubscribeDelay:null==t?void 0:t.minResubscribeDelay,maxResubscribeDelay:null==t?void 0:t.maxResubscribeDelay,delta:null==t?void 0:t.delta,tagsFilter:null==t?void 0:t.tagsFilter,map:!0,mapPresenceType:2,mapPageSize:null==t?void 0:t.pageSize,mapUnrecoverableStrategy:null==t?void 0:t.unrecoverableStrategy});return this._subs[e]=s,s}newMapUsersSubscription(e,t){if(null!==this.getSubscription(e))throw Error("Subscription to the channel "+e+" already exists");let s=new x(this,e,{token:null==t?void 0:t.token,getToken:null==t?void 0:t.getToken,data:null==t?void 0:t.data,minResubscribeDelay:null==t?void 0:t.minResubscribeDelay,maxResubscribeDelay:null==t?void 0:t.maxResubscribeDelay,delta:null==t?void 0:t.delta,tagsFilter:null==t?void 0:t.tagsFilter,map:!0,mapPresenceType:3,mapPageSize:null==t?void 0:t.pageSize,mapUnrecoverableStrategy:null==t?void 0:t.unrecoverableStrategy});return this._subs[e]=s,s}newSharedPollSubscription(e,t){if(null!==this.getSubscription(e))throw Error("Subscription to the channel "+e+" already exists");let s=new D(this,e,{token:null==t?void 0:t.token,getToken:null==t?void 0:t.getToken,data:null==t?void 0:t.data,minResubscribeDelay:null==t?void 0:t.minResubscribeDelay,maxResubscribeDelay:null==t?void 0:t.maxResubscribeDelay,delta:null==t?void 0:t.delta,sharedPoll:!0,sharedPollGetSignature:null==t?void 0:t.getSignature});return this._subs[e]=s,s}getSubscription(e){return this._getSub(e)}getMapSubscription(e){return this._getSub(e)}getSharedPollSubscription(e){return this._getSub(e)}removeSubscription(e){e&&(e.state!==S.Unsubscribed&&e.unsubscribe(),this._removeSubscription(e))}
2removeMapSubscription(e){this.removeSubscription(e)}removeSharedPollSubscription(e){this.removeSubscription(e)}subscriptions(){return this._subs}mapSubscriptions(){let e={};for(let[t,s]of Object.entries(this._subs))"map"===s.type&&(e[t]=s);return e}sharedPollSubscriptions(){let e={};for(let[t,s]of Object.entries(this._subs))"shared_poll"===s.type&&(e[t]=s);return e}ready(e){return t(this,void 0,void 0,function*(){switch(this.state){case v.Disconnected:throw{code:_.clientDisconnected,message:"client disconnected"};case v.Connected:return;default:return new Promise((t,s)=>{let i={resolve:t,reject:s};e&&(i.timeout=setTimeout(()=>{s({code:_.timeout,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=i})}})}connect(){this._isConnected()?this._debug("connect called when already connected"):this._isConnecting()?this._debug("connect called when already connecting"):(this._debug("connect called"),this._reconnectAttempts=0,this._startConnecting())}disconnect(){this._disconnect(f.disconnectCalled,"disconnect called",!1)}setToken(e){this._token=e}setData(e){this._data=e}setHeaders(e){this._config.headers=e}send(e){return t(this,void 0,void 0,function*(){if(yield this._methodCall(),!this._transportSendCommands([{send:{data:e}}]))throw this._createErrorObject(_.transportWriteError,"transport write error")})}rpc(e,s){return t(this,void 0,void 0,function*(){return yield this._methodCall(),{data:(yield this._callPromise({rpc:{method:e,data:s}},e=>e.rpc)).data}})}publish(e,s){return t(this,void 0,void 0,function*(){return yield this._methodCall(),yield this._callPromise({publish:{channel:e,data:s}},()=>({})),{}})}mapPublish(e,s,i){return t(this,void 0,void 0,function*(){return yield this._methodCall(),yield this._callPromise({publish:{channel:e,type:1,key:s,data:i}},()=>({})),{}})}mapRemove(e,s){return t(this,void 0,void 0,function*(){return yield this._methodCall(),yield this._callPromise({publish:{channel:e,type:1,key:s,removed:!0}},()=>({})),{}})}history(e,s){return t(this,void 0,void 0,function*(){let t={history:this._getHistoryRequest(e,s)};yield this._methodCall();let i=yield this._callPromise(t,e=>e.history),r=[];if(i.publications)for(let t=0;t<i.publications.length;t++)r.push(this._getPublicationContext(e,i.publications[t]));return{publications:r,epoch:i.epoch||"",offset:i.offset||0}})}presence(e){return t(this,void 0,void 0,function*(){yield this._methodCall();let t=(yield this._callPromise({presence:{channel:e}},e=>e.presence)).presence;for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let s=t[e],i=s.conn_info,r=s.chan_info;i&&(s.connInfo=i),r&&(s.chanInfo=r)}return{clients:t}})}presenceStats(e){return t(this,void 0,void 0,function*(){yield this._methodCall();let t=yield this._callPromise({presence_stats:{channel:e}},e=>e.presence_stats);return{numUsers:t.num_users,numClients:t.num_clients}})}startBatching(){this._batching=!0}stopBatching(){let e=this;Promise.resolve().then(function(){Promise.resolve().then(function(){e._batching=!1,e._flush()})})}_debug(...e){if(this._debugEnabled&&globalThis.console){let t=globalThis.console.debug;k(t)&&t.apply(globalThis.console,e)}}_codecName(){return this._codec.name()}_formatOverride(){}_configure(){if(!("Promise"in globalThis))throw Error("Promise polyfill required");if(!this._endpoint)throw Error("endpoint configuration required");if(null!==this._config.token&&(this._token=this._config.token),null!==this._config.data&&(this._data=this._config.data),this._codec=new A,this._formatOverride(),(!0===this._config.debug||"u">typeof localStorage&&"function"==typeof localStorage.getItem&&localStorage.getItem("centrifuge.debug"))&&(this._debugEnabled=!0),this._debug("config",this._config),"string"==typeof this._endpoint);else if(Array.isArray(this._endpoint)){for(let e in this._transports=this._endpoint,this._emulation=!0,this._transports)if(this._transports.hasOwnProperty(e)){let t=this._transports[e];if(!t.endpoint||!t.transport)throw Error("malformed transport configuration");let s=t.transport;if(0>["websocket","http_stream","sse","sockjs","webtransport"].indexOf(s))throw Error("unsupported transport name: "+s)}}else throw Error("unsupported url configuration type: only string or array of objects are supported")}_setState(e){if(this.state!==e){this._reconnecting=!1;let t=this.state;
2return this.state=e,this.emit("state",{newState:e,oldState:t}),!0}return!1}_isDisconnected(){return this.state===v.Disconnected}_isConnecting(){return this.state===v.Connecting}_isConnected(){return this.state===v.Connected}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let e=null;null!==this._config.networkEventTarget?e=this._config.networkEventTarget:void 0!==globalThis.addEventListener&&(e=globalThis),e&&(e.addEventListener("offline",()=>{this._debug("offline event triggered"),(this.state===v.Connected||this.state===v.Connecting)&&(this._disconnect(p.transportClosed,"transport closed",!0),this._deviceWentOffline=!0)}),e.addEventListener("online",()=>{this._debug("online event triggered"),this.state===v.Connecting&&(this._deviceWentOffline&&!this._transportClosed&&(this._deviceWentOffline=!1,this._transportClosed=!0),this._clearReconnectTimeout(),this._startReconnecting())}),this._networkEventsSet=!0)}_getReconnectDelay(){let e=R(this._reconnectAttempts,this._config.minReconnectDelay,this._config.maxReconnectDelay);return this._reconnectAttempts+=1,e}_clearOutgoingRequests(){for(let e in this._callbacks)if(this._callbacks.hasOwnProperty(e)){let t=this._callbacks[e];clearTimeout(t.timeout);let s=t.errback;if(!s)continue;s({error:this._createErrorObject(_.connectionClosed,"connection closed")})}this._callbacks={}}_clearConnectedState(){for(let e in this._client=null,this._clearServerPingTimeout(),this._clearRefreshTimeout(),this._subs){if(!this._subs.hasOwnProperty(e))continue;let t=this._subs[e];t.state===S.Subscribed&&t._setSubscribing(b.transportClosed,"transport closed")}for(let e in this._serverSubs)this._serverSubs.hasOwnProperty(e)&&this.emit("subscribing",{channel:e})}_handleWriteError(e){for(let t of e){let e=t.id;if(!(e in this._callbacks))continue;let s=this._callbacks[e];clearTimeout(this._callbacks[e].timeout),delete this._callbacks[e],(0,s.errback)({error:this._createErrorObject(_.transportWriteError,"transport write error")})}}_transportSendCommands(e){if(!e.length)return!0;if(!this._transport)return!1;try{this._transport.send(this._codec.encodeCommands(e),this._session,this._node)}catch(t){return this._debug("error writing commands",t),this._handleWriteError(e),!1}return!0}_initializeTransport(){let e,t;null!==this._config.websocket?e=this._config.websocket:("function"==typeof globalThis.WebSocket||"object"==typeof globalThis.WebSocket)&&(e=globalThis.WebSocket);let s=null;null!==this._config.sockjs?s=this._config.sockjs:void 0!==globalThis.SockJS&&(s=globalThis.SockJS);let i=null;null!==this._config.eventsource?i=this._config.eventsource:void 0!==globalThis.EventSource&&(i=globalThis.EventSource);let r=null;null!==this._config.fetch?r=this._config.fetch:void 0!==globalThis.fetch&&(r=globalThis.fetch);let n=null;if(null!==this._config.readableStream?n=this._config.readableStream:void 0!==globalThis.ReadableStream&&(n=globalThis.ReadableStream),this._emulation){this._currentTransportIndex>=this._transports.length&&(this._triedAllTransports=!0,this._currentTransportIndex=0);let t=0;for(;;){if(t>=this._transports.length)throw Error("no supported transport found");let o=this._transports[this._currentTransportIndex],a=o.transport,h=o.endpoint;if("websocket"===a){if(this._debug("trying websocket transport"),this._transport=new I(h,{websocket:e}),!this._transport.supported()){this._debug("websocket transport not available"),this._currentTransportIndex++,t++;continue}}else if("webtransport"===a){if(this._debug("trying webtransport transport"),this._transport=new j(h,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("webtransport transport not available"),this._currentTransportIndex++,t++;continue}}else if("http_stream"===a){if(this._debug("trying http_stream transport"),this._transport=new M(h,{fetch:r,readableStream:n,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("http_stream transport not available"),this._currentTransportIndex++,t++;continue}}else if("sse"===a){if(this._debug("trying sse transport"),this._transport=new U(h,{eventsource:i,fetch:r,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug("sse transport not available"),this._currentTransportIndex++,t++;continue}}else if("sockjs"===a){if(this._debug("trying sockjs"),this._transport=new O(h,{sockjs:s,sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug("sockjs transport not available"),this._currentTransportIndex++,t++;continue}}else throw Error("unknown transport "+a);break}}else{var o;if(o=this._endpoint,0===o.lastIndexOf("http",0))throw Error("Provide explicit transport endpoints configuration in case of using HTTP (i.e. using array of TransportEndpoint instead of a single str
2ing), or use ws(s):// scheme in an endpoint if you aimed using WebSocket transport");if(this._debug("client will use websocket"),this._transport=new I(this._endpoint,{websocket:e}),!this._transport.supported())throw Error("WebSocket constructor not found, make sure it is available globally or passed as a dependency in Centrifuge options")}let a=this,h=this._transport,l=this._nextTransportId();a._debug("id of transport",l);let c=!1,u=[];if(this._transport.emulation()){let e=a._sendConnect(!0);u.push(e)}this._setNetworkEvents();let d=this._codec.encodeCommands(u);this._transportClosed=!1,t=setTimeout(function(){h.close()},this._config.timeout),this._transport.initialize(this._codecName(),{onOpen:function(){if(t&&(clearTimeout(t),t=null),a._transportId!=l){a._debug("open callback from non-actual transport"),h.close();return}c=!0,a._debug(h.subName(),"transport open"),h.emulation()||(a._transportIsOpen=!0,a._transportWasOpen=!0,a.startBatching(),a._sendConnect(!1),a._sendSubscribeCommands(),a.stopBatching(),a.emit("__centrifuge_debug:connect_frame_sent",{}))},onError:function(e){a._transportId!=l?a._debug("error callback from non-actual transport"):a._debug("transport level error",e)},onClose:function(e){if(t&&(clearTimeout(t),t=null),a._transportId!=l)return void a._debug("close callback from non-actual transport");a._debug(h.subName(),"transport closed"),a._transportClosed=!0,a._transportIsOpen=!1;let s="connection closed",i=!0,r=0;if(e&&"code"in e&&e.code&&(r=e.code),e&&e.reason)try{let t=JSON.parse(e.reason);s=t.reason,i=t.reconnect}catch(t){s=e.reason,(r>=3500&&r<4e3||r>=4500&&r<5e3)&&(i=!1)}r<3e3?(1009===r?(r=f.messageSizeLimit,s="message size limit exceeded",i=!1):(r=p.transportClosed,s="transport closed"),a._emulation&&!a._transportWasOpen&&(a._currentTransportIndex++,a._currentTransportIndex>=a._transports.length&&(a._triedAllTransports=!0,a._currentTransportIndex=0))):a._transportWasOpen=!0,a._isConnecting()&&!c&&a.emit("error",{type:"transport",error:{code:_.transportClosed,message:"transport closed"},transport:h.name()}),a._reconnecting=!1,a._disconnect(r,s,i)},onMessage:function(e){a._dataReceived(e)}},d),a.emit("__centrifuge_debug:transport_initialized",{})}_sendConnect(e){let t=this._constructConnectCommand(),s=this;return this._call(t,e).then(e=>{let t=e.reply.connect;s._connectResponse(t),e.next&&e.next()},e=>{s._connectError(e.error),e.next&&e.next()}),t}_startReconnecting(){if(this._debug("start reconnecting"),!this._isConnecting())return void this._debug("stop reconnecting: client not in connecting state");if(this._reconnecting)return void this._debug("reconnect already in progress, return from reconnect routine");if(!1===this._transportClosed)return void this._debug("waiting for transport close");this._reconnecting=!0;let e=""===this._token;if(!(this._refreshRequired||e&&null!==this._config.getToken))return void(this._config.getData?this._config.getData().then(e=>{this._isConnecting()&&(this._data=e,this._initializeTransport())}).catch(e=>this._handleGetDataError(e)):this._initializeTransport());let t=this;this._getToken().then(function(e){if(t._isConnecting()){if(null==e||void 0==e)return void t._failUnauthorized();t._token=e,t._debug("connection token refreshed"),t._config.getData?t._config.getData().then(function(e){t._isConnecting()&&(t._data=e,t._initializeTransport())}).catch(e=>t._handleGetDataError(e)):t._initializeTransport()}}).catch(function(e){if(!t._isConnecting())return;if(e instanceof F)return void t._failUnauthorized();t.emit("error",{type:"connectToken",error:{code:_.clientConnectToken,message:void 0!==e?e.toString():""}});let s=t._getReconnectDelay();t._debug("error on getting connection token, reconnect after "+s+" milliseconds",e),t._reconnecting=!1,t._reconnectTimeout=setTimeout(()=>{t._startReconnecting()},s)})}_handleGetDataError(e){if(e instanceof F)return void this._failUnauthorized();this.emit("error",{type:"connectData",error:{code:_.badConfiguration,message:(null==e?void 0:e.toString())||""}});let t=this._getReconnectDelay();this._debug("error on getting connect data, reconnect after "+t+" milliseconds",e),this._reconnecting=!1,this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},t)}_connectError(e){this.state===v.Connecting&&(109===e.code&&(this._refreshRequired=!0),e.code<100||!0===e.temporary||109===e.code?(this.emit
2("error",{type:"connect",error:e}),this._debug("closing transport due to connect error"),this._disconnect(e.code,e.message,!0)):this._disconnect(e.code,e.message,!1))}_scheduleReconnect(){if(!this._isConnecting())return;let e=!1;!this._emulation||this._transportWasOpen||this._triedAllTransports||(e=!0);let t=this._getReconnectDelay();e&&(t=0),this._debug("reconnect after "+t+" milliseconds"),this._clearReconnectTimeout(),this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},t)}_constructConnectCommand(){let e={};this._token&&(e.token=this._token),this._data&&(e.data=this._data),this._config.name&&(e.name=this._config.name),this._config.version&&(e.version=this._config.version),Object.keys(this._config.headers).length>0&&(e.headers=this._config.headers);let t={},s=!1;for(let e in this._serverSubs)if(this._serverSubs.hasOwnProperty(e)&&this._serverSubs[e].recoverable){s=!0;let i={recover:!0};this._serverSubs[e].offset&&(i.offset=this._serverSubs[e].offset),this._serverSubs[e].epoch&&(i.epoch=this._serverSubs[e].epoch),t[e]=i}return s&&(e.subs=t),{connect:e}}_getHistoryRequest(e,t){let s={channel:e};return void 0!==t&&(t.since&&(s.since={offset:t.since.offset},t.since.epoch&&(s.since.epoch=t.since.epoch)),void 0!==t.limit&&(s.limit=t.limit),!0===t.reverse&&(s.reverse=!0)),s}_methodCall(){return this._isConnected()?Promise.resolve():new Promise((e,t)=>{let s=setTimeout(function(){t({code:_.timeout,message:"timeout"})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:s,resolve:e,reject:t}})}_callPromise(e,t){return new Promise((s,i)=>{this._call(e,!1).then(e=>{var i;s(t(e.reply)),null==(i=e.next)||i.call(e)},e=>{var t;i(e.error),null==(t=e.next)||t.call(e)})})}_dataReceived(e){this._serverPing>0&&this._waitServerPing();let t=this._codec.decodeReplies(e);this._dispatchPromise=this._dispatchPromise.then(()=>{let e;this._dispatchPromise=new Promise(t=>{e=t}),this._dispatchSynchronized(t,e)})}_dispatchSynchronized(e,t){let s=Promise.resolve();for(let t in e)e.hasOwnProperty(t)&&(s=s.then(()=>this._dispatchReply(e[t])));s.then(()=>{t()})}_dispatchReply(e){let t,s=new Promise(e=>{t=e});if(null==e)return this._debug("dispatch: got undefined or null reply"),t(),s;let i=e.id;return i&&i>0?this._handleReply(e,t):e.push?this._handlePush(e.push,t):this._handleServerPing(t),s}_call(e,t){return new Promise((s,i)=>{e.id=this._nextCommandId(),this._registerCall(e.id,s,i),t||this._addCommand(e)})}_startConnecting(){this._debug("start connecting"),this._setState(v.Connecting)&&this.emit("connecting",{code:p.connectCalled,reason:"connect called"}),this._client=null,this._startReconnecting()}_disconnect(e,t,s){if(e===f.stateInvalidated)for(let e in this._token="",this._refreshRequired=!0,this._subs)this._subs.hasOwnProperty(e)&&this._subs[e]._invalidateState();if(this._isDisconnected())return;this._transportIsOpen=!1;let i=this.state;this._reconnecting=!1;let r={code:e,reason:t},n=!1;if(s?n=this._setState(v.Connecting):(n=this._setState(v.Disconnected),this._rejectPromises({code:_.clientDisconnected,message:"disconnected"})),this._clearOutgoingRequests(),i===v.Connecting&&this._clearReconnectTimeout(),i===v.Connected&&this._clearConnectedState(),n&&(this._isConnecting()?this.emit("connecting",r):this.emit("disconnected",r)),this._transport){this._debug("closing existing transport");let e=this._transport;this._transport=null,e.close(),this._transportClosed=!0,this._nextTransportId()}else this._debug("no transport to close");this._scheduleReconnect()}_failUnauthorized(){this._disconnect(f.unauthorized,"unauthorized",!1)}_getToken(){return(this._debug("get connection token"),this._config.getToken)?this._config.getToken({}):(this.emit("error",{type:"configuration",error:{code:_.badConfiguration,message:"token expired but no getToken function set in the configuration"}}),Promise.reject(new F("")))}_refresh(){let e=this._client,t=this;this._getToken().then(function(s){if(e!==t._client)return;if(!s)return void t._failUnauthorized();if(t._token=s,t._debug("connection token refreshed"),!t._isConnected())return;let i={refresh:{token:t._token}};t._call(i,!1).then(e=>{let s=e.reply.refresh;t._refreshResponse(s),e.next&&e.next()},e=>{t._refreshError(e.error),e.next&&e.next()})}
2).catch(function(e){if(t._isConnected()){if(e instanceof F)return void t._failUnauthorized();t.emit("error",{type:"refreshToken",error:{code:_.clientRefreshToken,message:void 0!==e?e.toString():""}}),t._refreshTimeout=setTimeout(()=>t._refresh(),t._getRefreshRetryDelay())}})}_refreshError(e){e.code<100||!0===e.temporary?(this.emit("error",{type:"refresh",error:e}),this._refreshTimeout=setTimeout(()=>this._refresh(),this._getRefreshRetryDelay())):this._disconnect(e.code,e.message,!1)}_getRefreshRetryDelay(){return R(0,5e3,1e4)}_refreshResponse(e){this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),e.expires&&(this._client=e.client,this._refreshTimeout=setTimeout(()=>this._refresh(),w(e.ttl)))}_removeSubscription(e){null!==e&&delete this._subs[e.channel]}_unsubscribe(e){if(!this._transportIsOpen)return Promise.resolve();let t={unsubscribe:{channel:e.channel}},s=this;return new Promise((e,i)=>{this._call(t,!1).then(t=>{e(),t.next&&t.next()},t=>{e(),t.next&&t.next(),s._disconnect(p.unsubscribeError,"unsubscribe error",!0)})})}_getSub(e,t){if(t&&t>0){for(let e in this._subs)if(this._subs.hasOwnProperty(e)){let s=this._subs[e];if(s._id===t)return s}return null}let s=this._subs[e];return s||null}_isServerSub(e){return void 0!==this._serverSubs[e]}_sendSubscribeCommands(){let e=[];for(let t in this._subs){if(!this._subs.hasOwnProperty(t))continue;let s=this._subs[t];if(!0!==s._inflight&&s.state===S.Subscribing){let t=s._subscribe();t&&e.push(t)}}return e}_connectResponse(e){if(this._transportIsOpen=!0,this._transportWasOpen=!0,this._reconnectAttempts=0,this._refreshRequired=!1,this._isConnected())return;this._client=e.client,this._setState(v.Connected),this._refreshTimeout&&clearTimeout(this._refreshTimeout),e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),w(e.ttl))),this._session=e.session,this._node=e.node,this.startBatching(),this._sendSubscribeCommands(),this.stopBatching();let t={client:e.client,transport:this._transport.subName()};e.data&&(t.data=e.data),this.emit("connected",t),this._resolvePromises(),this._processServerSubs(e.subs||{}),e.ping&&e.ping>0?(this._serverPing=1e3*e.ping,this._sendPong=!0===e.pong,this._waitServerPing()):this._serverPing=0}_processServerSubs(e){for(let t in e){if(!e.hasOwnProperty(t))continue;let s=e[t];this._serverSubs[t]={offset:s.offset,epoch:s.epoch,recoverable:s.recoverable||!1};let i=this._getSubscribeContext(t,s);this.emit("subscribed",i)}for(let t in e){if(!e.hasOwnProperty(t))continue;let s=e[t];if(s.recovered){let e=s.publications;if(e&&e.length>0)for(let s in e)e.hasOwnProperty(s)&&this._handlePublication(t,e[s])}}for(let t in this._serverSubs)this._serverSubs.hasOwnProperty(t)&&(e[t]||(this.emit("unsubscribed",{channel:t}),delete this._serverSubs[t]))}_clearRefreshTimeout(){null!==this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null)}_clearReconnectTimeout(){null!==this._reconnectTimeout&&(clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null)}_clearServerPingTimeout(){null!==this._serverPingTimeout&&(clearTimeout(this._serverPingTimeout),this._serverPingTimeout=null)}_waitServerPing(){0===this._config.maxServerPingDelay||this._isConnected()&&(this._clearServerPingTimeout(),this._serverPingTimeout=setTimeout(()=>{this._isConnected()&&this._disconnect(p.noPing,"no ping",!0)},this._serverPing+this._config.maxServerPingDelay))}_getSubscribeContext(e,t){let s={channel:e,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1,hasRecoveredPublications:!1};t.recovered&&(s.recovered=!0),t.positioned&&(s.positioned=!0),t.recoverable&&(s.recoverable=!0),t.was_recovering&&(s.wasRecovering=!0);let i="";"epoch"in t&&(i=t.epoch);let r=0;return"offset"in t&&(r=t.offset),(s.positioned||s.recoverable)&&(s.streamPosition={offset:r,epoch:i}),Array.isArray(t.publications)&&t.publications.length>0&&(s.hasRecoveredPublications=!0),t.data&&(s.data=t.data),s}_handleReply(e,t){let s=e.id;if(!(s in this._callbacks))return void t();let i=this._callbacks[s];if(clearTimeout(this._callbacks[s].timeout),delete this._callbacks[s],"error"in e&&null!==e.error){let s=i.errback;if(!s)return void t();s({error:{code:e.error.code,message:e.error.message||"",temporary:e.error.temporary||!1},next:t})}else{let s=i.callback;if(!s)return;s({reply:e,next:t})}}_handleJoin(e,t,s){let i=this._getSub(e,s);if(!i){if(e&&this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(t.info)};
2this.emit("join",s)}return}i._handleJoin(t)}_handleLeave(e,t,s){let i=this._getSub(e,s);if(!i){if(e&&this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(t.info)};this.emit("leave",s)}return}i._handleLeave(t)}_handleUnsubscribe(e,t){let s=this._getSub(e,0);if(!s&&e){this._isServerSub(e)&&(delete this._serverSubs[e],this.emit("unsubscribed",{channel:e}));return}t.code<2500?s._setUnsubscribed(t.code,t.reason,!1):(t.code===g.stateInvalidated&&s._invalidateState(),s._setSubscribing(t.code,t.reason))}_handleSubscribe(e,t){this._serverSubs[e]={offset:t.offset,epoch:t.epoch,recoverable:t.recoverable||!1},this.emit("subscribed",this._getSubscribeContext(e,t))}_handleDisconnect(e){let t=e.code,s=!0;(t>=3500&&t<4e3||t>=4500&&t<5e3)&&(s=!1),this._disconnect(t,e.reason,s)}_getPublicationContext(e,t){let s={channel:e,data:t.data};return t.offset&&(s.offset=t.offset),t.info&&(s.info=this._getJoinLeaveContext(t.info)),t.tags&&(s.tags=t.tags),s}_getJoinLeaveContext(e){let t={client:e.client,user:e.user},s=e.conn_info;s&&(t.connInfo=s);let i=e.chan_info;return i&&(t.chanInfo=i),t}_handlePublication(e,t,s){let i=this._getSub(e,s);if(!i){if(e&&this._isServerSub(e)){let s=this._getPublicationContext(e,t);this.emit("publication",s),void 0!==t.offset&&(this._serverSubs[e].offset=t.offset)}return}i._handlePublication(t)}_handleMessage(e){this.emit("message",{data:e.data})}_handleServerPing(e){this._sendPong&&this._transportSendCommands([{}]),e()}_handlePush(e,t){let s=e.channel,i=e.id;e.pub?this._handlePublication(s,e.pub,i):e.message?this._handleMessage(e.message):e.join?this._handleJoin(s,e.join,i):e.leave?this._handleLeave(s,e.leave,i):e.unsubscribe?this._handleUnsubscribe(s,e.unsubscribe):e.subscribe?this._handleSubscribe(s,e.subscribe):e.disconnect&&this._handleDisconnect(e.disconnect),t()}_flush(){let e=this._commands.slice(0);this._commands=[],this._transportSendCommands(e)}_createErrorObject(e,t,s){let i={code:e,message:t};return s&&(i.temporary=!0),i}_registerCall(e,t,s){this._callbacks[e]={callback:t,errback:s,timeout:null},this._callbacks[e].timeout=setTimeout(()=>{delete this._callbacks[e],k(s)&&s({error:this._createErrorObject(_.timeout,"timeout")})},this._config.timeout)}_addCommand(e){this._batching?this._commands.push(e):this._transportSendCommands([e])}_nextPromiseId(){return++this._promiseId}_nextTransportId(){return++this._transportId}_resolvePromises(){for(let e in this._promises)this._promises.hasOwnProperty(e)&&(this._promises[e].timeout&&clearTimeout(this._promises[e].timeout),this._promises[e].resolve(),delete this._promises[e])}_rejectPromises(e){for(let t in this._promises)this._promises.hasOwnProperty(t)&&(this._promises[t].timeout&&clearTimeout(this._promises[t].timeout),this._promises[t].reject(e),delete this._promises[t])}}G.SubscriptionState=S,G.State=v,G.UnauthorizedError=F,e.s(["Centrifuge",0,G,"State",0,v,"SubscriptionState",0,S],271734);var W=e.i(716584);function q(e){return e?.method==="subscription"}e.s(["K_CENTRIFUGE_EXPIRED_TRESHOLD_TIME",0,45e3,"K_PRO_CENTRIFUGE_WS_DEBUG_MODE",0,!1,"K_PRO_CENTRIFUGE_WS_URL",0,"wss://centrifuge.pintu.pro/centrifuge"],996479),e.s(["debugCentrifuge",0,function(e){},"wsResponseIsSubsciption",0,q,"wsResponseIsSubsciptionAndHasChannel",0,function(e,t){return q(e)&&!(0,W.isEmpty)(t)&&e.channel===t}],300433);var V=e.i(192290);let J=V.default.createContext(void 0);e.s(["default",0,J],407036),e.s(["default",0,function(){let e=V.default.useContext(J);if(void 0===e)throw Error("useCentrifuge must be used within a CentrifugeProvider");return e}],460069)}]); 3 4//# debugId=6266068d-d2f9-0fec-f2c8-6a6967196797 5//# sourceMappingURL=1vujrf0zctcme.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.