lled, "unsubscribe called", !0)
}
publish(e) {
return __awaiter(this, void 0, void 0, (function*() {
return yield this._methodCall(),
this._centrifuge.publish(this.channel, e)
}
))
}
presence() {
return __awaiter(this, void 0, void 0, (function*() {
return yield this._methodCall(),
this._centrifuge.presence(this.channel)
}
))
}
presenceStats() {
return __awaiter(this, void 0, void 0, (function*() {
return yield this._methodCall(),
this._centrifuge.presenceStats(this.channel)
}
))
}
history(e) {
return __awaiter(this, void 0, void 0, (function*() {
return yield this._methodCall(),
this._centrifuge.history(this.channel, e)
}
))
}
setTagsFilter(e) {
if (e && this._delta)
throw new Error("cannot use delta and tagsFilter together");
this._tagsFilter = e
}
setData(e) {
this._data = e
}
_methodCall() {
return this._isSubscribed() ? Promise.resolve() : this._isUnsubscribed() ? Promise.reject({
code: errorCodes.subscriptionUnsubscribed,
message: this.state
}) : new Promise(( (e, t) => {
const n = this._centrifuge._config.timeout
, i = setTimeout(( () => {
t({
code: errorCodes.timeout,
message: "timeout"
})
}
), n);
this._promises[this._nextPromiseId()] = {
timeout: i,
resolve: e,
reject: t
}
}
))
}
_nextPromiseId() {
return ++this._promiseId
}
_needRecover() {
return !0 === this._recover
}
_isUnsubscribed() {
return this.state === SubscriptionState.Unsubscribed
}
_isSubscribing() {
return this.state === SubscriptionState.Subscribing
}
_isSubscribed() {
return this.state === SubscriptionState.Subscribed
}
_setState(e) {
if (this.state !== e) {
const t = this.state;
return this.state = e,
this.emit("state", {
newState: e,
oldState: t,
channel: this.channel
}),
!0
}
return !1
}
_usesToken() {
return "" !== this._token || null !== this._getToken
}
_clearSubscribingState() {
this._resubscribeAttempts = 0,
this._clearResubscribeTimeout()
}
_clearSubscribedState() {
this._clearRefreshTimeout()
}
_setSubscribed(e) {
if (!this._isSubscribing())
return;
this._clearSubscribingState(),
e.id && (this._id = e.id),
e.recoverable && (this._recover = !0,
this._offset = e.offset || 0,
this._epoch = e.epoch || ""),
e.delta ? this._delta_negotiated = !0 : this._delta_negotiated = !1,
this._setState(SubscriptionState.Subscribed);
const t = this._centrifuge._getSubscribeContext(this.channel, e);
this.emit("subscribed", t),
this._resolvePromises();
const n = e.publications;
if (n && n.length > 0)
for (const e in n)
n.hasOwnProperty(e) && this._handlePublication(n[e]);
!0 === e.expires && (this._refreshTimeout = setTimeout(( () => this._refresh()), ttlMilliseconds(e.ttl)))
}
_setSubscribing(e, t) {
return __awaiter(this, void 0, void 0, (function*() {
this._isSubscribing() || (this._isSubscribed() && this._clearSubscribedState(),
this._setState(SubscriptionState.Subscribing) && this.emit("subscribing", {
channel: this.channel,
code: e,
reason: t
}),
this._centrifuge._transport && this._centrifuge._transport.emulation() && (yield this._unsubPromise),
this._isSubscribing() && this._subscribe())
}
))
}
_subscribe() {
return this._debug("subscribing on", this.channel),
this._isTransportOpen() ? this._inflight ? null : (this._inflight = !0,
this._canSubscribeWithoutGettingToken() ? this._subscribeWithoutToken() : (this._getSubscriptionToken().then((e => this._handleTokenResponse(e))).catch((e => this._handleTokenError(e))),
null)) : (this._debug("delay subscribe on", this.channel, "till connected"),
null)
}
_isTransportOpen() {
return this._centrifuge._transportIsOpen
}
_canSubscribeWithoutGettingToken() {
return !this._usesToken() || !!this._token
}
_subscribeWithoutToken() {
return this._getData ? (this._getDataAndSubscribe(this._token),
null) : this._sendSubscribe(this._token)
}
_getDataAndSubscribe(e) {
this._getData ? this._getData({
channel: this.cha |