t("open"));
let n = ""
, r = 0
, s = new Uint8Array;
const o = t.body.getReader();
return new e.options.readableStream({
start: t => function a() {
return o.read().then(( ({done: o, value: c}) => {
if (o)
return i.dispatchEvent(new Event("close")),
void t.close();
try {
if ("json" === e._protocol)
for (n += e._utf8decoder.decode(c); r < n.length; )
if ("\n" === n[r]) {
const e = n.substring(0, r);
i.dispatchEvent(new MessageEvent("message",{
data: e
})),
n = n.substring(r + 1),
r = 0
} else
++r;
else {
const t = new Uint8Array(s.length + c.length);
for (t.set(s),
t.set(c, s.length),
s = t; ; ) {
const t = e.options.decoder.decodeReply(s);
if (!t.ok)
break;
{
const e = s.slice(0, t.pos);
i.dispatchEvent(new MessageEvent("message",{
data: e
})),
s = s.slice(t.pos)
}
}
}
} catch (e) {
return i.dispatchEvent(new Event("error",{
detail: e
})),
i.dispatchEvent(new Event("close")),
void t.close()
}
a()
}
)).catch((function(e) {
i.dispatchEvent(new Event("error",{
detail: e
})),
i.dispatchEvent(new Event("close")),
t.close()
}
))
}()
})
}
)).catch((e => {
i.dispatchEvent(new Event("error",{
detail: e
})),
i.dispatchEvent(new Event("close"))
}
)),
i
}
supported() {
return null !== this.options.fetch && null !== this.options.readableStream && "undefined" != typeof TextDecoder && "undefined" != typeof AbortController && "undefined" != typeof EventTarget && "undefined" != typeof Event && "undefined" != typeof MessageEvent && "undefined" != typeof Error
}
initialize(e, t, n) {
let i, r;
this._protocol = e,
this._abortController = new AbortController,
"json" === e ? (i = {
Accept: "application/json",
"Content-Type": "application/json"
},
r = n) : (i = {
Accept: "application/octet-stream",
"Content-Type": "application/octet-stream"
},
r = n);
const s = {
method: "POST",
headers: i,
body: r,
mode: "cors",
credentials: "same-origin",
signal: this._abortController.signal
}
, o = this._fetchEventTarget(this, this.endpoint, s);
o.addEventListener("open", ( () => {
t.onOpen()
}
)),
o.addEventListener("error", (e => {
this._abortController.abort(),
t.onError(e)
}
)),
o.addEventListener("close", ( () => {
this._abortController.abort(),
t.onClose({
code: 4,
reason: "connection closed"
})
}
)),
o.addEventListener("message", (e => {
t.onMessage(e.data)
}
))
}
close() {
this._abortController.abort()
}
send(e, t, n) {
let i, r;
const s = {
session: t,
node: n,
data: e
};
"json" === this._protocol ? (i = {
"Content-Type": "application/json"
},
r = JSON.stringify(s)) : (i = {
"Content-Type": "application/octet-stream"
},
r = this.options.encoder.encodeEmulationRequest(s));
const o = {
method: "POST",
headers: i,
body: r,
mode: "cors",
|