nnect(i, t, n)
},
onMessage: function(e) {
s._dataReceived(e)
}
}, u),
s.emit("__centrifuge_debug:transport_initialized", {})
}
_sendConnect(e) {
const t = this._constructConnectCommand()
, n = this;
return this._call(t, e).then((e => {
const t = e.reply.connect;
n._connectResponse(t),
e.next && e.next()
}
), (e => {
n._connectError(e.error),
e.next && e.next()
}
)),
t
}
_startReconnecting() {
if (this._debug("start reconnecting"),
!this._isConnecting())
return void this._debug("stop reconnecting: client not in connecting state");
if (this._reconnecting)
return void this._debug("reconnect already in progress, return from reconnect routine");
if (!1 === this._transportClosed)
return void this._debug("waiting for transport close");
this._reconnecting = !0;
const e = "" === this._token;
if (!(this._refreshRequired || e && null !== this._config.getToken))
return void (this._config.getData ? this._config.getData().then((e => {
this._isConnecting() && (this._data = e,
this._initializeTransport())
}
)).catch((e => this._handleGetDataError(e))) : this._initializeTransport());
const t = this;
this._getToken().then((function(e) {
t._isConnecting() && (null != e && null != e ? (t._token = e,
t._debug("connection token refreshed"),
t._config.getData ? t._config.getData().then((function(e) {
t._isConnecting() && (t._data = e,
t._initializeTransport())
}
)).catch((e => t._handleGetDataError(e))) : t._initializeTransport()) : t._failUnauthorized())
}
)).catch((function(e) {
if (!t._isConnecting())
return;
if (e instanceof UnauthorizedError)
return void t._failUnauthorized();
t.emit("error", {
type: "connectToken",
error: {
code: errorCodes.clientConnectToken,
message: void 0 !== e ? e.toString() : ""
}
});
const n = t._getReconnectDelay();
t._debug("error on getting connection token, reconnect after " + n + " milliseconds", e),
t._reconnecting = !1,
t._reconnectTimeout = setTimeout(( () => {
t._startReconnecting()
}
), n)
}
))
}
_handleGetDataError(e) {
if (e instanceof UnauthorizedError)
return void this._failUnauthorized();
this.emit("error", {
type: "connectData",
error: {
code: errorCodes.badConfiguration,
message: (null == e ? void 0 : e.toString()) || ""
}
});
const t = this._getReconnectDelay();
this._debug("error on getting connect data, reconnect after " + t + " milliseconds", e),
this._reconnecting = !1,
this._reconnectTimeout = setTimeout(( () => {
this._startReconnecting()
}
), t)
}
_connectError(e) {
this.state === State$1.Connecting && (109 === e.code && (this._refreshRequired = !0),
e.code < 100 || !0 === e.temporary || 109 === e.code ? (this.emit("error", {
type: "connect",
error: e
}),
this._debug("closing transport due to connect error"),
this._disconnect(e.code, e.message, !0)) : this._disconnect(e.code, e.message, !1))
}
_scheduleReconnect() {
if (!this._isConnecting())
return;
let e = !1;
!this._emulation || this._transportWasOpen || this._triedAllTransports || (e = !0);
let t = this._getReconnectDelay();
e && (t = 0),
this._debug("reconnect after " + t + " milliseconds"),
this._clearReconnectTimeout(),
this._reconnectTimeout = setTimeout(( () => {
this._startReconnecting()
}
), t)
}
_constructConnectCommand() {
const e = {};
this._token && (e.token = this._token),
this._data && (e.data = this._data),
this._config.name && (e.name = this._config.name),
this._config.version && (e.version = this._config.version),
Object.keys(this._config.headers).length > 0 && (e.headers = this._config.headers);
const t = {};
let n = !1;
for (const e in this._serverSubs)
if (this._serverSubs.hasOwnProperty(e) && this._serverSubs[e].recoverable) {
n = !0;
const i = {
recover: !0
};
this._serverSubs[e].offset && (i.offset = this._serverSubs[e].offset),
this._serverSubs[e].epoch && (i.epoch |