r && (this._tagsFilter = e.tagsFilter),
this._tagsFilter && this._delta)
throw new Error("cannot use delta and tagsFilter together")
}
}
_getOffset() {
const e = this._offset;
return null !== e ? e : 0
}
_getEpoch() {
const e = this._epoch;
return null !== e ? e : ""
}
_clearRefreshTimeout() {
null !== this._refreshTimeout && (clearTimeout(this._refreshTimeout),
this._refreshTimeout = null)
}
_clearResubscribeTimeout() {
null !== this._resubscribeTimeout && (clearTimeout(this._resubscribeTimeout),
this._resubscribeTimeout = null)
}
_getSubscriptionToken() {
this._debug("get subscription token for channel", this.channel);
const e = {
channel: this.channel
}
, t = this._getToken;
return null === t ? (this.emit("error", {
type: "configuration",
channel: this.channel,
error: {
code: errorCodes.badConfiguration,
message: "provide a function to get channel subscription token"
}
}),
Promise.reject(new UnauthorizedError(""))) : t(e)
}
_refresh() {
this._clearRefreshTimeout();
const e = this;
this._getSubscriptionToken().then((function(t) {
if (!e._isSubscribed())
return;
if (!t)
return void e._failUnauthorized();
e._token = t;
const n = {
sub_refresh: {
channel: e.channel,
token: t
}
};
e._centrifuge._call(n).then((t => {
const n = t.reply.sub_refresh;
e._refreshResponse(n),
t.next && t.next()
}
), (t => {
e._refreshError(t.error),
t.next && t.next()
}
))
}
)).catch((function(t) {
t instanceof UnauthorizedError ? e._failUnauthorized() : (e.emit("error", {
type: "refreshToken",
channel: e.channel,
error: {
code: errorCodes.subscriptionRefreshToken,
message: void 0 !== t ? t.toString() : ""
}
}),
e._refreshTimeout = setTimeout(( () => e._refresh()), e._getRefreshRetryDelay()))
}
))
}
_refreshResponse(e) {
this._isSubscribed() && (this._debug("subscription token refreshed, channel", this.channel),
this._clearRefreshTimeout(),
!0 === e.expires && (this._refreshTimeout = setTimeout(( () => this._refresh()), ttlMilliseconds(e.ttl))))
}
_refreshError(e) {
this._isSubscribed() && (e.code < 100 || !0 === e.temporary ? (this.emit("error", {
type: "refresh",
channel: this.channel,
error: e
}),
this._refreshTimeout = setTimeout(( () => this._refresh()), this._getRefreshRetryDelay())) : this._setUnsubscribed(e.code, e.message, !0))
}
_getRefreshRetryDelay() {
return backoff(0, 1e4, 2e4)
}
_failUnauthorized() {
this._setUnsubscribed(unsubscribedCodes.unauthorized, "unauthorized", !0)
}
}
class SockjsTransport {
constructor(e, t) {
this.endpoint = e,
this.options = t,
this._transport = null
}
name() {
return "sockjs"
}
subName() {
return "sockjs-" + this._transport.transport
}
emulation() {
return !1
}
supported() {
return null !== this.options.sockjs
}
initialize(e, t) {
this._transport = new this.options.sockjs(this.endpoint,null,this.options.sockjsOptions),
this._transport.onopen = () => {
t.onOpen()
}
,
this._transport.onerror = e => {
t.onError(e)
}
,
this._transport.onclose = e => {
t.onClose(e)
}
,
this._transport.onmessage = e => {
t.onMessage(e.data)
}
}
close() {
this._transport.close()
}
send(e) {
this._transport.send(e)
}
}
class WebsocketTransport {
constructor(e, t) {
this.endpoint = e,
this.options = t,
this._transport = null
}
name() {
return "websocket"
}
subName() {
return "websocket"
}
emulation() {
return !1
}
supported() {
return void 0 !== this.options.websocket && null !== this.options.websocket
}
initialize(e, t) {
let n = "";
"protobuf" === e && (n = "centrifuge-protobuf"),
this._transport = "" |