centrifuge 5.3.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ This SDK provides a client to connect to [Centrifugo](https://github.com/centrif
5
5
 
6
6
  The features implemented by this SDK can be found in [SDK feature matrix](https://centrifugal.dev/docs/transports/client_sdk#sdk-feature-matrix).
7
7
 
8
- > `centrifuge-js` v5.x is compatible with [Centrifugo](https://github.com/centrifugal/centrifugo) server v4 and v5 and [Centrifuge](https://github.com/centrifugal/centrifuge) >= 0.25.0. For Centrifugo v2, Centrifugo v3 and Centrifuge < 0.25.0 you should use `centrifuge-js` v2.x.
8
+ > `centrifuge-js` v5.x is compatible with [Centrifugo](https://github.com/centrifugal/centrifugo) server v6, v5 and v4, and [Centrifuge](https://github.com/centrifugal/centrifuge) >= 0.25.0. For Centrifugo v2, Centrifugo v3 and Centrifuge < 0.25.0 you should use `centrifuge-js` v2.x.
9
9
 
10
10
  * [Install](#install)
11
11
  * [Quick start](#quick-start)
@@ -131,14 +131,14 @@ Supported transports are:
131
131
  * `websocket`
132
132
  * `http_stream`
133
133
  * `sse`
134
- * `sockjs` - SockJS can also be used as a fallback, SockJS is currently in DEPRECATED status in Centrifugal ecosystem. Also, sticky sessions must be used on the backend in distributed case with it. See more details below
134
+ * `sockjs` - SockJS can also be used as a fallback in Centrifugo < v6, in Centrifugo v6 SockJS was removed and will be removed in `centrifuge-js` v6 too. Also, sticky sessions must be used on the backend in distributed case with it. See more details below
135
135
  * `webtransport` - this SDK also supports WebTransport in experimental form. See details below
136
136
 
137
137
  If you want to use sticky sessions on a load balancer level as an optimimization for Centrifugal bidirectional emulation layer keep in mind that we currently use `same-origin` credentials policy for emulation requests in `http_stream` and `sse` transport cases. So cookies will only be passed in same-origin case. Please open an issue in case you need to configure more relaxed credentials. Though in most cases stickyness based on client's IP may be sufficient enough.
138
138
 
139
139
  ### Using SockJS
140
140
 
141
- **SockJS usage is DEPRECATED in the Centrifugal ecosystem**
141
+ **SockJS usage is DEPRECATED**. Its support was removed in Centrifugo v6, and it will also be removed from this SDK in v6 release.
142
142
 
143
143
  If you want to use SockJS you must also import SockJS client before centrifuge.js
144
144
 
package/build/index.js CHANGED
@@ -912,9 +912,10 @@ class Subscription extends EventEmitter$1 {
912
912
  // we also need to check for transport state before sending subscription
913
913
  // because it may change for subscription with side effects (getData, getToken options)
914
914
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
915
- if (!this._centrifuge._transportIsOpen) {
915
+ if (!this._centrifuge._transportIsOpen || this._inflight) {
916
916
  return null;
917
917
  }
918
+ this._inflight = true;
918
919
  const channel = this.channel;
919
920
  const req = {
920
921
  channel: channel
@@ -949,7 +950,6 @@ class Subscription extends EventEmitter$1 {
949
950
  req.delta = this._delta;
950
951
  }
951
952
  const cmd = { subscribe: req };
952
- this._inflight = true;
953
953
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
954
954
  this._centrifuge._call(cmd).then(resolveCtx => {
955
955
  this._inflight = false;
@@ -1006,6 +1006,7 @@ class Subscription extends EventEmitter$1 {
1006
1006
  }
1007
1007
  this._clearSubscribingState();
1008
1008
  }
1009
+ this._inflight = false;
1009
1010
  if (this._setState(exports.SubscriptionState.Unsubscribed)) {
1010
1011
  this.emit('unsubscribed', { channel: this.channel, code: code, reason: reason });
1011
1012
  }
package/build/index.mjs CHANGED
@@ -910,9 +910,10 @@ class Subscription extends EventEmitter$1 {
910
910
  // we also need to check for transport state before sending subscription
911
911
  // because it may change for subscription with side effects (getData, getToken options)
912
912
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
913
- if (!this._centrifuge._transportIsOpen) {
913
+ if (!this._centrifuge._transportIsOpen || this._inflight) {
914
914
  return null;
915
915
  }
916
+ this._inflight = true;
916
917
  const channel = this.channel;
917
918
  const req = {
918
919
  channel: channel
@@ -947,7 +948,6 @@ class Subscription extends EventEmitter$1 {
947
948
  req.delta = this._delta;
948
949
  }
949
950
  const cmd = { subscribe: req };
950
- this._inflight = true;
951
951
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
952
952
  this._centrifuge._call(cmd).then(resolveCtx => {
953
953
  this._inflight = false;
@@ -1004,6 +1004,7 @@ class Subscription extends EventEmitter$1 {
1004
1004
  }
1005
1005
  this._clearSubscribingState();
1006
1006
  }
1007
+ this._inflight = false;
1007
1008
  if (this._setState(SubscriptionState.Unsubscribed)) {
1008
1009
  this.emit('unsubscribed', { channel: this.channel, code: code, reason: reason });
1009
1010
  }
@@ -914,9 +914,10 @@ class Subscription extends EventEmitter$2 {
914
914
  // we also need to check for transport state before sending subscription
915
915
  // because it may change for subscription with side effects (getData, getToken options)
916
916
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
917
- if (!this._centrifuge._transportIsOpen) {
917
+ if (!this._centrifuge._transportIsOpen || this._inflight) {
918
918
  return null;
919
919
  }
920
+ this._inflight = true;
920
921
  const channel = this.channel;
921
922
  const req = {
922
923
  channel: channel
@@ -951,7 +952,6 @@ class Subscription extends EventEmitter$2 {
951
952
  req.delta = this._delta;
952
953
  }
953
954
  const cmd = { subscribe: req };
954
- this._inflight = true;
955
955
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
956
956
  this._centrifuge._call(cmd).then(resolveCtx => {
957
957
  this._inflight = false;
@@ -1008,6 +1008,7 @@ class Subscription extends EventEmitter$2 {
1008
1008
  }
1009
1009
  this._clearSubscribingState();
1010
1010
  }
1011
+ this._inflight = false;
1011
1012
  if (this._setState(exports.SubscriptionState.Unsubscribed)) {
1012
1013
  this.emit('unsubscribed', { channel: this.channel, code: code, reason: reason });
1013
1014
  }
@@ -912,9 +912,10 @@ class Subscription extends EventEmitter$2 {
912
912
  // we also need to check for transport state before sending subscription
913
913
  // because it may change for subscription with side effects (getData, getToken options)
914
914
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
915
- if (!this._centrifuge._transportIsOpen) {
915
+ if (!this._centrifuge._transportIsOpen || this._inflight) {
916
916
  return null;
917
917
  }
918
+ this._inflight = true;
918
919
  const channel = this.channel;
919
920
  const req = {
920
921
  channel: channel
@@ -949,7 +950,6 @@ class Subscription extends EventEmitter$2 {
949
950
  req.delta = this._delta;
950
951
  }
951
952
  const cmd = { subscribe: req };
952
- this._inflight = true;
953
953
  // @ts-ignore – we are hiding some symbols from public API autocompletion.
954
954
  this._centrifuge._call(cmd).then(resolveCtx => {
955
955
  this._inflight = false;
@@ -1006,6 +1006,7 @@ class Subscription extends EventEmitter$2 {
1006
1006
  }
1007
1007
  this._clearSubscribingState();
1008
1008
  }
1009
+ this._inflight = false;
1009
1010
  if (this._setState(SubscriptionState.Unsubscribed)) {
1010
1011
  this.emit('unsubscribed', { channel: this.channel, code: code, reason: reason });
1011
1012
  }
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var re=Object.create;var B=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var he=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var le=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of ae(s))!ue.call(o,n)&&n!==e&&B(o,n,{get:()=>s[n],enumerable:!(t=oe(s,n))||t.enumerable});return o};var J=(o,s,e)=>(e=o!=null?re(ce(o)):{},le(s||!o||!o.__esModule?B(e,"default",{value:o,enumerable:!0}):e,o));var z=he((Pe,U)=>{"use strict";var y=typeof Reflect=="object"?Reflect:null,q=y&&typeof y.apply=="function"?y.apply:function(s,e,t){return Function.prototype.apply.call(s,e,t)},P;y&&typeof y.ownKeys=="function"?P=y.ownKeys:Object.getOwnPropertySymbols?P=function(s){return Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s))}:P=function(s){return Object.getOwnPropertyNames(s)};function fe(o){console&&console.warn&&console.warn(o)}var F=Number.isNaN||function(s){return s!==s};function h(){h.init.call(this)}U.exports=h;U.exports.once=be;h.EventEmitter=h;h.prototype._events=void 0;h.prototype._eventsCount=0;h.prototype._maxListeners=void 0;var H=10;function C(o){if(typeof o!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof o)}Object.defineProperty(h,"defaultMaxListeners",{enumerable:!0,get:function(){return H},set:function(o){if(typeof o!="number"||o<0||F(o))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+o+".");H=o}});h.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};h.prototype.setMaxListeners=function(s){if(typeof s!="number"||s<0||F(s))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+s+".");return this._maxListeners=s,this};function V(o){return o._maxListeners===void 0?h.defaultMaxListeners:o._maxListeners}h.prototype.getMaxListeners=function(){return V(this)};h.prototype.emit=function(s){for(var e=[],t=1;t<arguments.length;t++)e.push(arguments[t]);var n=s==="error",i=this._events;if(i!==void 0)n=n&&i.error===void 0;else if(!n)return!1;if(n){var r;if(e.length>0&&(r=e[0]),r instanceof Error)throw r;var a=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw a.context=r,a}var c=i[s];if(c===void 0)return!1;if(typeof c=="function")q(c,this,e);else for(var u=c.length,_=Y(c,u),t=0;t<u;++t)q(_[t],this,e);return!0};function K(o,s,e,t){var n,i,r;if(C(e),i=o._events,i===void 0?(i=o._events=Object.create(null),o._eventsCount=0):(i.newListener!==void 0&&(o.emit("newListener",s,e.listener?e.listener:e),i=o._events),r=i[s]),r===void 0)r=i[s]=e,++o._eventsCount;else if(typeof r=="function"?r=i[s]=t?[e,r]:[r,e]:t?r.unshift(e):r.push(e),n=V(o),n>0&&r.length>n&&!r.warned){r.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(s)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=o,a.type=s,a.count=r.length,fe(a)}return o}h.prototype.addListener=function(s,e){return K(this,s,e,!1)};h.prototype.on=h.prototype.addListener;h.prototype.prependListener=function(s,e){return K(this,s,e,!0)};function pe(){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 G(o,s,e){var t={fired:!1,wrapFn:void 0,target:o,type:s,listener:e},n=pe.bind(t);return n.listener=e,t.wrapFn=n,n}h.prototype.once=function(s,e){return C(e),this.on(s,G(this,s,e)),this};h.prototype.prependOnceListener=function(s,e){return C(e),this.prependListener(s,G(this,s,e)),this};h.prototype.removeListener=function(s,e){var t,n,i,r,a;if(C(e),n=this._events,n===void 0)return this;if(t=n[s],t===void 0)return this;if(t===e||t.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete n[s],n.removeListener&&this.emit("removeListener",s,t.listener||e));else if(typeof t!="function"){for(i=-1,r=t.length-1;r>=0;r--)if(t[r]===e||t[r].listener===e){a=t[r].listener,i=r;break}if(i<0)return this;i===0?t.shift():de(t,i),t.length===1&&(n[s]=t[0]),n.removeListener!==void 0&&this.emit("removeListener",s,a||e)}return this};h.prototype.off=h.prototype.removeListener;h.prototype.removeAllListeners=function(s){var e,t,n;if(t=this._events,t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[s]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[s]),this;if(arguments.length===0){var i=Object.keys(t),r;for(n=0;n<i.length;++n)r=i[n],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=t[s],typeof e=="function")this.removeListener(s,e);else if(e!==void 0)for(n=e.length-1;n>=0;n--)this.removeListener(s,e[n]);return this};function Q(o,s,e){var t=o._events;if(t===void 0)return[];var n=t[s];return n===void 0?[]:typeof n=="function"?e?[n.listener||n]:[n]:e?_e(n):Y(n,n.length)}h.prototype.listeners=function(s){return Q(this,s,!0)};h.prototype.rawListeners=function(s){return Q(this,s,!1)};h.listenerCount=function(o,s){return typeof o.listenerCount=="function"?o.listenerCount(s):X.call(o,s)};h.prototype.listenerCount=X;function X(o){var s=this._events;if(s!==void 0){var e=s[o];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}h.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function Y(o,s){for(var e=new Array(s),t=0;t<s;++t)e[t]=o[t];return e}function de(o,s){for(;s+1<o.length;s++)o[s]=o[s+1];o.pop()}function _e(o){for(var s=new Array(o.length),e=0;e<s.length;++e)s[e]=o[e].listener||o[e];return s}function be(o,s){return new Promise(function(e,t){function n(r){o.removeListener(s,i),t(r)}function i(){typeof o.removeListener=="function"&&o.removeListener("error",n),e([].slice.call(arguments))}Z(o,s,i,{once:!0}),s!=="error"&&me(o,n,{once:!0})})}function me(o,s,e){typeof o.on=="function"&&Z(o,"error",s,e)}function Z(o,s,e,t){if(typeof o.on=="function")t.once?o.once(s,e):o.on(s,e);else if(typeof o.addEventListener=="function")o.addEventListener(s,function n(i){t.once&&o.removeEventListener(s,n),e(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof o)}});var ne=J(z());var k=(t=>(t.Disconnected="disconnected",t.Connecting="connecting",t.Connected="connected",t))(k||{}),R=(t=>(t.Unsubscribed="unsubscribed",t.Subscribing="subscribing",t.Subscribed="subscribed",t))(R||{});function $(o,s){return o.lastIndexOf(s,0)===0}function M(o){return o==null?!1:typeof o=="function"}function ee(o,s){if(globalThis.console){let e=globalThis.console[o];M(e)&&e.apply(globalThis.console,s)}}function ge(o,s){return Math.floor(Math.random()*(s-o+1)+o)}function S(o,s,e){o>31&&(o=31);let t=ge(0,Math.min(e,s*Math.pow(2,o)));return Math.min(e,s+t)}function te(o){return"error"in o&&o.error!==null}function x(o){return Math.min(o*1e3,2147483647)}var O=class extends ne.default{constructor(e,t,n){super();this._resubscribeTimeout=null;this._refreshTimeout=null;this.channel=t,this.state="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._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._prevValue=null,this._unsubPromise=Promise.resolve(),this._setOptions(n),this._centrifuge._debugEnabled?(this.on("state",i=>{this._centrifuge._debug("subscription state",t,i.oldState,"->",i.newState)}),this.on("error",i=>{this._centrifuge._debug("subscription error",t,i)})):this.on("error",function(){Function.prototype()})}ready(e){return this.state==="unsubscribed"?Promise.reject({code:7,message:this.state}):this.state==="subscribed"?Promise.resolve():new Promise((t,n)=>{let i={resolve:t,reject:n};e&&(i.timeout=setTimeout(function(){n({code:1,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=i})}subscribe(){this._isSubscribed()||(this._resubscribeAttempts=0,this._setSubscribing(0,"subscribe called"))}unsubscribe(){this._unsubPromise=this._setUnsubscribed(0,"unsubscribe called",!0)}publish(e){let t=this;return this._methodCall().then(function(){return t._centrifuge.publish(t.channel,e)})}presence(){let e=this;return this._methodCall().then(function(){return e._centrifuge.presence(e.channel)})}presenceStats(){let e=this;return this._methodCall().then(function(){return e._centrifuge.presenceStats(e.channel)})}history(e){let t=this;return this._methodCall().then(function(){return t._centrifuge.history(t.channel,e)})}_methodCall(){return this._isSubscribed()?Promise.resolve():this._isUnsubscribed()?Promise.reject({code:7,message:this.state}):new Promise((e,t)=>{let n=setTimeout(function(){t({code:1,message:"timeout"})},this._centrifuge._config.timeout);this._promises[this._nextPromiseId()]={timeout:n,resolve:e,reject:t}})}_nextPromiseId(){return++this._promiseId}_needRecover(){return this._recover===!0}_isUnsubscribed(){return this.state==="unsubscribed"}_isSubscribing(){return this.state==="subscribing"}_isSubscribed(){return this.state==="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()}_setSubscribed(e){if(!this._isSubscribing())return;this._clearSubscribingState(),e.recoverable&&(this._recover=!0,this._offset=e.offset||0,this._epoch=e.epoch||""),e.delta?this._delta_negotiated=!0:this._delta_negotiated=!1,this._setState("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 i in n)n.hasOwnProperty(i)&&this._handlePublication(n[i]);e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),x(e.ttl)))}async _setSubscribing(e,t){this._isSubscribing()||(this._isSubscribed()&&this._clearSubscribedState(),this._setState("subscribing")&&this.emit("subscribing",{channel:this.channel,code:e,reason:t}),this._centrifuge._transport&&this._centrifuge._transport.emulation()&&await this._unsubPromise,this._isSubscribing()&&this._subscribe())}_subscribe(){if(this._centrifuge._debug("subscribing on",this.channel),!this._centrifuge._transportIsOpen)return this._centrifuge._debug("delay subscribe on",this.channel,"till connected"),null;let e=this,t={channel:e.channel};return!this._usesToken()||this._token?e._getData?(e._getData(t).then(function(n){e._isSubscribing()&&(e._data=n,e._sendSubscribe(e._token))}),null):e._sendSubscribe(e._token):(this._getSubscriptionToken().then(function(n){if(e._isSubscribing()){if(!n){e._failUnauthorized();return}e._token=n,e._getData?e._getData(t).then(function(i){e._isSubscribing()&&(e._data=i,e._sendSubscribe(n))}):e._sendSubscribe(n)}}).catch(function(n){if(e._isSubscribing()){if(n instanceof m){e._failUnauthorized();return}e.emit("error",{type:"subscribeToken",channel:e.channel,error:{code:8,message:n!==void 0?n.toString():""}}),e._scheduleResubscribe()}}),null)}_sendSubscribe(e){if(!this._centrifuge._transportIsOpen)return null;let n={channel:this.channel};if(e&&(n.token=e),this._data&&(n.data=this._data),this._positioned&&(n.positioned=!0),this._recoverable&&(n.recoverable=!0),this._joinLeave&&(n.join_leave=!0),this._needRecover()){n.recover=!0;let r=this._getOffset();r&&(n.offset=r);let a=this._getEpoch();a&&(n.epoch=a)}this._delta&&(n.delta=this._delta);let i={subscribe:n};return this._inflight=!0,this._centrifuge._call(i).then(r=>{this._inflight=!1;let a=r.reply.subscribe;this._handleSubscribeResponse(a),r.next&&r.next()},r=>{this._inflight=!1,this._handleSubscribeError(r.error),r.next&&r.next()}),i}_handleSubscribeError(e){if(this._isSubscribing()){if(e.code===1){this._centrifuge._disconnect(3,"subscribe timeout",!0);return}this._subscribeError(e)}}_handleSubscribeResponse(e){this._isSubscribing()&&this._setSubscribed(e)}_setUnsubscribed(e,t,n){if(this._isUnsubscribed())return Promise.resolve();let i=Promise.resolve();return this._isSubscribed()?(n&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribedState()):this._isSubscribing()&&(this._inflight&&n&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribingState()),this._setState("unsubscribed")&&this.emit("unsubscribed",{channel:this.channel,code:e,reason:t}),this._rejectPromises({code:7,message:this.state}),i}_handlePublication(e){if(this._delta&&this._delta_negotiated){let{newData:n,newPrevValue:i}=this._centrifuge._codec.applyDeltaIfNeeded(e,this._prevValue);e.data=n,this._prevValue=i}let t=this._centrifuge._getPublicationContext(this.channel,e);this.emit("publication",t),e.offset&&(this._offset=e.offset)}_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(){let e=this,t=this._getResubscribeDelay();this._resubscribeTimeout=setTimeout(function(){e._isSubscribing()&&e._subscribe()},t)}_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};this._centrifuge.state==="connected"&&this.emit("error",t),this._scheduleResubscribe()}else this._setUnsubscribed(e.code,e.message,!1)}_getResubscribeDelay(){let e=S(this._resubscribeAttempts,this._minResubscribeDelay,this._maxResubscribeDelay);return this._resubscribeAttempts++,e}_setOptions(e){if(e&&(e.since&&(this._offset=e.since.offset,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 new Error("unsupported delta format");this._delta=e.delta}}_getOffset(){let e=this._offset;return e!==null?e:0}_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._centrifuge._debug("get subscription token for channel",this.channel);let e={channel:this.channel},t=this._getToken;if(t===null)throw this.emit("error",{type:"configuration",channel:this.channel,error:{code:12,message:"provide a function to get channel subscription token"}}),new m("");return 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 i={sub_refresh:{channel:e.channel,token:t}};e._centrifuge._call(i).then(r=>{let a=r.reply.sub_refresh;e._refreshResponse(a),r.next&&r.next()},r=>{e._refreshError(r.error),r.next&&r.next()})}).catch(function(t){if(t instanceof m){e._failUnauthorized();return}e.emit("error",{type:"refreshToken",channel:e.channel,error:{code:9,message:t!==void 0?t.toString():""}}),e._refreshTimeout=setTimeout(()=>e._refresh(),e._getRefreshRetryDelay())})}_refreshResponse(e){this._isSubscribed()&&(this._centrifuge._debug("subscription token refreshed, channel",this.channel),this._clearRefreshTimeout(),e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),x(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 S(0,1e4,2e4)}_failUnauthorized(){this._setUnsubscribed(1,"unauthorized",!0)}};var L=class{constructor(s,e){this.endpoint=s,this.options=e,this._transport=null}name(){return"sockjs"}subName(){return"sockjs-"+this._transport.transport}emulation(){return!1}supported(){return this.options.sockjs!==null}initialize(s,e){this._transport=new this.options.sockjs(this.endpoint,null,this.options.sockjsOptions),this._transport.onopen=()=>{e.onOpen()},this._transport.onerror=t=>{e.onError(t)},this._transport.onclose=t=>{e.onClose(t)},this._transport.onmessage=t=>{e.onMessage(t.data)}}close(){this._transport.close()}send(s){this._transport.send(s)}};var T=class{constructor(s,e){this.endpoint=s,this.options=e,this._transport=null}name(){return"websocket"}subName(){return"websocket"}emulation(){return!1}supported(){return this.options.websocket!==void 0&&this.options.websocket!==null}initialize(s,e){let t="";s==="protobuf"&&(t="centrifuge-protobuf"),t!==""?this._transport=new this.options.websocket(this.endpoint,t):this._transport=new this.options.websocket(this.endpoint),s==="protobuf"&&(this._transport.binaryType="arraybuffer"),this._transport.onopen=()=>{e.onOpen()},this._transport.onerror=n=>{e.onError(n)},this._transport.onclose=n=>{e.onClose(n)},this._transport.onmessage=n=>{e.onMessage(n.data)}}close(){this._transport.close()}send(s){this._transport.send(s)}};var D=class{constructor(s,e){this.endpoint=s,this.options=e,this._abortController=null,this._utf8decoder=new TextDecoder,this._protocol="json"}name(){return"http_stream"}subName(){return"http_stream"}emulation(){return!0}_handleErrors(s){if(!s.ok)throw new Error(s.status);return s}_fetchEventTarget(s,e,t){let n=new EventTarget,i=s.options.fetch;return i(e,t).then(s._handleErrors).then(r=>{n.dispatchEvent(new Event("open"));let a="",c=0,u=new Uint8Array,_=r.body.getReader();return new s.options.readableStream({start(v){function E(){return _.read().then(({done:b,value:l})=>{if(b){n.dispatchEvent(new Event("close")),v.close();return}try{if(s._protocol==="json")for(a+=s._utf8decoder.decode(l);c<a.length;)if(a[c]===`
1
+ "use strict";(()=>{var re=Object.create;var B=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var he=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var le=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of ae(s))!ue.call(o,n)&&n!==e&&B(o,n,{get:()=>s[n],enumerable:!(t=oe(s,n))||t.enumerable});return o};var J=(o,s,e)=>(e=o!=null?re(ce(o)):{},le(s||!o||!o.__esModule?B(e,"default",{value:o,enumerable:!0}):e,o));var z=he((Pe,U)=>{"use strict";var y=typeof Reflect=="object"?Reflect:null,q=y&&typeof y.apply=="function"?y.apply:function(s,e,t){return Function.prototype.apply.call(s,e,t)},P;y&&typeof y.ownKeys=="function"?P=y.ownKeys:Object.getOwnPropertySymbols?P=function(s){return Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s))}:P=function(s){return Object.getOwnPropertyNames(s)};function fe(o){console&&console.warn&&console.warn(o)}var F=Number.isNaN||function(s){return s!==s};function h(){h.init.call(this)}U.exports=h;U.exports.once=be;h.EventEmitter=h;h.prototype._events=void 0;h.prototype._eventsCount=0;h.prototype._maxListeners=void 0;var H=10;function C(o){if(typeof o!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof o)}Object.defineProperty(h,"defaultMaxListeners",{enumerable:!0,get:function(){return H},set:function(o){if(typeof o!="number"||o<0||F(o))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+o+".");H=o}});h.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};h.prototype.setMaxListeners=function(s){if(typeof s!="number"||s<0||F(s))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+s+".");return this._maxListeners=s,this};function V(o){return o._maxListeners===void 0?h.defaultMaxListeners:o._maxListeners}h.prototype.getMaxListeners=function(){return V(this)};h.prototype.emit=function(s){for(var e=[],t=1;t<arguments.length;t++)e.push(arguments[t]);var n=s==="error",i=this._events;if(i!==void 0)n=n&&i.error===void 0;else if(!n)return!1;if(n){var r;if(e.length>0&&(r=e[0]),r instanceof Error)throw r;var a=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw a.context=r,a}var c=i[s];if(c===void 0)return!1;if(typeof c=="function")q(c,this,e);else for(var u=c.length,_=Y(c,u),t=0;t<u;++t)q(_[t],this,e);return!0};function K(o,s,e,t){var n,i,r;if(C(e),i=o._events,i===void 0?(i=o._events=Object.create(null),o._eventsCount=0):(i.newListener!==void 0&&(o.emit("newListener",s,e.listener?e.listener:e),i=o._events),r=i[s]),r===void 0)r=i[s]=e,++o._eventsCount;else if(typeof r=="function"?r=i[s]=t?[e,r]:[r,e]:t?r.unshift(e):r.push(e),n=V(o),n>0&&r.length>n&&!r.warned){r.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(s)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=o,a.type=s,a.count=r.length,fe(a)}return o}h.prototype.addListener=function(s,e){return K(this,s,e,!1)};h.prototype.on=h.prototype.addListener;h.prototype.prependListener=function(s,e){return K(this,s,e,!0)};function pe(){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 G(o,s,e){var t={fired:!1,wrapFn:void 0,target:o,type:s,listener:e},n=pe.bind(t);return n.listener=e,t.wrapFn=n,n}h.prototype.once=function(s,e){return C(e),this.on(s,G(this,s,e)),this};h.prototype.prependOnceListener=function(s,e){return C(e),this.prependListener(s,G(this,s,e)),this};h.prototype.removeListener=function(s,e){var t,n,i,r,a;if(C(e),n=this._events,n===void 0)return this;if(t=n[s],t===void 0)return this;if(t===e||t.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete n[s],n.removeListener&&this.emit("removeListener",s,t.listener||e));else if(typeof t!="function"){for(i=-1,r=t.length-1;r>=0;r--)if(t[r]===e||t[r].listener===e){a=t[r].listener,i=r;break}if(i<0)return this;i===0?t.shift():de(t,i),t.length===1&&(n[s]=t[0]),n.removeListener!==void 0&&this.emit("removeListener",s,a||e)}return this};h.prototype.off=h.prototype.removeListener;h.prototype.removeAllListeners=function(s){var e,t,n;if(t=this._events,t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[s]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[s]),this;if(arguments.length===0){var i=Object.keys(t),r;for(n=0;n<i.length;++n)r=i[n],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=t[s],typeof e=="function")this.removeListener(s,e);else if(e!==void 0)for(n=e.length-1;n>=0;n--)this.removeListener(s,e[n]);return this};function Q(o,s,e){var t=o._events;if(t===void 0)return[];var n=t[s];return n===void 0?[]:typeof n=="function"?e?[n.listener||n]:[n]:e?_e(n):Y(n,n.length)}h.prototype.listeners=function(s){return Q(this,s,!0)};h.prototype.rawListeners=function(s){return Q(this,s,!1)};h.listenerCount=function(o,s){return typeof o.listenerCount=="function"?o.listenerCount(s):X.call(o,s)};h.prototype.listenerCount=X;function X(o){var s=this._events;if(s!==void 0){var e=s[o];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}h.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function Y(o,s){for(var e=new Array(s),t=0;t<s;++t)e[t]=o[t];return e}function de(o,s){for(;s+1<o.length;s++)o[s]=o[s+1];o.pop()}function _e(o){for(var s=new Array(o.length),e=0;e<s.length;++e)s[e]=o[e].listener||o[e];return s}function be(o,s){return new Promise(function(e,t){function n(r){o.removeListener(s,i),t(r)}function i(){typeof o.removeListener=="function"&&o.removeListener("error",n),e([].slice.call(arguments))}Z(o,s,i,{once:!0}),s!=="error"&&me(o,n,{once:!0})})}function me(o,s,e){typeof o.on=="function"&&Z(o,"error",s,e)}function Z(o,s,e,t){if(typeof o.on=="function")t.once?o.once(s,e):o.on(s,e);else if(typeof o.addEventListener=="function")o.addEventListener(s,function n(i){t.once&&o.removeEventListener(s,n),e(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof o)}});var ne=J(z());var k=(t=>(t.Disconnected="disconnected",t.Connecting="connecting",t.Connected="connected",t))(k||{}),R=(t=>(t.Unsubscribed="unsubscribed",t.Subscribing="subscribing",t.Subscribed="subscribed",t))(R||{});function $(o,s){return o.lastIndexOf(s,0)===0}function M(o){return o==null?!1:typeof o=="function"}function ee(o,s){if(globalThis.console){let e=globalThis.console[o];M(e)&&e.apply(globalThis.console,s)}}function ge(o,s){return Math.floor(Math.random()*(s-o+1)+o)}function S(o,s,e){o>31&&(o=31);let t=ge(0,Math.min(e,s*Math.pow(2,o)));return Math.min(e,s+t)}function te(o){return"error"in o&&o.error!==null}function x(o){return Math.min(o*1e3,2147483647)}var O=class extends ne.default{constructor(e,t,n){super();this._resubscribeTimeout=null;this._refreshTimeout=null;this.channel=t,this.state="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._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._prevValue=null,this._unsubPromise=Promise.resolve(),this._setOptions(n),this._centrifuge._debugEnabled?(this.on("state",i=>{this._centrifuge._debug("subscription state",t,i.oldState,"->",i.newState)}),this.on("error",i=>{this._centrifuge._debug("subscription error",t,i)})):this.on("error",function(){Function.prototype()})}ready(e){return this.state==="unsubscribed"?Promise.reject({code:7,message:this.state}):this.state==="subscribed"?Promise.resolve():new Promise((t,n)=>{let i={resolve:t,reject:n};e&&(i.timeout=setTimeout(function(){n({code:1,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=i})}subscribe(){this._isSubscribed()||(this._resubscribeAttempts=0,this._setSubscribing(0,"subscribe called"))}unsubscribe(){this._unsubPromise=this._setUnsubscribed(0,"unsubscribe called",!0)}publish(e){let t=this;return this._methodCall().then(function(){return t._centrifuge.publish(t.channel,e)})}presence(){let e=this;return this._methodCall().then(function(){return e._centrifuge.presence(e.channel)})}presenceStats(){let e=this;return this._methodCall().then(function(){return e._centrifuge.presenceStats(e.channel)})}history(e){let t=this;return this._methodCall().then(function(){return t._centrifuge.history(t.channel,e)})}_methodCall(){return this._isSubscribed()?Promise.resolve():this._isUnsubscribed()?Promise.reject({code:7,message:this.state}):new Promise((e,t)=>{let n=setTimeout(function(){t({code:1,message:"timeout"})},this._centrifuge._config.timeout);this._promises[this._nextPromiseId()]={timeout:n,resolve:e,reject:t}})}_nextPromiseId(){return++this._promiseId}_needRecover(){return this._recover===!0}_isUnsubscribed(){return this.state==="unsubscribed"}_isSubscribing(){return this.state==="subscribing"}_isSubscribed(){return this.state==="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()}_setSubscribed(e){if(!this._isSubscribing())return;this._clearSubscribingState(),e.recoverable&&(this._recover=!0,this._offset=e.offset||0,this._epoch=e.epoch||""),e.delta?this._delta_negotiated=!0:this._delta_negotiated=!1,this._setState("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 i in n)n.hasOwnProperty(i)&&this._handlePublication(n[i]);e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),x(e.ttl)))}async _setSubscribing(e,t){this._isSubscribing()||(this._isSubscribed()&&this._clearSubscribedState(),this._setState("subscribing")&&this.emit("subscribing",{channel:this.channel,code:e,reason:t}),this._centrifuge._transport&&this._centrifuge._transport.emulation()&&await this._unsubPromise,this._isSubscribing()&&this._subscribe())}_subscribe(){if(this._centrifuge._debug("subscribing on",this.channel),!this._centrifuge._transportIsOpen)return this._centrifuge._debug("delay subscribe on",this.channel,"till connected"),null;let e=this,t={channel:e.channel};return!this._usesToken()||this._token?e._getData?(e._getData(t).then(function(n){e._isSubscribing()&&(e._data=n,e._sendSubscribe(e._token))}),null):e._sendSubscribe(e._token):(this._getSubscriptionToken().then(function(n){if(e._isSubscribing()){if(!n){e._failUnauthorized();return}e._token=n,e._getData?e._getData(t).then(function(i){e._isSubscribing()&&(e._data=i,e._sendSubscribe(n))}):e._sendSubscribe(n)}}).catch(function(n){if(e._isSubscribing()){if(n instanceof m){e._failUnauthorized();return}e.emit("error",{type:"subscribeToken",channel:e.channel,error:{code:8,message:n!==void 0?n.toString():""}}),e._scheduleResubscribe()}}),null)}_sendSubscribe(e){if(!this._centrifuge._transportIsOpen||this._inflight)return null;this._inflight=!0;let n={channel:this.channel};if(e&&(n.token=e),this._data&&(n.data=this._data),this._positioned&&(n.positioned=!0),this._recoverable&&(n.recoverable=!0),this._joinLeave&&(n.join_leave=!0),this._needRecover()){n.recover=!0;let r=this._getOffset();r&&(n.offset=r);let a=this._getEpoch();a&&(n.epoch=a)}this._delta&&(n.delta=this._delta);let i={subscribe:n};return this._centrifuge._call(i).then(r=>{this._inflight=!1;let a=r.reply.subscribe;this._handleSubscribeResponse(a),r.next&&r.next()},r=>{this._inflight=!1,this._handleSubscribeError(r.error),r.next&&r.next()}),i}_handleSubscribeError(e){if(this._isSubscribing()){if(e.code===1){this._centrifuge._disconnect(3,"subscribe timeout",!0);return}this._subscribeError(e)}}_handleSubscribeResponse(e){this._isSubscribing()&&this._setSubscribed(e)}_setUnsubscribed(e,t,n){if(this._isUnsubscribed())return Promise.resolve();let i=Promise.resolve();return this._isSubscribed()?(n&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribedState()):this._isSubscribing()&&(this._inflight&&n&&(i=this._centrifuge._unsubscribe(this)),this._clearSubscribingState()),this._inflight=!1,this._setState("unsubscribed")&&this.emit("unsubscribed",{channel:this.channel,code:e,reason:t}),this._rejectPromises({code:7,message:this.state}),i}_handlePublication(e){if(this._delta&&this._delta_negotiated){let{newData:n,newPrevValue:i}=this._centrifuge._codec.applyDeltaIfNeeded(e,this._prevValue);e.data=n,this._prevValue=i}let t=this._centrifuge._getPublicationContext(this.channel,e);this.emit("publication",t),e.offset&&(this._offset=e.offset)}_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(){let e=this,t=this._getResubscribeDelay();this._resubscribeTimeout=setTimeout(function(){e._isSubscribing()&&e._subscribe()},t)}_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};this._centrifuge.state==="connected"&&this.emit("error",t),this._scheduleResubscribe()}else this._setUnsubscribed(e.code,e.message,!1)}_getResubscribeDelay(){let e=S(this._resubscribeAttempts,this._minResubscribeDelay,this._maxResubscribeDelay);return this._resubscribeAttempts++,e}_setOptions(e){if(e&&(e.since&&(this._offset=e.since.offset,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 new Error("unsupported delta format");this._delta=e.delta}}_getOffset(){let e=this._offset;return e!==null?e:0}_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._centrifuge._debug("get subscription token for channel",this.channel);let e={channel:this.channel},t=this._getToken;if(t===null)throw this.emit("error",{type:"configuration",channel:this.channel,error:{code:12,message:"provide a function to get channel subscription token"}}),new m("");return 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 i={sub_refresh:{channel:e.channel,token:t}};e._centrifuge._call(i).then(r=>{let a=r.reply.sub_refresh;e._refreshResponse(a),r.next&&r.next()},r=>{e._refreshError(r.error),r.next&&r.next()})}).catch(function(t){if(t instanceof m){e._failUnauthorized();return}e.emit("error",{type:"refreshToken",channel:e.channel,error:{code:9,message:t!==void 0?t.toString():""}}),e._refreshTimeout=setTimeout(()=>e._refresh(),e._getRefreshRetryDelay())})}_refreshResponse(e){this._isSubscribed()&&(this._centrifuge._debug("subscription token refreshed, channel",this.channel),this._clearRefreshTimeout(),e.expires===!0&&(this._refreshTimeout=setTimeout(()=>this._refresh(),x(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 S(0,1e4,2e4)}_failUnauthorized(){this._setUnsubscribed(1,"unauthorized",!0)}};var L=class{constructor(s,e){this.endpoint=s,this.options=e,this._transport=null}name(){return"sockjs"}subName(){return"sockjs-"+this._transport.transport}emulation(){return!1}supported(){return this.options.sockjs!==null}initialize(s,e){this._transport=new this.options.sockjs(this.endpoint,null,this.options.sockjsOptions),this._transport.onopen=()=>{e.onOpen()},this._transport.onerror=t=>{e.onError(t)},this._transport.onclose=t=>{e.onClose(t)},this._transport.onmessage=t=>{e.onMessage(t.data)}}close(){this._transport.close()}send(s){this._transport.send(s)}};var T=class{constructor(s,e){this.endpoint=s,this.options=e,this._transport=null}name(){return"websocket"}subName(){return"websocket"}emulation(){return!1}supported(){return this.options.websocket!==void 0&&this.options.websocket!==null}initialize(s,e){let t="";s==="protobuf"&&(t="centrifuge-protobuf"),t!==""?this._transport=new this.options.websocket(this.endpoint,t):this._transport=new this.options.websocket(this.endpoint),s==="protobuf"&&(this._transport.binaryType="arraybuffer"),this._transport.onopen=()=>{e.onOpen()},this._transport.onerror=n=>{e.onError(n)},this._transport.onclose=n=>{e.onClose(n)},this._transport.onmessage=n=>{e.onMessage(n.data)}}close(){this._transport.close()}send(s){this._transport.send(s)}};var D=class{constructor(s,e){this.endpoint=s,this.options=e,this._abortController=null,this._utf8decoder=new TextDecoder,this._protocol="json"}name(){return"http_stream"}subName(){return"http_stream"}emulation(){return!0}_handleErrors(s){if(!s.ok)throw new Error(s.status);return s}_fetchEventTarget(s,e,t){let n=new EventTarget,i=s.options.fetch;return i(e,t).then(s._handleErrors).then(r=>{n.dispatchEvent(new Event("open"));let a="",c=0,u=new Uint8Array,_=r.body.getReader();return new s.options.readableStream({start(v){function E(){return _.read().then(({done:b,value:l})=>{if(b){n.dispatchEvent(new Event("close")),v.close();return}try{if(s._protocol==="json")for(a+=s._utf8decoder.decode(l);c<a.length;)if(a[c]===`
2
2
  `){let p=a.substring(0,c);n.dispatchEvent(new MessageEvent("message",{data:p})),a=a.substring(c+1),c=0}else++c;else{let p=new Uint8Array(u.length+l.length);for(p.set(u),p.set(l,u.length),u=p;;){let d=s.options.decoder.decodeReply(u);if(d.ok){let f=u.slice(0,d.pos);n.dispatchEvent(new MessageEvent("message",{data:f})),u=u.slice(d.pos);continue}break}}}catch(p){n.dispatchEvent(new Event("error",{detail:p})),n.dispatchEvent(new Event("close")),v.close();return}E()}).catch(function(b){n.dispatchEvent(new Event("error",{detail:b})),n.dispatchEvent(new Event("close")),v.close()})}return E()}})}).catch(r=>{n.dispatchEvent(new Event("error",{detail:r})),n.dispatchEvent(new Event("close"))}),n}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(s,e,t){this._protocol=s,this._abortController=new AbortController;let n,i;s==="json"?(n={Accept:"application/json","Content-Type":"application/json"},i=t):(n={Accept:"application/octet-stream","Content-Type":"application/octet-stream"},i=t);let r={method:"POST",headers:n,body:i,mode:"cors",credentials:"same-origin",cache:"no-cache",signal:this._abortController.signal},a=this._fetchEventTarget(this,this.endpoint,r);a.addEventListener("open",()=>{e.onOpen()}),a.addEventListener("error",c=>{this._abortController.abort(),e.onError(c)}),a.addEventListener("close",()=>{this._abortController.abort(),e.onClose({code:4,reason:"connection closed"})}),a.addEventListener("message",c=>{e.onMessage(c.data)})}close(){this._abortController.abort()}send(s,e,t){let n,i,r={session:e,node:t,data:s};this._protocol==="json"?(n={"Content-Type":"application/json"},i=JSON.stringify(r)):(n={"Content-Type":"application/octet-stream"},i=this.options.encoder.encodeEmulationRequest(r));let a=this.options.fetch,c={method:"POST",headers:n,body:i,mode:"cors",credentials:"same-origin",cache:"no-cache"};a(this.options.emulationEndpoint,c)}};var I=class{constructor(s,e){this.endpoint=s,this.options=e,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(s,e,t){let n;globalThis&&globalThis.document&&globalThis.document.baseURI?n=new URL(this.endpoint,globalThis.document.baseURI):n=new URL(this.endpoint),n.searchParams.append("cf_connect",t);let i={},r=new this.options.eventsource(n.toString(),i);this._transport=r;let a=this;r.onopen=function(){e.onOpen()},r.onerror=function(c){r.close(),e.onError(c),e.onClose({code:4,reason:"connection closed"})},r.onmessage=function(c){e.onMessage(c.data)},a._onClose=function(){e.onClose({code:4,reason:"connection closed"})}}close(){this._transport.close(),this._onClose!==null&&this._onClose()}send(s,e,t){let n={session:e,node:t,data:s},i={"Content-Type":"application/json"},r=JSON.stringify(n),a=this.options.fetch,c={method:"POST",headers:i,body:r,mode:"cors",credentials:"same-origin",cache:"no-cache"};a(this.options.emulationEndpoint,c)}};var j=class{constructor(s,e){this.endpoint=s,this.options=e,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}async initialize(s,e){let t;globalThis&&globalThis.document&&globalThis.document.baseURI?t=new URL(this.endpoint,globalThis.document.baseURI):t=new URL(this.endpoint),s==="protobuf"&&t.searchParams.append("cf_protocol","protobuf"),this._protocol=s;let n=new EventTarget;this._transport=new this.options.webtransport(t.toString()),this._transport.closed.then(()=>{e.onClose({code:4,reason:"connection closed"})}).catch(()=>{e.onClose({code:4,reason:"connection closed"})});try{await this._transport.ready}catch{this.close();return}let i;try{i=await this._transport.createBidirectionalStream()}catch{this.close();return}this._stream=i,this._writer=this._stream.writable.getWriter(),n.addEventListener("close",()=>{e.onClose({code:4,reason:"connection closed"})}),n.addEventListener("message",r=>{e.onMessage(r.data)}),this._startReading(n),e.onOpen()}async _startReading(s){let e=this._stream.readable.getReader(),t="",n=0,i=new Uint8Array;try{for(;;){let{done:r,value:a}=await e.read();if(a.length>0)if(this._protocol==="json")for(t+=this._utf8decoder.decode(a);n<t.length;)if(t[n]===`
3
3
  `){let c=t.substring(0,n);s.dispatchEvent(new MessageEvent("message",{data:c})),t=t.substring(n+1),n=0}else++n;else{let c=new Uint8Array(i.length+a.length);for(c.set(i),c.set(a,i.length),i=c;;){let u=this.options.decoder.decodeReply(i);if(u.ok){let _=i.slice(0,u.pos);s.dispatchEvent(new MessageEvent("message",{data:_})),i=i.slice(u.pos);continue}break}}if(r)break}}catch{s.dispatchEvent(new Event("close"))}}async close(){try{this._writer&&await this._writer.close(),this._transport.close()}catch{}}async send(s){let e;this._protocol==="json"?e=new TextEncoder().encode(s+`
4
4
  `):e=s;try{await this._writer.write(e)}catch{this.close()}}};var xe=[-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],N=class{constructor(s){this.a=s,this.pos=0}haveBytes(){return this.pos<this.a.length}getByte(){let s=this.a[this.pos];if(this.pos++,this.pos>this.a.length)throw new RangeError("out of bounds");return s}getChar(){return String.fromCharCode(this.getByte())}getInt(){let s=0,e;for(;this.haveBytes()&&(e=xe[127&this.getByte()])>=0;)s=(s<<6)+e;return this.pos--,s>>>0}},W=class{constructor(){this.a=[]}toByteArray(s){return Array.isArray(s)?this.a:new Uint8Array(this.a)}putArray(s,e,t){for(let n=e;n<t;n++)this.a.push(s[n])}};function Te(o){let s=0,e=0,t=0,n=0,i=0,r=o.length;for(;r>=16;)s=s+o[i+0]|0,e=e+o[i+1]|0,t=t+o[i+2]|0,n=n+o[i+3]|0,s=s+o[i+4]|0,e=e+o[i+5]|0,t=t+o[i+6]|0,n=n+o[i+7]|0,s=s+o[i+8]|0,e=e+o[i+9]|0,t=t+o[i+10]|0,n=n+o[i+11]|0,s=s+o[i+12]|0,e=e+o[i+13]|0,t=t+o[i+14]|0,n=n+o[i+15]|0,i+=16,r-=16;for(;r>=4;)s=s+o[i+0]|0,e=e+o[i+1]|0,t=t+o[i+2]|0,n=n+o[i+3]|0,i+=4,r-=4;switch(n=((n+(t<<8)|0)+(e<<16)|0)+(s<<24)|0,r){case 3:n=n+(o[i+2]<<8)|0;case 2:n=n+(o[i+1]<<16)|0;case 1:n=n+(o[i+0]<<24)|0}return n>>>0}function ie(o,s){let e=0,t=new N(s),n=o.length,i=s.length,r=t.getInt();if(t.getChar()!==`