@ethora/chat-component
Version:
1. npm create vite@latest 2. select name of project, select type (react/js) 3. cd project-name 4. npm i 5. npm i @ethora/chat-component 6. go to file src/App.tsx and replace it with this code
1,607 lines (1,606 loc) • 1.77 MB
JavaScript
import { jsx as h, jsxs as S, Fragment as we } from "react/jsx-runtime";
import * as _e from "react";
import Be, { createContext as a1, useContext as zA, useState as H, useEffect as se, useDebugValue as Uf, createElement as up, useRef as he, Fragment as zf, useMemo as ke, useCallback as ee, forwardRef as hp, PureComponent as mp, useSyncExternalStore as gp } from "react";
function _i(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
function pp(n) {
if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
var e = n.default;
if (typeof e == "function") {
var i = function t() {
var r = !1;
try {
r = this instanceof t;
} catch {
}
return r ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
};
i.prototype = e.prototype;
} else i = {};
return Object.defineProperty(i, "__esModule", { value: !0 }), Object.keys(n).forEach(function(t) {
var r = Object.getOwnPropertyDescriptor(n, t);
Object.defineProperty(i, t, r.get ? r : {
enumerable: !0,
get: function() {
return n[t];
}
});
}), i;
}
var $i = {}, et = {}, Nn = {}, sa, Vf;
function VA() {
return Vf || (Vf = 1, sa = class extends Error {
constructor(e) {
super(e), this.name = "TimeoutError";
}
}), sa;
}
var aa, Jf;
function o1() {
return Jf || (Jf = 1, aa = function(e) {
let i;
const t = new Promise((r) => {
i = setTimeout(r, e);
});
return t.timeout = i, t;
}), aa;
}
var oa, Xf;
function vp() {
if (Xf) return oa;
Xf = 1;
const n = VA(), e = o1();
return oa = function(t, r) {
const s = e(r);
function a() {
clearTimeout(s.timeout);
}
return Promise.race([
t.finally(a),
s.then(() => {
throw new n();
})
]);
}, oa;
}
var Aa, Kf;
function bp() {
if (Kf) return Aa;
Kf = 1;
const n = VA();
return Aa = function(i, t, r = "error", s) {
return new Promise((a, o) => {
let A;
const f = () => {
clearTimeout(A), i.removeListener(t, l), i.removeListener(r, d);
};
function d(c) {
o(c), f();
}
function l(c) {
a(c), f();
}
i.once(t, l), r && i.once(r, d), s && (A = setTimeout(() => {
f(), o(new n());
}, s));
});
}, Aa;
}
var zt = { exports: {} }, Zf;
function Rt() {
if (Zf) return zt.exports;
Zf = 1;
var n = typeof Reflect == "object" ? Reflect : null, e = n && typeof n.apply == "function" ? n.apply : function(v, p, x) {
return Function.prototype.apply.call(v, p, x);
}, i;
n && typeof n.ownKeys == "function" ? i = n.ownKeys : Object.getOwnPropertySymbols ? i = function(v) {
return Object.getOwnPropertyNames(v).concat(Object.getOwnPropertySymbols(v));
} : i = function(v) {
return Object.getOwnPropertyNames(v);
};
function t(w) {
console && console.warn && console.warn(w);
}
var r = Number.isNaN || function(v) {
return v !== v;
};
function s() {
s.init.call(this);
}
zt.exports = s, zt.exports.once = C, s.EventEmitter = s, s.prototype._events = void 0, s.prototype._eventsCount = 0, s.prototype._maxListeners = void 0;
var a = 10;
function o(w) {
if (typeof w != "function")
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof w);
}
Object.defineProperty(s, "defaultMaxListeners", {
enumerable: !0,
get: function() {
return a;
},
set: function(w) {
if (typeof w != "number" || w < 0 || r(w))
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + w + ".");
a = w;
}
}), s.init = function() {
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
}, s.prototype.setMaxListeners = function(v) {
if (typeof v != "number" || v < 0 || r(v))
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + v + ".");
return this._maxListeners = v, this;
};
function A(w) {
return w._maxListeners === void 0 ? s.defaultMaxListeners : w._maxListeners;
}
s.prototype.getMaxListeners = function() {
return A(this);
}, s.prototype.emit = function(v) {
for (var p = [], x = 1; x < arguments.length; x++) p.push(arguments[x]);
var B = v === "error", I = this._events;
if (I !== void 0)
B = B && I.error === void 0;
else if (!B)
return !1;
if (B) {
var E;
if (p.length > 0 && (E = p[0]), E instanceof Error)
throw E;
var D = new Error("Unhandled error." + (E ? " (" + E.message + ")" : ""));
throw D.context = E, D;
}
var M = I[v];
if (M === void 0)
return !1;
if (typeof M == "function")
e(M, this, p);
else
for (var N = M.length, L = m(M, N), x = 0; x < N; ++x)
e(L[x], this, p);
return !0;
};
function f(w, v, p, x) {
var B, I, E;
if (o(p), I = w._events, I === void 0 ? (I = w._events = /* @__PURE__ */ Object.create(null), w._eventsCount = 0) : (I.newListener !== void 0 && (w.emit(
"newListener",
v,
p.listener ? p.listener : p
), I = w._events), E = I[v]), E === void 0)
E = I[v] = p, ++w._eventsCount;
else if (typeof E == "function" ? E = I[v] = x ? [p, E] : [E, p] : x ? E.unshift(p) : E.push(p), B = A(w), B > 0 && E.length > B && !E.warned) {
E.warned = !0;
var D = new Error("Possible EventEmitter memory leak detected. " + E.length + " " + String(v) + " listeners added. Use emitter.setMaxListeners() to increase limit");
D.name = "MaxListenersExceededWarning", D.emitter = w, D.type = v, D.count = E.length, t(D);
}
return w;
}
s.prototype.addListener = function(v, p) {
return f(this, v, p, !1);
}, s.prototype.on = s.prototype.addListener, s.prototype.prependListener = function(v, p) {
return f(this, v, p, !0);
};
function d() {
if (!this.fired)
return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
}
function l(w, v, p) {
var x = { fired: !1, wrapFn: void 0, target: w, type: v, listener: p }, B = d.bind(x);
return B.listener = p, x.wrapFn = B, B;
}
s.prototype.once = function(v, p) {
return o(p), this.on(v, l(this, v, p)), this;
}, s.prototype.prependOnceListener = function(v, p) {
return o(p), this.prependListener(v, l(this, v, p)), this;
}, s.prototype.removeListener = function(v, p) {
var x, B, I, E, D;
if (o(p), B = this._events, B === void 0)
return this;
if (x = B[v], x === void 0)
return this;
if (x === p || x.listener === p)
--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete B[v], B.removeListener && this.emit("removeListener", v, x.listener || p));
else if (typeof x != "function") {
for (I = -1, E = x.length - 1; E >= 0; E--)
if (x[E] === p || x[E].listener === p) {
D = x[E].listener, I = E;
break;
}
if (I < 0)
return this;
I === 0 ? x.shift() : g(x, I), x.length === 1 && (B[v] = x[0]), B.removeListener !== void 0 && this.emit("removeListener", v, D || p);
}
return this;
}, s.prototype.off = s.prototype.removeListener, s.prototype.removeAllListeners = function(v) {
var p, x, B;
if (x = this._events, x === void 0)
return this;
if (x.removeListener === void 0)
return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : x[v] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete x[v]), this;
if (arguments.length === 0) {
var I = Object.keys(x), E;
for (B = 0; B < I.length; ++B)
E = I[B], E !== "removeListener" && this.removeAllListeners(E);
return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this;
}
if (p = x[v], typeof p == "function")
this.removeListener(v, p);
else if (p !== void 0)
for (B = p.length - 1; B >= 0; B--)
this.removeListener(v, p[B]);
return this;
};
function c(w, v, p) {
var x = w._events;
if (x === void 0)
return [];
var B = x[v];
return B === void 0 ? [] : typeof B == "function" ? p ? [B.listener || B] : [B] : p ? b(B) : m(B, B.length);
}
s.prototype.listeners = function(v) {
return c(this, v, !0);
}, s.prototype.rawListeners = function(v) {
return c(this, v, !1);
}, s.listenerCount = function(w, v) {
return typeof w.listenerCount == "function" ? w.listenerCount(v) : u.call(w, v);
}, s.prototype.listenerCount = u;
function u(w) {
var v = this._events;
if (v !== void 0) {
var p = v[w];
if (typeof p == "function")
return 1;
if (p !== void 0)
return p.length;
}
return 0;
}
s.prototype.eventNames = function() {
return this._eventsCount > 0 ? i(this._events) : [];
};
function m(w, v) {
for (var p = new Array(v), x = 0; x < v; ++x)
p[x] = w[x];
return p;
}
function g(w, v) {
for (; v + 1 < w.length; v++)
w[v] = w[v + 1];
w.pop();
}
function b(w) {
for (var v = new Array(w.length), p = 0; p < v.length; ++p)
v[p] = w[p].listener || w[p];
return v;
}
function C(w, v) {
return new Promise(function(p, x) {
function B(E) {
w.removeListener(v, I), x(E);
}
function I() {
typeof w.removeListener == "function" && w.removeListener("error", B), p([].slice.call(arguments));
}
k(w, v, I, { once: !0 }), v !== "error" && y(w, B, { once: !0 });
});
}
function y(w, v, p) {
typeof w.on == "function" && k(w, "error", v, p);
}
function k(w, v, p, x) {
if (typeof w.on == "function")
x.once ? w.once(v, p) : w.on(v, p);
else if (typeof w.addEventListener == "function")
w.addEventListener(v, function B(I) {
x.once && w.removeEventListener(v, B), p(I);
});
else
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof w);
}
return zt.exports;
}
var fa, $f;
function wp() {
return $f || ($f = 1, fa = function() {
this.promise = new Promise((e, i) => {
this.resolve = e, this.reject = i;
});
}), fa;
}
var ed;
function Ct() {
if (ed) return Nn;
ed = 1;
const n = vp(), e = o1(), i = VA(), t = bp(), r = Rt(), s = wp();
return Nn.EventEmitter = r, Nn.timeout = n, Nn.delay = e, Nn.TimeoutError = i, Nn.promise = t, Nn.Deferred = s, Nn;
}
var sn = { exports: {} }, nt = {}, nd;
function A1() {
return nd || (nd = 1, nt.detect = function(e) {
return !(!e || e.replaceAll(String.raw`\20`, "").replaceAll(String.raw`\22`, "").replaceAll(String.raw`\26`, "").replaceAll(String.raw`\27`, "").replaceAll(String.raw`\2f`, "").replaceAll(String.raw`\3a`, "").replaceAll(String.raw`\3c`, "").replaceAll(String.raw`\3e`, "").replaceAll(String.raw`\40`, "").replaceAll(String.raw`\5c`, "").search(/[ "&'/:<>@\\]/g) === -1);
}, nt.escape = function(e) {
return e === null ? null : e.replaceAll(/^\s+|\s+$/g, "").replaceAll("\\", String.raw`\5c`).replaceAll(" ", String.raw`\20`).replaceAll('"', String.raw`\22`).replaceAll("&", String.raw`\26`).replaceAll("'", String.raw`\27`).replaceAll("/", String.raw`\2f`).replaceAll(":", String.raw`\3a`).replaceAll("<", String.raw`\3c`).replaceAll(">", String.raw`\3e`).replaceAll("@", String.raw`\40`);
}, nt.unescape = function(e) {
return e === null ? null : e.replaceAll(String.raw`\20`, " ").replaceAll(String.raw`\22`, '"').replaceAll(String.raw`\26`, "&").replaceAll(String.raw`\27`, "'").replaceAll(String.raw`\2f`, "/").replaceAll(String.raw`\3a`, ":").replaceAll(String.raw`\3c`, "<").replaceAll(String.raw`\3e`, ">").replaceAll(String.raw`\40`, "@").replaceAll(String.raw`\5c`, "\\");
}), nt;
}
var da, id;
function f1() {
if (id) return da;
id = 1;
const n = A1();
class e {
constructor(t, r, s) {
if (typeof r != "string" || !r)
throw new TypeError("Invalid domain.");
this.setDomain(r), this.setLocal(typeof t == "string" ? t : ""), this.setResource(typeof s == "string" ? s : "");
}
[Symbol.toPrimitive](t) {
return t === "number" ? NaN : this.toString();
}
toString(t) {
let r = this._domain;
return this._local && (r = this.getLocal(t) + "@" + r), this._resource && (r = r + "/" + this._resource), r;
}
/**
* Convenience method to distinguish users
* */
bare() {
return this._resource ? new e(this._local, this._domain, null) : this;
}
/**
* Comparison function
* */
equals(t) {
return this._local === t._local && this._domain === t._domain && this._resource === t._resource;
}
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-localpart
* */
setLocal(t, r) {
return r = r || n.detect(t), r && (t = n.escape(t)), this._local = t && t.toLowerCase(), this;
}
getLocal(t = !1) {
let r = null;
return r = t ? n.unescape(this._local) : this._local, r;
}
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-domain
*/
setDomain(t) {
return this._domain = t.toLowerCase(), this;
}
getDomain() {
return this._domain;
}
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart
*/
setResource(t) {
return this._resource = t, this;
}
getResource() {
return this._resource;
}
}
return Object.defineProperty(e.prototype, "local", {
get: e.prototype.getLocal,
set: e.prototype.setLocal
}), Object.defineProperty(e.prototype, "domain", {
get: e.prototype.getDomain,
set: e.prototype.setDomain
}), Object.defineProperty(e.prototype, "resource", {
get: e.prototype.getResource,
set: e.prototype.setResource
}), da = e, da;
}
var ca, td;
function yp() {
if (td) return ca;
td = 1;
const n = f1();
return ca = function(i) {
let t, r;
const s = i.indexOf("/");
s !== -1 && (r = i.slice(s + 1), i = i.slice(0, s));
const a = i.indexOf("@");
return a !== -1 && (t = i.slice(0, a), i = i.slice(a + 1)), new n(t, i, r);
}, ca;
}
var rd;
function Es() {
if (rd) return sn.exports;
rd = 1;
const n = f1(), e = A1(), i = yp();
function t(...r) {
return !r[1] && !r[2] ? i(...r) : new n(...r);
}
return sn.exports = t.bind(), sn.exports.jid = t, sn.exports.JID = n, sn.exports.equal = function(s, a) {
return s.equals(a);
}, sn.exports.detectEscape = e.detect, sn.exports.escapeLocal = e.escape, sn.exports.unescapeLocal = e.unescape, sn.exports.parse = i, sn.exports;
}
var la = { exports: {} }, pi = {}, sd;
function JA() {
if (sd) return pi;
sd = 1;
const n = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'"
};
function e(A) {
return n[A];
}
const i = {
"&": "&",
"<": "<",
">": ">",
""": '"',
"'": "'"
};
function t(A) {
if (A[1] === "#") {
const f = A[2] === "x" ? parseInt(A.slice(3), 16) : parseInt(A.slice(2), 10);
if (f === 9 || f === 10 || f === 13 || f >= 32 && f <= 55295 || f >= 57344 && f <= 65533 || f >= 65536 && f <= 1114111)
return String.fromCodePoint(f);
throw new Error("Illegal XML character 0x" + f.toString(16));
}
if (i[A])
return i[A] || A;
throw new Error("Illegal XML entity " + A);
}
function r(A) {
return A.replace(/["&'<>]/g, e);
}
function s(A) {
let f = "", d = -1, l = -1, c = 0;
for (; (d = A.indexOf("&", c)) !== -1 && (l = A.indexOf(";", d + 1)) !== -1; )
f = f + A.slice(c, d) + t(A.slice(d, l + 1)), c = l + 1;
return c === 0 ? A : (f = f + A.substring(c), f);
}
function a(A) {
return A.replace(/[&<>]/g, e);
}
function o(A) {
return A.replace(/&(amp|#38|lt|#60|gt|#62);/g, t);
}
return pi.escapeXML = r, pi.escapeXMLText = a, pi.unescapeXML = s, pi.unescapeXMLText = o, pi;
}
var ua, ad;
function XA() {
if (ad) return ua;
ad = 1;
var n = JA();
class e {
constructor(t, r) {
this.name = t, this.parent = null, this.children = [], this.attrs = {}, this.setAttrs(r);
}
/* Accessors */
/**
* if (element.is('message', 'jabber:client')) ...
**/
is(t, r) {
return this.getName() === t && (!r || this.getNS() === r);
}
/* without prefix */
getName() {
const t = this.name.indexOf(":");
return t >= 0 ? this.name.slice(t + 1) : this.name;
}
/**
* retrieves the namespace of the current element, upwards recursively
**/
getNS() {
const t = this.name.indexOf(":");
if (t >= 0) {
const r = this.name.slice(0, t);
return this.findNS(r);
}
return this.findNS();
}
/**
* find the namespace to the given prefix, upwards recursively
**/
findNS(t) {
if (t) {
const r = "xmlns:" + t;
if (this.attrs[r])
return this.attrs[r];
if (this.parent)
return this.parent.findNS(t);
} else {
if (this.attrs.xmlns)
return this.attrs.xmlns;
if (this.parent)
return this.parent.findNS();
}
}
/**
* Recursiverly gets all xmlns defined, in the form of {url:prefix}
**/
getXmlns() {
let t = {};
this.parent && (t = this.parent.getXmlns());
for (const r in this.attrs) {
const s = r.match("xmlns:?(.*)");
this.attrs.hasOwnProperty(r) && s && (t[this.attrs[r]] = s[1]);
}
return t;
}
setAttrs(t) {
typeof t == "string" ? this.attrs.xmlns = t : t && Object.assign(this.attrs, t);
}
/**
* xmlns can be null, returns the matching attribute.
**/
getAttr(t, r) {
if (!r)
return this.attrs[t];
const s = this.getXmlns();
return s[r] ? this.attrs[[s[r], t].join(":")] : null;
}
/**
* xmlns can be null
**/
getChild(t, r) {
return this.getChildren(t, r)[0];
}
/**
* xmlns can be null
**/
getChildren(t, r) {
const s = [];
for (const a of this.children)
a.getName && a.getName() === t && (!r || a.getNS() === r) && s.push(a);
return s;
}
/**
* xmlns and recursive can be null
**/
getChildByAttr(t, r, s, a) {
return this.getChildrenByAttr(t, r, s, a)[0];
}
/**
* xmlns and recursive can be null
**/
getChildrenByAttr(t, r, s, a) {
let o = [];
for (const A of this.children)
A.attrs && A.attrs[t] === r && (!s || A.getNS() === s) && o.push(A), a && A.getChildrenByAttr && o.push(A.getChildrenByAttr(t, r, s, !0));
return a && (o = o.flat()), o;
}
getChildrenByFilter(t, r) {
let s = [];
for (const a of this.children)
t(a) && s.push(a), r && a.getChildrenByFilter && s.push(a.getChildrenByFilter(t, !0));
return r && (s = s.flat()), s;
}
getText() {
let t = "";
for (const r of this.children)
(typeof r == "string" || typeof r == "number") && (t += r);
return t;
}
getChildText(t, r) {
const s = this.getChild(t, r);
return s ? s.getText() : null;
}
/**
* Return all direct descendents that are Elements.
* This differs from `getChildren` in that it will exclude text nodes,
* processing instructions, etc.
*/
getChildElements() {
return this.getChildrenByFilter((t) => t instanceof e);
}
/* Builder */
/** returns uppermost parent */
root() {
return this.parent ? this.parent.root() : this;
}
/** just parent or itself */
up() {
return this.parent ? this.parent : this;
}
/** create child node and return it */
c(t, r) {
return this.cnode(new e(t, r));
}
cnode(t) {
return this.children.push(t), typeof t == "object" && (t.parent = this), t;
}
append(...t) {
for (const r of t)
this.children.push(r), typeof r == "object" && (r.parent = this);
}
prepend(...t) {
for (const r of t)
this.children.unshift(r), typeof r == "object" && (r.parent = this);
}
/** add text node and return element */
t(t) {
return this.children.push(t), this;
}
/* Manipulation */
/**
* Either:
* el.remove(childEl)
* el.remove('author', 'urn:...')
*/
remove(t, r) {
const s = typeof t == "string" ? (a) => !(a.is && a.is(t, r)) : (a) => a !== t;
return this.children = this.children.filter(s), this;
}
text(t) {
return t && this.children.length === 1 ? (this.children[0] = t, this) : this.getText();
}
attr(t, r) {
return typeof r < "u" || r === null ? (this.attrs || (this.attrs = {}), this.attrs[t] = r, this) : this.attrs[t];
}
/* Serialization */
toString() {
let t = "";
return this.write((r) => {
t += r;
}), t;
}
_addChildren(t) {
t(">");
for (const r of this.children)
r != null && (r.write ? r.write(t) : typeof r == "string" ? t(n.escapeXMLText(r)) : r.toString && t(n.escapeXMLText(r.toString(10))));
t("</"), t(this.name), t(">");
}
write(t) {
t("<"), t(this.name);
for (const r in this.attrs) {
const s = this.attrs[r];
s != null && (t(" "), t(r), t('="'), t(n.escapeXML(typeof s == "string" ? s : s.toString(10))), t('"'));
}
this.children.length === 0 ? t("/>") : this._addChildren(t);
}
}
return e.prototype.tree = e.prototype.root, ua = e, ua;
}
var ha, od;
function kp() {
if (od) return ha;
od = 1;
var n = XA();
function e(t, r) {
if (Array.isArray(r)) {
for (const s of r) e(t, s);
return;
}
r === "" || r == null || r === !0 || r === !1 || t.cnode(r);
}
function i(t, r, ...s) {
if (typeof r == "object" && r !== null) {
delete r.__source, delete r.__self;
for (const [o, A] of Object.entries(r))
A == null ? delete r[o] : r[o] = A.toString(10);
}
const a = new n(t, r);
for (const o of s)
e(a, o);
return a;
}
return ha = i, ha;
}
var ma, Ad;
function Cp() {
if (Ad) return ma;
Ad = 1;
var n = Rt(), e = JA();
const i = 0, t = 1, r = 2, s = 3, a = 4, o = 5, A = 6, f = 7, d = 8, l = 9, c = 10;
class u extends n.EventEmitter {
constructor() {
super();
let g = i, b, C, y, k, w, v, p, x, B = 0, I;
this._handleTagOpening = function(D, M, N) {
D ? this.emit("endElement", M, !1) : (this.emit("startElement", M, N), v && this.emit("endElement", M, !0));
}, this.write = function(D) {
typeof D != "string" && (D = D.toString());
let M = 0;
b && (D = b + D, M += C ? 0 : b.length, C = !1, b = null);
function N() {
if (typeof B == "number") {
const L = D.slice(B, M);
return B = void 0, L;
}
}
for (; M < D.length; M++) {
switch (g) {
case i: {
const j = D.indexOf("<", M);
j !== -1 && M !== j && (M = j);
break;
}
case d: {
const j = D.indexOf(x, M);
j !== -1 && (M = j);
break;
}
case t: {
const j = D.indexOf("-->", M);
j !== -1 && (M = j + 2);
break;
}
case c: {
const j = D.indexOf("]]>", M);
j !== -1 && (M = j + 2);
break;
}
}
const L = D.charCodeAt(M);
switch (g) {
case i:
if (L === 60) {
const j = N();
j && this.emit("text", e.unescapeXML(j)), g = s, B = M + 1, k = {};
}
break;
case l:
if (L === 93)
if (D.substr(M + 1, 2) === "]>") {
const j = N();
j && this.emit("text", j), g = i;
} else D.length < M + 2 && (C = !0, M = D.length);
break;
case s:
L === 47 && B === M ? (B = M + 1, w = !0) : L === 33 ? D.substr(M + 1, 7) === "[CDATA[" ? (B = M + 8, g = l) : D.length < M + 8 && "[CDATA[".startsWith(D.slice(M + 1)) ? (C = !0, M = D.length) : (B = void 0, g = t) : L === 63 ? (B = void 0, g = r) : (L <= 32 || L === 47 || L === 62) && (y = N(), M--, g = a);
break;
case t:
if (L === 62) {
const j = D.charCodeAt(M - 1), Y = D.charCodeAt(M - 2);
(j === 45 && Y === 45 || j === 93 && Y === 93) && (g = i);
}
break;
case r:
L === 62 && D.charCodeAt(M - 1) === 63 && (g = i);
break;
case a:
L === 62 ? (this._handleTagOpening(w, y, k), y = void 0, k = void 0, w = void 0, v = void 0, g = i, B = M + 1) : L === 47 ? v = !0 : L > 32 && (B = M, g = o);
break;
case o:
(L <= 32 || L === 61) && (I = N(), M--, g = A);
break;
case A:
L === 61 && (g = f);
break;
case f:
(L === 34 || L === 39) && (p = L, x = L === 34 ? '"' : "'", g = d, B = M + 1);
break;
case d:
if (L === p) {
const j = e.unescapeXML(N());
k[I] = j, I = void 0, g = a;
}
break;
}
}
typeof B == "number" && B <= D.length && (b = D.slice(B), B = 0);
};
}
end(g) {
g && this.write(g), this.write = function() {
};
}
}
return ma = u, ma;
}
var ga, fd;
function d1() {
return fd || (fd = 1, ga = class extends Error {
constructor(...e) {
super(...e), this.name = "XMLError";
}
}), ga;
}
var pa, dd;
function c1() {
if (dd) return pa;
dd = 1;
const n = Cp(), e = XA(), i = Rt(), t = d1();
class r extends i {
constructor() {
super();
const a = new n();
this.root = null, this.cursor = null, a.on("startElement", this.onStartElement.bind(this)), a.on("endElement", this.onEndElement.bind(this)), a.on("text", this.onText.bind(this)), this.parser = a;
}
onStartElement(a, o) {
const A = new e(a, o), { root: f, cursor: d } = this;
f ? d !== f && d.append(A) : (this.root = A, this.emit("start", A)), this.cursor = A;
}
onEndElement(a) {
const { root: o, cursor: A } = this;
if (a !== A.name) {
this.emit("error", new t(`${A.name} must be closed.`));
return;
}
if (A === o) {
this.emit("end", o);
return;
}
if (!A.parent) {
A.parent = o, this.emit("element", A), this.cursor = o;
return;
}
this.cursor = A.parent;
}
onText(a) {
const { cursor: o } = this;
if (!o) {
this.emit("error", new t(`${a} must be a child.`));
return;
}
o.t(a);
}
write(a) {
this.parser.write(a);
}
end(a) {
a && this.parser.write(a);
}
}
return r.XMLError = t, pa = r, pa;
}
var cd;
function mn() {
return cd || (cd = 1, function(n) {
const e = XA(), i = kp(), t = c1(), {
escapeXML: r,
unescapeXML: s,
escapeXMLText: a,
unescapeXMLText: o
} = JA(), A = d1();
function f(...d) {
return i(...d);
}
n.exports = f, Object.assign(n.exports, {
Element: e,
createElement: i,
Parser: t,
escapeXML: r,
unescapeXML: s,
escapeXMLText: a,
unescapeXMLText: o,
XMLError: A
});
}(la)), la.exports;
}
var va, ld;
function KA() {
if (ld) return va;
ld = 1;
class n extends Error {
constructor(i, t, r) {
super(i + (t ? ` - ${t}` : "")), this.name = "XMPPError", this.condition = i, this.text = t, this.application = r;
}
static fromElement(i) {
const [t, r, s] = i.getChildElements();
let a, o;
r && (r.is("text") ? a = r : r && (o = r), s && (o = s));
const A = new this(
t.name,
a ? a.text() : "",
o
);
return A.element = i, A;
}
}
return va = n, va;
}
var ba, ud;
function xp() {
if (ud) return ba;
ud = 1;
const n = KA();
class e extends n {
constructor(...t) {
super(...t), this.name = "StreamError";
}
}
return ba = e, ba;
}
var wa = { exports: {} }, hd;
function Ep() {
return hd || (hd = 1, function(n) {
function e(r) {
let { port: s, hostname: a, protocol: o } = new URL(r);
return a === "[::1]" && (a = "::1"), { port: s, hostname: a, protocol: o };
}
function i(r) {
const { port: s, hostname: a } = e(`http://${r}`);
return { port: s, hostname: a };
}
function t(r) {
return r.includes("://") ? e(r) : i(r);
}
Object.assign(n.exports, { parseURI: e, parseHost: i, parseService: t });
}(wa)), wa.exports;
}
var ya, md;
function l1() {
if (md) return ya;
md = 1;
const { EventEmitter: n, promise: e } = Ct(), i = Es(), t = mn(), r = xp(), { parseHost: s, parseService: a } = Ep(), o = "urn:ietf:params:xml:ns:xmpp-streams", A = "http://etherx.jabber.org/streams";
class f extends n {
constructor(l = {}) {
super(), this.jid = null, this.timeout = 2e3, this.options = l, this.socketListeners = /* @__PURE__ */ Object.create(null), this.parserListeners = /* @__PURE__ */ Object.create(null), this.status = "offline", this.socket = null, this.parser = null, this.root = null;
}
_reset() {
this.jid = null, this.status = "offline", this._detachSocket(), this._detachParser();
}
async _streamError(l, c) {
try {
await this.send(
// prettier-ignore
t("stream:error", {}, [
t(l, { xmlns: o }, c)
])
);
} catch {
}
return this._end();
}
_onData(l) {
const c = l.toString("utf8");
this.emit("input", c), this.parser.write(c);
}
_onParserError(l) {
this._streamError("bad-format"), this._detachParser(), this.emit("error", l);
}
_attachSocket(l) {
this.socket = l;
const c = this.socketListeners;
c.data = this._onData.bind(this), c.close = (u, m) => {
this._reset(), this._status("disconnect", { clean: !u, event: m });
}, c.connect = () => {
this._status("connect");
}, c.error = (u) => {
this.emit("error", u);
}, this.socket.on("close", c.close), this.socket.on("data", c.data), this.socket.on("error", c.error), this.socket.on("connect", c.connect);
}
_detachSocket() {
const { socketListeners: l, socket: c } = this;
for (const u of Object.getOwnPropertyNames(l))
c.removeListener(u, l[u]), delete l[u];
return this.socket = null, c;
}
_onElement(l) {
const c = l.is("error", A);
c && this._onStreamError(l), this.emit("element", l), this.emit(this.isStanza(l) ? "stanza" : "nonza", l), c && this._end();
}
// https://xmpp.org/rfcs/rfc6120.html#streams-error
_onStreamError(l) {
const c = r.fromElement(l);
if (c.condition === "see-other-host")
return this._onSeeOtherHost(c);
this.emit("error", c);
}
// https://xmpp.org/rfcs/rfc6120.html#streams-error-conditions-see-other-host
async _onSeeOtherHost(l) {
const { protocol: c } = a(this.options.service), u = l.element.getChildText("see-other-host"), { port: m } = s(u);
let g;
g = m ? `${c || "xmpp:"}//${u}` : (c ? `${c}//` : "") + u;
try {
await e(this, "disconnect");
const { domain: b, lang: C } = this.options;
await this.connect(g), await this.open({ domain: b, lang: C });
} catch (b) {
this.emit("error", b);
}
}
_attachParser(l) {
this.parser = l;
const c = this.parserListeners;
c.element = this._onElement.bind(this), c.error = this._onParserError.bind(this), c.end = (u) => {
this._detachParser(), this._status("close", u);
}, c.start = (u) => {
this._status("open", u);
}, this.parser.on("error", c.error), this.parser.on("element", c.element), this.parser.on("end", c.end), this.parser.on("start", c.start);
}
_detachParser() {
const l = this.parserListeners;
for (const c of Object.getOwnPropertyNames(l))
this.parser.removeListener(c, l[c]), delete l[c];
this.parser = null;
}
_jid(l) {
return this.jid = i(l), this.jid;
}
_status(l, ...c) {
this.status = l, this.emit("status", l, ...c), this.emit(l, ...c);
}
async _end() {
let l;
try {
l = await this.close();
} catch {
}
try {
await this.disconnect();
} catch {
}
return l;
}
/**
* Opens the socket then opens the stream
*/
async start() {
if (this.status !== "offline")
throw new Error("Connection is not offline");
const { service: l, domain: c, lang: u } = this.options;
await this.connect(l);
const m = e(this, "online");
return await this.open({ domain: c, lang: u }), m;
}
/**
* Connects the socket
*/
async connect(l) {
this._status("connecting", l);
const c = new this.Socket();
return this._attachSocket(c), c.connect(this.socketParameters(l)), e(c, "connect");
}
/**
* Disconnects the socket
* https://xmpp.org/rfcs/rfc6120.html#streams-close
* https://tools.ietf.org/html/rfc7395#section-3.6
*/
async disconnect(l = this.timeout) {
this.socket && this._status("disconnecting"), this.socket.end(), await e(this.socket, "close", "error", l);
}
/**
* Opens the stream
*/
async open(l) {
this._status("opening"), typeof l == "string" && (l = { domain: l });
const { domain: c, lang: u, timeout: m = this.timeout } = l, g = this.headerElement();
return g.attrs.to = c, g.attrs["xml:lang"] = u, this.root = g, this._attachParser(new this.Parser()), await this.write(this.header(g)), e(this, "open", "error", m);
}
/**
* Closes the stream then closes the socket
* https://xmpp.org/rfcs/rfc6120.html#streams-close
* https://tools.ietf.org/html/rfc7395#section-3.6
*/
async stop() {
const l = await this._end();
return this.status !== "offline" && this._status("offline", l), l;
}
/**
* Closes the stream and wait for the server to close it
* https://xmpp.org/rfcs/rfc6120.html#streams-close
* https://tools.ietf.org/html/rfc7395#section-3.6
*/
async close(l = this.timeout) {
const c = this.footer(this.footerElement()), u = Promise.all([
e(this.parser, "end", "error", l),
this.write(c)
]);
this.parser && this.socket && this._status("closing");
const [m] = await u;
return this.root = null, m;
}
/**
* Restart the stream
* https://xmpp.org/rfcs/rfc6120.html#streams-negotiation-restart
*/
async restart() {
this._detachParser();
const { domain: l, lang: c } = this.options;
return this.open({ domain: l, lang: c });
}
async send(l) {
l.parent = this.root, await this.write(l.toString()), this.emit("send", l);
}
sendReceive(l, c = this.timeout) {
return Promise.all([
this.send(l),
e(this, "element", "error", c)
]).then(([, u]) => u);
}
write(l) {
return new Promise((c, u) => {
if (this.status === "closing") {
u(new Error("Connection is closing"));
return;
}
this.socket.write(l, (m) => {
if (m)
return u(m);
this.emit("output", l), c();
});
});
}
isStanza(l) {
const { name: c } = l;
return c === "iq" || c === "message" || c === "presence";
}
isNonza(l) {
return !this.isStanza(l);
}
// Override
header(l) {
return l.toString();
}
// Override
headerElement() {
return new t.Element("", {
version: "1.0",
xmlns: this.NS
});
}
// Override
footer(l) {
return l.toString();
}
// Override
footerElement() {
}
// Override
socketParameters() {
}
}
return f.prototype.NS = "", f.prototype.Socket = null, f.prototype.Parser = null, ya = f, ya;
}
var ka, gd;
function Ip() {
if (gd) return ka;
gd = 1;
const n = l1();
class e extends n {
constructor(t) {
super(t), this.transports = [];
}
send(t, ...r) {
return this.Transport.prototype.send.call(this, t, ...r);
}
sendMany(...t) {
return this.Transport.prototype.sendMany.call(this, ...t);
}
_findTransport(t) {
return this.transports.find((r) => {
try {
return r.prototype.socketParameters(t) !== void 0;
} catch {
return !1;
}
});
}
connect(t) {
const r = this._findTransport(t);
if (!r)
throw new Error("No compatible connection method found.");
return this.Transport = r, this.Socket = r.prototype.Socket, this.Parser = r.prototype.Parser, super.connect(t);
}
socketParameters(...t) {
return this.Transport.prototype.socketParameters(...t);
}
header(...t) {
return this.Transport.prototype.header(...t);
}
headerElement(...t) {
return this.Transport.prototype.headerElement(...t);
}
footer(...t) {
return this.Transport.prototype.footer(...t);
}
footerElement(...t) {
return this.Transport.prototype.footerElement(...t);
}
}
return e.prototype.NS = "jabber:client", ka = e, ka;
}
var pd;
function Bp() {
if (pd) return et;
pd = 1;
const n = Ip(), e = mn(), i = Es();
return et.Client = n, et.xml = e, et.jid = i, et;
}
var Ca, vd;
function Dp() {
return vd || (vd = 1, Ca = function(e) {
return (e.split("://")[1] || e).split(":")[0].split("/")[0];
}), Ca;
}
var xa, bd;
function Np() {
if (bd) return xa;
bd = 1;
const { EventEmitter: n } = Ct();
class e extends n {
constructor(t) {
super(), this.delay = 1e3, this.entity = t, this._timeout = null;
}
scheduleReconnect() {
const { entity: t, delay: r, _timeout: s } = this;
clearTimeout(s), this._timeout = setTimeout(async () => {
if (t.status === "disconnect")
try {
await this.reconnect();
} catch {
}
}, r);
}
async reconnect() {
const { entity: t } = this;
this.emit("reconnecting");
const { service: r, domain: s, lang: a } = t.options;
await t.connect(r), await t.open({ domain: s, lang: a }), this.emit("reconnected");
}
start() {
const { entity: t } = this, r = {};
r.disconnect = () => {
this.scheduleReconnect();
}, this.listeners = r, t.on("disconnect", r.disconnect);
}
stop() {
const { entity: t, listeners: r, _timeout: s } = this;
t.removeListener("disconnect", r.disconnect), clearTimeout(s);
}
}
return xa = function({ entity: t }) {
const r = new e(t);
return r.start(), r;
}, xa;
}
const Sp = {}, Tp = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
default: Sp
}, Symbol.toStringTag, { value: "Module" })), Bi = /* @__PURE__ */ pp(Tp);
var Ea, wd;
function Mp() {
if (wd) return Ea;
wd = 1;
const n = Bi, e = globalThis.WebSocket || n, i = Rt(), t = "ECONNERROR";
class r extends i {
constructor() {
super(), this.listeners = /* @__PURE__ */ Object.create(null);
}
connect(a) {
this.url = a, this._attachSocket(new e(a, ["xmpp"]));
}
_attachSocket(a) {
this.socket = a;
const { listeners: o } = this;
o.open = () => {
this.emit("connect");
}, o.message = ({ data: A }) => this.emit("data", A), o.error = (A) => {
const { url: f } = this;
let { error: d } = A;
d || (d = new Error(`WebSocket ${t} ${f}`), d.errno = t, d.code = t), d.event = A, d.url = f, this.emit("error", d);
}, o.close = (A) => {
this._detachSocket(), this.emit("close", !A.wasClean, A);
}, this.socket.addEventListener("open", o.open), this.socket.addEventListener("message", o.message), this.socket.addEventListener("error", o.error), this.socket.addEventListener("close", o.close);
}
_detachSocket() {
delete this.url;
const { socket: a, listeners: o } = this;
for (const A of Object.getOwnPropertyNames(o))
a.removeEventListener(A, o[A]), delete o[A];
delete this.socket;
}
end() {
this.socket.close();
}
write(a, o) {
e === n ? this.socket.send(a, o) : (this.socket.send(a), o());
}
}
return Ea = r, Ea;
}
var Ia, yd;
function Rp() {
if (yd) return Ia;
yd = 1;
const { Parser: n, Element: e, XMLError: i } = mn();
return Ia = class extends n {
onStartElement(r, s) {
const a = new e(r, s), { cursor: o } = this;
o && o.append(a), this.cursor = a;
}
onEndElement(r) {
const { cursor: s } = this;
if (r !== s.name) {
this.emit("error", new i(`${s.name} must be closed.`));
return;
}
if (s.parent) {
this.cursor = s.parent;
return;
}
s.is("open", "urn:ietf:params:xml:ns:xmpp-framing") ? this.emit("start", s) : s.is("close", "urn:ietf:params:xml:ns:xmpp-framing") ? this.emit("end", s) : this.emit("element", s), this.cursor = null;
}
}, Ia;
}
var Ba, kd;
function Pp() {
if (kd) return Ba;
kd = 1;
const n = Mp(), e = l1(), i = mn(), t = Rp(), r = "urn:ietf:params:xml:ns:xmpp-framing";
class s extends e {
send(o, ...A) {
return !o.attrs.xmlns && super.isStanza(o) && (o.attrs.xmlns = "jabber:client"), super.send(o, ...A);
}
async sendMany(o) {
for (const A of o)
await this.send(A);
}
// https://tools.ietf.org/html/rfc7395#section-3.6
footerElement() {
return new i.Element("close", {
xmlns: r
});
}
// https://tools.ietf.org/html/rfc7395#section-3.4
headerElement() {
const o = super.headerElement();
return o.name = "open", o.attrs.xmlns = r, o;
}
socketParameters(o) {
return /^wss?:\/\//.test(o) ? o : void 0;
}
}
return s.prototype.Socket = n, s.prototype.NS = "jabber:client", s.prototype.Parser = t, Ba = s, Ba;
}
var Da, Cd;
function Qp() {
if (Cd) return Da;
Cd = 1;
const n = Pp();
return Da = function({ entity: i }) {
i.transports.push(n);
}, Da;
}
var Na, xd;
function Op() {
if (xd) return Na;
xd = 1, Na = n;
function n(e) {
if (!Array.isArray(e)) throw new TypeError("Middleware stack must be an array!");
for (const i of e)
if (typeof i != "function") throw new TypeError("Middleware must be composed of functions!");
return function(i, t) {
let r = -1;
return s(0);
function s(a) {
if (a <= r) return Promise.reject(new Error("next() called multiple times"));
r = a;
let o = e[a];
if (a === e.length && (o = t), !o) return Promise.resolve();
try {
return Promise.resolve(o(i, s.bind(null, a + 1)));
} catch (A) {
return Promise.reject(A);
}
}
};
}
return Na;
}
var Sa, Ed;
function u1() {
return Ed || (Ed = 1, Sa = class {
constructor(e, i) {
this.stanza = i, this.entity = e;
const { name: t, attrs: r } = i, { type: s, id: a } = r;
this.name = t, this.id = a || "", t === "message" ? this.type = s || "normal" : t === "presence" ? this.type = s || "available" : this.type = s || "", this.from = null, this.to = null, this.local = "", this.domain = "", this.resource = "";
}
}), Sa;
}
var Ta, Id;
function Lp() {
if (Id) return Ta;
Id = 1;
const n = u1(), e = Es();
return Ta = class extends n {
constructor(t, r) {
super(t, r);
const { jid: s, domain: a } = t, o = r.attrs.to || s && s.toString(), A = r.attrs.from || a;
o && (this.to = new e(o)), A && (this.from = new e(A), this.local = this.from.local, this.domain = this.from.domain, this.resource = this.from.resource);
}
}, Ta;
}
var Ma, Bd;
function Fp() {
if (Bd) return Ma;
Bd = 1;
const n = u1(), e = Es();
return Ma = class extends n {
constructor(t, r) {
super(t, r);
const { jid: s, domain: a } = t, o = r.attrs.from || s && s.toString(), A = r.attrs.to || a;
o && (this.from = new e(o)), A && (this.to = new e(A), this.local = this.to.local, this.domain = this.to.domain, this.resource = this.to.resource);
}
}, Ma;
}
var Ra, Dd;
function jp() {
if (Dd) return Ra;
Dd = 1;
const n = Op(), e = Lp(), i = Fp();
function t(s, a, o) {
return (A) => {
const f = new o(s, A);
return n(a)(f);
};
}
function r(s) {
return (a, o) => {
o().then((A) => A && s.send(A)).catch((A) => s.emit("error", A));
};
}
return Ra = function({ entity: a }) {
const o = [r(a)], A = [], f = t(a, o, e), d = t(a, A, i);
return a.on("element", f), a.hookOutgoing = d, {
use(l) {
return o.push(l), l;
},
filter(l) {
return A.push(l), l;
}
};
}, Ra;
}
var Pa, Nd;
function Wp() {
return Nd || (Nd = 1, Pa = function() {
return async ({ stanza: e, entity: i }, t) => {
if (!e.is("features", "http://etherx.jabber.org/streams"))
return t();
!await t() && i.jid && i._status("online", i.jid);
};
}), Pa;
}
var Qa, Sd;
function Gp() {
if (Sd) return Qa;
Sd = 1;
const n = Wp();
return Qa = function({ middleware: i }) {
i.use(n());
function t(r, s, a) {
return i.use((o, A) => {
const { stanza: f } = o;
if (!f.is("features", "http://etherx.jabber.org/streams"))
return A();
const d = f.getChild(r, s);
return d ? a(o, A, d) : A();
});
}
return {
use: t
};
}, Qa;
}
var Oa, Td;
function Yp() {
return Td || (Td = 1, Oa = function() {
let e;
for (; !e; )
e = Math.random().toString(36).slice(2, 12);
return e;
}), Oa;
}
var La, Md;
function _p() {
if (Md) return La;
Md = 1;
const n = KA();
class e extends n {
constructor(t, r, s, a) {
super(t, r, s), this.type = a, this.name = "StanzaError";
}
static fromElement(t) {
const r = super.fromElement(t);
return r.type = t.attrs.type, r;
}
}
return La = e, La;
}
var Fa, Rd;
function qp() {
if (Rd) return Fa;
Rd = 1;
const n = Yp(), e = _p(), { Deferred: i } = Ct(), t = Ct().timeout, r = mn();
function s({ name: o, type: A }) {
return !(o !== "iq" || A !== "error" && A !== "result");
}
class a {
constructor({ entity: A, middleware: f }) {
this.handlers = /* @__PURE__ */ new Map(), this.entity = A, this.middleware = f;
}
start() {
this.middleware.use(this._route.bind(this));
}
_route({ type: A, name: f, id: d, stanza: l }, c) {
if (!s({ name: f, type: A })) return c();
const u = this.handlers.get(d);
if (!u)
return c();
A === "error" ? u.reject(e.fromElement(l.getChild("error"))) : u.resolve(l), this.handlers.delete(d);
}
async request(A, f = 30 * 1e3) {
A.attrs.id || (A.attrs.id = n());
const d = new i();
this.handlers.set(A.attrs.id, d);
try {
await this.entity.send(A), await t(d.promise, f);
} catch (l) {
throw this.handlers.delete(A.attrs.id), l;
}
return d.promise;
}
_childRequest(A, f, d, ...l) {
const {
name: c,
attrs: { xmlns: u }
} = f;
return this.request(r("iq", { type: A, to: d }, f), ...l).then(
(m) => m.getChild(c, u)
);
}
async get(...A) {
return this._childRequest("get", ...A);
}
async set(...A) {
return this._childRequest("set", ...A);
}
}
return Fa = function(...A) {
const f = new a(...A);
return f.start(), f;
}, Fa;
}
var ja, Pd;
function Hp() {
if (Pd) return ja;
Pd = 1;
const n = mn(), e = "urn:ietf:params:xml:ns:xmpp-stanzas";
function i({ name: d, type: l }) {
return !(d !== "iq" || l === "error" || l === "result");
}
function t({ type: d }, l, c) {
return !(d !== "get" && d !== "set" || l.length !== 1 || !c);
}
function r({ stanza: d }) {
return n("iq", {
to: d.attrs.from,
from: d.attrs.to,
id: d.attrs.id
});
}
function s(d, l) {
const c = r(d);
return c.attrs.type = "result", l && c.append(l), c;
}
function a(d, l, c) {
const u = r(d);
return u.attrs.type = "error", c && u.append(c), u.append(l), u;
}
function o(d, l) {
return n("error", { type: d }, n(l, e));
}
function A(d) {
return async function(c, u) {
if (!i(c)) return u();
const { stanza: m } = c, g = m.getChildElements(), [b] = g;
if (!t(c, g, b))
return a(c, o("modify", "bad-request"), b);
c.element = b;
let C;
try {
C = await u();
} catch (y) {
d.emit("error", y), C = o("cancel", "internal-server-error");
}
return C || (C = o("cancel", "service-unavailable")), C instanceof n.Element && C.is("error") ? a(c, C, b) : s(
c,
C instanceof n.Element ? C : void 0
);
};
}