PageSourceSearch

https://tldv.io/app/assets/meeting-D1AwyuOc.js

js tldv.io collected 2026-10-01 11:42:20 UTC 85,969 bytes, 8 lines download raw bytes

vendor: 4,428 bytes, line 1
1import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{A as t,j as n}from"./react-vendor-BERBVPaj.js";import{C as r,S as i,k as a}from"./policies-C74xZeOL.js";import{t as o}from"./logger-C4ee1UZI.js";import{i as s,n as c}from"./firebase-CR_sTUNN.js";function l(e=200){let t=new Set;return{isDuplicate(n){if(!n)return!1;if(t.has(n))return!0;if(t.add(n),t.size>e){let e=t.values().next().value;e!==void 0&&t.delete(e)}return!1}}}function u(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||(n=Promise))(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function d(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}var f={exports:{}},p;function m(){if(p)return f.exports;p=1;var e=typeof Reflect==`object`?Reflect:null,t=e&&typeof e.apply==`function`?e.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},n=e&&typeof e.ownKeys==`function`?e.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function r(e){console&&console.warn&&console.warn(e)}var i=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}f.exports=a,f.exports.once=y,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var o=10;function s(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if(typeof e!=`number`||e<0||i(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);o=e}}),a.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if(typeof e!=`number`||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};function c(e){return e._maxListeners===void 0?a.defaultMaxListeners:e._maxListeners}a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e===`error`,a=this._events;if(a!==void 0)i=i&&a.error===void 0;else if(!i)return!1;if(i){var o;if(n.length>0&&(o=n[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)t(c,this,n);else for(var l=c.length,u=g(c,l),r=0;r<l;++r)t(u[r],this,n);return!0};function l(e,t,n,i){var a,o,l;if(s(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),l=o[t]),l===void 0)l=o[t]=n,++e._eventsCount;else if(typeof l==`function`?l=o[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),a=c(e),a>0&&l.length>a&&!l.warned){l.warned=!0;var u=Error(`Possible EventEmitter memory leak detected. `+l.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);u.name=`MaxListenersExceededWarning`,u.emitter=e,u.type=t,u.count=l.length,r(u)}return e}a.prototype.addListener=function(e,t){return l(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return l(this,e,t,!0)};function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=u.bind(r);return i.listener=n,r.wrapFn=i,i}a.prototype.once=function(e,t){return s(t),this.on(e,d(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,d(this,e,t)),this},a.prototype.removeListener=function(e,t){var n,r,i,a,o;if(s(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit
1(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}a.prototype.listeners=function(e){return m(this,e,!0)},a.prototype.rawListeners=function(e){return m(this,e,!1)},a.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},a.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}return f.exports}var h=d(m()),g;(function(e){e[e.timeout=1]=`timeout`,e[e.transportClosed=2]=`transportClosed`,e[e.clientDisconnected=3]=`clientDisconnected`,e[e.clientClosed=4]=`clientClosed`,e[e.clientConnectToken=5]=`clientConnectToken`,e[e.clientRefreshToken=6]=`clientRefreshToken`,e[e.subscriptionUnsubscribed=7]=`subscriptionUnsubscribed`,e[e.subscriptionSubscribeToken=8]=`subscriptionSubscribeToken`,e[e.subscriptionRefreshToken=9]=`subscriptionRefreshToken`,e[e.transportWriteError=10]=`transportWriteError`,e[e.connectionClosed=11]=`connectionClosed`,e[e.badConfiguration=12]=`badConfiguration`,e[e.subscriptionGetState=13]=`subscriptionGetState`,e[e.sharedPollGetSignature=14]=`sharedPollGetSignature`})(g||(g={}));var _;(function(e){e[e.connectCalled=0]=`connectCalled`,e[e.transportClosed=1]=`transportClosed`,e[e.noPing=2]=`noPing`,e[e.subscribeTimeout=3]=`subscribeTimeout`,e[e.unsubscribeError=4]=`unsubscribeError`})(_||(_={}));var v;(function(e){e[e.disconnectCalled=0]=`disconnectCalled`,e[e.unauthorized=1]=`unauthorized`,e[e.badProtocol=2]=`badProtocol`,e[e.messageSizeLimit=3]=`messageSizeLimit`,e[e.stateInvalidated=3014]=`stateInvalidated`})(v||(v={}));var y;(function(e){e[e.subscribeCalled=0]=`subscribeCalled`,e[e.transportClosed=1]=`transportClosed`})(y||(y={}));var b;(function(e){e[e.unsubscribeCalled=0]=`unsubscribeCalled`,e[e.unauthorized=1]=`unauthorized`,e[e.clientClosed=2]=`clientClosed`,e[e.stateInvalidated=2502]=`stateInvalidated`})(b||(b={}));var x;(function(e){e[e.channelCompaction=1]=`channelCompaction`,e[e.rejectUnrecovered=2]=`rejectUnrecovered`})(x||(x={}));var S;(function(e){e.Disconnected=`disconnected`,e.Connecting=`connecting`,e.Connected=`connected`})(S||(S={}));var C;(function(e){e.Unsubscribed=`unsubscribed`,e.Subscribing=`subscribing`,e.Subscribed=`subscribed`})(C||(C={}));function w(e,t){return e.lastIndexOf(t,0)===0}function T(e){return e!=null&&typeof e==`function`}function ee(e,t){if(globalThis.console){let n=globalThis.console[e];T(n)&&n.apply(globalThis.console,t)}}function E(e,t){return Math.floor(Math.random()*(t-e+1)+e)}function D(e,t,n){e>31&&(e=31);let r=E(0,Math.min(n,t*2**e));return Math.min(n,t+r)}function O(e){return`error`in e&&e.error!==null}function k(e){return Math.min(e*1e3,2147483647)}function A(e){try{return typeof localStorage>`u`||localStorage===null||!T(localStorage.getItem)?null:localStorage.getItem(e)}catch{return null}}var j;(function(e){e[e.Live=0]=`Live`,e[e.Stream=1]=`Stream`,e[e.State=2]=`State`})(j||(j={}));var M=class extends h{constructor(e,t,n){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
1InFlight=!1,this.channel=t,this.state=C.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(n),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===C.Unsubscribed?Promise.reject({code:g.subscriptionUnsubscribed,message:this.state}):this.state===C.Subscribed?Promise.resolve():new Promise((t,n)=>{let r={resolve:t,reject:n};e&&(r.timeout=setTimeout(function(){n({code:g.timeout,message:`timeout`})},e)),this._promises[this._nextPromiseId()]=r})}subscribe(){this._isSubscribed()||(this._resubscribeAttempts=0,this._setSubscribing(y.subscribeCalled,`subscribe called`))}unsubscribe(){this._unsubPromise=this._setUnsubscribed(b.unsubscribeCalled,`unsubscribe called`,!0)}_debouncedPublish(e,t,n){let r=this._debouncePending.get(e);if(r)return r.data=t,r.dirty=!0,Promise.resolve({});let i={data:t,dirty:!1,timer:null};return i.timer=setTimeout(()=>{let t=this._debouncePending.get(e);if(!t||!t.dirty){this._debouncePending.delete(e);return}t.dirty=!1;let r=t.data;(n?this._centrifuge.mapPublish(this.channel,e,r):this._centrifuge.publish(this.channel,r)).catch(()=>{}),t.timer=setTimeout(()=>{let t=this._debouncePending.get(e);if(!t||!t.dirty){this._debouncePending.delete(e);return}this._debouncePending.delete(e),this._debouncedPublish(e,t.data,n)},this._debounceMs)},this._debounceMs),this._debouncePending.set(e,i),n?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 u(this,void 0,void 0,function*(){return yield this._methodCall(),this._centrifuge.presence(this.channel)})}presenceStats(){return u(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:g.subscriptionUnsubscribed,message:this.state}):new Promise((e,t)=>{let n=this._centrifuge._config.timeout,r=setTimeout(()=>{t({code:g.timeout,message:`timeout`})},n);this._promises[this._nextPromiseId()]={timeout:r,resolve:e,reject:t}})}_nextPromiseId(){return++this._promiseId}_needRecover(){return this._recover===!0}_isUnsubscribed(){return this.state===C.Unsubscribed}_isSubscribing(){return this.state===C.Subscribing}_isSubscribed(){return this.state===C.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!==``||this._getToken!==null}_clearSubscribingState(){this._resubscribeAttempts=0,this._clearResubscribeTimeout()}_clearSubscribedState(){this._clearRefreshTimeout(),this._cancelAllDebounce(),this._clearSharedPollSignatureRefresh(),this._clearSharedPollTrackRetry(),this._clearSharedPollReplayRetry(),this._sharedPollSignatureRefreshTargetMs=null,this._sharedPollSignatureRefresh
1InFlight=!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||``),this._delta_negotiated=!!e.delta,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(C.Subscribed);let t=this._centrifuge._getSubscribeContext(this.channel,e);this.emit(`subscribed`,t),this._resolvePromises();let n=e.publications;if(n&&n.length>0)for(let e in n)n.hasOwnProperty(e)&&this._handlePublication(n[e]);e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),k(e.ttl)))}_setSubscribing(e,t){return u(this,void 0,void 0,function*(){this._isSubscribing()||(this._isSubscribed()&&this._clearSubscribedState(),this._id=0,this._setState(C.Subscribing)&&this.emit(`subscribing`,{channel:this.channel,code:e,reason:t}),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&&this._offset===null?(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:g.subscriptionGetState,message: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 V){this._inflight=!1,this._failUnauthorized();return}this.emit(`error`,{type:`subscribeData`,channel:this.channel,error:{code:g.badConfiguration,message: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 V){this._inflight=!1,this._failUnauthorized();return}this.emit(`error`,{type:`subscribeToken`,channel:this.channel,error:{code:g.subscriptionSubscribeToken,message: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};
1if(this._positioned&&(t.positioned=!0),this._recoverable&&(t.recoverable=!0),this._joinLeave&&(t.join_leave=!0),t.flag=x.channelCompaction,this._getState&&(t.flag|=x.rejectUnrecovered),this._needRecover()){t.recover=!0;let e=this._getOffset();e&&(t.offset=e);let n=this._getEpoch();n&&(t.epoch=n)}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===g.timeout){this._centrifuge._disconnect(_.subscribeTimeout,`subscribe timeout`,!0);return}if(e.code===112&&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,n){if(this._isUnsubscribed())return Promise.resolve();let r=Promise.resolve();return this._isSubscribed()?(n&&(r=this._centrifuge._unsubscribe(this)),this._clearSubscribedState()):this._isSubscribing()&&(this._inflight&&n&&(r=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(C.Unsubscribed)&&this.emit(`unsubscribed`,{channel:this.channel,code:e,reason:t}),this._rejectPromises({code:g.subscriptionUnsubscribed,message:this.state}),r}_handlePublication(e){if(this._delta&&this._delta_negotiated){let t=(this._map||this._sharedPoll)&&e.key||``,{newData:n,newPrevValue:r,isDelta:i,wireBytes:a,fullBytes:o}=this._centrifuge._codec.applyDeltaIfNeeded(e,this._prevValueMap.get(t));e.data=n,this._deltaNumPubs++,this._deltaBytesReceived+=a,this._deltaBytesDecoded+=o,i?this._deltaNumDelta++:this._deltaNumFull++,e.removed?this._prevValueMap.delete(t):this._prevValueMap.set(t,r)}let t;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(typeof e.data==`string`){let t=e.data,n=new TextEncoder().encode(t);e.removed?this._prevValueMap.delete(e.key):this._prevValueMap.set(e.key,n);let r=n.length;this._deltaNumPubs++,this._deltaNumFull++,this._deltaBytesReceived+=r,this._deltaBytesDecoded+=r,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()){this._debug(`not in subscribing state, skip resubscribe scheduling`,this.channel);return}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||e.code===109||e.temporary===!0){e.code===109&&(this._token=``);let t={channel:this.channel,type:`subscribe`,error:e};
1this._centrifuge.state===S.Connected&&this.emit(`error`,t),this._scheduleResubscribe()}else this._setUnsubscribed(e.code,e.message,!1)}}_getResubscribeDelay(){let e=D(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),e.minResubscribeDelay!==void 0&&(this._minResubscribeDelay=e.minResubscribeDelay),e.maxResubscribeDelay!==void 0&&(this._maxResubscribeDelay=e.maxResubscribeDelay),e.token&&(this._token=e.token),e.getToken&&(this._getToken=e.getToken),e.positioned===!0&&(this._positioned=!0),e.recoverable===!0&&(this._recoverable=!0),e.joinLeave===!0&&(this._joinLeave=!0),e.delta){if(e.delta!==`fossil`)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),e.map===!0&&(this._map=!0),e.mapPageSize!==void 0&&(this._mapPageSize=e.mapPageSize),e.mapPresenceType!==void 0&&(this._mapPresenceType=e.mapPresenceType,this._map=!0),e.mapUnrecoverableStrategy&&(this._mapUnrecoverableStrategy=e.mapUnrecoverableStrategy),e.sharedPoll===!0&&(this._sharedPoll=!0),e.sharedPollGetSignature&&(this._sharedPollGetSignature=e.sharedPollGetSignature)}}_getOffset(){let e=this._offset;return e===null?0:e}_getEpoch(){let e=this._epoch;return e===null?``:e}_clearRefreshTimeout(){this._refreshTimeout!==null&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null)}_clearResubscribeTimeout(){this._resubscribeTimeout!==null&&(clearTimeout(this._resubscribeTimeout),this._resubscribeTimeout=null)}_getSubscriptionToken(){this._debug(`get subscription token for channel`,this.channel);let e={channel:this.channel},t=this._getToken;
vendor: 11,891 bytes, line 1
1return t===null?(this.emit(`error`,{type:`configuration`,channel:this.channel,error:{code:g.badConfiguration,message:`provide a function to get channel subscription token`}}),Promise.reject(new V(``))):t(e)}_refresh(){this._clearRefreshTimeout();let e=this;this._getSubscriptionToken().then(function(t){if(!e._isSubscribed())return;if(!t){e._failUnauthorized();return}e._token=t;let n={sub_refresh:{channel:e.channel,token:t}};e._centrifuge._call(n).then(t=>{let n=t.reply.sub_refresh;e._refreshResponse(n),t.next&&t.next()},t=>{e._refreshError(t.error),t.next&&t.next()})}).catch(function(t){if(t instanceof V){e._failUnauthorized();return}e.emit(`error`,{type:`refreshToken`,channel:e.channel,error:{code:g.subscriptionRefreshToken,message:t===void 0?``:t.toString()}}),e._refreshTimeout=setTimeout(()=>e._refresh(),e._getRefreshRetryDelay())})}_refreshResponse(e){this._isSubscribed()&&(this._debug(`subscription token refreshed, channel`,this.channel),this._clearRefreshTimeout(),e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),k(e.ttl))))}_refreshError(e){this._isSubscribed()&&(e.code<100||e.temporary===!0?(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 D(0,1e4,2e4)}_failUnauthorized(){this._setUnsubscribed(b.unauthorized,`unauthorized`,!0)}_sendTrackRequest(e,t){if(e.length===0)return Promise.resolve();let n=[],r=[],i=100;if(t&&t.length>0)for(let e of t)i+=e.length+4;for(let t of e){let e=100;for(let n of t.items)e+=n.key.length+16;r.length>0&&i+e>6e4&&(n.push(r),r=[],i=100),r.push(t),i+=e}r.length>0&&n.push(r);let a=(e,t)=>new Promise((n,r)=>{let i={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&&(i.untrack=t);let a={sub_refresh:i};this._centrifuge._call(a).then(e=>{this._handleTrackResponse(e.reply.sub_refresh),e.next&&e.next(),n()},e=>{e.next&&e.next(),r(e.error)})});return n.reduce((e,n,r)=>e.then(()=>a(n,r===0?t:void 0)),Promise.resolve())}_sendUntrackRequest(e){return new Promise((t,n)=>{let r={sub_refresh:{channel:this.channel,type:2,untrack:e}};this._centrifuge._call(r).then(e=>{e.next&&e.next(),t()},e=>{e.next&&e.next(),n(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&&e.expires===!0&&e.ttl>0){let t=Date.now()+e.ttl*1e3;this._maybeScheduleSharedPollSignatureRefresh(t)}}_maybeScheduleSharedPollSignatureRefresh(e){if(e===null){this._sharedPollSignatureRefreshTargetMs=null,this._clearSharedPollSignatureRefresh();return}this._isSubscribed()&&(this._sharedPollSignatureRefreshTargetMs!==null&&e>=this._sharedPollSignatureRefreshTargetMs||(this._sharedPollSignatureRefreshTargetMs=e,this._clearSharedPollSignatureRefresh(),this._sharedPollSignatureRefreshTimeout=setTimeout(()=>this._sharedPollRefreshSignature(),Math.max(0,e-Date.now()))))}_clearSharedPollSignatureRefresh(){this._sharedPollSignatureRefreshTimeout!==null&&(clearTimeout(this._sharedPollSignatureRefreshTimeout),this._sharedPollSignatureRefreshTimeout=null),this._sharedPollSignatureRefreshAttempts=0}_clearSharedPollTrackRetry(){this._sharedPollTrackRetryTimeout!==null&&(clearTimeout(this._sharedPollTrackRetryTimeout),this._sharedPollTrackRetryTimeout=null),this._sharedPollTrackRetryAttempts=0}_clearSharedPollReplayRetry(){this._sharedPollReplayRetryTimeout!==null&&(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}),e.code===109){this._sharedPollRefreshSignature();return}(e.code<100||e.temporary===!0)&&(this._sharedPollTrackRetryTimeout=setTimeout(()=>this._sharedPollReplayTrack(),D(this._sharedPollTrackRetryAttempts++,1e3,15e3)))}}_sharedPollRefreshSignature(){if(this._clearSharedPollSignatureRefresh(),!this._isSubscribed()||!this._sharedPollGetSignature||this._sharedPollTrackedItems.size===0||this._sharedPollSignatureRefreshInFlight)return;this._sharedPollSignatureRefreshTargetMs=null,this._sharedPollSignatureRefreshInFlight=!0;let e=Array.from(this._sharedPollTrackedItems.keys()),t=this;this._sharedPollGetSignature({keys:e}).then(n=>{if(t._sharedPollSignatureRefreshInFlight=!1,!t._isSubscribed())return;t._sharedPollSignatureRefreshAttempts=0;let r=new Set(n.keys),i=[];for(let n of e)r.has(n)||(t._sharedPollTrackedItems.delete(n),i.push(n),t.emit(`update`,{channel:t.channel,key:n,data:null,removed:!0}));i.length>0&&t._sendUntrackRequest(i).catch(e=>{t.emit(`error`,{type:`untrack`,channel:t.channel,error:e})});let a=[];for(let e of n.keys){let n=t._sharedPollTrackedItems.get(e);n!==void 0&&a.push({key:e,version:n})}let o=new Set(n.keys),s=t._sharedPollSignatures.filter(e=>e.keys.some(e=>t._sharedPollTrackedItems.has(e)&&!o.has(e)));t._sharedPollSignatures=a.length>0?[{keys:n.keys,signature:n.signature},...s]:s,a.length!==0&&t._sendTrackRequest([{items:a,signature:n.signature}]).catch(e=>{t._handleTrackError(e)})}).catch(e=>{t._sharedPollSignatureRefreshInFlight=!1,t.emit(`error`,{type:`signatureRefresh`,channel:t.channel,error:{code:g.sharedPollGetSignature,message:e===void 0?``:e.toString()}}),t._sharedPollSignatureRefreshTimeout=setTimeout(()=>t._sharedPollRefreshSignature(),D(t._sharedPollSignatureRefreshAttempts++,5e3,3e4))})}_sharedPollReplayTrack(){if(!this._isSubscribed()||this._sharedPollTrackedItems.size===0&&this._sharedPollSignatures.length===0)return;let e=new Set,t=[],n=[];for(let r of this._sharedPollSignatures){let i=r.keys.map(e=>({key:e,version:this._sharedPollTrackedItems.get(e)??0}));t.push({items:i,signature:r.signature});for(let t of r.keys)this._sharedPollTrackedItems.has(t)?e.add(t):n.push(t)}t.length>0&&this._sendTrackRequest(t,n).catch(e=>{this._handleTrackError(e)});let r=[];for(let t of this._sharedPollTrackedItems.keys())e.has(t)||r.push(t);if(r.length===0)return;if(!this._sharedPollGetSignature){this.emit(`error`,{type:`track`,channel:this.channel,error:{code:g.sharedPollGetSignature,message:`getSignature callback required for tracked keys without an explicit signature`}});return}let i=this;this._sharedPollGetSignature({keys:r}).then(e=>{if(!i._isSubscribed())return;i._clearSharedPollReplayRetry();let t=new Set(e.keys),n=[];for(let e of r)t.has(e)||(i._sharedPollTrackedItems.delete(e),n.push(e),i.emit(`update`,{channel:i.channel,key:e,data:null,removed:!0}));n.length>0&&i._sendUntrackRequest(n).catch(e=>{i.emit(`error`,{type:`untrack`,channel:i.channel,error:e})});let a=[];for(let t of e.keys){let e=i._sharedPollTrackedItems.get(t);e!==void 0&&a.push({key:t,version:e})}a.length!==0&&(i._sharedPollSignatures.push({keys:e.keys,signature:e.signature}),i._sendTrackRequest([{items:a,signature:e.signature}]).catch(e=>{i._handleTrackError(e)}))}).catch(e=>{i.emit(`error`,{type:`signatureRefresh`,channel:i.channel,error:{code:g.sharedPollGetSignature,message:e===void 0?``:e.toString()}}),i._sharedPollReplayRetryTimeout=setTimeout(()=>i._sharedPollReplayTrack(),D(i._sharedPollReplayRetryAttempts++,5e3,3e4))})}_mapSubscribe(){if(this._debug(`starting map subscribe on`,this.channel),this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapCursor=``,this._recover&&this._offset!==null&&this._epoch!==null||(this._prevValueMap=new Map),this._mapPhase=j.State,this._recover&&this._offset!==null&&this._epoch!==null){this._debug(`map subscribe: recovering from position, skipping to stream phase`),this._mapPhase=j.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(j.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=>{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=j.Stream,this._fetchStream()}_fetchStream(){if(!this._isSubscribing()||!this._isTransportOpen()){this._inflight=!1;return}let e=this._buildMapSubscribeCommand(j.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=j.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));e.offset!==void 0&&(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=j.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:n,newPrevValue:r,isDelta:i,wireBytes:a,fullBytes:o}=this._centrifuge._codec.applyDeltaIfNeeded(t,this._prevValueMap.get(e));t.data=n,this._deltaNumPubs++,this._deltaBytesReceived+=a,this._deltaBytesDecoded+=o,i?this._deltaNumDelta++:this._deltaNumFull++,t.removed?this._prevValueMap.delete(e):this._prevValueMap.set(e,r)}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=e.recoverable===!0,this._delta_negotiated=!!e.delta,e.publish_debounce&&(this._debounceMs=e.publish_debounce),this._setState(C.Subscribed);let t=this._centrifuge._getSubscribeContext(this.channel,e);
1if(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=[]}this.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,e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),k(e.ttl)))}_handleMapSubscribeError(e){if(this._inflight=!1,this._isSubscribing()){if(e.code===g.timeout){this._centrifuge._disconnect(_.subscribeTimeout,`subscribe timeout`,!0);return}if(this._mapStateBuffer=[],this._mapStreamBuffer=[],this._mapPhase=null,this._prevValueMap=new Map,e.code===112&&this._mapUnrecoverableStrategy===`from_scratch`){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 n={channel:this.channel,type:this._mapPresenceType||1,phase:e};return this._token&&(n.token=this._token),this._tagsFilter&&(n.tf=this._tagsFilter),this._delta&&(n.delta=this._delta),n.flag=x.channelCompaction,e===j.State&&(this._mapPageSize>0&&(n.limit=this._mapPageSize),t&&(n.cursor=t),this._epoch?(n.offset=this._offset,n.epoch=this._epoch):this._data&&(n.data=this._data)),e===j.Stream&&(this._mapPageSize>0&&(n.limit=this._mapPageSize),n.offset=this._offset,n.epoch=this._epoch,this._recover&&(n.recover=!0,this._mapStreamBuffer.length===0&&this._data&&(n.data=this._data))),{subscribe:n}}_getMapUpdateContext(e){let t={channel:this.channel,data:e.data,key:e.key||``};return e.removed===!0&&(t.removed=!0),e.offset!==void 0&&(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 e.removed===!0&&(t.removed=!0),e.version!==void 0&&(t.version=e.version),t}},N=class extends M{publish(e){return u(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 u(this,void 0,void 0,function*(){return yield this._methodCall(),this._centrifuge.history(this.channel,e)})}},P=class extends M{publish(e,t){return u(this,void 0,void 0,function*(){return yield this._methodCall(),this._debounceMs>0?this._debouncedPublish(e,t,!0):this._centrifuge.mapPublish(this.channel,e,t)})}remove(e){return u(this,void 0,void 0,function*(){return yield this._methodCall(),this._cancelDebounce(e),this._centrifuge.mapRemove(this.channel,e)})}},te=class extends M{track(e,t){if(e.length===0)return;let n,r=t;n=typeof e[0]==`string`?e.map(e=>({key:e,version:0})):e;for(let e of n){let t=this._sharedPollTrackedItems.get(e.key);(t===void 0||e.version>t)&&this._sharedPollTrackedItems.set(e.key,e.version)}if(r!==void 0){this._sharedPollSignatures.push({keys:n.map(e=>e.key),signature:r}),this._isSubscribed()&&this._sendTrackRequest([{items:n,signature:r}]).catch(e=>{this._handleTrackError(e)});return}if(!this._sharedPollGetSignature){this.emit(`error`,{type:`track`,channel:this.channel,error:{code:g.sharedPollGetSignature,message:`getSignature callback required for track(keys)`}});return}if(!this._isSubscribed())return;let i=n.map(e=>e.key);this._sharedPollGetSignature({keys:i}).then(e=>{if(!this._isSubscribed())return;let t=new Set(e.keys),n=[];for(let e of i)t.has(e)||(this._sharedPollTrackedItems.delete(e),n.push(e),this.emit(`update`,{channel:this.channel,key:e,data:null,removed:!0}));n.length>0&&this._sendUntrackRequest(n).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);e!==void 0&&r.push({key:t,version:e})}r.length!==0&&(this._sharedPollSignatures.push({keys:e.keys,signature:e.signature}),this._sendTrackRequest([{items:r,signature:e.signature}]).catch(e=>{this._handleTrackError(e)}))}).catch(e=>
1{this.emit(`error`,{type:`track`,channel:this.channel,error:{code:g.sharedPollGetSignature,message:e===void 0?`getSignature failed`:e.toString()}})})}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=>{this.emit(`error`,{type:`untrack`,channel:this.channel,error:e})})}trackedKeys(){return new Set(this._sharedPollTrackedItems.keys())}},ne=class{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 this.options.sockjs!==null}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)}},F=class{constructor(e,t){this.endpoint=e,this.options=t,this._transport=null}name(){return`websocket`}subName(){return`websocket`}emulation(){return!1}supported(){return this.options.websocket!==void 0&&this.options.websocket!==null}initialize(e,t){let n=``;e===`protobuf`&&(n=`centrifuge-protobuf`),this._transport=n===``?new this.options.websocket(this.endpoint):new this.options.websocket(this.endpoint,n),e===`protobuf`&&(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)}},re=class{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,n){let r=new EventTarget,i=e.options.fetch;return i(t,n).then(e._handleErrors).then(t=>{r.dispatchEvent(new Event(`open`));let n=``,i=0,a=new Uint8Array,o=t.body.getReader();return new e.options.readableStream({start(t){function s(){return o.read().then(({done:o,value:c})=>{if(o){r.dispatchEvent(new Event(`close`)),t.close();return}try{if(e._protocol===`json`)for(n+=e._utf8decoder.decode(c,{stream:!0});i<n.length;)if(n[i]===`
2`){let e=n.substring(0,i);r.dispatchEvent(new MessageEvent(`message`,{data:e})),n=n.substring(i+1),i=0}else++i;else{let t=new Uint8Array(a.length+c.length);for(t.set(a),t.set(c,a.length),a=t;;){let t=e.options.decoder.decodeReply(a);if(t.ok){let e=a.slice(0,t.pos);r.dispatchEvent(new MessageEvent(`message`,{data:e})),a=a.slice(t.pos);continue}break}}}catch(e){r.dispatchEvent(new Event(`error`,{detail:e})),r.dispatchEvent(new Event(`close`)),t.close();return}s()}).catch(function(e){r.dispatchEvent(new Event(`error`,{detail:e})),r.dispatchEvent(new Event(`close`)),t.close()})}return s()}})}).catch(e=>{r.dispatchEvent(new Event(`error`,{detail:e})),r.dispatchEvent(new Event(`close`))}),r}supported(){return this.options.fetch!==null&&this.options.readableStream!==null&&typeof TextDecoder<`u`&&typeof AbortController<`u`&&typeof EventTarget<`u`&&typeof Event<`u`&&typeof MessageEvent<`u`&&typeof Error<`u`}initialize(e,t,n){this._protocol=e,this._abortController=new AbortController;let r,i;e===`json`?(r={Accept:`application/json`,"Content-Type":`application/json`},i=n):(r={Accept:`application/octet-stream`,"Content-Type":`application/octet-stream`},i=n);let a={method:`POST`,headers:r,body:i,mode:`cors`,credentials:`same-origin`,signal:this._abortController.signal},o=this._fetchEventTarget(this,this.endpoint,a);o.addEventListener(`open`,()=>{t.onOpen()}),o.addEventListener(`error`,e=>{this._abortController.abort(),t.onError(e)}),o.addEventListener(`close`,()=>{this._abortController.abort(),t.onClose({code:4,reason:`connection closed`})}),o.addEventListener(`message`,e=>{t.onMessage(e.data)})}close(){this._abortController.abort()}send(e,t,n){let r,i,a={session:t,node:n,data:e};this._protocol===`json`?(r={"Content-Type":`application/json`},i=JSON.stringify(a)):(r={"Content-Type":`application/octet-stream`},i=this.options.encoder.encodeEmulationRequest(a));let o=this.options.fetch,s={method:`POST`,headers:r,body:i,mode:`cors`,credentials:`same-origin`};o(this.options.emulationEndpoint,s)}},ie=class{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 this.options.eventsource!==null&&this.options.fetch!==null}initialize(e,t,n){let r;r=globalThis&&globalThis.document&&globalThis.document.baseURI?new URL(this.endpoint,globalThis.document.baseURI):new URL(this.endpoint),r.searchParams.append(`cf_connect`,n);let i=new this.options.eventsource(r.toString(),{});this._transport=i;let a=this;i.onopen=function(){t.onOpen()},i.onerror=function(e){i.close(),t.onError(e),t.onClose({code:4,reason:`connection closed`})},i.onmessage=function(e){t.onMessage(e.data)},a._onClose=function(){t.onClose({code:4,reason:`connection closed`})}}close(){this._transport.close(),this._onClose!==null&&this._onClose()}send(e,t,n){let r={session:t,node:n,data:e},i={"Content-Type":`application/json`},a=JSON.stringify(r),o=this.options.fetch,s={method:`POST`,headers:i,body:a,mode:`cors`,credentials:`same-origin`};o(this.options.emulationEndpoint,s)}},ae=class{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 this.options.webtransport!==void 0&&this.options.webtransport!==null}initialize(e,t){return u(this,void 0,void 0,function*(){let n;n=globalThis&&globalThis.document&&globalThis.document.baseURI?new URL(this.endpoint,globalThis.document.baseURI):new URL(this.endpoint),e===`protobuf`&&n.searchParams.append(`cf_protocol`,`protobuf`),this._protocol=e;let r=new EventTarget;this._transport=new this.options.webtransport(n.toString()),this._transport.closed.then(()=>{t.onClose({code:4,reason:`connection closed`})}).catch(()=>{t.onClose({code:4,reason:`connection closed`})});try{yield this._transport.ready}catch{this.close();return}let i;try{i=yield this._transport.createBidirectionalStream()}catch{this.close();return}this._stream=i,this._writer=this._stream.writable.getWriter(),r.addEventListener(`close`,()=>{t.onClose({code:4,reason:`connection closed`})}),r.addEventListener(`message`,e=>{t.onMessage(e.data)}),this._startReading(r),t.onOpen()})}_startReading(e){return u(this,void 0,void 0,function*(){let t=this._stream.readable.getReader(),n=``,r=0,i=new Uint8Array;try{for(;;){let{done:a,value:o}=yield t.read();if(o&&o.length>0){if(this._protocol===`json`)for(n+=this._utf8decoder.decode(o,{stream:!0});r<n.length;)if(n[r]===`
3`){let t=n.substring(0,r);e.dispatchEvent(new MessageEvent(`message`,{data:t})),n=n.substring(r+1),r=0}else++r;else{let t=new Uint8Array(i.length+o.length);for(t.set(i),t.set(o,i.length),i=t;;){let t=this.options.decoder.decodeReply(i);if(t.ok){let n=i.slice(0,t.pos);e.dispatchEvent(new MessageEvent(`message`,{data:n})),i=i.slice(t.pos);continue}break}}}if(a)break}}catch{e.dispatchEvent(new Event(`close`))}})}close(){return u(this,void 0,void 0,function*(){try{this._writer&&(yield this._writer.close()),this._transport.close()}catch{}})}send(e){return u(this,void 0,void 0,function*(){let t;t=this._protocol===`json`?new TextEncoder().encode(e+`
4`):e;try{yield this._writer.write(t)}catch{this.close()}})}},oe=[-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],se=class{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=0,t;for(;this.haveBytes()&&(t=oe[127&this.getByte()])>=0;)e=(e<<6)+t;return this.pos--,e>>>0}},I=class{constructor(){this.a=[]}toByteArray(e){return Array.isArray(e)?this.a:new Uint8Array(this.a)}putArray(e,t,n){for(let r=t;r<n;r++)this.a.push(e[r])}};function L(e){let t=0,n=0,r=0,i=0,a=0,o=e.length;for(;o>=16;)t=t+e[a+0]|0,n=n+e[a+1]|0,r=r+e[a+2]|0,i=i+e[a+3]|0,t=t+e[a+4]|0,n=n+e[a+5]|0,r=r+e[a+6]|0,i=i+e[a+7]|0,t=t+e[a+8]|0,n=n+e[a+9]|0,r=r+e[a+10]|0,i=i+e[a+11]|0,t=t+e[a+12]|0,n=n+e[a+13]|0,r=r+e[a+14]|0,i=i+e[a+15]|0,a+=16,o-=16;for(;o>=4;)t=t+e[a+0]|0,n=n+e[a+1]|0,r=r+e[a+2]|0,i=i+e[a+3]|0,a+=4,o-=4;switch(i=((i+(r<<8)|0)+(n<<16)|0)+(t<<24)|0,o){case 3:i=i+(e[a+2]<<8)|0;case 2:i=i+(e[a+1]<<16)|0;case 1:i=i+(e[a+0]<<24)|0}return i>>>0}function R(e,t){let n=0,r=new se(t),i=e.length,a=t.length,o=r.getInt();if(r.getChar()!==`
5`)throw Error(`size integer not terminated by '\\n'`);let s=new I;for(;r.haveBytes();){let t=r.getInt(),c;switch(r.getChar()){case`@`:if(c=r.getInt(),r.haveBytes()&&r.getChar()!==`,`)throw Error(`copy command not terminated by ','`);if(n+=t,n>o)throw Error(`copy exceeds output file size`);
5if(c+t>i)throw Error(`copy extends past end of input`);s.putArray(e,c,c+t);break;case`:`:if(n+=t,n>o)throw Error(`insert command gives an output larger than predicted`);if(t>a)throw Error(`insert count exceeds size of delta`);s.putArray(r.a,r.pos,r.pos+t),r.pos+=t;break;case`;`:{let r=s.toByteArray(e);if(t!==L(r))throw Error(`bad checksum`);if(n!==o)throw Error(`generated size does not match predicted size`);return r}default:throw Error(`unknown delta operator`)}}throw Error(`unterminated delta`)}var z=class{name(){return`json`}encodeCommands(e){return e.map(e=>JSON.stringify(e)).join(`
6`)}decodeReplies(e){return e.trim().split(`
7`).map(e=>JSON.parse(e))}applyDeltaIfNeeded(e,t){let n,r,i,a;if(e.delta){a=!0;let o=new TextEncoder().encode(e.data),s=R(t,o);n=JSON.parse(new TextDecoder().decode(s)),r=s,i=o.length}else a=!1,n=JSON.parse(e.data),r=new TextEncoder().encode(e.data),i=r.length;return{newData:n,newPrevValue:r,isDelta:a,wireBytes:i,fullBytes:r.length}}},B={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},V=class extends Error{constructor(e){super(e),this.name=this.constructor.name}},H=class extends h{constructor(e,t){super(),this._reconnectTimeout=null,this._refreshTimeout=null,this._serverPingTimeout=null,this.state=S.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 z,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({},B),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(this.getSubscription(e)!==null)throw Error(`Subscription to the channel `+e+` already exists`);let n=new N(this,e,t);return this._subs[e]=n,n}newMapSubscription(e,t){if(this.getSubscription(e)!==null)throw Error(`Subscription to the channel `+e+` already exists`);let n=new P(this,e,{token:t?.token,getToken:t?.getToken,data:t?.data,minResubscribeDelay:t?.minResubscribeDelay,maxResubscribeDelay:t?.maxResubscribeDelay,delta:t?.delta,tagsFilter:t?.tagsFilter,map:!0,mapPageSize:t?.pageSize,mapUnrecoverableStrategy:t?.unrecoverableStrategy});return this._subs[e]=n,n}newMapClientsSubscription(e,t){if(this.getSubscription(e)!==null)throw Error(`Subscription to the channel `+e+` already exists`);let n=new P(this,e,{token:t?.token,getToken:t?.getToken,data:t?.data,minResubscribeDelay:t?.minResubscribeDelay,maxResubscribeDelay:t?.maxResubscribeDelay,delta:t?.delta,tagsFilter:t?.tagsFilter,map:!0,mapPresenceType:2,mapPageSize:t?.pageSize,mapUnrecoverableStrategy:t?.unrecoverableStrategy});return this._subs[e]=n,n}newMapUsersSubscription(e,t){if(this.getSubscription(e)!==null)throw Error(`Subscription to the channel `+e+` already exists`);let n=new P(this,e,{token:t?.token,getToken:t?.getToken,data:t?.data,minResubscribeDelay:t?.minResubscribeDelay,maxResubscribeDelay:t?.maxResubscribeDelay,delta:t?.delta,tagsFilter:t?.tagsFilter,map:!0,mapPresenceType:3,mapPageSize:t?.pageSize,mapUnrecoverableStrategy:t?.unrecoverableStrategy});return this._subs[e]=n,n}newSharedPollSubscription(e,t){if(this.getSubscription(e)!==null)throw Error(`Subscription to the channel `+e+` already exists`);let n=new te(this,e,{token:t?.token,getToken:t?.getToken,data:t?.data,minResubscribeDelay:t?.minResubscribeDelay,maxResubscribeDelay:t?.maxResubscribeDelay,delta:t?.delta,sharedPoll:!0,sharedPollGetSignature:t?.getSignature});return this._subs[e]=n,n}getSubscription(e){return this._getSub(e)}getMapSubscription(e){return this._getSub(e)}getSharedPollSubscription(e){return this._getSub(e)}removeSubscription(e){e&&(e.state!==C.Unsubscribed&&e.unsubscribe(),this._removeSubscription(e))}
7removeMapSubscription(e){this.removeSubscription(e)}removeSharedPollSubscription(e){this.removeSubscription(e)}subscriptions(){return this._subs}mapSubscriptions(){let e={};for(let[t,n]of Object.entries(this._subs))n.type===`map`&&(e[t]=n);return e}sharedPollSubscriptions(){let e={};for(let[t,n]of Object.entries(this._subs))n.type===`shared_poll`&&(e[t]=n);return e}ready(e){return u(this,void 0,void 0,function*(){switch(this.state){case S.Disconnected:throw{code:g.clientDisconnected,message:`client disconnected`};case S.Connected:return;default:return new Promise((t,n)=>{let r={resolve:t,reject:n};e&&(r.timeout=setTimeout(()=>{n({code:g.timeout,message:`timeout`})},e)),this._promises[this._nextPromiseId()]=r})}})}connect(){if(this._isConnected()){this._debug(`connect called when already connected`);return}if(this._isConnecting()){this._debug(`connect called when already connecting`);return}this._debug(`connect called`),this._reconnectAttempts=0,this._startConnecting()}disconnect(){this._disconnect(v.disconnectCalled,`disconnect called`,!1)}setToken(e){this._token=e}setData(e){this._data=e}setHeaders(e){this._config.headers=e}send(e){return u(this,void 0,void 0,function*(){let t={send:{data:e}};if(yield this._methodCall(),!this._transportSendCommands([t]))throw this._createErrorObject(g.transportWriteError,`transport write error`)})}rpc(e,t){return u(this,void 0,void 0,function*(){let n={rpc:{method:e,data:t}};return yield this._methodCall(),{data:(yield this._callPromise(n,e=>e.rpc)).data}})}publish(e,t){return u(this,void 0,void 0,function*(){let n={publish:{channel:e,data:t}};return yield this._methodCall(),yield this._callPromise(n,()=>({})),{}})}mapPublish(e,t,n){return u(this,void 0,void 0,function*(){let r={publish:{channel:e,type:1,key:t,data:n}};return yield this._methodCall(),yield this._callPromise(r,()=>({})),{}})}mapRemove(e,t){return u(this,void 0,void 0,function*(){let n={publish:{channel:e,type:1,key:t,removed:!0}};return yield this._methodCall(),yield this._callPromise(n,()=>({})),{}})}history(e,t){return u(this,void 0,void 0,function*(){let n={history:this._getHistoryRequest(e,t)};yield this._methodCall();let r=yield this._callPromise(n,e=>e.history),i=[];if(r.publications)for(let t=0;t<r.publications.length;t++)i.push(this._getPublicationContext(e,r.publications[t]));return{publications:i,epoch:r.epoch||``,offset:r.offset||0}})}presence(e){return u(this,void 0,void 0,function*(){let t={presence:{channel:e}};yield this._methodCall();let n=(yield this._callPromise(t,e=>e.presence)).presence;for(let e in n)if(Object.prototype.hasOwnProperty.call(n,e)){let t=n[e],r=t.conn_info,i=t.chan_info;r&&(t.connInfo=r),i&&(t.chanInfo=i)}return{clients:n}})}presenceStats(e){return u(this,void 0,void 0,function*(){let t={presence_stats:{channel:e}};yield this._methodCall();let n=yield this._callPromise(t,e=>e.presence_stats);return{numUsers:n.num_users,numClients:n.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){this._debugEnabled&&ee(`debug`,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(this._config.token!==null&&(this._token=this._config.token),this._config.data!==null&&(this._data=this._config.data),this._codec=new z,this._formatOverride(),(this._config.debug===!0||A(`centrifuge.debug`))&&(this._debugEnabled=!0),this._debug(`config`,this._config),typeof this._endpoint!=`string`){if(Array.isArray(this._endpoint)){this._transports=this._endpoint,this._emulation=!0;for(let e in this._transports)if(this._transports.hasOwnProperty(e)){let t=this._transports[e];if(!t.endpoint||!t.transport)throw Error(`malformed transport configuration`);let n=t.transport;if([`websocket`,`http_stream`,`sse`,`sockjs`,`webtransport`].indexOf(n)<0)throw Error(`unsupported transport name: `+n)}}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;
7return this.state=e,this.emit(`state`,{newState:e,oldState:t}),!0}return!1}_isDisconnected(){return this.state===S.Disconnected}_isConnecting(){return this.state===S.Connecting}_isConnected(){return this.state===S.Connected}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let e=null;this._config.networkEventTarget===null?globalThis.addEventListener!==void 0&&(e=globalThis):e=this._config.networkEventTarget,e&&(e.addEventListener(`offline`,()=>{this._debug(`offline event triggered`),(this.state===S.Connected||this.state===S.Connecting)&&(this._disconnect(_.transportClosed,`transport closed`,!0),this._deviceWentOffline=!0)}),e.addEventListener(`online`,()=>{this._debug(`online event triggered`),this.state===S.Connecting&&(this._deviceWentOffline&&!this._transportClosed&&(this._deviceWentOffline=!1,this._transportClosed=!0),this._clearReconnectTimeout(),this._startReconnecting())}),this._networkEventsSet=!0)}_getReconnectDelay(){let e=D(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 n=t.errback;if(!n)continue;n({error:this._createErrorObject(g.connectionClosed,`connection closed`)})}this._callbacks={}}_clearConnectedState(){this._client=null,this._clearServerPingTimeout(),this._clearRefreshTimeout();for(let e in this._subs){if(!this._subs.hasOwnProperty(e))continue;let t=this._subs[e];t.state===C.Subscribed&&t._setSubscribing(y.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 n=this._callbacks[e];clearTimeout(this._callbacks[e].timeout),delete this._callbacks[e];let r=n.errback;r({error:this._createErrorObject(g.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}_advanceTransportIndex(){this._currentTransportIndex++,this._currentTransportIndex>=this._transports.length&&(this._triedAllTransports=!0,this._currentTransportIndex=0)}_initializeTransport(){let e;this._config.websocket===null?(typeof globalThis.WebSocket==`function`||typeof globalThis.WebSocket==`object`)&&(e=globalThis.WebSocket):e=this._config.websocket;let t=null;this._config.sockjs===null?globalThis.SockJS!==void 0&&(t=globalThis.SockJS):t=this._config.sockjs;let n=null;this._config.eventsource===null?globalThis.EventSource!==void 0&&(n=globalThis.EventSource):n=this._config.eventsource;let r=null;this._config.fetch===null?globalThis.fetch!==void 0&&(r=globalThis.fetch):r=this._config.fetch;let i=null;if(this._config.readableStream===null?globalThis.ReadableStream!==void 0&&(i=globalThis.ReadableStream):i=this._config.readableStream,this._emulation){this._currentTransportIndex>=this._transports.length&&(this._triedAllTransports=!0,this._currentTransportIndex=0);let a=0;for(;;){if(a>=this._transports.length)throw Error(`no supported transport found`);let o=this._transports[this._currentTransportIndex],s=o.transport,c=o.endpoint;if(s===`websocket`){if(this._debug(`trying websocket transport`),this._transport=new F(c,{websocket:e}),!this._transport.supported()){this._debug(`websocket transport not available`),this._advanceTransportIndex(),a++;continue}}else if(s===`webtransport`){if(this._debug(`trying webtransport transport`),this._transport=new ae(c,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug(`webtransport transport not available`),this._advanceTransportIndex(),a++;continue}}else if(s===`http_stream`){if(this._debug(`trying http_stream transport`),this._transport=new re(c,{fetch:r,readableStream:i,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug(`http_stream transport not available`),this._advanceTransportIndex(),a++;continue}}else if(s===`sse`){if(this._debug(`trying sse transport`),this._transport=new ie(c,{eventsource:n,fetch:r,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug(`sse transport not available`),this._advanceTransportIndex(),a++;continue}}else if(s===`sockjs`){if(this._debug(`trying sockjs`),this._transport=new ne(c,{sockjs:t,
vendor: 4,166 bytes, line 7
7sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug(`sockjs transport not available`),this._advanceTransportIndex(),a++;continue}}else throw Error(`unknown transport `+s);break}}else{if(w(this._endpoint,`http`))throw Error(`Provide explicit transport endpoints configuration in case of using HTTP (i.e. using array of TransportEndpoint instead of a single string), or use ws(s):// scheme in an endpoint if you aimed using WebSocket transport`);if(this._debug(`client will use websocket`),this._transport=new F(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,o=this._transport,s=this._nextTransportId();a._debug(`id of transport`,s);let c=!1,l=[];if(this._transport.emulation()){let e=a._sendConnect(!0);l.push(e)}this._setNetworkEvents();let u=this._codec.encodeCommands(l);this._transportClosed=!1;let d;d=setTimeout(function(){o.close()},this._config.timeout),this._transport.initialize(this._codecName(),{onOpen:function(){if(d&&(clearTimeout(d),d=null),a._transportId!=s){a._debug(`open callback from non-actual transport`),o.close();return}c=!0,a._debug(o.subName(),`transport open`),!o.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){if(a._transportId!=s){a._debug(`error callback from non-actual transport`);return}a._debug(`transport level error`,e)},onClose:function(e){if(d&&(clearTimeout(d),d=null),a._transportId!=s){a._debug(`close callback from non-actual transport`);return}a._debug(o.subName(),`transport closed`),a._transportClosed=!0,a._transportIsOpen=!1;let t=`connection closed`,n=!0,r=0;if(e&&`code`in e&&e.code&&(r=e.code),e&&e.reason)try{let r=JSON.parse(e.reason);t=r.reason,n=r.reconnect}catch{t=e.reason,(r>=3500&&r<4e3||r>=4500&&r<5e3)&&(n=!1)}r<3e3?(r===1009?(r=v.messageSizeLimit,t=`message size limit exceeded`,n=!1):(r=_.transportClosed,t=`transport closed`),a._emulation&&!a._transportWasOpen&&a._advanceTransportIndex()):a._transportWasOpen=!0,a._isConnecting()&&!c&&a.emit(`error`,{type:`transport`,error:{code:g.transportClosed,message:`transport closed`},transport:o.name()}),a._reconnecting=!1,a._disconnect(r,t,n)},onMessage:function(e){a._dataReceived(e)}},u),a.emit(`__centrifuge_debug:transport_initialized`,{})}_sendConnect(e){let t=this._constructConnectCommand(),n=this;return this._call(t,e).then(e=>{let t=e.reply.connect;n._connectResponse(t),e.next&&e.next()},e=>{n._connectError(e.error),e.next&&e.next()}),t}_startReconnecting(){if(this._debug(`start reconnecting`),!this._isConnecting()){this._debug(`stop reconnecting: client not in connecting state`);return}if(this._reconnecting){this._debug(`reconnect already in progress, return from reconnect routine`);return}if(this._transportClosed===!1){this._debug(`waiting for transport close`);return}this._reconnecting=!0;let e=this._token===``;if(!(this._refreshRequired||e&&this._config.getToken!==null)){this._config.getData?this._config.getData().then(e=>{this._isConnecting()&&(this._data=e,this._initializeTransport())}).catch(e=>this._handleGetDataError(e)):this._initializeTransport();return}let t=this;this._getToken().then(function(e){if(t._isConnecting()){if(e==null||e==null){t._failUnauthorized();return}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 V){t._failUnauthorized();return}t.emit(`error`,{type:`connectToken`,error:{code:g.clientConnectToken,message:e===void 0?``:e.toString()}});let n=t._getReconnectDelay();t._debug(`error on getting connection token, reconnect after `+n+` milliseconds`,e),t._reconnecting=!1,t._reconnectTimeout=setTimeout(()=>{t._startReconnecting()},n)})}_handleGetDataError(e){if(e instanceof V){this._failUnauthorized();return}
7this.emit(`error`,{type:`connectData`,error:{code:g.badConfiguration,message: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===S.Connecting&&(e.code===109&&(this._refreshRequired=!0),e.code<100||e.temporary===!0||e.code===109?(this.emit(`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={},n=!1;for(let e in this._serverSubs)if(this._serverSubs.hasOwnProperty(e)&&this._serverSubs[e].recoverable){n=!0;let r={recover:!0};this._serverSubs[e].offset&&(r.offset=this._serverSubs[e].offset),this._serverSubs[e].epoch&&(r.epoch=this._serverSubs[e].epoch),t[e]=r}return n&&(e.subs=t),{connect:e}}_getHistoryRequest(e,t){let n={channel:e};return t!==void 0&&(t.since&&(n.since={offset:t.since.offset},t.since.epoch&&(n.since.epoch=t.since.epoch)),t.limit!==void 0&&(n.limit=t.limit),t.reverse===!0&&(n.reverse=!0)),n}_methodCall(){return this._isConnected()?Promise.resolve():new Promise((e,t)=>{let n=setTimeout(function(){t({code:g.timeout,message:`timeout`})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:n,resolve:e,reject:t}})}_callPromise(e,t){return new Promise((n,r)=>{this._call(e,!1).then(e=>{var r;n(t(e.reply)),(r=e.next)==null||r.call(e)},e=>{var t;r(e.error),(t=e.next)==null||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 n=Promise.resolve();for(let t in e)e.hasOwnProperty(t)&&(n=n.then(()=>this._dispatchReply(e[t])));n.then(()=>{t()})}_dispatchReply(e){let t,n=new Promise(e=>{t=e});if(e==null)return this._debug(`dispatch: got undefined or null reply`),t(),n;let r=e.id;return r&&r>0?this._handleReply(e,t):e.push?this._handlePush(e.push,t):this._handleServerPing(t),n}_call(e,t){return new Promise((n,r)=>{e.id=this._nextCommandId(),this._registerCall(e.id,n,r),t||this._addCommand(e)})}_startConnecting(){this._debug(`start connecting`),this._setState(S.Connecting)&&this.emit(`connecting`,{code:_.connectCalled,reason:`connect called`}),this._client=null,this._startReconnecting()}_disconnect(e,t,n){if(e===v.stateInvalidated){this._token=``,this._refreshRequired=!0;for(let e in this._subs)this._subs.hasOwnProperty(e)&&this._subs[e]._invalidateState();for(let e in this._serverSubs)this._serverSubs.hasOwnProperty(e)&&(this._serverSubs[e].offset=0,this._serverSubs[e].epoch=`_`)}if(this._isDisconnected())return;this._transportIsOpen=!1;let r=this.state;this._reconnecting=!1;let i={code:e,reason:t},a;if(n?a=this._setState(S.Connecting):(a=this._setState(S.Disconnected),this._rejectPromises({code:g.clientDisconnected,message:`disconnected`})),this._clearOutgoingRequests(),r===S.Connecting&&this._clearReconnectTimeout(),r===S.Connected&&this._clearConnectedState(),a&&(this._isConnecting()?this.emit(`connecting`,i):this.emit(`disconnected`,i)),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(v.unauthorized,`unauthorized`,!1)}_getToken(){return this._debug(`get connection token`),this._config.getToken?this._config.getToken({}
vendor: 4,970 bytes, line 7
7):(this.emit(`error`,{type:`configuration`,error:{code:g.badConfiguration,message:`token expired but no getToken function set in the configuration`}}),Promise.reject(new V(``)))}_refresh(){let e=this._client,t=this;this._getToken().then(function(n){if(e!==t._client)return;if(!n){t._failUnauthorized();return}if(t._token=n,t._debug(`connection token refreshed`),!t._isConnected())return;let r={refresh:{token:t._token}};t._call(r,!1).then(e=>{let n=e.reply.refresh;t._refreshResponse(n),e.next&&e.next()},e=>{t._refreshError(e.error),e.next&&e.next()})}).catch(function(e){if(t._isConnected()){if(e instanceof V){t._failUnauthorized();return}t.emit(`error`,{type:`refreshToken`,error:{code:g.clientRefreshToken,message:e===void 0?``:e.toString()}}),t._refreshTimeout=setTimeout(()=>t._refresh(),t._getRefreshRetryDelay())}})}_refreshError(e){e.code<100||e.temporary===!0?(this.emit(`error`,{type:`refresh`,error:e}),this._refreshTimeout=setTimeout(()=>this._refresh(),this._getRefreshRetryDelay())):this._disconnect(e.code,e.message,!1)}_getRefreshRetryDelay(){return D(0,5e3,1e4)}_refreshResponse(e){this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),e.expires&&(this._client=e.client,this._refreshTimeout=setTimeout(()=>this._refresh(),k(e.ttl)))}_removeSubscription(e){e!==null&&delete this._subs[e.channel]}_unsubscribe(e){if(!this._transportIsOpen)return Promise.resolve();let t={unsubscribe:{channel:e.channel}},n=this;return new Promise((e,r)=>{this._call(t,!1).then(t=>{e(),t.next&&t.next()},t=>{e(),t.next&&t.next(),n._disconnect(_.unsubscribeError,`unsubscribe error`,!0)})})}_getSub(e,t){if(t&&t>0){for(let e in this._subs)if(this._subs.hasOwnProperty(e)){let n=this._subs[e];if(n._id===t)return n}return null}return this._subs[e]||null}_isServerSub(e){return this._serverSubs[e]!==void 0}_sendSubscribeCommands(){let e=[];for(let t in this._subs){if(!this._subs.hasOwnProperty(t))continue;let n=this._subs[t];if(n._inflight!==!0&&n.state===C.Subscribing){let t=n._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(S.Connected),this._refreshTimeout&&clearTimeout(this._refreshTimeout),e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),k(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=e.ping*1e3,this._sendPong=e.pong===!0,this._waitServerPing()):this._serverPing=0}_processServerSubs(e){for(let t in e){if(!e.hasOwnProperty(t))continue;let n=e[t];this._serverSubs[t]={offset:n.offset,epoch:n.epoch,recoverable:n.recoverable||!1};let r=this._getSubscribeContext(t,n);this.emit(`subscribed`,r)}for(let t in e){if(!e.hasOwnProperty(t))continue;let n=e[t];if(n.recovered){let e=n.publications;if(e&&e.length>0)for(let n in e)e.hasOwnProperty(n)&&this._handlePublication(t,e[n])}}for(let t in this._serverSubs)this._serverSubs.hasOwnProperty(t)&&(e[t]||(this.emit(`unsubscribed`,{channel:t}),delete this._serverSubs[t]))}_clearRefreshTimeout(){this._refreshTimeout!==null&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null)}_clearReconnectTimeout(){this._reconnectTimeout!==null&&(clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null)}_clearServerPingTimeout(){this._serverPingTimeout!==null&&(clearTimeout(this._serverPingTimeout),this._serverPingTimeout=null)}_waitServerPing(){this._config.maxServerPingDelay!==0&&this._isConnected()&&(this._clearServerPingTimeout(),this._serverPingTimeout=setTimeout(()=>{this._isConnected()&&this._disconnect(_.noPing,`no ping`,!0)},this._serverPing+this._config.maxServerPingDelay))}_getSubscribeContext(e,t){let n={channel:e,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1,hasRecoveredPublications:!1};t.recovered&&(n.recovered=!0),t.positioned&&(n.positioned=!0),t.recoverable&&(n.recoverable=!0),t.was_recovering&&(n.wasRecovering=!0);let r=``;`epoch`in t&&(r=t.epoch);let i=0;return`offset`in t&&(i=t.offset),(n.positioned||n.recoverable)&&(n.streamPosition={offset:i,epoch:r}),Array.isArray(t.publications)&&t.publications.length>0&&(n.hasRecoveredPublications=!0),t.data&&(n.data=t.data),n}_handleReply(e,t){let n=e.id;if(!(n in this._callbacks)){t();return}let r=this._callbacks[n];if(clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n],O(e)){let n=r.errback;if(!n){t();return}n({error:{code:e.error.code,message:e.error.message||``,temporary:e.error.temporary||!1},next:t})}else{let n=r.callback;if(!n)return;n({reply:e,next:t})}}_handleJoin(e,t,n){let r=this._getSub(e,n);if(!r){if(e&&this._isServerSub(e)){let n={channel:e,info:this._getJoinLeaveContext(t.info)};
7this.emit(`join`,n)}return}r._handleJoin(t)}_handleLeave(e,t,n){let r=this._getSub(e,n);if(!r){if(e&&this._isServerSub(e)){let n={channel:e,info:this._getJoinLeaveContext(t.info)};this.emit(`leave`,n)}return}r._handleLeave(t)}_handleUnsubscribe(e,t){let n=this._getSub(e,0);if(!n&&e){this._isServerSub(e)&&(delete this._serverSubs[e],this.emit(`unsubscribed`,{channel:e}));return}t.code<2500?n._setUnsubscribed(t.code,t.reason,!1):(t.code===b.stateInvalidated&&n._invalidateState(),n._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,n=!0;(t>=3500&&t<4e3||t>=4500&&t<5e3)&&(n=!1),this._disconnect(t,e.reason,n)}_getPublicationContext(e,t){let n={channel:e,data:t.data};return t.offset&&(n.offset=t.offset),t.info&&(n.info=this._getJoinLeaveContext(t.info)),t.tags&&(n.tags=t.tags),n}_getJoinLeaveContext(e){let t={client:e.client,user:e.user},n=e.conn_info;n&&(t.connInfo=n);let r=e.chan_info;return r&&(t.chanInfo=r),t}_handlePublication(e,t,n){let r=this._getSub(e,n);if(!r){if(e&&this._isServerSub(e)){let n=this._getPublicationContext(e,t);this.emit(`publication`,n),t.offset!==void 0&&(this._serverSubs[e].offset=t.offset)}return}r._handlePublication(t)}_handleMessage(e){this.emit(`message`,{data:e.data})}_handleServerPing(e){this._sendPong&&this._transportSendCommands([{}]),e()}_handlePush(e,t){let n=e.channel,r=e.id;e.pub?this._handlePublication(n,e.pub,r):e.message?this._handleMessage(e.message):e.join?this._handleJoin(n,e.join,r):e.leave?this._handleLeave(n,e.leave,r):e.unsubscribe?this._handleUnsubscribe(n,e.unsubscribe):e.subscribe?this._handleSubscribe(n,e.subscribe):e.disconnect&&this._handleDisconnect(e.disconnect),t()}_flush(){let e=this._commands.slice(0);this._commands=[],this._transportSendCommands(e)}_createErrorObject(e,t,n){let r={code:e,message:t};return n&&(r.temporary=!0),r}_registerCall(e,t,n){this._callbacks[e]={callback:t,errback:n,timeout:null},this._callbacks[e].timeout=setTimeout(()=>{delete this._callbacks[e],T(n)&&n({error:this._createErrorObject(g.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])}};H.SubscriptionState=C,H.State=S,H.UnauthorizedError=V;var U={DISCONNECTED:`disconnected`,CONNECTING:`connecting`,CONNECTED:`connected`},W={SSE:`sse`,HTTP_STREAM:`http_stream`,WEBSOCKET:`websocket`},G=/^[a-z][a-z\d+\-.]*:\/\//i,K=/\/$/;function q(e){let t=e.replace(K,``);if(G.test(t))return t;let n=globalThis.location?.origin;if(!n)throw Error(`Centrifugo url "${e}" is relative, which only works in a browser. Configure an absolute URL.`);return new URL(t,n).toString().replace(K,``)}function ce(e,t){let n=`${q(e)}/connection/${t}`;return t===W.WEBSOCKET?n.replace(/^http/,`ws`):n}function le(e){return`${q(e)}/emulation`}var ue={version:`0.2.9`}.version,de=Object.defineProperty,fe=(e,t,n)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J=(e,t,n)=>fe(e,typeof t==`symbol`?t:t+``,n),pe={warn:()=>{},error:()=>{}},me=class{constructor(e){J(this,`config`),J(this,`logger`),J(this,`centrifuge`,null),J(this,`channels`,new Map),J(this,`connectionStateListeners`,new Set),J(this,`connectionState`,U.DISCONNECTED),this.config=e,this.logger=e.logger??pe}get isEnabled(){return!!this.config.url}getConnectionState(){return this.connectionState}onConnectionStateChange(e){return this.connectionStateListeners.add(e),()=>{this.connectionStateListeners.delete(e)}}subscribe(e,t){if(!this.isEnabled)return()=>{};let n=this.channels.get(e)??this.createChannelEntry(e);return n.listeners.add(t),()=>{n.listeners.delete(t),n.listeners.size===0&&this.removeChannelEntry(e)}}
7destroy(){this.channels.forEach((e,t)=>this.removeChannelEntry(t)),this.disconnect()}get transport(){return this.config.transport??W.WEBSOCKET}createChannelEntry(e){let t=this.connect(),n=t.getSubscription(e)??t.newSubscription(e),i={subscription:n,listeners:new Set};return n.on(`publication`,async n=>{let a=r(n.data);if(!a.success){this.logger.warn(`Unparseable publication on ${e}`,{data:n.data,error:a.error});return}for(let e of i.listeners)try{e(a.data)}catch(e){this.logger.error(`Failed to execute listener for channel ${n.channel}`,{channel:n.channel,error:e})}try{await t.rpc(`ack`,{deliveryId:a.data.deliveryId,channel:n.channel,traceId:a.data.metadata?.traceId})}catch(e){this.logger.error(`Failed to send RPC for event ACK`,{channel:n.channel,error:e})}}),n.on(`error`,t=>{this.handleError(Error(`Subscription error on ${e}`),{channel:e,context:t})}),this.channels.set(e,i),n.subscribe(),i}removeChannelEntry(e){let t=this.channels.get(e);t&&(t.listeners.clear(),t.subscription.unsubscribe(),this.centrifuge?.removeSubscription(t.subscription),this.channels.delete(e),this.channels.size===0&&this.disconnect())}buildCentrifugeOptions(){let{getHeaders:e,getConnectData:t,getToken:n,runtime:r,debug:i,clientInfo:a}=this.config,o={emulationEndpoint:this.config.emulationEndpoint??le(this.config.url),debug:!!i},s=e?.();return s&&(o.headers=s),o.data={...t?.(),clientInfo:{packageVersion:ue,...a}},a?.appName&&(o.name=a.appName),a?.appVersion&&(o.version=a.appVersion),n&&(o.getToken=()=>Promise.resolve(n())),r?.websocket&&(o.websocket=r.websocket),r?.fetch&&(o.fetch=r.fetch),r?.eventsource&&(o.eventsource=r.eventsource),r?.readableStream&&(o.readableStream=r.readableStream),o}connect(){if(this.centrifuge)return this.centrifuge;let e=new H([{transport:this.transport,endpoint:ce(this.config.url,this.transport)}],this.buildCentrifugeOptions());return e.on(`connecting`,()=>this.setConnectionState(U.CONNECTING)),e.on(`connected`,()=>{this.setConnectionState(U.CONNECTED)}),e.on(`disconnected`,()=>{this.setConnectionState(U.DISCONNECTED)}),e.on(`error`,e=>{this.handleError(Error(`Realtime connection error`),{context:e})}),this.centrifuge=e,e.connect(),e}disconnect(){this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge.removeAllListeners(),this.centrifuge=null,this.setConnectionState(U.DISCONNECTED))}setConnectionState(e){this.connectionState!==e&&(this.connectionState=e,this.connectionStateListeners.forEach(t=>t(e)))}handleError(e,t){this.logger.error(e.message,t),this.config.onError?.(e,t)}},Y=e(n()),X=(0,Y.createContext)(null);function he(){return(0,Y.useContext)(X)}var Z=t();function ge({children:e,config:t}){let[n]=(0,Y.useState)(()=>new me(t));return(0,Y.useEffect)(()=>()=>n.destroy(),[n]),(0,Z.jsx)(X.Provider,{value:n,children:e})}function Q(e,t,n,r,i){let a=he(),s=(0,Y.useRef)(r),c=i?.enabled??!0,u=e.events[n],d=(t?Array.isArray(t)?t:[t]:[]).map(t=>({name:e.makeName(t),args:t})),f=JSON.stringify(d.map(e=>e.name)),p=(0,Y.useMemo)(()=>d,[f]);(0,Y.useEffect)(()=>{s.current=r},[r]),(0,Y.useEffect)(()=>{if(!a||!c||!p.length||!u)return;let e=p.map(e=>{let t=l();return a.subscribe(e.name,r=>{if(r.type!==n||t.isDuplicate(r.deliveryId))return;let i=u.safeParse(r.payload);if(!i.success){o.warn(`realtime`,`Unexpected payload for "${n}" on ${e.name}`,{payload:r.payload,error:i.error});return}s.current(i.data,r,e.args)})});return()=>e.forEach(e=>e())},[a,c,p,n,u])}var $=({meetingIds:e,enabled:t,onMeetingStatusChanged:n})=>{Q(i,e.map(e=>({meetingId:e})),a.STATUS_CHANGED,(e,t,{meetingId:r})=>n(r,e),{enabled:t})},_e=({meetingId:e,enabled:t,onMeetingStatusChanged:n})=>{$({meetingIds:e?[e]:[],enabled:t,onMeetingStatusChanged:(e,t)=>n(t)})},ve=new s(c);export{ge as a,Q as i,_e as n,W as o,$ as r,ve as t};
8//# sourceMappingURL=meeting-D1AwyuOc.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.