null === (t = e.next) || void 0 === t || t.call(e)
}
))
}
))
}
_dataReceived(e) {
this._serverPing > 0 && this._waitServerPing();
const t = this._codec.decodeReplies(e);
this._dispatchPromise = this._dispatchPromise.then(( () => {
let e;
this._dispatchPromise = new Promise((t => {
e = t
}
)),
this._dispatchSynchronized(t, e)
}
))
}
_dispatchSynchronized(e, t) {
let n = Promise.resolve();
for (const t in e)
e.hasOwnProperty(t) && (n = n.then(( () => this._dispatchReply(e[t]))));
n = n.then(( () => {
t()
}
))
}
_dispatchReply(e) {
let t;
const n = new Promise((e => {
t = e
}
));
if (null == e)
return this._debug("dispatch: got undefined or null reply"),
t(),
n;
const i = e.id;
return i && i > 0 ? this._handleReply(e, t) : e.push ? this._handlePush(e.push, t) : this._handleServerPing(t),
n
}
_call(e, t) {
return new Promise(( (n, i) => {
e.id = this._nextCommandId(),
this._registerCall(e.id, n, i),
t || this._addCommand(e)
}
))
}
_startConnecting() {
this._debug("start connecting"),
this._setState(State$1.Connecting) && this.emit("connecting", {
code: connectingCodes.connectCalled,
reason: "connect called"
}),
this._client = null,
this._startReconnecting()
}
_disconnect(e, t, n) {
if (this._isDisconnected())
return;
this._transportIsOpen = !1;
const i = this.state;
this._reconnecting = !1;
const r = {
code: e,
reason: t
};
let s = !1;
if (n ? s = this._setState(State$1.Connecting) : (s = this._setState(State$1.Disconnected),
this._rejectPromises({
code: errorCodes.clientDisconnected,
message: "disconnected"
})),
this._clearOutgoingRequests(),
i === State$1.Connecting && this._clearReconnectTimeout(),
i === State$1.Connected && this._clearConnectedState(),
s && (this._isConnecting() ? this.emit("connecting", r) : this.emit("disconnected", r)),
this._transport) {
this._debug("closing existing transport");
const e = this._transport;
this._transport = null,
e.close(),
this._transportClosed = !0,
this._nextTransportId()
} else
this._debug("no transport to close");
this._scheduleReconnect()
}
_failUnauthorized() {
this._disconnect(disconnectedCodes.unauthorized, "unauthorized", !1)
}
_getToken() {
return this._debug("get connection token"),
this._config.getToken ? this._config.getToken({}) : (this.emit("error", {
type: "configuration",
error: {
code: errorCodes.badConfiguration,
message: "token expired but no getToken function set in the configuration"
}
}),
Promise.reject(new UnauthorizedError("")))
}
_refresh() {
const e = this._client
, t = this;
this._getToken().then((function(n) {
if (e !== t._client)
return;
if (!n)
return void t._failUnauthorized();
if (t._token = n,
t._debug("connection token refreshed"),
!t._isConnected())
return;
const i = {
refresh: {
token: t._token
}
};
t._call(i, !1).then((e => {
const n = e.reply.refresh;
t._refreshResponse(n),
e.next && e.next()
}
), (e => {
t._refreshError(e.error),
e.next && e.next()
}
))
}
)).catch((function(e) {
t._isConnected() && (e instanceof UnauthorizedError ? t._failUnauthorized() : (t.emit("error", {
type: "refreshToken",
error: {
code: errorCodes.clientRefreshToken,
message: void 0 !== e ? e.toString() : ""
}
}),
t._refreshTimeout = setTimeout(( () => t._refresh()), t._getRefreshRetryDelay())))
}
))
}
_refreshError(e) {
e.code < 100 || !0 === e.temporary ? (this.emit("error", {
type: "refresh",
error: e
}),
this._refreshTimeout = setTimeout(( () => this._refresh()), this._getRefreshRetryDelay())) : this._disconnect(e.code, e.message, !1)
}
_getRefreshRetryDelay() {
return backoff(0, 5e3, 1e4)
}
_refreshRespon |