return this._inflight = !1,
void this._failUnauthorized();
this.emit("error", {
type: "subscribeToken",
channel: this.channel,
error: {
code: errorCodes.subscriptionSubscribeToken,
message: (null == e ? void 0 : e.toString()) || ""
}
}),
this._inflight = !1,
this._scheduleResubscribe()
} else
this._inflight = !1
}
_sendSubscribe(e) {
if (!this._isTransportOpen())
return this._inflight = !1,
null;
const t = this._buildSubscribeCommand(e);
return this._centrifuge._call(t).then((e => {
this._inflight = !1;
const t = e.reply.subscribe;
this._handleSubscribeResponse(t),
e.next && e.next()
}
), (e => {
this._inflight = !1,
this._handleSubscribeError(e.error),
e.next && e.next()
}
)),
t
}
_buildSubscribeCommand(e) {
const t = {
channel: this.channel
};
if (e && (t.token = e),
this._data && (t.data = this._data),
this._positioned && (t.positioned = !0),
this._recoverable && (t.recoverable = !0),
this._joinLeave && (t.join_leave = !0),
t.flag = subscriptionFlags.channelCompaction,
this._needRecover()) {
t.recover = !0;
const e = this._getOffset();
e && (t.offset = e);
const n = this._getEpoch();
n && (t.epoch = n)
}
return this._delta && (t.delta = this._delta),
this._tagsFilter && (t.tf = this._tagsFilter),
{
subscribe: t
}
}
_debug(...e) {
this._centrifuge._debug(...e)
}
_handleSubscribeError(e) {
this._isSubscribing() && (e.code !== errorCodes.timeout ? this._subscribeError(e) : this._centrifuge._disconnect(connectingCodes.subscribeTimeout, "subscribe timeout", !0))
}
_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(SubscriptionState.Unsubscribed) && this.emit("unsubscribed", {
channel: this.channel,
code: e,
reason: t
}),
this._rejectPromises({
code: errorCodes.subscriptionUnsubscribed,
message: this.state
}),
i
}
_handlePublication(e) {
if (this._delta && this._delta_negotiated) {
const {newData: t, newPrevValue: n} = this._centrifuge._codec.applyDeltaIfNeeded(e, this._prevValue);
e.data = t,
this._prevValue = n
}
const t = this._centrifuge._getPublicationContext(this.channel, e);
this.emit("publication", t),
e.offset && (this._offset = e.offset)
}
_handleJoin(e) {
const t = this._centrifuge._getJoinLeaveContext(e.info);
this.emit("join", {
channel: this.channel,
info: t
})
}
_handleLeave(e) {
const t = this._centrifuge._getJoinLeaveContext(e.info);
this.emit("leave", {
channel: this.channel,
info: t
})
}
_resolvePromises() {
for (const 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 (const 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() {
if (!this._isSubscribing())
return void this._debug("not in subscribing state, skip resubscribe scheduling", this.channel);
const e = this
, t = this._getResubscribeDelay();
this._resubscribeTimeout = setTimeout((function() {
e._isSubscribing() && e._subscribe()
}
), t),
this._debug("resubscribe scheduled after " + t, this.channel)
}
_subscribeError(e) {
if (this._isSubscribing())
if (e.code < 100 || 109 === e.code || !0 === e.temporary) {
109 === e.code && (this._token = "");
const t = {
channel: this.channel,
|