centrifuge 5.2.0-beta.1 → 5.2.0

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.
@@ -11338,6 +11338,10 @@ var nested = {
11338
11338
  delta: {
11339
11339
  type: "bool",
11340
11340
  id: 8
11341
+ },
11342
+ time: {
11343
+ type: "int64",
11344
+ id: 9
11341
11345
  }
11342
11346
  },
11343
11347
  reserved: [
@@ -11473,6 +11477,10 @@ var nested = {
11473
11477
  node: {
11474
11478
  type: "string",
11475
11479
  id: 10
11480
+ },
11481
+ time: {
11482
+ type: "int64",
11483
+ id: 11
11476
11484
  }
11477
11485
  }
11478
11486
  },
@@ -11571,6 +11579,10 @@ var nested = {
11571
11579
  node: {
11572
11580
  type: "string",
11573
11581
  id: 10
11582
+ },
11583
+ time: {
11584
+ type: "int64",
11585
+ id: 11
11574
11586
  }
11575
11587
  }
11576
11588
  },
@@ -11336,6 +11336,10 @@ var nested = {
11336
11336
  delta: {
11337
11337
  type: "bool",
11338
11338
  id: 8
11339
+ },
11340
+ time: {
11341
+ type: "int64",
11342
+ id: 9
11339
11343
  }
11340
11344
  },
11341
11345
  reserved: [
@@ -11471,6 +11475,10 @@ var nested = {
11471
11475
  node: {
11472
11476
  type: "string",
11473
11477
  id: 10
11478
+ },
11479
+ time: {
11480
+ type: "int64",
11481
+ id: 11
11474
11482
  }
11475
11483
  }
11476
11484
  },
@@ -11569,6 +11577,10 @@ var nested = {
11569
11577
  node: {
11570
11578
  type: "string",
11571
11579
  id: 10
11580
+ },
11581
+ time: {
11582
+ type: "int64",
11583
+ id: 11
11572
11584
  }
11573
11585
  }
11574
11586
  },
@@ -7,5 +7,5 @@
7
7
  `):e=t;try{await this._writer.write(e)}catch{this.close()}}};var Ai=[-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],pt=class{constructor(t){this.a=t,this.pos=0}haveBytes(){return this.pos<this.a.length}getByte(){let t=this.a[this.pos];if(this.pos++,this.pos>this.a.length)throw new RangeError("out of bounds");return t}getChar(){return String.fromCharCode(this.getByte())}getInt(){let t=0,e;for(;this.haveBytes()&&(e=Ai[127&this.getByte()])>=0;)t=(t<<6)+e;return this.pos--,t>>>0}},yt=class{constructor(){this.a=[]}toByteArray(t){return Array.isArray(t)?this.a:new Uint8Array(this.a)}putArray(t,e,n){this.a.push(...t.slice(e,n))}};function qi(r){let t=0,e=0,n=0,i=0,s=0,o=r.length;for(;o>=16;)t=t+r[s+0]|0,e=e+r[s+1]|0,n=n+r[s+2]|0,i=i+r[s+3]|0,t=t+r[s+4]|0,e=e+r[s+5]|0,n=n+r[s+6]|0,i=i+r[s+7]|0,t=t+r[s+8]|0,e=e+r[s+9]|0,n=n+r[s+10]|0,i=i+r[s+11]|0,t=t+r[s+12]|0,e=e+r[s+13]|0,n=n+r[s+14]|0,i=i+r[s+15]|0,s+=16,o-=16;for(;o>=4;)t=t+r[s+0]|0,e=e+r[s+1]|0,n=n+r[s+2]|0,i=i+r[s+3]|0,s+=4,o-=4;switch(i=((i+(n<<8)|0)+(e<<16)|0)+(t<<24)|0,o){case 3:i=i+(r[s+2]<<8)|0;case 2:i=i+(r[s+1]<<16)|0;case 1:i=i+(r[s+0]<<24)|0}return i>>>0}function Ue(r,t){let e=0,n=new pt(t),i=r.length,s=t.length,o=n.getInt();if(n.getChar()!==`
8
8
  `)throw new Error("size integer not terminated by '\\n'");let a=new yt;for(;n.haveBytes();){let u=n.getInt(),c;switch(n.getChar()){case"@":if(c=n.getInt(),n.haveBytes()&&n.getChar()!==",")throw new Error("copy command not terminated by ','");if(e+=u,e>o)throw new Error("copy exceeds output file size");if(c+u>i)throw new Error("copy extends past end of input");a.putArray(r,c,c+u);break;case":":if(e+=u,e>o)throw new Error("insert command gives an output larger than predicted");if(u>s)throw new Error("insert count exceeds size of delta");a.putArray(n.a,n.pos,n.pos+u),n.pos+=u;break;case";":{let l=a.toByteArray(r);if(u!==qi(l))throw new Error("bad checksum");if(e!==o)throw new Error("generated size does not match predicted size");return l}default:throw new Error("unknown delta operator")}}throw new Error("unterminated delta")}var ve=class{name(){return"json"}encodeCommands(t){return t.map(e=>JSON.stringify(e)).join(`
9
9
  `)}decodeReplies(t){return t.trim().split(`
10
- `).map(e=>JSON.parse(e))}applyDeltaIfNeeded(t,e){let n,i;if(t.delta){let s=Ue(e,new TextEncoder().encode(t.data));n=JSON.parse(new TextDecoder().decode(s)),i=s}else n=JSON.parse(t.data),i=new TextEncoder().encode(t.data);return{newData:n,newPrevValue:i}}};var Tn=lt(ht()),Di={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},z=class extends Error{constructor(t){super(t),this.name=this.constructor.name}},re=class extends Tn.default{constructor(e,n){super();this._reconnectTimeout=null;this._refreshTimeout=null;this._serverPingTimeout=null;this.state="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 ve,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={...Di,...n},this._configure(),this._debugEnabled?(this.on("state",i=>{this._debug("client state",i.oldState,"->",i.newState)}),this.on("error",i=>{this._debug("client error",i)})):this.on("error",function(){Function.prototype()})}newSubscription(e,n){if(this.getSubscription(e)!==null)throw new Error("Subscription to the channel "+e+" already exists");let i=new Be(this,e,n);return this._subs[e]=i,i}getSubscription(e){return this._getSub(e)}removeSubscription(e){e&&(e.state!=="unsubscribed"&&e.unsubscribe(),this._removeSubscription(e))}subscriptions(){return this._subs}ready(e){return this.state==="disconnected"?Promise.reject({code:3,message:"client disconnected"}):this.state==="connected"?Promise.resolve():new Promise((n,i)=>{let s={resolve:n,reject:i};e&&(s.timeout=setTimeout(function(){i({code:1,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=s})}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(0,"disconnect called",!1)}setToken(e){this._token=e}send(e){let n={send:{data:e}},i=this;return this._methodCall().then(function(){return i._transportSendCommands([n])?Promise.resolve():Promise.reject(i._createErrorObject(10,"transport write error"))})}rpc(e,n){let i={rpc:{method:e,data:n}},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(o){return{data:o.rpc.data}})})}publish(e,n){let i={publish:{channel:e,data:n}},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(){return{}})})}history(e,n){let i={history:this._getHistoryRequest(e,n)},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(o){let a=o.history,u=[];if(a.publications)for(let c=0;c<a.publications.length;c++)u.push(s._getPublicationContext(e,a.publications[c]));return{publications:u,epoch:a.epoch||"",offset:a.offset||0}})})}presence(e){let n={presence:{channel:e}},i=this;return this._methodCall().then(function(){return i._callPromise(n,function(s){let o=s.presence.presence;for(let a in o)if(o.hasOwnProperty(a)){let u=o[a].conn_info,c=o[a].chan_info;u&&(o[a].connInfo=u),c&&(o[a].chanInfo=c)}return{clients:o}})})}presenceStats(e){let n={presence_stats:{channel:e}},i=this;return this._methodCall().then(function(){return i._callPromise(n,function(s){let o=s.presence_stats;return{numUsers:o.num_users,numClients:o.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&&xn("debug",e)}_formatOverride(){}_configure(){if(!("Promise"in globalThis))throw new Error("Promise polyfill required");if(!this._endpoint)throw new 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 ve,this._formatOverride(),(this._config.debug===!0||typeof localStorage<"u"&&localStorage.getItem("centrifuge.debug"))&&(this._debugEnabled=!0),this._debug("config",this._config),typeof this._endpoint!="string")if(typeof this._endpoint=="object"&&this._endpoint instanceof Array){this._transports=this._endpoint,this._emulation=!0;for(let e in this._transports)if(this._transports.hasOwnProperty(e)){let n=this._transports[e];if(!n.endpoint||!n.transport)throw new Error("malformed transport configuration");let i=n.transport;if(["websocket","http_stream","sse","sockjs","webtransport"].indexOf(i)<0)throw new Error("unsupported transport name: "+i)}}else throw new Error("unsupported url configuration type: only string or array of objects are supported")}_setState(e){if(this.state!==e){this._reconnecting=!1;let n=this.state;return this.state=e,this.emit("state",{newState:e,oldState:n}),!0}return!1}_isDisconnected(){return this.state==="disconnected"}_isConnecting(){return this.state==="connecting"}_isConnected(){return this.state==="connected"}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let e=null;this._config.networkEventTarget!==null?e=this._config.networkEventTarget:typeof globalThis.addEventListener<"u"&&(e=globalThis),e&&(e.addEventListener("offline",()=>{this._debug("offline event triggered"),(this.state==="connected"||this.state==="connecting")&&(this._disconnect(1,"transport closed",!0),this._deviceWentOffline=!0)}),e.addEventListener("online",()=>{this._debug("online event triggered"),this.state==="connecting"&&(this._deviceWentOffline&&!this._transportClosed&&(this._deviceWentOffline=!1,this._transportClosed=!0),this._clearReconnectTimeout(),this._startReconnecting())}),this._networkEventsSet=!0)}_getReconnectDelay(){let e=le(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 n=this._callbacks[e];clearTimeout(n.timeout);let i=n.errback;if(!i)continue;i({error:this._createErrorObject(11,"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 n=this._subs[e];n.state==="subscribed"&&n._setSubscribing(1,"transport closed")}for(let e in this._serverSubs)this._serverSubs.hasOwnProperty(e)&&this.emit("subscribing",{channel:e})}_handleWriteError(e){for(let n of e){let i=n.id;if(!(i in this._callbacks))continue;let s=this._callbacks[i];clearTimeout(this._callbacks[i].timeout),delete this._callbacks[i];let o=s.errback;o({error:this._createErrorObject(10,"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(n){return this._debug("error writing commands",n),this._handleWriteError(e),!1}return!0}_initializeTransport(){let e;this._config.websocket!==null?e=this._config.websocket:typeof globalThis.WebSocket!="function"&&typeof globalThis.WebSocket!="object"||(e=globalThis.WebSocket);let n=null;this._config.sockjs!==null?n=this._config.sockjs:typeof globalThis.SockJS<"u"&&(n=globalThis.SockJS);let i=null;this._config.eventsource!==null?i=this._config.eventsource:typeof globalThis.EventSource<"u"&&(i=globalThis.EventSource);let s=null;this._config.fetch!==null?s=this._config.fetch:typeof globalThis.fetch<"u"&&(s=globalThis.fetch);let o=null;if(this._config.readableStream!==null?o=this._config.readableStream:typeof globalThis.ReadableStream<"u"&&(o=globalThis.ReadableStream),this._emulation){this._currentTransportIndex>=this._transports.length&&(this._triedAllTransports=!0,this._currentTransportIndex=0);let h=0;for(;;){if(h>=this._transports.length)throw new Error("no supported transport found");let y=this._transports[this._currentTransportIndex],v=y.transport,w=y.endpoint;if(v==="websocket"){if(this._debug("trying websocket transport"),this._transport=new be(w,{websocket:e}),!this._transport.supported()){this._debug("websocket transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="webtransport"){if(this._debug("trying webtransport transport"),this._transport=new Me(w,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("webtransport transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="http_stream"){if(this._debug("trying http_stream transport"),this._transport=new Fe(w,{fetch:s,readableStream:o,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("http_stream transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="sse"){if(this._debug("trying sse transport"),this._transport=new Je(w,{eventsource:i,fetch:s,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug("sse transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="sockjs"){if(this._debug("trying sockjs"),this._transport=new je(w,{sockjs:n,sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug("sockjs transport not available"),this._currentTransportIndex++,h++;continue}}else throw new Error("unknown transport "+v);break}}else{if(Sn(this._endpoint,"http"))throw new 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 be(this._endpoint,{websocket:e}),!this._transport.supported())throw new Error("WebSocket not available")}let a=this,u=this._transport,c=this._nextTransportId();a._debug("id of transport",c);let l=!1,b=[];if(this._transport.emulation()){let h=a._sendConnect(!0);b.push(h)}this._setNetworkEvents();let x=this._codec.encodeCommands(b);this._transportClosed=!1;let p;p=setTimeout(function(){u.close()},this._config.timeout),this._transport.initialize(this._codec.name(),{onOpen:function(){if(p&&(clearTimeout(p),p=null),a._transportId!=c){a._debug("open callback from non-actual transport"),u.close();return}l=!0,a._debug(u.subName(),"transport open"),!u.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(h){if(a._transportId!=c){a._debug("error callback from non-actual transport");return}a._debug("transport level error",h)},onClose:function(h){if(p&&(clearTimeout(p),p=null),a._transportId!=c){a._debug("close callback from non-actual transport");return}a._debug(u.subName(),"transport closed"),a._transportClosed=!0,a._transportIsOpen=!1;let y="connection closed",v=!0,w=0;if(h&&"code"in h&&h.code&&(w=h.code),h&&h.reason)try{let ge=JSON.parse(h.reason);y=ge.reason,v=ge.reconnect}catch{y=h.reason,(w>=3500&&w<4e3||w>=4500&&w<5e3)&&(v=!1)}w<3e3?(w===1009?(w=3,y="message size limit exceeded",v=!1):(w=1,y="transport closed"),a._emulation&&!a._transportWasOpen&&(a._currentTransportIndex++,a._currentTransportIndex>=a._transports.length&&(a._triedAllTransports=!0,a._currentTransportIndex=0))):a._transportWasOpen=!0,a._isConnecting()&&!l&&a.emit("error",{type:"transport",error:{code:2,message:"transport closed"},transport:u.name()}),a._reconnecting=!1,a._disconnect(w,y,v)},onMessage:function(h){a._dataReceived(h)}},x),a.emit("__centrifuge_debug:transport_initialized",{})}_sendConnect(e){let n=this._constructConnectCommand(),i=this;return this._call(n,e).then(s=>{let o=s.reply.connect;i._connectResponse(o),s.next&&s.next()},s=>{i._connectError(s.error),s.next&&s.next()}),n}_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,n=this._token==="";if(!(this._refreshRequired||n&&this._config.getToken!==null)){this._config.getData?this._config.getData().then(function(s){e._isConnecting()&&(e._data=s,e._initializeTransport())}):this._initializeTransport();return}this._getToken().then(function(s){if(e._isConnecting()){if(s==null||s==null){e._failUnauthorized();return}e._token=s,e._debug("connection token refreshed"),e._config.getData?e._config.getData().then(function(o){e._isConnecting()&&(e._data=o,e._initializeTransport())}):e._initializeTransport()}}).catch(function(s){if(!e._isConnecting())return;if(s instanceof z){e._failUnauthorized();return}e.emit("error",{type:"connectToken",error:{code:5,message:s!==void 0?s.toString():""}});let o=e._getReconnectDelay();e._debug("error on connection token refresh, reconnect after "+o+" milliseconds",s),e._reconnecting=!1,e._reconnectTimeout=setTimeout(()=>{e._startReconnecting()},o)})}_connectError(e){this.state==="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 n=this._getReconnectDelay();e&&(n=0),this._debug("reconnect after "+n+" milliseconds"),this._clearReconnectTimeout(),this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},n)}_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);let n={},i=!1;for(let s in this._serverSubs)if(this._serverSubs.hasOwnProperty(s)&&this._serverSubs[s].recoverable){i=!0;let o={recover:!0};this._serverSubs[s].offset&&(o.offset=this._serverSubs[s].offset),this._serverSubs[s].epoch&&(o.epoch=this._serverSubs[s].epoch),n[s]=o}return i&&(e.subs=n),{connect:e}}_getHistoryRequest(e,n){let i={channel:e};return n!==void 0&&(n.since&&(i.since={offset:n.since.offset},n.since.epoch&&(i.since.epoch=n.since.epoch)),n.limit!==void 0&&(i.limit=n.limit),n.reverse===!0&&(i.reverse=!0)),i}_methodCall(){return this._isConnected()?Promise.resolve():new Promise((e,n)=>{let i=setTimeout(function(){n({code:1,message:"timeout"})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:i,resolve:e,reject:n}})}_callPromise(e,n){return new Promise((i,s)=>{this._call(e,!1).then(o=>{i(n(o.reply)),o.next&&o.next()},o=>{s(o.error),o.next&&o.next()})})}_dataReceived(e){this._serverPing>0&&this._waitServerPing();let n=this._codec.decodeReplies(e);this._dispatchPromise=this._dispatchPromise.then(()=>{let i;this._dispatchPromise=new Promise(s=>{i=s}),this._dispatchSynchronized(n,i)})}_dispatchSynchronized(e,n){let i=Promise.resolve();for(let s in e)e.hasOwnProperty(s)&&(i=i.then(()=>this._dispatchReply(e[s])));i=i.then(()=>{n()})}_dispatchReply(e){let n,i=new Promise(o=>{n=o});if(e==null)return this._debug("dispatch: got undefined or null reply"),n(),i;let s=e.id;return s&&s>0?this._handleReply(e,n):e.push?this._handlePush(e.push,n):this._handleServerPing(n),i}_call(e,n){return new Promise((i,s)=>{e.id=this._nextCommandId(),this._registerCall(e.id,i,s),n||this._addCommand(e)})}_startConnecting(){this._debug("start connecting"),this._setState("connecting")&&this.emit("connecting",{code:0,reason:"connect called"}),this._client=null,this._startReconnecting()}_disconnect(e,n,i){if(this._isDisconnected())return;this._transportIsOpen=!1;let s=this.state;this._reconnecting=!1;let o={code:e,reason:n},a=!1;if(i?a=this._setState("connecting"):(a=this._setState("disconnected"),this._rejectPromises({code:3,message:"disconnected"})),this._clearOutgoingRequests(),s==="connecting"&&this._clearReconnectTimeout(),s==="connected"&&this._clearConnectedState(),a&&(this._isConnecting()?this.emit("connecting",o):this.emit("disconnected",o)),this._transport){this._debug("closing existing transport");let u=this._transport;this._transport=null,u.close(),this._transportClosed=!0,this._nextTransportId()}else this._debug("no transport to close");this._scheduleReconnect()}_failUnauthorized(){this._disconnect(1,"unauthorized",!1)}_getToken(){if(this._debug("get connection token"),!this._config.getToken)throw this.emit("error",{type:"configuration",error:{code:12,message:"token expired but no getToken function set in the configuration"}}),new z("");return this._config.getToken({})}_refresh(){let e=this._client,n=this;this._getToken().then(function(i){if(e!==n._client)return;if(!i){n._failUnauthorized();return}if(n._token=i,n._debug("connection token refreshed"),!n._isConnected())return;let s={refresh:{token:n._token}};n._call(s,!1).then(o=>{let a=o.reply.refresh;n._refreshResponse(a),o.next&&o.next()},o=>{n._refreshError(o.error),o.next&&o.next()})}).catch(function(i){if(n._isConnected()){if(i instanceof z){n._failUnauthorized();return}n.emit("error",{type:"refreshToken",error:{code:6,message:i!==void 0?i.toString():""}}),n._refreshTimeout=setTimeout(()=>n._refresh(),n._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 le(0,5e3,1e4)}_refreshResponse(e){this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),e.expires&&(this._client=e.client,this._refreshTimeout=setTimeout(()=>this._refresh(),fe(e.ttl)))}_removeSubscription(e){e!==null&&delete this._subs[e.channel]}_unsubscribe(e){if(!this._transportIsOpen)return;let i={unsubscribe:{channel:e.channel}},s=this;this._call(i,!1).then(o=>{o.next&&o.next()},o=>{o.next&&o.next(),s._disconnect(4,"unsubscribe error",!0)})}_getSub(e){let n=this._subs[e];return n||null}_isServerSub(e){return this._serverSubs[e]!==void 0}_sendSubscribeCommands(){let e=[];for(let n in this._subs){if(!this._subs.hasOwnProperty(n))continue;let i=this._subs[n];if(i._inflight!==!0&&i.state==="subscribing"){let s=i._subscribe();s&&e.push(s)}}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("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),fe(e.ttl))),this._session=e.session,this._node=e.node,this.startBatching(),this._sendSubscribeCommands(),this.stopBatching();let n={client:e.client,transport:this._transport.subName()};e.data&&(n.data=e.data),this.emit("connected",n),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 n in e){if(!e.hasOwnProperty(n))continue;let i=e[n];this._serverSubs[n]={offset:i.offset,epoch:i.epoch,recoverable:i.recoverable||!1};let s=this._getSubscribeContext(n,i);this.emit("subscribed",s)}for(let n in e){if(!e.hasOwnProperty(n))continue;let i=e[n];if(i.recovered){let s=i.publications;if(s&&s.length>0)for(let o in s)s.hasOwnProperty(o)&&this._handlePublication(n,s[o])}}for(let n in this._serverSubs)this._serverSubs.hasOwnProperty(n)&&(e[n]||(this.emit("unsubscribed",{channel:n}),delete this._serverSubs[n]))}_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(2,"no ping",!0)},this._serverPing+this._config.maxServerPingDelay))}_getSubscribeContext(e,n){let i={channel:e,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1};n.recovered&&(i.recovered=!0),n.positioned&&(i.positioned=!0),n.recoverable&&(i.recoverable=!0),n.was_recovering&&(i.wasRecovering=!0);let s="";"epoch"in n&&(s=n.epoch);let o=0;return"offset"in n&&(o=n.offset),(i.positioned||i.recoverable)&&(i.streamPosition={offset:o,epoch:s}),n.data&&(i.data=n.data),i}_handleReply(e,n){let i=e.id;if(!(i in this._callbacks)){n();return}let s=this._callbacks[i];if(clearTimeout(this._callbacks[i].timeout),delete this._callbacks[i],On(e)){let o=s.errback;if(!o){n();return}let a=e.error;o({error:a,next:n})}else{let o=s.callback;if(!o)return;o({reply:e,next:n})}}_handleJoin(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(n.info)};this.emit("join",s)}return}i._handleJoin(n)}_handleLeave(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(n.info)};this.emit("leave",s)}return}i._handleLeave(n)}_handleUnsubscribe(e,n){let i=this._getSub(e);if(!i){this._isServerSub(e)&&(delete this._serverSubs[e],this.emit("unsubscribed",{channel:e}));return}n.code<2500?i._setUnsubscribed(n.code,n.reason,!1):i._setSubscribing(n.code,n.reason)}_handleSubscribe(e,n){this._serverSubs[e]={offset:n.offset,epoch:n.epoch,recoverable:n.recoverable||!1},this.emit("subscribed",this._getSubscribeContext(e,n))}_handleDisconnect(e){let n=e.code,i=!0;(n>=3500&&n<4e3||n>=4500&&n<5e3)&&(i=!1),this._disconnect(n,e.reason,i)}_getPublicationContext(e,n){let i={channel:e,data:n.data};return n.offset&&(i.offset=n.offset),n.info&&(i.info=this._getJoinLeaveContext(n.info)),n.tags&&(i.tags=n.tags),i}_getJoinLeaveContext(e){let n={client:e.client,user:e.user};return e.conn_info&&(n.connInfo=e.conn_info),e.chan_info&&(n.chanInfo=e.chan_info),n}_handlePublication(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s=this._getPublicationContext(e,n);this.emit("publication",s),n.offset!==void 0&&(this._serverSubs[e].offset=n.offset)}return}i._handlePublication(n)}_handleMessage(e){this.emit("message",{data:e.data})}_handleServerPing(e){if(this._sendPong){let n={};this._transportSendCommands([n])}e()}_handlePush(e,n){let i=e.channel;e.pub?this._handlePublication(i,e.pub):e.message?this._handleMessage(e.message):e.join?this._handleJoin(i,e.join):e.leave?this._handleLeave(i,e.leave):e.unsubscribe?this._handleUnsubscribe(i,e.unsubscribe):e.subscribe?this._handleSubscribe(i,e.subscribe):e.disconnect&&this._handleDisconnect(e.disconnect),n()}_flush(){let e=this._commands.slice(0);this._commands=[],this._transportSendCommands(e)}_createErrorObject(e,n,i){let s={code:e,message:n};return i&&(s.temporary=!0),s}_registerCall(e,n,i){this._callbacks[e]={callback:n,errback:i,timeout:null},this._callbacks[e].timeout=setTimeout(()=>{delete this._callbacks[e],dt(i)&&i({error:this._createErrorObject(1,"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 n in this._promises)this._promises.hasOwnProperty(n)&&(this._promises[n].timeout&&clearTimeout(this._promises[n].timeout),this._promises[n].reject(e),delete this._promises[n])}};re.SubscriptionState=Ie;re.State=Le;re.UnauthorizedError=z;var ne=lt(fi());var ln={};bi(ln,{default:()=>Os,nested:()=>xs});var xs={centrifugal:{nested:{centrifuge:{nested:{protocol:{options:{go_package:"./;protocol"},nested:{Error:{fields:{code:{type:"uint32",id:1},message:{type:"string",id:2},temporary:{type:"bool",id:3}}},EmulationRequest:{fields:{node:{type:"string",id:1},session:{type:"string",id:2},data:{type:"bytes",id:3}}},Command:{fields:{id:{type:"uint32",id:1},connect:{type:"ConnectRequest",id:4},subscribe:{type:"SubscribeRequest",id:5},unsubscribe:{type:"UnsubscribeRequest",id:6},publish:{type:"PublishRequest",id:7},presence:{type:"PresenceRequest",id:8},presence_stats:{type:"PresenceStatsRequest",id:9},history:{type:"HistoryRequest",id:10},ping:{type:"PingRequest",id:11},send:{type:"SendRequest",id:12},rpc:{type:"RPCRequest",id:13},refresh:{type:"RefreshRequest",id:14},sub_refresh:{type:"SubRefreshRequest",id:15}},reserved:[[2,2],[3,3]]},Reply:{fields:{id:{type:"uint32",id:1},error:{type:"Error",id:2},push:{type:"Push",id:4},connect:{type:"ConnectResult",id:5},subscribe:{type:"SubscribeResult",id:6},unsubscribe:{type:"UnsubscribeResult",id:7},publish:{type:"PublishResult",id:8},presence:{type:"PresenceResult",id:9},presence_stats:{type:"PresenceStatsResult",id:10},history:{type:"HistoryResult",id:11},ping:{type:"PingResult",id:12},rpc:{type:"RPCResult",id:13},refresh:{type:"RefreshResult",id:14},sub_refresh:{type:"SubRefreshResult",id:15}},reserved:[[3,3]]},Push:{fields:{channel:{type:"string",id:2},pub:{type:"Publication",id:4},join:{type:"Join",id:5},leave:{type:"Leave",id:6},unsubscribe:{type:"Unsubscribe",id:7},message:{type:"Message",id:8},subscribe:{type:"Subscribe",id:9},connect:{type:"Connect",id:10},disconnect:{type:"Disconnect",id:11},refresh:{type:"Refresh",id:12}},reserved:[[1,1],[3,3]]},ClientInfo:{fields:{user:{type:"string",id:1},client:{type:"string",id:2},conn_info:{type:"bytes",id:3},chan_info:{type:"bytes",id:4}}},Publication:{fields:{data:{type:"bytes",id:4},info:{type:"ClientInfo",id:5},offset:{type:"uint64",id:6},tags:{keyType:"string",type:"string",id:7},delta:{type:"bool",id:8}},reserved:[[1,1],[2,2],[3,3]]},Join:{fields:{info:{type:"ClientInfo",id:1}}},Leave:{fields:{info:{type:"ClientInfo",id:1}}},Unsubscribe:{fields:{code:{type:"uint32",id:2},reason:{type:"string",id:3}},reserved:[[1,1]]},Subscribe:{fields:{recoverable:{type:"bool",id:1},epoch:{type:"string",id:4},offset:{type:"uint64",id:5},positioned:{type:"bool",id:6},data:{type:"bytes",id:7}},reserved:[[2,2],[3,3]]},Message:{fields:{data:{type:"bytes",id:1}}},Connect:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},data:{type:"bytes",id:3},subs:{keyType:"string",type:"SubscribeResult",id:4},expires:{type:"bool",id:5},ttl:{type:"uint32",id:6},ping:{type:"uint32",id:7},pong:{type:"bool",id:8},session:{type:"string",id:9},node:{type:"string",id:10}}},Disconnect:{fields:{code:{type:"uint32",id:1},reason:{type:"string",id:2},reconnect:{type:"bool",id:3}}},Refresh:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2}}},ConnectRequest:{fields:{token:{type:"string",id:1},data:{type:"bytes",id:2},subs:{keyType:"string",type:"SubscribeRequest",id:3},name:{type:"string",id:4},version:{type:"string",id:5}}},ConnectResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4},data:{type:"bytes",id:5},subs:{keyType:"string",type:"SubscribeResult",id:6},ping:{type:"uint32",id:7},pong:{type:"bool",id:8},session:{type:"string",id:9},node:{type:"string",id:10}}},RefreshRequest:{fields:{token:{type:"string",id:1}}},RefreshResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4}}},SubscribeRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2},recover:{type:"bool",id:3},epoch:{type:"string",id:6},offset:{type:"uint64",id:7},data:{type:"bytes",id:8},positioned:{type:"bool",id:9},recoverable:{type:"bool",id:10},join_leave:{type:"bool",id:11},delta:{type:"string",id:12}},reserved:[[4,4],[5,5]]},SubscribeResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2},recoverable:{type:"bool",id:3},epoch:{type:"string",id:6},publications:{rule:"repeated",type:"Publication",id:7},recovered:{type:"bool",id:8},offset:{type:"uint64",id:9},positioned:{type:"bool",id:10},data:{type:"bytes",id:11},was_recovering:{type:"bool",id:12},delta:{type:"bool",id:13}},reserved:[[4,4],[5,5]]},SubRefreshRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2}}},SubRefreshResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2}}},UnsubscribeRequest:{fields:{channel:{type:"string",id:1}}},UnsubscribeResult:{fields:{}},PublishRequest:{fields:{channel:{type:"string",id:1},data:{type:"bytes",id:2}}},PublishResult:{fields:{}},PresenceRequest:{fields:{channel:{type:"string",id:1}}},PresenceResult:{fields:{presence:{keyType:"string",type:"ClientInfo",id:1}}},PresenceStatsRequest:{fields:{channel:{type:"string",id:1}}},PresenceStatsResult:{fields:{num_clients:{type:"uint32",id:1},num_users:{type:"uint32",id:2}}},StreamPosition:{fields:{offset:{type:"uint64",id:1},epoch:{type:"string",id:2}}},HistoryRequest:{fields:{channel:{type:"string",id:1},limit:{type:"int32",id:7},since:{type:"StreamPosition",id:8},reverse:{type:"bool",id:9}},reserved:[[2,2],[3,3],[4,4],[5,5],[6,6]]},HistoryResult:{fields:{publications:{rule:"repeated",type:"Publication",id:1},epoch:{type:"string",id:2},offset:{type:"uint64",id:3}}},PingRequest:{fields:{}},PingResult:{fields:{}},RPCRequest:{fields:{data:{type:"bytes",id:1},method:{type:"string",id:2}}},RPCResult:{fields:{data:{type:"bytes",id:1}}},SendRequest:{fields:{data:{type:"bytes",id:1}}}}}}}}}},Os={nested:xs};var fn=ne.Root.fromJSON(ln),Es=fn.lookupType("protocol.Command"),di=fn.lookupType("protocol.Reply"),Ts=fn.lookupType("protocol.EmulationRequest"),at=class{name(){return"protobuf"}encodeEmulationRequest(t){let e=ne.Writer.create();return Ts.encode(t,e),e.finish()}encodeCommands(t){let e=ne.Writer.create();for(let n in t)if(t.hasOwnProperty(n)){let i=Object.assign({},t[n]);Es.encodeDelimited(i,e)}return e.finish()}decodeReplies(t){let e=[],n=ne.Reader.create(new Uint8Array(t));for(;n.pos<n.len;){let i=di.decodeDelimited(n);e.push(i)}return e}decodeReply(t){let e=ne.Reader.create(new Uint8Array(t));for(;e.pos<e.len;)return di.decodeDelimited(e),{ok:!0,pos:e.pos};return{ok:!1}}applyDeltaIfNeeded(t,e){let n,i;if(t.delta){let s=Ue(e,t.data);n=new Uint8Array(s),i=s}else n=t.data,i=t.data;return{newData:n,newPrevValue:i}}};var ut=class extends re{_formatOverride(){this._codec=new at}};globalThis.Centrifuge=ut;})();
10
+ `).map(e=>JSON.parse(e))}applyDeltaIfNeeded(t,e){let n,i;if(t.delta){let s=Ue(e,new TextEncoder().encode(t.data));n=JSON.parse(new TextDecoder().decode(s)),i=s}else n=JSON.parse(t.data),i=new TextEncoder().encode(t.data);return{newData:n,newPrevValue:i}}};var Tn=lt(ht()),Di={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},z=class extends Error{constructor(t){super(t),this.name=this.constructor.name}},re=class extends Tn.default{constructor(e,n){super();this._reconnectTimeout=null;this._refreshTimeout=null;this._serverPingTimeout=null;this.state="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 ve,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={...Di,...n},this._configure(),this._debugEnabled?(this.on("state",i=>{this._debug("client state",i.oldState,"->",i.newState)}),this.on("error",i=>{this._debug("client error",i)})):this.on("error",function(){Function.prototype()})}newSubscription(e,n){if(this.getSubscription(e)!==null)throw new Error("Subscription to the channel "+e+" already exists");let i=new Be(this,e,n);return this._subs[e]=i,i}getSubscription(e){return this._getSub(e)}removeSubscription(e){e&&(e.state!=="unsubscribed"&&e.unsubscribe(),this._removeSubscription(e))}subscriptions(){return this._subs}ready(e){return this.state==="disconnected"?Promise.reject({code:3,message:"client disconnected"}):this.state==="connected"?Promise.resolve():new Promise((n,i)=>{let s={resolve:n,reject:i};e&&(s.timeout=setTimeout(function(){i({code:1,message:"timeout"})},e)),this._promises[this._nextPromiseId()]=s})}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(0,"disconnect called",!1)}setToken(e){this._token=e}send(e){let n={send:{data:e}},i=this;return this._methodCall().then(function(){return i._transportSendCommands([n])?Promise.resolve():Promise.reject(i._createErrorObject(10,"transport write error"))})}rpc(e,n){let i={rpc:{method:e,data:n}},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(o){return{data:o.rpc.data}})})}publish(e,n){let i={publish:{channel:e,data:n}},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(){return{}})})}history(e,n){let i={history:this._getHistoryRequest(e,n)},s=this;return this._methodCall().then(function(){return s._callPromise(i,function(o){let a=o.history,u=[];if(a.publications)for(let c=0;c<a.publications.length;c++)u.push(s._getPublicationContext(e,a.publications[c]));return{publications:u,epoch:a.epoch||"",offset:a.offset||0}})})}presence(e){let n={presence:{channel:e}},i=this;return this._methodCall().then(function(){return i._callPromise(n,function(s){let o=s.presence.presence;for(let a in o)if(o.hasOwnProperty(a)){let u=o[a].conn_info,c=o[a].chan_info;u&&(o[a].connInfo=u),c&&(o[a].chanInfo=c)}return{clients:o}})})}presenceStats(e){let n={presence_stats:{channel:e}},i=this;return this._methodCall().then(function(){return i._callPromise(n,function(s){let o=s.presence_stats;return{numUsers:o.num_users,numClients:o.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&&xn("debug",e)}_formatOverride(){}_configure(){if(!("Promise"in globalThis))throw new Error("Promise polyfill required");if(!this._endpoint)throw new 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 ve,this._formatOverride(),(this._config.debug===!0||typeof localStorage<"u"&&localStorage.getItem("centrifuge.debug"))&&(this._debugEnabled=!0),this._debug("config",this._config),typeof this._endpoint!="string")if(typeof this._endpoint=="object"&&this._endpoint instanceof Array){this._transports=this._endpoint,this._emulation=!0;for(let e in this._transports)if(this._transports.hasOwnProperty(e)){let n=this._transports[e];if(!n.endpoint||!n.transport)throw new Error("malformed transport configuration");let i=n.transport;if(["websocket","http_stream","sse","sockjs","webtransport"].indexOf(i)<0)throw new Error("unsupported transport name: "+i)}}else throw new Error("unsupported url configuration type: only string or array of objects are supported")}_setState(e){if(this.state!==e){this._reconnecting=!1;let n=this.state;return this.state=e,this.emit("state",{newState:e,oldState:n}),!0}return!1}_isDisconnected(){return this.state==="disconnected"}_isConnecting(){return this.state==="connecting"}_isConnected(){return this.state==="connected"}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let e=null;this._config.networkEventTarget!==null?e=this._config.networkEventTarget:typeof globalThis.addEventListener<"u"&&(e=globalThis),e&&(e.addEventListener("offline",()=>{this._debug("offline event triggered"),(this.state==="connected"||this.state==="connecting")&&(this._disconnect(1,"transport closed",!0),this._deviceWentOffline=!0)}),e.addEventListener("online",()=>{this._debug("online event triggered"),this.state==="connecting"&&(this._deviceWentOffline&&!this._transportClosed&&(this._deviceWentOffline=!1,this._transportClosed=!0),this._clearReconnectTimeout(),this._startReconnecting())}),this._networkEventsSet=!0)}_getReconnectDelay(){let e=le(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 n=this._callbacks[e];clearTimeout(n.timeout);let i=n.errback;if(!i)continue;i({error:this._createErrorObject(11,"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 n=this._subs[e];n.state==="subscribed"&&n._setSubscribing(1,"transport closed")}for(let e in this._serverSubs)this._serverSubs.hasOwnProperty(e)&&this.emit("subscribing",{channel:e})}_handleWriteError(e){for(let n of e){let i=n.id;if(!(i in this._callbacks))continue;let s=this._callbacks[i];clearTimeout(this._callbacks[i].timeout),delete this._callbacks[i];let o=s.errback;o({error:this._createErrorObject(10,"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(n){return this._debug("error writing commands",n),this._handleWriteError(e),!1}return!0}_initializeTransport(){let e;this._config.websocket!==null?e=this._config.websocket:typeof globalThis.WebSocket!="function"&&typeof globalThis.WebSocket!="object"||(e=globalThis.WebSocket);let n=null;this._config.sockjs!==null?n=this._config.sockjs:typeof globalThis.SockJS<"u"&&(n=globalThis.SockJS);let i=null;this._config.eventsource!==null?i=this._config.eventsource:typeof globalThis.EventSource<"u"&&(i=globalThis.EventSource);let s=null;this._config.fetch!==null?s=this._config.fetch:typeof globalThis.fetch<"u"&&(s=globalThis.fetch);let o=null;if(this._config.readableStream!==null?o=this._config.readableStream:typeof globalThis.ReadableStream<"u"&&(o=globalThis.ReadableStream),this._emulation){this._currentTransportIndex>=this._transports.length&&(this._triedAllTransports=!0,this._currentTransportIndex=0);let h=0;for(;;){if(h>=this._transports.length)throw new Error("no supported transport found");let y=this._transports[this._currentTransportIndex],v=y.transport,w=y.endpoint;if(v==="websocket"){if(this._debug("trying websocket transport"),this._transport=new be(w,{websocket:e}),!this._transport.supported()){this._debug("websocket transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="webtransport"){if(this._debug("trying webtransport transport"),this._transport=new Me(w,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("webtransport transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="http_stream"){if(this._debug("trying http_stream transport"),this._transport=new Fe(w,{fetch:s,readableStream:o,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("http_stream transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="sse"){if(this._debug("trying sse transport"),this._transport=new Je(w,{eventsource:i,fetch:s,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug("sse transport not available"),this._currentTransportIndex++,h++;continue}}else if(v==="sockjs"){if(this._debug("trying sockjs"),this._transport=new je(w,{sockjs:n,sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug("sockjs transport not available"),this._currentTransportIndex++,h++;continue}}else throw new Error("unknown transport "+v);break}}else{if(Sn(this._endpoint,"http"))throw new 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 be(this._endpoint,{websocket:e}),!this._transport.supported())throw new Error("WebSocket not available")}let a=this,u=this._transport,c=this._nextTransportId();a._debug("id of transport",c);let l=!1,b=[];if(this._transport.emulation()){let h=a._sendConnect(!0);b.push(h)}this._setNetworkEvents();let x=this._codec.encodeCommands(b);this._transportClosed=!1;let p;p=setTimeout(function(){u.close()},this._config.timeout),this._transport.initialize(this._codec.name(),{onOpen:function(){if(p&&(clearTimeout(p),p=null),a._transportId!=c){a._debug("open callback from non-actual transport"),u.close();return}l=!0,a._debug(u.subName(),"transport open"),!u.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(h){if(a._transportId!=c){a._debug("error callback from non-actual transport");return}a._debug("transport level error",h)},onClose:function(h){if(p&&(clearTimeout(p),p=null),a._transportId!=c){a._debug("close callback from non-actual transport");return}a._debug(u.subName(),"transport closed"),a._transportClosed=!0,a._transportIsOpen=!1;let y="connection closed",v=!0,w=0;if(h&&"code"in h&&h.code&&(w=h.code),h&&h.reason)try{let ge=JSON.parse(h.reason);y=ge.reason,v=ge.reconnect}catch{y=h.reason,(w>=3500&&w<4e3||w>=4500&&w<5e3)&&(v=!1)}w<3e3?(w===1009?(w=3,y="message size limit exceeded",v=!1):(w=1,y="transport closed"),a._emulation&&!a._transportWasOpen&&(a._currentTransportIndex++,a._currentTransportIndex>=a._transports.length&&(a._triedAllTransports=!0,a._currentTransportIndex=0))):a._transportWasOpen=!0,a._isConnecting()&&!l&&a.emit("error",{type:"transport",error:{code:2,message:"transport closed"},transport:u.name()}),a._reconnecting=!1,a._disconnect(w,y,v)},onMessage:function(h){a._dataReceived(h)}},x),a.emit("__centrifuge_debug:transport_initialized",{})}_sendConnect(e){let n=this._constructConnectCommand(),i=this;return this._call(n,e).then(s=>{let o=s.reply.connect;i._connectResponse(o),s.next&&s.next()},s=>{i._connectError(s.error),s.next&&s.next()}),n}_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,n=this._token==="";if(!(this._refreshRequired||n&&this._config.getToken!==null)){this._config.getData?this._config.getData().then(function(s){e._isConnecting()&&(e._data=s,e._initializeTransport())}):this._initializeTransport();return}this._getToken().then(function(s){if(e._isConnecting()){if(s==null||s==null){e._failUnauthorized();return}e._token=s,e._debug("connection token refreshed"),e._config.getData?e._config.getData().then(function(o){e._isConnecting()&&(e._data=o,e._initializeTransport())}):e._initializeTransport()}}).catch(function(s){if(!e._isConnecting())return;if(s instanceof z){e._failUnauthorized();return}e.emit("error",{type:"connectToken",error:{code:5,message:s!==void 0?s.toString():""}});let o=e._getReconnectDelay();e._debug("error on connection token refresh, reconnect after "+o+" milliseconds",s),e._reconnecting=!1,e._reconnectTimeout=setTimeout(()=>{e._startReconnecting()},o)})}_connectError(e){this.state==="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 n=this._getReconnectDelay();e&&(n=0),this._debug("reconnect after "+n+" milliseconds"),this._clearReconnectTimeout(),this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},n)}_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);let n={},i=!1;for(let s in this._serverSubs)if(this._serverSubs.hasOwnProperty(s)&&this._serverSubs[s].recoverable){i=!0;let o={recover:!0};this._serverSubs[s].offset&&(o.offset=this._serverSubs[s].offset),this._serverSubs[s].epoch&&(o.epoch=this._serverSubs[s].epoch),n[s]=o}return i&&(e.subs=n),{connect:e}}_getHistoryRequest(e,n){let i={channel:e};return n!==void 0&&(n.since&&(i.since={offset:n.since.offset},n.since.epoch&&(i.since.epoch=n.since.epoch)),n.limit!==void 0&&(i.limit=n.limit),n.reverse===!0&&(i.reverse=!0)),i}_methodCall(){return this._isConnected()?Promise.resolve():new Promise((e,n)=>{let i=setTimeout(function(){n({code:1,message:"timeout"})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:i,resolve:e,reject:n}})}_callPromise(e,n){return new Promise((i,s)=>{this._call(e,!1).then(o=>{i(n(o.reply)),o.next&&o.next()},o=>{s(o.error),o.next&&o.next()})})}_dataReceived(e){this._serverPing>0&&this._waitServerPing();let n=this._codec.decodeReplies(e);this._dispatchPromise=this._dispatchPromise.then(()=>{let i;this._dispatchPromise=new Promise(s=>{i=s}),this._dispatchSynchronized(n,i)})}_dispatchSynchronized(e,n){let i=Promise.resolve();for(let s in e)e.hasOwnProperty(s)&&(i=i.then(()=>this._dispatchReply(e[s])));i=i.then(()=>{n()})}_dispatchReply(e){let n,i=new Promise(o=>{n=o});if(e==null)return this._debug("dispatch: got undefined or null reply"),n(),i;let s=e.id;return s&&s>0?this._handleReply(e,n):e.push?this._handlePush(e.push,n):this._handleServerPing(n),i}_call(e,n){return new Promise((i,s)=>{e.id=this._nextCommandId(),this._registerCall(e.id,i,s),n||this._addCommand(e)})}_startConnecting(){this._debug("start connecting"),this._setState("connecting")&&this.emit("connecting",{code:0,reason:"connect called"}),this._client=null,this._startReconnecting()}_disconnect(e,n,i){if(this._isDisconnected())return;this._transportIsOpen=!1;let s=this.state;this._reconnecting=!1;let o={code:e,reason:n},a=!1;if(i?a=this._setState("connecting"):(a=this._setState("disconnected"),this._rejectPromises({code:3,message:"disconnected"})),this._clearOutgoingRequests(),s==="connecting"&&this._clearReconnectTimeout(),s==="connected"&&this._clearConnectedState(),a&&(this._isConnecting()?this.emit("connecting",o):this.emit("disconnected",o)),this._transport){this._debug("closing existing transport");let u=this._transport;this._transport=null,u.close(),this._transportClosed=!0,this._nextTransportId()}else this._debug("no transport to close");this._scheduleReconnect()}_failUnauthorized(){this._disconnect(1,"unauthorized",!1)}_getToken(){if(this._debug("get connection token"),!this._config.getToken)throw this.emit("error",{type:"configuration",error:{code:12,message:"token expired but no getToken function set in the configuration"}}),new z("");return this._config.getToken({})}_refresh(){let e=this._client,n=this;this._getToken().then(function(i){if(e!==n._client)return;if(!i){n._failUnauthorized();return}if(n._token=i,n._debug("connection token refreshed"),!n._isConnected())return;let s={refresh:{token:n._token}};n._call(s,!1).then(o=>{let a=o.reply.refresh;n._refreshResponse(a),o.next&&o.next()},o=>{n._refreshError(o.error),o.next&&o.next()})}).catch(function(i){if(n._isConnected()){if(i instanceof z){n._failUnauthorized();return}n.emit("error",{type:"refreshToken",error:{code:6,message:i!==void 0?i.toString():""}}),n._refreshTimeout=setTimeout(()=>n._refresh(),n._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 le(0,5e3,1e4)}_refreshResponse(e){this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),e.expires&&(this._client=e.client,this._refreshTimeout=setTimeout(()=>this._refresh(),fe(e.ttl)))}_removeSubscription(e){e!==null&&delete this._subs[e.channel]}_unsubscribe(e){if(!this._transportIsOpen)return;let i={unsubscribe:{channel:e.channel}},s=this;this._call(i,!1).then(o=>{o.next&&o.next()},o=>{o.next&&o.next(),s._disconnect(4,"unsubscribe error",!0)})}_getSub(e){let n=this._subs[e];return n||null}_isServerSub(e){return this._serverSubs[e]!==void 0}_sendSubscribeCommands(){let e=[];for(let n in this._subs){if(!this._subs.hasOwnProperty(n))continue;let i=this._subs[n];if(i._inflight!==!0&&i.state==="subscribing"){let s=i._subscribe();s&&e.push(s)}}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("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),e.expires&&(this._refreshTimeout=setTimeout(()=>this._refresh(),fe(e.ttl))),this._session=e.session,this._node=e.node,this.startBatching(),this._sendSubscribeCommands(),this.stopBatching();let n={client:e.client,transport:this._transport.subName()};e.data&&(n.data=e.data),this.emit("connected",n),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 n in e){if(!e.hasOwnProperty(n))continue;let i=e[n];this._serverSubs[n]={offset:i.offset,epoch:i.epoch,recoverable:i.recoverable||!1};let s=this._getSubscribeContext(n,i);this.emit("subscribed",s)}for(let n in e){if(!e.hasOwnProperty(n))continue;let i=e[n];if(i.recovered){let s=i.publications;if(s&&s.length>0)for(let o in s)s.hasOwnProperty(o)&&this._handlePublication(n,s[o])}}for(let n in this._serverSubs)this._serverSubs.hasOwnProperty(n)&&(e[n]||(this.emit("unsubscribed",{channel:n}),delete this._serverSubs[n]))}_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(2,"no ping",!0)},this._serverPing+this._config.maxServerPingDelay))}_getSubscribeContext(e,n){let i={channel:e,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1};n.recovered&&(i.recovered=!0),n.positioned&&(i.positioned=!0),n.recoverable&&(i.recoverable=!0),n.was_recovering&&(i.wasRecovering=!0);let s="";"epoch"in n&&(s=n.epoch);let o=0;return"offset"in n&&(o=n.offset),(i.positioned||i.recoverable)&&(i.streamPosition={offset:o,epoch:s}),n.data&&(i.data=n.data),i}_handleReply(e,n){let i=e.id;if(!(i in this._callbacks)){n();return}let s=this._callbacks[i];if(clearTimeout(this._callbacks[i].timeout),delete this._callbacks[i],On(e)){let o=s.errback;if(!o){n();return}let a=e.error;o({error:a,next:n})}else{let o=s.callback;if(!o)return;o({reply:e,next:n})}}_handleJoin(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(n.info)};this.emit("join",s)}return}i._handleJoin(n)}_handleLeave(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s={channel:e,info:this._getJoinLeaveContext(n.info)};this.emit("leave",s)}return}i._handleLeave(n)}_handleUnsubscribe(e,n){let i=this._getSub(e);if(!i){this._isServerSub(e)&&(delete this._serverSubs[e],this.emit("unsubscribed",{channel:e}));return}n.code<2500?i._setUnsubscribed(n.code,n.reason,!1):i._setSubscribing(n.code,n.reason)}_handleSubscribe(e,n){this._serverSubs[e]={offset:n.offset,epoch:n.epoch,recoverable:n.recoverable||!1},this.emit("subscribed",this._getSubscribeContext(e,n))}_handleDisconnect(e){let n=e.code,i=!0;(n>=3500&&n<4e3||n>=4500&&n<5e3)&&(i=!1),this._disconnect(n,e.reason,i)}_getPublicationContext(e,n){let i={channel:e,data:n.data};return n.offset&&(i.offset=n.offset),n.info&&(i.info=this._getJoinLeaveContext(n.info)),n.tags&&(i.tags=n.tags),i}_getJoinLeaveContext(e){let n={client:e.client,user:e.user};return e.conn_info&&(n.connInfo=e.conn_info),e.chan_info&&(n.chanInfo=e.chan_info),n}_handlePublication(e,n){let i=this._getSub(e);if(!i){if(this._isServerSub(e)){let s=this._getPublicationContext(e,n);this.emit("publication",s),n.offset!==void 0&&(this._serverSubs[e].offset=n.offset)}return}i._handlePublication(n)}_handleMessage(e){this.emit("message",{data:e.data})}_handleServerPing(e){if(this._sendPong){let n={};this._transportSendCommands([n])}e()}_handlePush(e,n){let i=e.channel;e.pub?this._handlePublication(i,e.pub):e.message?this._handleMessage(e.message):e.join?this._handleJoin(i,e.join):e.leave?this._handleLeave(i,e.leave):e.unsubscribe?this._handleUnsubscribe(i,e.unsubscribe):e.subscribe?this._handleSubscribe(i,e.subscribe):e.disconnect&&this._handleDisconnect(e.disconnect),n()}_flush(){let e=this._commands.slice(0);this._commands=[],this._transportSendCommands(e)}_createErrorObject(e,n,i){let s={code:e,message:n};return i&&(s.temporary=!0),s}_registerCall(e,n,i){this._callbacks[e]={callback:n,errback:i,timeout:null},this._callbacks[e].timeout=setTimeout(()=>{delete this._callbacks[e],dt(i)&&i({error:this._createErrorObject(1,"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 n in this._promises)this._promises.hasOwnProperty(n)&&(this._promises[n].timeout&&clearTimeout(this._promises[n].timeout),this._promises[n].reject(e),delete this._promises[n])}};re.SubscriptionState=Ie;re.State=Le;re.UnauthorizedError=z;var ne=lt(fi());var ln={};bi(ln,{default:()=>Os,nested:()=>xs});var xs={centrifugal:{nested:{centrifuge:{nested:{protocol:{options:{go_package:"./;protocol"},nested:{Error:{fields:{code:{type:"uint32",id:1},message:{type:"string",id:2},temporary:{type:"bool",id:3}}},EmulationRequest:{fields:{node:{type:"string",id:1},session:{type:"string",id:2},data:{type:"bytes",id:3}}},Command:{fields:{id:{type:"uint32",id:1},connect:{type:"ConnectRequest",id:4},subscribe:{type:"SubscribeRequest",id:5},unsubscribe:{type:"UnsubscribeRequest",id:6},publish:{type:"PublishRequest",id:7},presence:{type:"PresenceRequest",id:8},presence_stats:{type:"PresenceStatsRequest",id:9},history:{type:"HistoryRequest",id:10},ping:{type:"PingRequest",id:11},send:{type:"SendRequest",id:12},rpc:{type:"RPCRequest",id:13},refresh:{type:"RefreshRequest",id:14},sub_refresh:{type:"SubRefreshRequest",id:15}},reserved:[[2,2],[3,3]]},Reply:{fields:{id:{type:"uint32",id:1},error:{type:"Error",id:2},push:{type:"Push",id:4},connect:{type:"ConnectResult",id:5},subscribe:{type:"SubscribeResult",id:6},unsubscribe:{type:"UnsubscribeResult",id:7},publish:{type:"PublishResult",id:8},presence:{type:"PresenceResult",id:9},presence_stats:{type:"PresenceStatsResult",id:10},history:{type:"HistoryResult",id:11},ping:{type:"PingResult",id:12},rpc:{type:"RPCResult",id:13},refresh:{type:"RefreshResult",id:14},sub_refresh:{type:"SubRefreshResult",id:15}},reserved:[[3,3]]},Push:{fields:{channel:{type:"string",id:2},pub:{type:"Publication",id:4},join:{type:"Join",id:5},leave:{type:"Leave",id:6},unsubscribe:{type:"Unsubscribe",id:7},message:{type:"Message",id:8},subscribe:{type:"Subscribe",id:9},connect:{type:"Connect",id:10},disconnect:{type:"Disconnect",id:11},refresh:{type:"Refresh",id:12}},reserved:[[1,1],[3,3]]},ClientInfo:{fields:{user:{type:"string",id:1},client:{type:"string",id:2},conn_info:{type:"bytes",id:3},chan_info:{type:"bytes",id:4}}},Publication:{fields:{data:{type:"bytes",id:4},info:{type:"ClientInfo",id:5},offset:{type:"uint64",id:6},tags:{keyType:"string",type:"string",id:7},delta:{type:"bool",id:8},time:{type:"int64",id:9}},reserved:[[1,1],[2,2],[3,3]]},Join:{fields:{info:{type:"ClientInfo",id:1}}},Leave:{fields:{info:{type:"ClientInfo",id:1}}},Unsubscribe:{fields:{code:{type:"uint32",id:2},reason:{type:"string",id:3}},reserved:[[1,1]]},Subscribe:{fields:{recoverable:{type:"bool",id:1},epoch:{type:"string",id:4},offset:{type:"uint64",id:5},positioned:{type:"bool",id:6},data:{type:"bytes",id:7}},reserved:[[2,2],[3,3]]},Message:{fields:{data:{type:"bytes",id:1}}},Connect:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},data:{type:"bytes",id:3},subs:{keyType:"string",type:"SubscribeResult",id:4},expires:{type:"bool",id:5},ttl:{type:"uint32",id:6},ping:{type:"uint32",id:7},pong:{type:"bool",id:8},session:{type:"string",id:9},node:{type:"string",id:10},time:{type:"int64",id:11}}},Disconnect:{fields:{code:{type:"uint32",id:1},reason:{type:"string",id:2},reconnect:{type:"bool",id:3}}},Refresh:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2}}},ConnectRequest:{fields:{token:{type:"string",id:1},data:{type:"bytes",id:2},subs:{keyType:"string",type:"SubscribeRequest",id:3},name:{type:"string",id:4},version:{type:"string",id:5}}},ConnectResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4},data:{type:"bytes",id:5},subs:{keyType:"string",type:"SubscribeResult",id:6},ping:{type:"uint32",id:7},pong:{type:"bool",id:8},session:{type:"string",id:9},node:{type:"string",id:10},time:{type:"int64",id:11}}},RefreshRequest:{fields:{token:{type:"string",id:1}}},RefreshResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4}}},SubscribeRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2},recover:{type:"bool",id:3},epoch:{type:"string",id:6},offset:{type:"uint64",id:7},data:{type:"bytes",id:8},positioned:{type:"bool",id:9},recoverable:{type:"bool",id:10},join_leave:{type:"bool",id:11},delta:{type:"string",id:12}},reserved:[[4,4],[5,5]]},SubscribeResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2},recoverable:{type:"bool",id:3},epoch:{type:"string",id:6},publications:{rule:"repeated",type:"Publication",id:7},recovered:{type:"bool",id:8},offset:{type:"uint64",id:9},positioned:{type:"bool",id:10},data:{type:"bytes",id:11},was_recovering:{type:"bool",id:12},delta:{type:"bool",id:13}},reserved:[[4,4],[5,5]]},SubRefreshRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2}}},SubRefreshResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2}}},UnsubscribeRequest:{fields:{channel:{type:"string",id:1}}},UnsubscribeResult:{fields:{}},PublishRequest:{fields:{channel:{type:"string",id:1},data:{type:"bytes",id:2}}},PublishResult:{fields:{}},PresenceRequest:{fields:{channel:{type:"string",id:1}}},PresenceResult:{fields:{presence:{keyType:"string",type:"ClientInfo",id:1}}},PresenceStatsRequest:{fields:{channel:{type:"string",id:1}}},PresenceStatsResult:{fields:{num_clients:{type:"uint32",id:1},num_users:{type:"uint32",id:2}}},StreamPosition:{fields:{offset:{type:"uint64",id:1},epoch:{type:"string",id:2}}},HistoryRequest:{fields:{channel:{type:"string",id:1},limit:{type:"int32",id:7},since:{type:"StreamPosition",id:8},reverse:{type:"bool",id:9}},reserved:[[2,2],[3,3],[4,4],[5,5],[6,6]]},HistoryResult:{fields:{publications:{rule:"repeated",type:"Publication",id:1},epoch:{type:"string",id:2},offset:{type:"uint64",id:3}}},PingRequest:{fields:{}},PingResult:{fields:{}},RPCRequest:{fields:{data:{type:"bytes",id:1},method:{type:"string",id:2}}},RPCResult:{fields:{data:{type:"bytes",id:1}}},SendRequest:{fields:{data:{type:"bytes",id:1}}}}}}}}}},Os={nested:xs};var fn=ne.Root.fromJSON(ln),Es=fn.lookupType("protocol.Command"),di=fn.lookupType("protocol.Reply"),Ts=fn.lookupType("protocol.EmulationRequest"),at=class{name(){return"protobuf"}encodeEmulationRequest(t){let e=ne.Writer.create();return Ts.encode(t,e),e.finish()}encodeCommands(t){let e=ne.Writer.create();for(let n in t)if(t.hasOwnProperty(n)){let i=Object.assign({},t[n]);Es.encodeDelimited(i,e)}return e.finish()}decodeReplies(t){let e=[],n=ne.Reader.create(new Uint8Array(t));for(;n.pos<n.len;){let i=di.decodeDelimited(n);e.push(i)}return e}decodeReply(t){let e=ne.Reader.create(new Uint8Array(t));for(;e.pos<e.len;)return di.decodeDelimited(e),{ok:!0,pos:e.pos};return{ok:!1}}applyDeltaIfNeeded(t,e){let n,i;if(t.delta){let s=Ue(e,t.data);n=new Uint8Array(s),i=s}else n=t.data,i=t.data;return{newData:n,newPrevValue:i}}};var ut=class extends re{_formatOverride(){this._codec=new at}};globalThis.Centrifuge=ut;})();
11
11
  //# sourceMappingURL=centrifuge.protobuf.js.map