this._codec = new JsonCodec,
this._formatOverride(),
(!0 === this._config.debug || "undefined" != typeof localStorage && "function" == typeof localStorage.getItem && localStorage.getItem("centrifuge.debug")) && (this._debugEnabled = !0),
this._debug("config", this._config),
"string" == typeof this._endpoint)
;
else {
if (!Array.isArray(this._endpoint))
throw new Error("unsupported url configuration type: only string or array of objects are supported");
this._transports = this._endpoint,
this._emulation = !0;
for (const e in this._transports)
if (this._transports.hasOwnProperty(e)) {
const t = this._transports[e];
if (!t.endpoint || !t.transport)
throw new Error("malformed transport configuration");
const n = t.transport;
if (["websocket", "http_stream", "sse", "sockjs", "webtransport"].indexOf(n) < 0)
throw new Error("unsupported transport name: " + n)
}
}
}
_setState(e) {
if (this.state !== e) {
this._reconnecting = !1;
const t = this.state;
return this.state = e,
this.emit("state", {
newState: e,
oldState: t
}),
!0
}
return !1
}
_isDisconnected() {
return this.state === State$1.Disconnected
}
_isConnecting() {
return this.state === State$1.Connecting
}
_isConnected() {
return this.state === State$1.Connected
}
_nextCommandId() {
return ++this._commandId
}
_setNetworkEvents() {
if (this._networkEventsSet)
return;
let e = null;
null !== this._config.networkEventTarget ? e = this._config.networkEventTarget : void 0 !== globalThis.addEventListener && (e = globalThis),
e && (e.addEventListener("offline", ( () => {
this._debug("offline event triggered"),
this.state !== State$1.Connected && this.state !== State$1.Connecting || (this._disconnect(connectingCodes.transportClosed, "transport closed", !0),
this._deviceWentOffline = !0)
}
)),
e.addEventListener("online", ( () => {
this._debug("online event triggered"),
this.state === State$1.Connecting && (this._deviceWentOffline && !this._transportClosed && (this._deviceWentOffline = !1,
this._transportClosed = !0),
this._clearReconnectTimeout(),
this._startReconnecting())
}
)),
this._networkEventsSet = !0)
}
_getReconnectDelay() {
const e = backoff(this._reconnectAttempts, this._config.minReconnectDelay, this._config.maxReconnectDelay);
return this._reconnectAttempts += 1,
e
}
_clearOutgoingRequests() {
for (const e in this._callbacks)
if (this._callbacks.hasOwnProperty(e)) {
const t = this._callbacks[e];
clearTimeout(t.timeout);
const n = t.errback;
if (!n)
continue;
n({
error: this._createErrorObject(errorCodes.connectionClosed, "connection closed")
})
}
this._callbacks = {}
}
_clearConnectedState() {
this._client = null,
this._clearServerPingTimeout(),
this._clearRefreshTimeout();
for (const e in this._subs) {
if (!this._subs.hasOwnProperty(e))
continue;
const t = this._subs[e];
t.state === SubscriptionState.Subscribed && t._setSubscribing(subscribingCodes.transportClosed, "transport closed")
}
for (const e in this._serverSubs)
this._serverSubs.hasOwnProperty(e) && this.emit("subscribing", {
channel: e
})
}
_handleWriteError(e) {
for (const t of e) {
const e = t.id;
if (!(e in this._callbacks))
continue;
const n = this._callbacks[e];
clearTimeout(this._callbacks[e].timeout),
delete this._callbacks[e],
(0,
n.errback)({
error: this._createErrorObject(errorCodes.transportWriteError, "transport write error")
})
}
}
_transportSendCommands(e) {
if (!e.length)
return !0;
if (!this._transport)
return !1;
try {
this._transport.send(this._codec.encodeCommands(e), this._session, this._node)
} catch (t) {
return this._debug("error writing commands", t),
this._handleWriteError(e),
!1
}
return !0
}
_initializeTransport() {
let e;
null !== this._config.websocket ? e = this._config.websocket : "function" != typeof globalThis.WebSocket && "object" != typeof globalThis.WebSocket || (e = globalThis.WebSocket);
let t = null;
null |