or("out of bounds");
return e
}
getChar() {
return String.fromCharCode(this.getByte())
}
getInt() {
let e, t = 0;
for (; this.haveBytes() && (e = zValue[127 & this.getByte()]) >= 0; )
t = (t << 6) + e;
return this.pos--,
t >>> 0
}
}
, Writer$2 = class {
constructor() {
this.a = []
}
toByteArray(e) {
return Array.isArray(e) ? this.a : new Uint8Array(this.a)
}
putArray(e, t, n) {
for (let i = t; i < n; i++)
this.a.push(e[i])
}
}
;
function checksum(e) {
let t = 0
, n = 0
, i = 0
, r = 0
, s = 0
, o = e.length;
for (; o >= 16; )
t = t + e[s + 0] | 0,
n = n + e[s + 1] | 0,
i = i + e[s + 2] | 0,
r = r + e[s + 3] | 0,
t = t + e[s + 4] | 0,
n = n + e[s + 5] | 0,
i = i + e[s + 6] | 0,
r = r + e[s + 7] | 0,
t = t + e[s + 8] | 0,
n = n + e[s + 9] | 0,
i = i + e[s + 10] | 0,
r = r + e[s + 11] | 0,
t = t + e[s + 12] | 0,
n = n + e[s + 13] | 0,
i = i + e[s + 14] | 0,
r = r + e[s + 15] | 0,
s += 16,
o -= 16;
for (; o >= 4; )
t = t + e[s + 0] | 0,
n = n + e[s + 1] | 0,
i = i + e[s + 2] | 0,
r = r + e[s + 3] | 0,
s += 4,
o -= 4;
switch (r = ((r + (i << 8) | 0) + (n << 16) | 0) + (t << 24) | 0,
o) {
case 3:
r = r + (e[s + 2] << 8) | 0;
case 2:
r = r + (e[s + 1] << 16) | 0;
case 1:
r = r + (e[s + 0] << 24) | 0
}
return r >>> 0
}
function applyDelta(e, t) {
let n = 0;
const i = new Reader$2(t)
, r = e.length
, s = t.length
, o = i.getInt();
if ("\n" !== i.getChar())
throw new Error("size integer not terminated by '\\n'");
const a = new Writer$2;
for (; i.haveBytes(); ) {
const t = i.getInt();
let c;
switch (i.getChar()) {
case "@":
if (c = i.getInt(),
i.haveBytes() && "," !== i.getChar())
throw new Error("copy command not terminated by ','");
if (n += t,
n > o)
throw new Error("copy exceeds output file size");
if (c + t > r)
throw new Error("copy extends past end of input");
a.putArray(e, c, c + t);
break;
case ":":
if (n += t,
n > o)
throw new Error("insert command gives an output larger than predicted");
if (t > s)
throw new Error("insert count exceeds size of delta");
a.putArray(i.a, i.pos, i.pos + t),
i.pos += t;
break;
case ";":
{
const i = a.toByteArray(e);
if (t !== checksum(i))
throw new Error("bad checksum");
if (n !== o)
throw new Error("generated size does not match predicted size");
return i
}
default:
throw new Error("unknown delta operator")
}
}
throw new Error("unterminated delta")
}
class JsonCodec {
name() {
return "json"
}
encodeCommands(e) {
return e.map((e => JSON.stringify(e))).join("\n")
}
decodeReplies(e) {
return e.trim().split("\n").map((e => JSON.parse(e)))
}
applyDeltaIfNeeded(e, t) {
let n, i;
if (e.delta) {
const r = applyDelta(t, (new TextEncoder).encode(e.data));
n = JSON.parse((new TextDecoder).decode(r)),
i = r
} else
n = JSON.parse(e.data),
i = (new TextEncoder).encode(e.data);
return {
newData: n,
newPrevValue: i
}
}
}
const defaults = {
headers: {},
token: "",
getToken: null,
data: null,
getData: null,
debug: !1,
name: "js",
version: "",
fetch: null,
readableStream: null,
websocket: null,
eventsource: null,
sockjs: null,
sockjsOptions: {},
emulationEndpoint: "/emulation",
minReconnectDelay: 500,
maxReconnectDelay: 2e4,
timeout: 5e3,
maxServerPingDelay: 1e4,
networkEventTarget: null
};
class UnauthorizedError extends Error {
constructor(e) {
super(e),
this.name = this.constructor.name
}
}
class Centrifuge extends EventEmitter$1 {
constructor(e, t) {
super(),
this._reconnectTimeout = null,
this._refreshTimeout = null,
|