(this.on("state", (e => {
this._debug("client state", e.oldState, "->", e.newState)
}
)),
this.on("error", (e => {
this._debug("client error", e)
}
))) : this.on("error", (function() {
Function.prototype()
}
))
}
newSubscription(e, t) {
if (null !== this.getSubscription(e))
throw new Error("Subscription to the channel " + e + " already exists");
const n = new Subscription(this,e,t);
return this._subs[e] = n,
n
}
getSubscription(e) {
return this._getSub(e)
}
removeSubscription(e) {
e && (e.state !== SubscriptionState.Unsubscribed && e.unsubscribe(),
this._removeSubscription(e))
}
subscriptions() {
return this._subs
}
ready(e) {
return __awaiter(this, void 0, void 0, (function*() {
switch (this.state) {
case State$1.Disconnected:
throw {
code: errorCodes.clientDisconnected,
message: "client disconnected"
};
case State$1.Connected:
return;
default:
return new Promise(( (t, n) => {
const i = {
resolve: t,
reject: n
};
e && (i.timeout = setTimeout(( () => {
n({
code: errorCodes.timeout,
message: "timeout"
})
}
), e)),
this._promises[this._nextPromiseId()] = i
}
))
}
}
))
}
connect() {
this._isConnected() ? this._debug("connect called when already connected") : this._isConnecting() ? this._debug("connect called when already connecting") : (this._debug("connect called"),
this._reconnectAttempts = 0,
this._startConnecting())
}
disconnect() {
this._disconnect(disconnectedCodes.disconnectCalled, "disconnect called", !1)
}
setToken(e) {
this._token = e
}
setData(e) {
this._data = e
}
setHeaders(e) {
this._config.headers = e
}
send(e) {
return __awaiter(this, void 0, void 0, (function*() {
const t = {
send: {
data: e
}
};
if (yield this._methodCall(),
!this._transportSendCommands([t]))
throw this._createErrorObject(errorCodes.transportWriteError, "transport write error")
}
))
}
rpc(e, t) {
return __awaiter(this, void 0, void 0, (function*() {
const n = {
rpc: {
method: e,
data: t
}
};
return yield this._methodCall(),
{
data: (yield this._callPromise(n, (e => e.rpc))).data
}
}
))
}
publish(e, t) {
return __awaiter(this, void 0, void 0, (function*() {
const n = {
publish: {
channel: e,
data: t
}
};
return yield this._methodCall(),
yield this._callPromise(n, ( () => ({}))),
{}
}
))
}
history(e, t) {
return __awaiter(this, void 0, void 0, (function*() {
const n = {
history: this._getHistoryRequest(e, t)
};
yield this._methodCall();
const i = yield this._callPromise(n, (e => e.history))
, r = [];
if (i.publications)
for (let t = 0; t < i.publications.length; t++)
r.push(this._getPublicationContext(e, i.publications[t]));
return {
publications: r,
epoch: i.epoch || "",
offset: i.offset || 0
}
}
))
}
presence(e) {
return __awaiter(this, void 0, void 0, (function*() {
const t = {
presence: {
channel: e
}
};
yield this._methodCall();
const n = (yield this._callPromise(t, (e => e.presence))).presence;
for (const e in n)
if (Object.prototype.hasOwnProperty.call(n, e)) {
const t = n[e]
, i = t.conn_info
, r = t.chan_info;
i && (t.connInfo = i),
r && (t.chanInfo = r)
}
return {
clients: n
}
}
))
}
presenceStats(e) {
return |