@nethesis/chat-island 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/ChatIsland.d.ts +20 -0
- package/dist/api.d.ts +6 -0
- package/dist/chat-island-sw.js +18 -0
- package/dist/components/Avatar.d.ts +18 -0
- package/dist/components/Button.d.ts +23 -0
- package/dist/components/ChatWindow.d.ts +15 -0
- package/dist/components/Composer.d.ts +6 -0
- package/dist/components/Dock.d.ts +6 -0
- package/dist/components/EmojiPicker.d.ts +6 -0
- package/dist/components/MessageList.d.ts +22 -0
- package/dist/components/NewChat.d.ts +4 -0
- package/dist/drag.d.ts +10 -0
- package/dist/events.d.ts +34 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4887 -0
- package/dist/ogg.d.ts +4 -0
- package/dist/push.d.ts +6 -0
- package/dist/shortcodes-table.d.ts +2 -0
- package/dist/shortcodes.d.ts +2 -0
- package/dist/sound.d.ts +2 -0
- package/dist/store.d.ts +42 -0
- package/dist/types.d.ts +67 -0
- package/dist/xmpp.d.ts +96 -0
- package/dist-widget/chat-island-sw.js +18 -0
- package/dist-widget/index.widget.css +2 -0
- package/dist-widget/index.widget.js +9 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4887 @@
|
|
|
1
|
+
import e, { Component as t, memo as n, useCallback as r, useEffect as i, useLayoutEffect as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
2
|
+
import l from "use-sync-external-store/shim/with-selector.js";
|
|
3
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
var p = Object.create, m = Object.defineProperty, h = Object.getOwnPropertyDescriptor, g = Object.getOwnPropertyNames, _ = Object.getPrototypeOf, v = Object.prototype.hasOwnProperty, y = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), b = (e, t, n, r) => {
|
|
6
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = g(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !v.call(e, s) && s !== n && m(e, s, {
|
|
7
|
+
get: ((e) => t[e]).bind(null, s),
|
|
8
|
+
enumerable: !(r = h(t, s)) || r.enumerable
|
|
9
|
+
});
|
|
10
|
+
return e;
|
|
11
|
+
}, x = (e, t, n) => (n = e == null ? {} : p(_(e)), b(t || !e || !e.__esModule || !v.call(e, "default") ? m(n, "default", {
|
|
12
|
+
value: e,
|
|
13
|
+
enumerable: !0
|
|
14
|
+
}) : n, e));
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region node_modules/zustand/esm/react/shallow.mjs
|
|
17
|
+
function S(e, t) {
|
|
18
|
+
if (Object.is(e, t)) return !0;
|
|
19
|
+
if (typeof e != "object" || !e || typeof t != "object" || !t) return !1;
|
|
20
|
+
if (e instanceof Map && t instanceof Map) {
|
|
21
|
+
if (e.size !== t.size) return !1;
|
|
22
|
+
for (let [n, r] of e) if (!Object.is(r, t.get(n))) return !1;
|
|
23
|
+
return !0;
|
|
24
|
+
}
|
|
25
|
+
if (e instanceof Set && t instanceof Set) {
|
|
26
|
+
if (e.size !== t.size) return !1;
|
|
27
|
+
for (let n of e) if (!t.has(n)) return !1;
|
|
28
|
+
return !0;
|
|
29
|
+
}
|
|
30
|
+
let n = Object.keys(e);
|
|
31
|
+
if (n.length !== Object.keys(t).length) return !1;
|
|
32
|
+
for (let r of n) if (!Object.prototype.hasOwnProperty.call(t, r) || !Object.is(e[r], t[r])) return !1;
|
|
33
|
+
return !0;
|
|
34
|
+
}
|
|
35
|
+
var { useRef: C } = e;
|
|
36
|
+
function w(e) {
|
|
37
|
+
let t = C();
|
|
38
|
+
return (n) => {
|
|
39
|
+
let r = e(n);
|
|
40
|
+
return S(t.current, r) ? t.current : t.current = r;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/drag.ts
|
|
45
|
+
var T = 8;
|
|
46
|
+
function E(e, t) {
|
|
47
|
+
let [n, a] = c(() => {
|
|
48
|
+
try {
|
|
49
|
+
let e = localStorage.getItem(t);
|
|
50
|
+
return e ? JSON.parse(e) : null;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}), o = s(!1), l = r((t) => {
|
|
55
|
+
let n = e.current, r = n?.offsetWidth ?? 0, i = n?.offsetHeight ?? 0;
|
|
56
|
+
return {
|
|
57
|
+
right: Math.min(Math.max(T, t.right), Math.max(T, window.innerWidth - r - T)),
|
|
58
|
+
bottom: Math.min(Math.max(T, t.bottom), Math.max(T, window.innerHeight - i - T))
|
|
59
|
+
};
|
|
60
|
+
}, [e]);
|
|
61
|
+
return i(() => {
|
|
62
|
+
let e = () => a((e) => e && l(e));
|
|
63
|
+
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
64
|
+
}, [l]), {
|
|
65
|
+
anchor: n,
|
|
66
|
+
start: r((n) => {
|
|
67
|
+
if (n.button !== 0) return;
|
|
68
|
+
let r = e.current;
|
|
69
|
+
if (!r) return;
|
|
70
|
+
let i = r.getBoundingClientRect(), s = {
|
|
71
|
+
x: n.clientX,
|
|
72
|
+
y: n.clientY,
|
|
73
|
+
right: window.innerWidth - i.right,
|
|
74
|
+
bottom: window.innerHeight - i.bottom
|
|
75
|
+
};
|
|
76
|
+
o.current = !1;
|
|
77
|
+
let c = (e) => {
|
|
78
|
+
let t = e.clientX - s.x, n = e.clientY - s.y;
|
|
79
|
+
!o.current && Math.hypot(t, n) < 5 || (o.current = !0, a(l({
|
|
80
|
+
right: s.right - t,
|
|
81
|
+
bottom: s.bottom - n
|
|
82
|
+
})));
|
|
83
|
+
}, u = null, d = (e) => {
|
|
84
|
+
c(e), o.current && (u = l({
|
|
85
|
+
right: s.right - (e.clientX - s.x),
|
|
86
|
+
bottom: s.bottom - (e.clientY - s.y)
|
|
87
|
+
}));
|
|
88
|
+
}, f = () => {
|
|
89
|
+
if (window.removeEventListener("pointermove", d), window.removeEventListener("pointerup", f), window.removeEventListener("pointercancel", f), o.current && u) try {
|
|
90
|
+
localStorage.setItem(t, JSON.stringify(u));
|
|
91
|
+
} catch {}
|
|
92
|
+
};
|
|
93
|
+
window.addEventListener("pointermove", d), window.addEventListener("pointerup", f), window.addEventListener("pointercancel", f);
|
|
94
|
+
}, [
|
|
95
|
+
e,
|
|
96
|
+
l,
|
|
97
|
+
t
|
|
98
|
+
]),
|
|
99
|
+
onClickCapture: r((e) => {
|
|
100
|
+
o.current &&= (e.stopPropagation(), e.preventDefault(), !1);
|
|
101
|
+
}, [])
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region node_modules/ltx/lib/escape.js
|
|
106
|
+
var D = /* @__PURE__ */ y(((e) => {
|
|
107
|
+
var t = {
|
|
108
|
+
"&": "&",
|
|
109
|
+
"<": "<",
|
|
110
|
+
">": ">",
|
|
111
|
+
"\"": """,
|
|
112
|
+
"'": "'"
|
|
113
|
+
};
|
|
114
|
+
function n(e) {
|
|
115
|
+
return t[e];
|
|
116
|
+
}
|
|
117
|
+
var r = {
|
|
118
|
+
"&": "&",
|
|
119
|
+
"<": "<",
|
|
120
|
+
">": ">",
|
|
121
|
+
""": "\"",
|
|
122
|
+
"'": "'"
|
|
123
|
+
};
|
|
124
|
+
function i(e) {
|
|
125
|
+
if (e[1] === "#") {
|
|
126
|
+
let t = e[2] === "x" ? parseInt(e.slice(3), 16) : parseInt(e.slice(2), 10);
|
|
127
|
+
if (t === 9 || t === 10 || t === 13 || t >= 32 && t <= 55295 || t >= 57344 && t <= 65533 || t >= 65536 && t <= 1114111) return String.fromCodePoint(t);
|
|
128
|
+
throw Error("Illegal XML character 0x" + t.toString(16));
|
|
129
|
+
}
|
|
130
|
+
if (r[e]) return r[e] || e;
|
|
131
|
+
throw Error("Illegal XML entity " + e);
|
|
132
|
+
}
|
|
133
|
+
function a(e) {
|
|
134
|
+
return e.replace(/["&'<>]/g, n);
|
|
135
|
+
}
|
|
136
|
+
function o(e) {
|
|
137
|
+
let t = "", n = -1, r = -1, a = 0;
|
|
138
|
+
for (; (n = e.indexOf("&", a)) !== -1 && (r = e.indexOf(";", n + 1)) !== -1;) t = t + e.slice(a, n) + i(e.slice(n, r + 1)), a = r + 1;
|
|
139
|
+
return a === 0 ? e : (t += e.substring(a), t);
|
|
140
|
+
}
|
|
141
|
+
function s(e) {
|
|
142
|
+
return e.replace(/[&<>]/g, n);
|
|
143
|
+
}
|
|
144
|
+
function c(e) {
|
|
145
|
+
return e.replace(/&(amp|#38|lt|#60|gt|#62);/g, i);
|
|
146
|
+
}
|
|
147
|
+
e.escapeXML = a, e.escapeXMLText = s, e.unescapeXML = o, e.unescapeXMLText = c;
|
|
148
|
+
})), O = /* @__PURE__ */ y(((e, t) => {
|
|
149
|
+
var n = D(), r = class e {
|
|
150
|
+
constructor(e, t) {
|
|
151
|
+
this.name = e, this.parent = null, this.children = [], this.attrs = {}, this.setAttrs(t);
|
|
152
|
+
}
|
|
153
|
+
is(e, t) {
|
|
154
|
+
return this.getName() === e && (!t || this.getNS() === t);
|
|
155
|
+
}
|
|
156
|
+
getName() {
|
|
157
|
+
let e = this.name.indexOf(":");
|
|
158
|
+
return e >= 0 ? this.name.slice(e + 1) : this.name;
|
|
159
|
+
}
|
|
160
|
+
getNS() {
|
|
161
|
+
let e = this.name.indexOf(":");
|
|
162
|
+
if (e >= 0) {
|
|
163
|
+
let t = this.name.slice(0, e);
|
|
164
|
+
return this.findNS(t);
|
|
165
|
+
}
|
|
166
|
+
return this.findNS();
|
|
167
|
+
}
|
|
168
|
+
findNS(e) {
|
|
169
|
+
if (e) {
|
|
170
|
+
let t = "xmlns:" + e;
|
|
171
|
+
if (this.attrs[t]) return this.attrs[t];
|
|
172
|
+
if (this.parent) return this.parent.findNS(e);
|
|
173
|
+
} else {
|
|
174
|
+
if (this.attrs.xmlns) return this.attrs.xmlns;
|
|
175
|
+
if (this.parent) return this.parent.findNS();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
getXmlns() {
|
|
179
|
+
let e = {};
|
|
180
|
+
this.parent && (e = this.parent.getXmlns());
|
|
181
|
+
for (let t in this.attrs) {
|
|
182
|
+
let n = t.match("xmlns:?(.*)");
|
|
183
|
+
this.attrs.hasOwnProperty(t) && n && (e[this.attrs[t]] = n[1]);
|
|
184
|
+
}
|
|
185
|
+
return e;
|
|
186
|
+
}
|
|
187
|
+
setAttrs(e) {
|
|
188
|
+
typeof e == "string" ? this.attrs.xmlns = e : e && Object.assign(this.attrs, e);
|
|
189
|
+
}
|
|
190
|
+
getAttr(e, t) {
|
|
191
|
+
if (!t) return this.attrs[e];
|
|
192
|
+
let n = this.getXmlns();
|
|
193
|
+
return n[t] ? this.attrs[[n[t], e].join(":")] : null;
|
|
194
|
+
}
|
|
195
|
+
getChild(e, t) {
|
|
196
|
+
return this.getChildren(e, t)[0];
|
|
197
|
+
}
|
|
198
|
+
getChildren(e, t) {
|
|
199
|
+
let n = [];
|
|
200
|
+
for (let r of this.children) r.getName && r.getName() === e && (!t || r.getNS() === t) && n.push(r);
|
|
201
|
+
return n;
|
|
202
|
+
}
|
|
203
|
+
getChildByAttr(e, t, n, r) {
|
|
204
|
+
return this.getChildrenByAttr(e, t, n, r)[0];
|
|
205
|
+
}
|
|
206
|
+
getChildrenByAttr(e, t, n, r) {
|
|
207
|
+
let i = [];
|
|
208
|
+
for (let a of this.children) a.attrs && a.attrs[e] === t && (!n || a.getNS() === n) && i.push(a), r && a.getChildrenByAttr && i.push(a.getChildrenByAttr(e, t, n, !0));
|
|
209
|
+
return r && (i = i.flat()), i;
|
|
210
|
+
}
|
|
211
|
+
getChildrenByFilter(e, t) {
|
|
212
|
+
let n = [];
|
|
213
|
+
for (let r of this.children) e(r) && n.push(r), t && r.getChildrenByFilter && n.push(r.getChildrenByFilter(e, !0));
|
|
214
|
+
return t && (n = n.flat()), n;
|
|
215
|
+
}
|
|
216
|
+
getText() {
|
|
217
|
+
let e = "";
|
|
218
|
+
for (let t of this.children) (typeof t == "string" || typeof t == "number") && (e += t);
|
|
219
|
+
return e;
|
|
220
|
+
}
|
|
221
|
+
getChildText(e, t) {
|
|
222
|
+
let n = this.getChild(e, t);
|
|
223
|
+
return n ? n.getText() : null;
|
|
224
|
+
}
|
|
225
|
+
getChildElements() {
|
|
226
|
+
return this.getChildrenByFilter((t) => t instanceof e);
|
|
227
|
+
}
|
|
228
|
+
root() {
|
|
229
|
+
return this.parent ? this.parent.root() : this;
|
|
230
|
+
}
|
|
231
|
+
up() {
|
|
232
|
+
return this.parent ? this.parent : this;
|
|
233
|
+
}
|
|
234
|
+
c(t, n) {
|
|
235
|
+
return this.cnode(new e(t, n));
|
|
236
|
+
}
|
|
237
|
+
cnode(e) {
|
|
238
|
+
return this.children.push(e), typeof e == "object" && (e.parent = this), e;
|
|
239
|
+
}
|
|
240
|
+
append(...e) {
|
|
241
|
+
for (let t of e) this.children.push(t), typeof t == "object" && (t.parent = this);
|
|
242
|
+
}
|
|
243
|
+
prepend(...e) {
|
|
244
|
+
for (let t of e) this.children.unshift(t), typeof t == "object" && (t.parent = this);
|
|
245
|
+
}
|
|
246
|
+
t(e) {
|
|
247
|
+
return this.children.push(e), this;
|
|
248
|
+
}
|
|
249
|
+
remove(e, t) {
|
|
250
|
+
let n = typeof e == "string" ? (n) => !(n.is && n.is(e, t)) : (t) => t !== e;
|
|
251
|
+
return this.children = this.children.filter(n), this;
|
|
252
|
+
}
|
|
253
|
+
text(e) {
|
|
254
|
+
return e && this.children.length === 1 ? (this.children[0] = e, this) : this.getText();
|
|
255
|
+
}
|
|
256
|
+
attr(e, t) {
|
|
257
|
+
return t !== void 0 || t === null ? (this.attrs ||= {}, this.attrs[e] = t, this) : this.attrs[e];
|
|
258
|
+
}
|
|
259
|
+
toString() {
|
|
260
|
+
let e = "";
|
|
261
|
+
return this.write((t) => {
|
|
262
|
+
e += t;
|
|
263
|
+
}), e;
|
|
264
|
+
}
|
|
265
|
+
_addChildren(e) {
|
|
266
|
+
e(">");
|
|
267
|
+
for (let t of this.children) t != null && (t.write ? t.write(e) : typeof t == "string" ? e(n.escapeXMLText(t)) : t.toString && e(n.escapeXMLText(t.toString(10))));
|
|
268
|
+
e("</"), e(this.name), e(">");
|
|
269
|
+
}
|
|
270
|
+
write(e) {
|
|
271
|
+
e("<"), e(this.name);
|
|
272
|
+
for (let t in this.attrs) {
|
|
273
|
+
let r = this.attrs[t];
|
|
274
|
+
r != null && (e(" "), e(t), e("=\""), e(n.escapeXML(typeof r == "string" ? r : r.toString(10))), e("\""));
|
|
275
|
+
}
|
|
276
|
+
this.children.length === 0 ? e("/>") : this._addChildren(e);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
r.prototype.tree = r.prototype.root, t.exports = r;
|
|
280
|
+
})), ee = /* @__PURE__ */ y(((e, t) => {
|
|
281
|
+
var n = O();
|
|
282
|
+
function r(e, t) {
|
|
283
|
+
if (Array.isArray(t)) {
|
|
284
|
+
for (let n of t) r(e, n);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
t !== "" && t != null && t !== !0 && t !== !1 && e.cnode(t);
|
|
288
|
+
}
|
|
289
|
+
function i(e, t, ...i) {
|
|
290
|
+
if (typeof t == "object" && t) {
|
|
291
|
+
delete t.__source, delete t.__self;
|
|
292
|
+
for (let [e, n] of Object.entries(t)) n == null ? delete t[e] : t[e] = n.toString(10);
|
|
293
|
+
}
|
|
294
|
+
let a = new n(e, t);
|
|
295
|
+
for (let e of i) r(a, e);
|
|
296
|
+
return a;
|
|
297
|
+
}
|
|
298
|
+
t.exports = i;
|
|
299
|
+
})), k = /* @__PURE__ */ y(((e, t) => {
|
|
300
|
+
var n = typeof Reflect == "object" ? Reflect : null, r = n && typeof n.apply == "function" ? n.apply : function(e, t, n) {
|
|
301
|
+
return Function.prototype.apply.call(e, t, n);
|
|
302
|
+
}, i = n && typeof n.ownKeys == "function" ? n.ownKeys : Object.getOwnPropertySymbols ? function(e) {
|
|
303
|
+
return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
|
|
304
|
+
} : function(e) {
|
|
305
|
+
return Object.getOwnPropertyNames(e);
|
|
306
|
+
};
|
|
307
|
+
function a(e) {
|
|
308
|
+
console && console.warn && console.warn(e);
|
|
309
|
+
}
|
|
310
|
+
var o = Number.isNaN || function(e) {
|
|
311
|
+
return e !== e;
|
|
312
|
+
};
|
|
313
|
+
function s() {
|
|
314
|
+
s.init.call(this);
|
|
315
|
+
}
|
|
316
|
+
t.exports = s, t.exports.once = y, s.EventEmitter = s, s.prototype._events = void 0, s.prototype._eventsCount = 0, s.prototype._maxListeners = void 0;
|
|
317
|
+
var c = 10;
|
|
318
|
+
function l(e) {
|
|
319
|
+
if (typeof e != "function") throw TypeError("The \"listener\" argument must be of type Function. Received type " + typeof e);
|
|
320
|
+
}
|
|
321
|
+
Object.defineProperty(s, "defaultMaxListeners", {
|
|
322
|
+
enumerable: !0,
|
|
323
|
+
get: function() {
|
|
324
|
+
return c;
|
|
325
|
+
},
|
|
326
|
+
set: function(e) {
|
|
327
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
328
|
+
c = e;
|
|
329
|
+
}
|
|
330
|
+
}), s.init = function() {
|
|
331
|
+
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
|
|
332
|
+
}, s.prototype.setMaxListeners = function(e) {
|
|
333
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"n\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
334
|
+
return this._maxListeners = e, this;
|
|
335
|
+
};
|
|
336
|
+
function u(e) {
|
|
337
|
+
return e._maxListeners === void 0 ? s.defaultMaxListeners : e._maxListeners;
|
|
338
|
+
}
|
|
339
|
+
s.prototype.getMaxListeners = function() {
|
|
340
|
+
return u(this);
|
|
341
|
+
}, s.prototype.emit = function(e) {
|
|
342
|
+
for (var t = [], n = 1; n < arguments.length; n++) t.push(arguments[n]);
|
|
343
|
+
var i = e === "error", a = this._events;
|
|
344
|
+
if (a !== void 0) i &&= a.error === void 0;
|
|
345
|
+
else if (!i) return !1;
|
|
346
|
+
if (i) {
|
|
347
|
+
var o;
|
|
348
|
+
if (t.length > 0 && (o = t[0]), o instanceof Error) throw o;
|
|
349
|
+
var s = /* @__PURE__ */ Error("Unhandled error." + (o ? " (" + o.message + ")" : ""));
|
|
350
|
+
throw s.context = o, s;
|
|
351
|
+
}
|
|
352
|
+
var c = a[e];
|
|
353
|
+
if (c === void 0) return !1;
|
|
354
|
+
if (typeof c == "function") r(c, this, t);
|
|
355
|
+
else for (var l = c.length, u = g(c, l), n = 0; n < l; ++n) r(u[n], this, t);
|
|
356
|
+
return !0;
|
|
357
|
+
};
|
|
358
|
+
function d(e, t, n, r) {
|
|
359
|
+
var i, o, s;
|
|
360
|
+
if (l(n), o = e._events, o === void 0 ? (o = e._events = Object.create(null), e._eventsCount = 0) : (o.newListener !== void 0 && (e.emit("newListener", t, n.listener ? n.listener : n), o = e._events), s = o[t]), s === void 0) s = o[t] = n, ++e._eventsCount;
|
|
361
|
+
else if (typeof s == "function" ? s = o[t] = r ? [n, s] : [s, n] : r ? s.unshift(n) : s.push(n), i = u(e), i > 0 && s.length > i && !s.warned) {
|
|
362
|
+
s.warned = !0;
|
|
363
|
+
var c = /* @__PURE__ */ Error("Possible EventEmitter memory leak detected. " + s.length + " " + String(t) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
364
|
+
c.name = "MaxListenersExceededWarning", c.emitter = e, c.type = t, c.count = s.length, a(c);
|
|
365
|
+
}
|
|
366
|
+
return e;
|
|
367
|
+
}
|
|
368
|
+
s.prototype.addListener = function(e, t) {
|
|
369
|
+
return d(this, e, t, !1);
|
|
370
|
+
}, s.prototype.on = s.prototype.addListener, s.prototype.prependListener = function(e, t) {
|
|
371
|
+
return d(this, e, t, !0);
|
|
372
|
+
};
|
|
373
|
+
function f() {
|
|
374
|
+
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);
|
|
375
|
+
}
|
|
376
|
+
function p(e, t, n) {
|
|
377
|
+
var r = {
|
|
378
|
+
fired: !1,
|
|
379
|
+
wrapFn: void 0,
|
|
380
|
+
target: e,
|
|
381
|
+
type: t,
|
|
382
|
+
listener: n
|
|
383
|
+
}, i = f.bind(r);
|
|
384
|
+
return i.listener = n, r.wrapFn = i, i;
|
|
385
|
+
}
|
|
386
|
+
s.prototype.once = function(e, t) {
|
|
387
|
+
return l(t), this.on(e, p(this, e, t)), this;
|
|
388
|
+
}, s.prototype.prependOnceListener = function(e, t) {
|
|
389
|
+
return l(t), this.prependListener(e, p(this, e, t)), this;
|
|
390
|
+
}, s.prototype.removeListener = function(e, t) {
|
|
391
|
+
var n, r, i, a, o;
|
|
392
|
+
if (l(t), r = this._events, r === void 0 || (n = r[e], n === void 0)) return this;
|
|
393
|
+
if (n === t || n.listener === t) --this._eventsCount === 0 ? this._events = Object.create(null) : (delete r[e], r.removeListener && this.emit("removeListener", e, n.listener || t));
|
|
394
|
+
else if (typeof n != "function") {
|
|
395
|
+
for (i = -1, a = n.length - 1; a >= 0; a--) if (n[a] === t || n[a].listener === t) {
|
|
396
|
+
o = n[a].listener, i = a;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
if (i < 0) return this;
|
|
400
|
+
i === 0 ? n.shift() : _(n, i), n.length === 1 && (r[e] = n[0]), r.removeListener !== void 0 && this.emit("removeListener", e, o || t);
|
|
401
|
+
}
|
|
402
|
+
return this;
|
|
403
|
+
}, s.prototype.off = s.prototype.removeListener, s.prototype.removeAllListeners = function(e) {
|
|
404
|
+
var t, n = this._events, r;
|
|
405
|
+
if (n === void 0) return this;
|
|
406
|
+
if (n.removeListener === void 0) return arguments.length === 0 ? (this._events = Object.create(null), this._eventsCount = 0) : n[e] !== void 0 && (--this._eventsCount === 0 ? this._events = Object.create(null) : delete n[e]), this;
|
|
407
|
+
if (arguments.length === 0) {
|
|
408
|
+
var i = Object.keys(n), a;
|
|
409
|
+
for (r = 0; r < i.length; ++r) a = i[r], a !== "removeListener" && this.removeAllListeners(a);
|
|
410
|
+
return this.removeAllListeners("removeListener"), this._events = Object.create(null), this._eventsCount = 0, this;
|
|
411
|
+
}
|
|
412
|
+
if (t = n[e], typeof t == "function") this.removeListener(e, t);
|
|
413
|
+
else if (t !== void 0) for (r = t.length - 1; r >= 0; r--) this.removeListener(e, t[r]);
|
|
414
|
+
return this;
|
|
415
|
+
};
|
|
416
|
+
function m(e, t, n) {
|
|
417
|
+
var r = e._events;
|
|
418
|
+
if (r === void 0) return [];
|
|
419
|
+
var i = r[t];
|
|
420
|
+
return i === void 0 ? [] : typeof i == "function" ? n ? [i.listener || i] : [i] : n ? v(i) : g(i, i.length);
|
|
421
|
+
}
|
|
422
|
+
s.prototype.listeners = function(e) {
|
|
423
|
+
return m(this, e, !0);
|
|
424
|
+
}, s.prototype.rawListeners = function(e) {
|
|
425
|
+
return m(this, e, !1);
|
|
426
|
+
}, s.listenerCount = function(e, t) {
|
|
427
|
+
return typeof e.listenerCount == "function" ? e.listenerCount(t) : h.call(e, t);
|
|
428
|
+
}, s.prototype.listenerCount = h;
|
|
429
|
+
function h(e) {
|
|
430
|
+
var t = this._events;
|
|
431
|
+
if (t !== void 0) {
|
|
432
|
+
var n = t[e];
|
|
433
|
+
if (typeof n == "function") return 1;
|
|
434
|
+
if (n !== void 0) return n.length;
|
|
435
|
+
}
|
|
436
|
+
return 0;
|
|
437
|
+
}
|
|
438
|
+
s.prototype.eventNames = function() {
|
|
439
|
+
return this._eventsCount > 0 ? i(this._events) : [];
|
|
440
|
+
};
|
|
441
|
+
function g(e, t) {
|
|
442
|
+
for (var n = Array(t), r = 0; r < t; ++r) n[r] = e[r];
|
|
443
|
+
return n;
|
|
444
|
+
}
|
|
445
|
+
function _(e, t) {
|
|
446
|
+
for (; t + 1 < e.length; t++) e[t] = e[t + 1];
|
|
447
|
+
e.pop();
|
|
448
|
+
}
|
|
449
|
+
function v(e) {
|
|
450
|
+
for (var t = Array(e.length), n = 0; n < t.length; ++n) t[n] = e[n].listener || e[n];
|
|
451
|
+
return t;
|
|
452
|
+
}
|
|
453
|
+
function y(e, t) {
|
|
454
|
+
return new Promise(function(n, r) {
|
|
455
|
+
function i(n) {
|
|
456
|
+
e.removeListener(t, a), r(n);
|
|
457
|
+
}
|
|
458
|
+
function a() {
|
|
459
|
+
typeof e.removeListener == "function" && e.removeListener("error", i), n([].slice.call(arguments));
|
|
460
|
+
}
|
|
461
|
+
x(e, t, a, { once: !0 }), t !== "error" && b(e, i, { once: !0 });
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function b(e, t, n) {
|
|
465
|
+
typeof e.on == "function" && x(e, "error", t, n);
|
|
466
|
+
}
|
|
467
|
+
function x(e, t, n, r) {
|
|
468
|
+
if (typeof e.on == "function") r.once ? e.once(t, n) : e.on(t, n);
|
|
469
|
+
else if (typeof e.addEventListener == "function") e.addEventListener(t, function i(a) {
|
|
470
|
+
r.once && e.removeEventListener(t, i), n(a);
|
|
471
|
+
});
|
|
472
|
+
else throw TypeError("The \"emitter\" argument must be of type EventEmitter. Received type " + typeof e);
|
|
473
|
+
}
|
|
474
|
+
})), te = /* @__PURE__ */ y(((e, t) => {
|
|
475
|
+
var n = k(), r = D(), i = 0, a = 1, o = 2, s = 3, c = 4, l = 5, u = 6, d = 7, f = 8, p = 9, m = 10;
|
|
476
|
+
t.exports = class extends n.EventEmitter {
|
|
477
|
+
constructor() {
|
|
478
|
+
super();
|
|
479
|
+
let e = i, t, n, h, g, _, v, y, b, x = 0, S;
|
|
480
|
+
this._handleTagOpening = function(e, t, n) {
|
|
481
|
+
e ? this.emit("endElement", t, !1) : (this.emit("startElement", t, n), v && this.emit("endElement", t, !0));
|
|
482
|
+
}, this.write = function(C) {
|
|
483
|
+
typeof C != "string" && (C = C.toString());
|
|
484
|
+
let w = 0;
|
|
485
|
+
t &&= (C = t + C, w += n ? 0 : t.length, n = !1, null);
|
|
486
|
+
function T() {
|
|
487
|
+
if (typeof x == "number") {
|
|
488
|
+
let e = C.slice(x, w);
|
|
489
|
+
return x = void 0, e;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
for (; w < C.length; w++) {
|
|
493
|
+
switch (e) {
|
|
494
|
+
case i: {
|
|
495
|
+
let e = C.indexOf("<", w);
|
|
496
|
+
e !== -1 && w !== e && (w = e);
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
case f: {
|
|
500
|
+
let e = C.indexOf(b, w);
|
|
501
|
+
e !== -1 && (w = e);
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
case a: {
|
|
505
|
+
let e = C.indexOf("-->", w);
|
|
506
|
+
e !== -1 && (w = e + 2);
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
case m: {
|
|
510
|
+
let e = C.indexOf("]]>", w);
|
|
511
|
+
e !== -1 && (w = e + 2);
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
let t = C.charCodeAt(w);
|
|
516
|
+
switch (e) {
|
|
517
|
+
case i:
|
|
518
|
+
if (t === 60) {
|
|
519
|
+
let t = T();
|
|
520
|
+
t && this.emit("text", r.unescapeXML(t)), e = s, x = w + 1, g = {};
|
|
521
|
+
}
|
|
522
|
+
break;
|
|
523
|
+
case p:
|
|
524
|
+
if (t === 93) {
|
|
525
|
+
if (C.substr(w + 1, 2) === "]>") {
|
|
526
|
+
let t = T();
|
|
527
|
+
t && this.emit("text", t), e = i;
|
|
528
|
+
} else C.length < w + 2 && (n = !0, w = C.length);
|
|
529
|
+
}
|
|
530
|
+
break;
|
|
531
|
+
case s:
|
|
532
|
+
t === 47 && x === w ? (x = w + 1, _ = !0) : t === 33 ? C.substr(w + 1, 7) === "[CDATA[" ? (x = w + 8, e = p) : C.length < w + 8 && "[CDATA[".startsWith(C.slice(w + 1)) ? (n = !0, w = C.length) : (x = void 0, e = a) : t === 63 ? (x = void 0, e = o) : (t <= 32 || t === 47 || t === 62) && (h = T(), w--, e = c);
|
|
533
|
+
break;
|
|
534
|
+
case a:
|
|
535
|
+
if (t === 62) {
|
|
536
|
+
let t = C.charCodeAt(w - 1), n = C.charCodeAt(w - 2);
|
|
537
|
+
(t === 45 && n === 45 || t === 93 && n === 93) && (e = i);
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case o:
|
|
541
|
+
t === 62 && C.charCodeAt(w - 1) === 63 && (e = i);
|
|
542
|
+
break;
|
|
543
|
+
case c:
|
|
544
|
+
t === 62 ? (this._handleTagOpening(_, h, g), h = void 0, g = void 0, _ = void 0, v = void 0, e = i, x = w + 1) : t === 47 ? v = !0 : t > 32 && (x = w, e = l);
|
|
545
|
+
break;
|
|
546
|
+
case l:
|
|
547
|
+
(t <= 32 || t === 61) && (S = T(), w--, e = u);
|
|
548
|
+
break;
|
|
549
|
+
case u:
|
|
550
|
+
t === 61 && (e = d);
|
|
551
|
+
break;
|
|
552
|
+
case d:
|
|
553
|
+
(t === 34 || t === 39) && (y = t, b = t === 34 ? "\"" : "'", e = f, x = w + 1);
|
|
554
|
+
break;
|
|
555
|
+
case f: if (t === y) {
|
|
556
|
+
let t = r.unescapeXML(T());
|
|
557
|
+
g[S] = t, S = void 0, e = c;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
typeof x == "number" && x <= C.length && (t = C.slice(x), x = 0);
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
end(e) {
|
|
565
|
+
e && this.write(e), this.write = function() {};
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
})), A = D(), ne = /* @__PURE__ */ x(O(), 1), re = /* @__PURE__ */ x(ee(), 1), j = k(), ie = /* @__PURE__ */ x(te(), 1), ae = class extends Error {
|
|
569
|
+
constructor(e) {
|
|
570
|
+
super(e), this.name = "TimeoutError";
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region node_modules/@xmpp/events/lib/delay.js
|
|
575
|
+
function oe(e) {
|
|
576
|
+
let t, n = new Promise((n) => {
|
|
577
|
+
t = setTimeout(n, e);
|
|
578
|
+
});
|
|
579
|
+
return n.timeout = t, n;
|
|
580
|
+
}
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region node_modules/@xmpp/events/lib/timeout.js
|
|
583
|
+
function se(e, t) {
|
|
584
|
+
let n = oe(t);
|
|
585
|
+
function r() {
|
|
586
|
+
clearTimeout(n.timeout);
|
|
587
|
+
}
|
|
588
|
+
let i = new ae();
|
|
589
|
+
return Promise.race([e.finally(r), n.then(() => {
|
|
590
|
+
throw i;
|
|
591
|
+
})]);
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region node_modules/@xmpp/events/lib/onoff.js
|
|
595
|
+
var ce = /* @__PURE__ */ new WeakMap();
|
|
596
|
+
function le(e) {
|
|
597
|
+
let t = ce.get(e);
|
|
598
|
+
return t || (t = {
|
|
599
|
+
on: (e.addEventListener ?? e.addListener).bind(e),
|
|
600
|
+
off: (e.removeEventListener ?? e.removeListener).bind(e),
|
|
601
|
+
once: (e.once ?? ((t, n) => e.addEventListener(t, n, { once: !0 }))).bind(e)
|
|
602
|
+
}, ce.set(e, t)), t;
|
|
603
|
+
}
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region node_modules/@xmpp/events/lib/promise.js
|
|
606
|
+
function M(e, t, n = "error", r) {
|
|
607
|
+
return new Promise((i, a) => {
|
|
608
|
+
let o, { off: s, once: c } = le(e), l = () => {
|
|
609
|
+
clearTimeout(o), s(t, d), s(n, u);
|
|
610
|
+
};
|
|
611
|
+
function u(e) {
|
|
612
|
+
a(e), l();
|
|
613
|
+
}
|
|
614
|
+
function d(e) {
|
|
615
|
+
i(e), l();
|
|
616
|
+
}
|
|
617
|
+
if (c(t, d), n && c(n, u), r) {
|
|
618
|
+
let e = new ae();
|
|
619
|
+
o = setTimeout(() => {
|
|
620
|
+
l(), a(e);
|
|
621
|
+
}, r);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region node_modules/@xmpp/events/lib/Deferred.js
|
|
627
|
+
function ue() {
|
|
628
|
+
this.promise = new Promise((e, t) => {
|
|
629
|
+
this.resolve = e, this.reject = t;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region node_modules/@xmpp/events/lib/procedure.js
|
|
634
|
+
function de(e, t = null, n) {
|
|
635
|
+
return new Promise((r, i) => {
|
|
636
|
+
function a(t) {
|
|
637
|
+
e.removeListener("nonza", s), i(t);
|
|
638
|
+
}
|
|
639
|
+
function o(...t) {
|
|
640
|
+
e.removeListener("nonza", s), r(...t);
|
|
641
|
+
}
|
|
642
|
+
async function s(e) {
|
|
643
|
+
try {
|
|
644
|
+
await n(e, o);
|
|
645
|
+
} catch (e) {
|
|
646
|
+
a(e);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
t && e.send(t).catch(a), e.on("nonza", s);
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region node_modules/@xmpp/events/lib/listeners.js
|
|
654
|
+
function fe(e) {
|
|
655
|
+
return {
|
|
656
|
+
subscribe(t) {
|
|
657
|
+
let { on: n } = le(t);
|
|
658
|
+
for (let [t, r] of Object.entries(e)) n(t, r);
|
|
659
|
+
},
|
|
660
|
+
unsubscribe(t) {
|
|
661
|
+
let { off: n } = le(t);
|
|
662
|
+
for (let [t, r] of Object.entries(e)) n(t, r);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region node_modules/@xmpp/xml/lib/XMLError.js
|
|
668
|
+
var pe = class extends Error {
|
|
669
|
+
constructor(...e) {
|
|
670
|
+
super(...e), this.name = "XMLError";
|
|
671
|
+
}
|
|
672
|
+
}, me = class extends j.EventEmitter {
|
|
673
|
+
constructor() {
|
|
674
|
+
super();
|
|
675
|
+
let e = new ie.default();
|
|
676
|
+
this.root = null, this.cursor = null, e.on("startElement", this.onStartElement.bind(this)), e.on("endElement", this.onEndElement.bind(this)), e.on("text", this.onText.bind(this)), this.parser = e;
|
|
677
|
+
}
|
|
678
|
+
onStartElement(e, t) {
|
|
679
|
+
let n = new ne.default(e, t), { root: r, cursor: i } = this;
|
|
680
|
+
r ? i !== r && i.append(n) : (this.root = n, this.emit("start", n)), this.cursor = n;
|
|
681
|
+
}
|
|
682
|
+
onEndElement(e) {
|
|
683
|
+
let { root: t, cursor: n } = this;
|
|
684
|
+
if (e !== n.name) {
|
|
685
|
+
this.emit("error", new pe(`${n.name} must be closed.`));
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (n === t) {
|
|
689
|
+
this.emit("end", t);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (!n.parent) {
|
|
693
|
+
n.parent = t, this.emit("element", n), this.cursor = t;
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
this.cursor = n.parent;
|
|
697
|
+
}
|
|
698
|
+
onText(e) {
|
|
699
|
+
let { cursor: t } = this;
|
|
700
|
+
if (!t) {
|
|
701
|
+
this.emit("error", new pe(`${e} must be a child.`));
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
t.t(e);
|
|
705
|
+
}
|
|
706
|
+
write(e) {
|
|
707
|
+
this.parser.write(e);
|
|
708
|
+
}
|
|
709
|
+
end(e) {
|
|
710
|
+
e && this.parser.write(e);
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
me.XMLError = pe;
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region node_modules/@xmpp/xml/index.js
|
|
716
|
+
function N(...e) {
|
|
717
|
+
return (0, re.default)(...e);
|
|
718
|
+
}
|
|
719
|
+
Object.assign(N, {
|
|
720
|
+
Element: ne.default,
|
|
721
|
+
createElement: re.default,
|
|
722
|
+
Parser: me,
|
|
723
|
+
escapeXML: A.escapeXML,
|
|
724
|
+
unescapeXML: A.unescapeXML,
|
|
725
|
+
escapeXMLText: A.escapeXMLText,
|
|
726
|
+
unescapeXMLText: A.unescapeXMLText,
|
|
727
|
+
XMLError: pe,
|
|
728
|
+
xml: N
|
|
729
|
+
});
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region node_modules/@xmpp/jid/lib/escaping.js
|
|
732
|
+
function he(e) {
|
|
733
|
+
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);
|
|
734
|
+
}
|
|
735
|
+
function ge(e) {
|
|
736
|
+
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`);
|
|
737
|
+
}
|
|
738
|
+
function _e(e) {
|
|
739
|
+
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`, "\\");
|
|
740
|
+
}
|
|
741
|
+
//#endregion
|
|
742
|
+
//#region node_modules/@xmpp/jid/lib/JID.js
|
|
743
|
+
var P = class e {
|
|
744
|
+
constructor(e, t, n) {
|
|
745
|
+
if (typeof t != "string" || !t) throw TypeError("Invalid domain.");
|
|
746
|
+
this.setDomain(t), this.setLocal(typeof e == "string" ? e : ""), this.setResource(typeof n == "string" ? n : "");
|
|
747
|
+
}
|
|
748
|
+
[Symbol.toPrimitive](e) {
|
|
749
|
+
return e === "number" ? NaN : this.toString();
|
|
750
|
+
}
|
|
751
|
+
toString(e) {
|
|
752
|
+
let t = this._domain;
|
|
753
|
+
return this._local && (t = this.getLocal(e) + "@" + t), this._resource && (t = t + "/" + this._resource), t;
|
|
754
|
+
}
|
|
755
|
+
bare() {
|
|
756
|
+
return this._resource ? new e(this._local, this._domain, null) : this;
|
|
757
|
+
}
|
|
758
|
+
equals(e) {
|
|
759
|
+
return this._local === e._local && this._domain === e._domain && this._resource === e._resource;
|
|
760
|
+
}
|
|
761
|
+
setLocal(e, t) {
|
|
762
|
+
return t ||= he(e), t && (e = ge(e)), this._local = e && e.toLowerCase(), this;
|
|
763
|
+
}
|
|
764
|
+
getLocal(e = !1) {
|
|
765
|
+
let t = null;
|
|
766
|
+
return t = e ? _e(this._local) : this._local, t;
|
|
767
|
+
}
|
|
768
|
+
setDomain(e) {
|
|
769
|
+
return this._domain = e.toLowerCase(), this;
|
|
770
|
+
}
|
|
771
|
+
getDomain() {
|
|
772
|
+
return this._domain;
|
|
773
|
+
}
|
|
774
|
+
setResource(e) {
|
|
775
|
+
return this._resource = e, this;
|
|
776
|
+
}
|
|
777
|
+
getResource() {
|
|
778
|
+
return this._resource;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
Object.defineProperty(P.prototype, "local", {
|
|
782
|
+
get: P.prototype.getLocal,
|
|
783
|
+
set: P.prototype.setLocal
|
|
784
|
+
}), Object.defineProperty(P.prototype, "domain", {
|
|
785
|
+
get: P.prototype.getDomain,
|
|
786
|
+
set: P.prototype.setDomain
|
|
787
|
+
}), Object.defineProperty(P.prototype, "resource", {
|
|
788
|
+
get: P.prototype.getResource,
|
|
789
|
+
set: P.prototype.setResource
|
|
790
|
+
});
|
|
791
|
+
//#endregion
|
|
792
|
+
//#region node_modules/@xmpp/jid/lib/parse.js
|
|
793
|
+
function ve(e) {
|
|
794
|
+
let t, n, r = e.indexOf("/");
|
|
795
|
+
r !== -1 && (n = e.slice(r + 1), e = e.slice(0, r));
|
|
796
|
+
let i = e.indexOf("@");
|
|
797
|
+
return i !== -1 && (t = e.slice(0, i), e = e.slice(i + 1)), new P(t, e, n);
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region node_modules/@xmpp/jid/index.js
|
|
801
|
+
function ye(e, t) {
|
|
802
|
+
return e.equals(t);
|
|
803
|
+
}
|
|
804
|
+
function be(...e) {
|
|
805
|
+
return !e[1] && !e[2] ? ve(...e) : new P(...e);
|
|
806
|
+
}
|
|
807
|
+
var F = be.bind();
|
|
808
|
+
F.jid = be, F.JID = P, F.parse = ve, F.equal = ye, F.detectEscape = he, F.escapeLocal = ge, F.unescapeLocal = _e;
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region node_modules/@xmpp/error/index.js
|
|
811
|
+
var xe = class extends Error {
|
|
812
|
+
constructor(e, t, n) {
|
|
813
|
+
super(e + (t ? ` - ${t}` : "")), this.name = "XMPPError", this.condition = e, this.text = t, this.application = n;
|
|
814
|
+
}
|
|
815
|
+
static fromElement(e) {
|
|
816
|
+
let [t, n, r] = e.getChildElements(), i, a;
|
|
817
|
+
n && (n.is("text") ? i = n : n && (a = n), r && (a = r));
|
|
818
|
+
let o = new this(t.name, i ? i.text() : "", a);
|
|
819
|
+
return o.element = e, o;
|
|
820
|
+
}
|
|
821
|
+
}, Se = class extends xe {
|
|
822
|
+
constructor(...e) {
|
|
823
|
+
super(...e), this.name = "StreamError";
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
//#endregion
|
|
827
|
+
//#region node_modules/@xmpp/connection/lib/util.js
|
|
828
|
+
function Ce(e) {
|
|
829
|
+
let { port: t, hostname: n, protocol: r } = new URL(e);
|
|
830
|
+
return n === "[::1]" && (n = "::1"), {
|
|
831
|
+
port: t,
|
|
832
|
+
hostname: n,
|
|
833
|
+
protocol: r
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
function we(e) {
|
|
837
|
+
let { port: t, hostname: n } = Ce(`http://${e}`);
|
|
838
|
+
return {
|
|
839
|
+
port: t,
|
|
840
|
+
hostname: n
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
function Te(e) {
|
|
844
|
+
return e.includes("://") ? Ce(e) : we(e);
|
|
845
|
+
}
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region node_modules/@xmpp/connection/index.js
|
|
848
|
+
var Ee = "urn:ietf:params:xml:ns:xmpp-streams", De = "http://etherx.jabber.org/streams", Oe = class extends j.EventEmitter {
|
|
849
|
+
#e = null;
|
|
850
|
+
#t = null;
|
|
851
|
+
constructor(e = {}) {
|
|
852
|
+
super(), typeof e == "string" && (e = { domain: e }), this.jid = null, this.timeout = e.timeout || 2e3, this.options = e, this.status = "offline", this.socket = null, this.parser = null, this.root = null;
|
|
853
|
+
}
|
|
854
|
+
isSecure() {
|
|
855
|
+
return this.socket?.secure === !0;
|
|
856
|
+
}
|
|
857
|
+
async _streamError(e, t) {
|
|
858
|
+
try {
|
|
859
|
+
await this.send(N("stream:error", {}, [N(e, { xmlns: Ee }, t)]));
|
|
860
|
+
} catch {}
|
|
861
|
+
return this.disconnect();
|
|
862
|
+
}
|
|
863
|
+
_onData(e) {
|
|
864
|
+
let t = e.toString("utf8");
|
|
865
|
+
this.parser.write(t);
|
|
866
|
+
}
|
|
867
|
+
#n(e) {
|
|
868
|
+
this._streamError("bad-format"), this._detachParser(), this.emit("error", e);
|
|
869
|
+
}
|
|
870
|
+
#r(e, t) {
|
|
871
|
+
this._detachSocket(), this._status("disconnect", {
|
|
872
|
+
clean: !e,
|
|
873
|
+
reason: t
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
#i(e, t) {
|
|
877
|
+
this._detachParser(), this._status("close", {
|
|
878
|
+
clean: !e,
|
|
879
|
+
reason: t
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
_attachSocket(e) {
|
|
883
|
+
this.socket = e, this.#e ??= fe({
|
|
884
|
+
data: this._onData.bind(this),
|
|
885
|
+
close: this.#r.bind(this),
|
|
886
|
+
connect: () => this._status("connect"),
|
|
887
|
+
error: (e) => this.emit("error", e)
|
|
888
|
+
}), this.#e.subscribe(this.socket);
|
|
889
|
+
}
|
|
890
|
+
_detachSocket() {
|
|
891
|
+
this.socket && this.#e?.unsubscribe(this.socket), this.socket = null;
|
|
892
|
+
}
|
|
893
|
+
_onElement(e) {
|
|
894
|
+
let t = e.is("error", De);
|
|
895
|
+
t && this._onStreamError(e), this.emit("element", e), this.emit(this.isStanza(e) ? "stanza" : "nonza", e), t && this.disconnect();
|
|
896
|
+
}
|
|
897
|
+
_onStreamError(e) {
|
|
898
|
+
let t = Se.fromElement(e);
|
|
899
|
+
if (t.condition === "see-other-host") return this._onSeeOtherHost(t);
|
|
900
|
+
this.emit("error", t);
|
|
901
|
+
}
|
|
902
|
+
async _onSeeOtherHost(e) {
|
|
903
|
+
let { protocol: t } = Te(this.options.service), n = e.element.getChildText("see-other-host"), { port: r } = we(n), i;
|
|
904
|
+
i = r ? `${t || "xmpp:"}//${n}` : (t ? `${t}//` : "") + n;
|
|
905
|
+
try {
|
|
906
|
+
await M(this, "disconnect");
|
|
907
|
+
let { domain: e, lang: t } = this.options;
|
|
908
|
+
await this.connect(i), await this.open({
|
|
909
|
+
domain: e,
|
|
910
|
+
lang: t
|
|
911
|
+
});
|
|
912
|
+
} catch (e) {
|
|
913
|
+
this.emit("error", e);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
_attachParser(e) {
|
|
917
|
+
this.parser = e, this.#t ??= fe({
|
|
918
|
+
element: this._onElement.bind(this),
|
|
919
|
+
error: this.#n.bind(this),
|
|
920
|
+
end: this.#i.bind(this),
|
|
921
|
+
start: (e) => this._status("open", e)
|
|
922
|
+
}), this.#t.subscribe(this.parser);
|
|
923
|
+
}
|
|
924
|
+
_detachParser() {
|
|
925
|
+
this.parser && this.#t?.unsubscribe(this.parser), this.parser = null, this.root = null;
|
|
926
|
+
}
|
|
927
|
+
_jid(e) {
|
|
928
|
+
return this.jid = F(e), this.jid;
|
|
929
|
+
}
|
|
930
|
+
_status(e, ...t) {
|
|
931
|
+
this.status !== e && (this.status = e, this.emit("status", e, ...t), this.emit(e, ...t));
|
|
932
|
+
}
|
|
933
|
+
_ready(e = !1) {
|
|
934
|
+
e ? this.status = "online" : this._status("online", this.jid);
|
|
935
|
+
}
|
|
936
|
+
async disconnect() {
|
|
937
|
+
let e;
|
|
938
|
+
try {
|
|
939
|
+
e = await this._closeStream();
|
|
940
|
+
} catch (e) {
|
|
941
|
+
this.#i(e);
|
|
942
|
+
}
|
|
943
|
+
try {
|
|
944
|
+
await this._closeSocket();
|
|
945
|
+
} catch (e) {
|
|
946
|
+
this.#r(!0, e);
|
|
947
|
+
}
|
|
948
|
+
return e;
|
|
949
|
+
}
|
|
950
|
+
async start() {
|
|
951
|
+
if (this.status !== "offline") throw Error("Connection is not offline");
|
|
952
|
+
let { service: e, domain: t, lang: n } = this.options;
|
|
953
|
+
await this.connect(e);
|
|
954
|
+
let r = M(this, "online");
|
|
955
|
+
return await this.open({
|
|
956
|
+
domain: t,
|
|
957
|
+
lang: n
|
|
958
|
+
}), r;
|
|
959
|
+
}
|
|
960
|
+
async connect(e) {
|
|
961
|
+
this._status("connecting", e);
|
|
962
|
+
let t = new this.Socket();
|
|
963
|
+
return this._attachSocket(t), t.connect(this.socketParameters(e)), M(t, "connect");
|
|
964
|
+
}
|
|
965
|
+
async _closeSocket(e = this.timeout) {
|
|
966
|
+
this._status("disconnecting"), this.socket.end(), await M(this.socket, "close", "error", e);
|
|
967
|
+
}
|
|
968
|
+
async open(e) {
|
|
969
|
+
this._status("opening");
|
|
970
|
+
let { domain: t, lang: n } = e, r = this.headerElement();
|
|
971
|
+
return r.attrs.to = t, r.attrs["xml:lang"] = n, this.root = r, this._attachParser(new this.Parser()), await this.write(this.header(r)), M(this, "open", "error", this.timeout);
|
|
972
|
+
}
|
|
973
|
+
async stop() {
|
|
974
|
+
let e = await this.disconnect();
|
|
975
|
+
return this._status("offline", e), e;
|
|
976
|
+
}
|
|
977
|
+
async _closeStream(e = this.timeout) {
|
|
978
|
+
await this.#c("close");
|
|
979
|
+
let t = this.footer(this.footerElement());
|
|
980
|
+
return await this.write(t), this._status("closing"), M(this.parser, "end", "error", e);
|
|
981
|
+
}
|
|
982
|
+
async restart() {
|
|
983
|
+
this._detachParser();
|
|
984
|
+
let { domain: e, lang: t } = this.options;
|
|
985
|
+
return this.open({
|
|
986
|
+
domain: e,
|
|
987
|
+
lang: t
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
async send(e) {
|
|
991
|
+
e.parent = this.root, await this.write(e.toString()), this.emit("send", e);
|
|
992
|
+
}
|
|
993
|
+
sendReceive(e, t = this.timeout) {
|
|
994
|
+
return Promise.all([this.send(e), M(this, "element", "error", t)]).then(([, e]) => e);
|
|
995
|
+
}
|
|
996
|
+
async write(e) {
|
|
997
|
+
if (this.status === "closing") throw Error("Connection is closing");
|
|
998
|
+
return new Promise((t, n) => {
|
|
999
|
+
this.socket.write(e, (e) => e ? n(e) : t());
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
isStanza(e) {
|
|
1003
|
+
let { name: t } = e;
|
|
1004
|
+
return t === "iq" || t === "message" || t === "presence";
|
|
1005
|
+
}
|
|
1006
|
+
isNonza(e) {
|
|
1007
|
+
return !this.isStanza(e);
|
|
1008
|
+
}
|
|
1009
|
+
header(e) {
|
|
1010
|
+
return e.toString();
|
|
1011
|
+
}
|
|
1012
|
+
headerElement() {
|
|
1013
|
+
return new N.Element("", {
|
|
1014
|
+
version: "1.0",
|
|
1015
|
+
xmlns: this.NS
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
footer(e) {
|
|
1019
|
+
return e.toString();
|
|
1020
|
+
}
|
|
1021
|
+
footerElement() {}
|
|
1022
|
+
socketParameters() {}
|
|
1023
|
+
#a = /* @__PURE__ */ new Map();
|
|
1024
|
+
#o = /* @__PURE__ */ new Set(["close"]);
|
|
1025
|
+
hook(e, t) {
|
|
1026
|
+
this.#s(e), this.#a.has(e) || this.#a.set(e, /* @__PURE__ */ new Set()), this.#a.get(e).add([t]);
|
|
1027
|
+
}
|
|
1028
|
+
#s(e) {
|
|
1029
|
+
if (!this.#o.has(e)) throw Error(`Hook event name "${e}" is unknown.`);
|
|
1030
|
+
}
|
|
1031
|
+
unhook(e, t) {
|
|
1032
|
+
this.#s(e);
|
|
1033
|
+
let n = this.#a.get("event"), r = [...n].find((e) => e.handler === t);
|
|
1034
|
+
n.remove(r);
|
|
1035
|
+
}
|
|
1036
|
+
async #c(e, ...t) {
|
|
1037
|
+
this.#s(e);
|
|
1038
|
+
let n = this.#a.get(e);
|
|
1039
|
+
n && await Promise.all([...n].map(async ([e]) => {
|
|
1040
|
+
try {
|
|
1041
|
+
await e(...t);
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
this.emit("error", e);
|
|
1044
|
+
}
|
|
1045
|
+
}));
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
Oe.prototype.NS = "", Oe.prototype.Socket = null, Oe.prototype.Parser = null;
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region node_modules/@xmpp/client-core/lib/Client.js
|
|
1051
|
+
var ke = class extends Oe {
|
|
1052
|
+
constructor(e) {
|
|
1053
|
+
super(e), this.transports = [];
|
|
1054
|
+
}
|
|
1055
|
+
send(e, ...t) {
|
|
1056
|
+
return this.Transport.prototype.send.call(this, e, ...t);
|
|
1057
|
+
}
|
|
1058
|
+
sendMany(...e) {
|
|
1059
|
+
return this.Transport.prototype.sendMany.call(this, ...e);
|
|
1060
|
+
}
|
|
1061
|
+
_findTransport(e) {
|
|
1062
|
+
return this.transports.find((t) => {
|
|
1063
|
+
try {
|
|
1064
|
+
return t.prototype.socketParameters(e) !== void 0;
|
|
1065
|
+
} catch {
|
|
1066
|
+
return !1;
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
connect(e) {
|
|
1071
|
+
let t = this._findTransport(e);
|
|
1072
|
+
if (!t) throw Error("No compatible connection method found.");
|
|
1073
|
+
return this.Transport = t, this.Socket = t.prototype.Socket, this.Parser = t.prototype.Parser, super.connect(e);
|
|
1074
|
+
}
|
|
1075
|
+
socketParameters(...e) {
|
|
1076
|
+
return this.Transport.prototype.socketParameters(...e);
|
|
1077
|
+
}
|
|
1078
|
+
header(e, ...t) {
|
|
1079
|
+
let n = this.isSecure() && this.jid?.bare().toString();
|
|
1080
|
+
return n && (e.attrs.from = n), this.Transport.prototype.header(e, ...t);
|
|
1081
|
+
}
|
|
1082
|
+
headerElement(...e) {
|
|
1083
|
+
return this.Transport.prototype.headerElement(...e);
|
|
1084
|
+
}
|
|
1085
|
+
footer(...e) {
|
|
1086
|
+
return this.Transport.prototype.footer(...e);
|
|
1087
|
+
}
|
|
1088
|
+
footerElement(...e) {
|
|
1089
|
+
return this.Transport.prototype.footerElement(...e);
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
ke.prototype.NS = "jabber:client";
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region node_modules/@xmpp/reconnect/index.js
|
|
1095
|
+
var Ae = class extends j.EventEmitter {
|
|
1096
|
+
constructor(e) {
|
|
1097
|
+
super(), this.delay = 1e3, this.entity = e, this._timeout = null;
|
|
1098
|
+
}
|
|
1099
|
+
#e = () => {
|
|
1100
|
+
this.scheduleReconnect();
|
|
1101
|
+
};
|
|
1102
|
+
scheduleReconnect() {
|
|
1103
|
+
let { entity: e, delay: t, _timeout: n } = this;
|
|
1104
|
+
clearTimeout(n), this._timeout = setTimeout(async () => {
|
|
1105
|
+
if (e.status === "disconnect") try {
|
|
1106
|
+
await this.reconnect();
|
|
1107
|
+
} catch {}
|
|
1108
|
+
}, t);
|
|
1109
|
+
}
|
|
1110
|
+
async reconnect() {
|
|
1111
|
+
let { entity: e } = this;
|
|
1112
|
+
this.emit("reconnecting");
|
|
1113
|
+
let { service: t, domain: n, lang: r } = e.options;
|
|
1114
|
+
await e.connect(t), await e.open({
|
|
1115
|
+
domain: n,
|
|
1116
|
+
lang: r
|
|
1117
|
+
}), this.emit("reconnected");
|
|
1118
|
+
}
|
|
1119
|
+
start() {
|
|
1120
|
+
let { entity: e } = this;
|
|
1121
|
+
e.on("disconnect", this.#e);
|
|
1122
|
+
}
|
|
1123
|
+
stop() {
|
|
1124
|
+
let { entity: e, _timeout: t } = this;
|
|
1125
|
+
e.removeListener("disconnect", this.#e), clearTimeout(t);
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
function je({ entity: e }) {
|
|
1129
|
+
let t = new Ae(e);
|
|
1130
|
+
return t.start(), t;
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region node_modules/@xmpp/websocket/lib/Socket.js
|
|
1134
|
+
var Me = "ECONNERROR";
|
|
1135
|
+
function Ne(e) {
|
|
1136
|
+
let t = Ce(e);
|
|
1137
|
+
return !!(t.protocol === "wss:" || [
|
|
1138
|
+
"localhost",
|
|
1139
|
+
"127.0.0.1",
|
|
1140
|
+
"::1"
|
|
1141
|
+
].includes(t.hostname));
|
|
1142
|
+
}
|
|
1143
|
+
var Pe = class extends j.EventEmitter {
|
|
1144
|
+
#e = null;
|
|
1145
|
+
socket = null;
|
|
1146
|
+
url = null;
|
|
1147
|
+
secure = !1;
|
|
1148
|
+
connect(e) {
|
|
1149
|
+
this.url = e, this.secure = Ne(e), this._attachSocket(new WebSocket(e, ["xmpp"]));
|
|
1150
|
+
}
|
|
1151
|
+
_attachSocket(e) {
|
|
1152
|
+
this.socket = e, this.#e ??= fe({
|
|
1153
|
+
open: () => this.emit("connect"),
|
|
1154
|
+
message: ({ data: e }) => this.emit("data", e),
|
|
1155
|
+
error: (e) => {
|
|
1156
|
+
let { url: t } = this, { error: n } = e;
|
|
1157
|
+
n || (n = Error(e.message || `WebSocket ${Me} ${t}`), n.errno = Me, n.code = Me), n.event = e, n.url = t, this.emit("error", n);
|
|
1158
|
+
},
|
|
1159
|
+
close: (e) => {
|
|
1160
|
+
this._detachSocket(), this.emit("close", !e.wasClean, e);
|
|
1161
|
+
}
|
|
1162
|
+
}), this.#e.subscribe(this.socket);
|
|
1163
|
+
}
|
|
1164
|
+
_detachSocket() {
|
|
1165
|
+
this.url = null, this.secure = !1, this.socket && this.#e?.unsubscribe(this.socket), this.socket = null;
|
|
1166
|
+
}
|
|
1167
|
+
end() {
|
|
1168
|
+
this.socket.close();
|
|
1169
|
+
}
|
|
1170
|
+
write(e, t) {
|
|
1171
|
+
function n(e) {
|
|
1172
|
+
t && Promise.resolve().then(() => t(e));
|
|
1173
|
+
}
|
|
1174
|
+
try {
|
|
1175
|
+
this.socket.send(e);
|
|
1176
|
+
} catch (e) {
|
|
1177
|
+
n(e);
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
n();
|
|
1181
|
+
}
|
|
1182
|
+
}, Fe = class extends me {
|
|
1183
|
+
onStartElement(e, t) {
|
|
1184
|
+
let n = new ne.default(e, t), { cursor: r } = this;
|
|
1185
|
+
r && r.append(n), this.cursor = n;
|
|
1186
|
+
}
|
|
1187
|
+
onEndElement(e) {
|
|
1188
|
+
let { cursor: t } = this;
|
|
1189
|
+
if (e !== t.name) {
|
|
1190
|
+
this.emit("error", new pe(`${t.name} must be closed.`));
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
if (t.parent) {
|
|
1194
|
+
this.cursor = t.parent;
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
t.is("open", "urn:ietf:params:xml:ns:xmpp-framing") ? this.emit("start", t) : t.is("close", "urn:ietf:params:xml:ns:xmpp-framing") ? this.emit("end", t) : this.emit("element", t), this.cursor = null;
|
|
1198
|
+
}
|
|
1199
|
+
}, Ie = "urn:ietf:params:xml:ns:xmpp-framing", Le = class extends Oe {
|
|
1200
|
+
send(e, ...t) {
|
|
1201
|
+
return e.attrs.xmlns ??= this.NS, super.send(e, ...t);
|
|
1202
|
+
}
|
|
1203
|
+
async sendMany(e) {
|
|
1204
|
+
for (let t of e) t.attrs.xmlns ??= this.NS, t.parent = this.root, this.socket.write(t.toString()), this.emit("send", t);
|
|
1205
|
+
}
|
|
1206
|
+
footerElement() {
|
|
1207
|
+
return new N.Element("close", { xmlns: Ie });
|
|
1208
|
+
}
|
|
1209
|
+
headerElement() {
|
|
1210
|
+
let e = super.headerElement();
|
|
1211
|
+
return e.name = "open", e.attrs.xmlns = Ie, e;
|
|
1212
|
+
}
|
|
1213
|
+
socketParameters(e) {
|
|
1214
|
+
return /^wss?:\/\//.test(e) ? e : void 0;
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
Le.prototype.Socket = Pe, Le.prototype.NS = "jabber:client", Le.prototype.Parser = Fe;
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region node_modules/@xmpp/websocket/index.js
|
|
1220
|
+
function Re({ entity: e }) {
|
|
1221
|
+
e.transports.push(Le);
|
|
1222
|
+
}
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region __vite-browser-external
|
|
1225
|
+
var ze = /* @__PURE__ */ y(((e, t) => {
|
|
1226
|
+
t.exports = {};
|
|
1227
|
+
})), Be = /* @__PURE__ */ y(((e, t) => {
|
|
1228
|
+
t.exports = n;
|
|
1229
|
+
function n(e) {
|
|
1230
|
+
if (!Array.isArray(e)) throw TypeError("Middleware stack must be an array!");
|
|
1231
|
+
for (let t of e) if (typeof t != "function") throw TypeError("Middleware must be composed of functions!");
|
|
1232
|
+
return function(t, n) {
|
|
1233
|
+
let r = -1;
|
|
1234
|
+
return i(0);
|
|
1235
|
+
function i(a) {
|
|
1236
|
+
if (a <= r) return Promise.reject(/* @__PURE__ */ Error("next() called multiple times"));
|
|
1237
|
+
r = a;
|
|
1238
|
+
let o = e[a];
|
|
1239
|
+
if (a === e.length && (o = n), !o) return Promise.resolve();
|
|
1240
|
+
try {
|
|
1241
|
+
return Promise.resolve(o(t, i.bind(null, a + 1)));
|
|
1242
|
+
} catch (e) {
|
|
1243
|
+
return Promise.reject(e);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
})), I = /* @__PURE__ */ x(ze(), 1), Ve = /* @__PURE__ */ x(Be(), 1), He = class {
|
|
1249
|
+
constructor(e, t) {
|
|
1250
|
+
this.stanza = t, this.entity = e;
|
|
1251
|
+
let { name: n, attrs: r } = t, { type: i, id: a } = r;
|
|
1252
|
+
this.name = n, this.id = a || "", this.type = n === "message" ? i || "normal" : n === "presence" ? i || "available" : i || "", this.from = null, this.to = null, this.local = "", this.domain = "", this.resource = "";
|
|
1253
|
+
}
|
|
1254
|
+
}, Ue = class extends He {
|
|
1255
|
+
constructor(e, t) {
|
|
1256
|
+
super(e, t);
|
|
1257
|
+
let { jid: n } = e, { domain: r } = e.options ?? {}, i = t.attrs.to || n?.toString(), a = t.attrs.from || r;
|
|
1258
|
+
i && (this.to = new F(i)), a && (this.from = new F(a), this.local = this.from.local, this.domain = this.from.domain, this.resource = this.from.resource);
|
|
1259
|
+
}
|
|
1260
|
+
}, We = class extends He {
|
|
1261
|
+
constructor(e, t) {
|
|
1262
|
+
super(e, t);
|
|
1263
|
+
let { jid: n } = e, { domain: r } = e.options ?? {}, i = t.attrs.from || n?.toString(), a = t.attrs.to || r;
|
|
1264
|
+
i && (this.from = new F(i)), a && (this.to = new F(a), this.local = this.to.local, this.domain = this.to.domain, this.resource = this.to.resource);
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region node_modules/@xmpp/middleware/index.js
|
|
1269
|
+
function Ge(e, t, n) {
|
|
1270
|
+
return (r) => {
|
|
1271
|
+
let i = new n(e, r);
|
|
1272
|
+
return (0, Ve.default)(t)(i);
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
function Ke(e) {
|
|
1276
|
+
return (t, n) => {
|
|
1277
|
+
n().then((t) => t && e.send(t)).catch((t) => e.emit("error", t));
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function qe({ entity: e }) {
|
|
1281
|
+
let t = [Ke(e)], n = [], r = Ge(e, t, Ue), i = Ge(e, n, We);
|
|
1282
|
+
return e.on("element", r), e.on("send", i), {
|
|
1283
|
+
use(e) {
|
|
1284
|
+
return t.push(e), e;
|
|
1285
|
+
},
|
|
1286
|
+
filter(e) {
|
|
1287
|
+
return n.push(e), e;
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
//#endregion
|
|
1292
|
+
//#region node_modules/@xmpp/stream-features/index.js
|
|
1293
|
+
function Je({ middleware: e }) {
|
|
1294
|
+
function t(t, n, r) {
|
|
1295
|
+
return e.use((e, i) => {
|
|
1296
|
+
let { stanza: a } = e;
|
|
1297
|
+
if (!a.is("features", "http://etherx.jabber.org/streams")) return i();
|
|
1298
|
+
let o = a.getChild(t, n);
|
|
1299
|
+
return o ? r(e, i, o) : i();
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
return { use: t };
|
|
1303
|
+
}
|
|
1304
|
+
//#endregion
|
|
1305
|
+
//#region node_modules/@xmpp/id/index.js
|
|
1306
|
+
function Ye() {
|
|
1307
|
+
let e;
|
|
1308
|
+
for (; !e;) e = Math.random().toString(36).slice(2, 12);
|
|
1309
|
+
return e;
|
|
1310
|
+
}
|
|
1311
|
+
//#endregion
|
|
1312
|
+
//#region node_modules/@xmpp/middleware/lib/StanzaError.js
|
|
1313
|
+
var Xe = class extends xe {
|
|
1314
|
+
constructor(e, t, n, r) {
|
|
1315
|
+
super(e, t, n), this.type = r, this.name = "StanzaError";
|
|
1316
|
+
}
|
|
1317
|
+
static fromElement(e) {
|
|
1318
|
+
let t = super.fromElement(e);
|
|
1319
|
+
return t.type = e.attrs.type, t;
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
//#endregion
|
|
1323
|
+
//#region node_modules/@xmpp/iq/caller.js
|
|
1324
|
+
function Ze({ name: e, type: t }) {
|
|
1325
|
+
return !(e !== "iq" || t !== "error" && t !== "result");
|
|
1326
|
+
}
|
|
1327
|
+
var Qe = class {
|
|
1328
|
+
constructor({ entity: e, middleware: t }) {
|
|
1329
|
+
this.handlers = /* @__PURE__ */ new Map(), this.entity = e, this.middleware = t;
|
|
1330
|
+
}
|
|
1331
|
+
start() {
|
|
1332
|
+
this.middleware.use(this._route.bind(this));
|
|
1333
|
+
}
|
|
1334
|
+
_route({ type: e, name: t, id: n, stanza: r }, i) {
|
|
1335
|
+
if (!Ze({
|
|
1336
|
+
name: t,
|
|
1337
|
+
type: e
|
|
1338
|
+
})) return i();
|
|
1339
|
+
let a = this.handlers.get(n);
|
|
1340
|
+
if (!a) return i();
|
|
1341
|
+
e === "error" ? a.reject(Xe.fromElement(r.getChild("error"))) : a.resolve(r), this.handlers.delete(n);
|
|
1342
|
+
}
|
|
1343
|
+
async request(e, t = 3e4) {
|
|
1344
|
+
e.attrs.id || (e.attrs.id = Ye());
|
|
1345
|
+
let n = new ue();
|
|
1346
|
+
this.handlers.set(e.attrs.id, n);
|
|
1347
|
+
try {
|
|
1348
|
+
await this.entity.send(e), await se(n.promise, t);
|
|
1349
|
+
} catch (t) {
|
|
1350
|
+
throw this.handlers.delete(e.attrs.id), t;
|
|
1351
|
+
}
|
|
1352
|
+
return n.promise;
|
|
1353
|
+
}
|
|
1354
|
+
_childRequest(e, t, n, ...r) {
|
|
1355
|
+
let { name: i, attrs: { xmlns: a } } = t;
|
|
1356
|
+
return this.request(N("iq", {
|
|
1357
|
+
type: e,
|
|
1358
|
+
to: n
|
|
1359
|
+
}, t), ...r).then((e) => e.getChild(i, a));
|
|
1360
|
+
}
|
|
1361
|
+
async get(...e) {
|
|
1362
|
+
return this._childRequest("get", ...e);
|
|
1363
|
+
}
|
|
1364
|
+
async set(...e) {
|
|
1365
|
+
return this._childRequest("set", ...e);
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
function $e(...e) {
|
|
1369
|
+
let t = new Qe(...e);
|
|
1370
|
+
return t.start(), t;
|
|
1371
|
+
}
|
|
1372
|
+
//#endregion
|
|
1373
|
+
//#region node_modules/@xmpp/iq/callee.js
|
|
1374
|
+
var et = "urn:ietf:params:xml:ns:xmpp-stanzas";
|
|
1375
|
+
function tt({ name: e, type: t }) {
|
|
1376
|
+
return e === "iq" && t !== "error" && t !== "result";
|
|
1377
|
+
}
|
|
1378
|
+
function nt({ type: e }, t, n) {
|
|
1379
|
+
return !(e !== "get" && e !== "set" || t.length !== 1 || !n);
|
|
1380
|
+
}
|
|
1381
|
+
function rt({ stanza: e }) {
|
|
1382
|
+
return N("iq", {
|
|
1383
|
+
to: e.attrs.from,
|
|
1384
|
+
from: e.attrs.to,
|
|
1385
|
+
id: e.attrs.id
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
function it(e, t) {
|
|
1389
|
+
let n = rt(e);
|
|
1390
|
+
return n.attrs.type = "result", t && n.append(t), n;
|
|
1391
|
+
}
|
|
1392
|
+
function at(e, t, n) {
|
|
1393
|
+
let r = rt(e);
|
|
1394
|
+
return r.attrs.type = "error", n && r.append(n), r.append(t), r;
|
|
1395
|
+
}
|
|
1396
|
+
function ot(e, t) {
|
|
1397
|
+
return N("error", { type: e }, N(t, et));
|
|
1398
|
+
}
|
|
1399
|
+
function st(e) {
|
|
1400
|
+
return async function(t, n) {
|
|
1401
|
+
if (!tt(t)) return n();
|
|
1402
|
+
let { stanza: r } = t, i = r.getChildElements(), [a] = i;
|
|
1403
|
+
if (!nt(t, i, a)) return at(t, ot("modify", "bad-request"), a);
|
|
1404
|
+
t.element = a;
|
|
1405
|
+
let o;
|
|
1406
|
+
try {
|
|
1407
|
+
o = await n();
|
|
1408
|
+
} catch (t) {
|
|
1409
|
+
e.emit("error", t), o = ot("cancel", "internal-server-error");
|
|
1410
|
+
}
|
|
1411
|
+
return o ||= ot("cancel", "service-unavailable"), o instanceof N.Element && o.is("error") ? at(t, o, a) : it(t, o instanceof N.Element ? o : void 0);
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
function ct(e, t, n, r) {
|
|
1415
|
+
return (i, a) => i.type !== e | !i.element || !i.element.is(n, t) ? a() : r(i, a);
|
|
1416
|
+
}
|
|
1417
|
+
function lt({ middleware: e, entity: t }) {
|
|
1418
|
+
return e.use(st(t)), {
|
|
1419
|
+
get(t, n, r) {
|
|
1420
|
+
e.use(ct("get", t, n, r));
|
|
1421
|
+
},
|
|
1422
|
+
set(t, n, r) {
|
|
1423
|
+
e.use(ct("set", t, n, r));
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
//#endregion
|
|
1428
|
+
//#region node_modules/@xmpp/resolve/lib/dns.js
|
|
1429
|
+
var ut = ["ENOTFOUND", "ENODATA"];
|
|
1430
|
+
function dt(e, t = {}) {
|
|
1431
|
+
return t.all = !0, new Promise((n, r) => {
|
|
1432
|
+
I.default.lookup(e, t, (e, t) => {
|
|
1433
|
+
if (e) return r(e);
|
|
1434
|
+
let i = [];
|
|
1435
|
+
for (let { family: e, address: n } of t) {
|
|
1436
|
+
let t = `://${e === 4 ? n : "[" + n + "]"}:`;
|
|
1437
|
+
i.push({
|
|
1438
|
+
family: e,
|
|
1439
|
+
address: n,
|
|
1440
|
+
uri: "xmpps" + t + "5223"
|
|
1441
|
+
}, {
|
|
1442
|
+
family: e,
|
|
1443
|
+
address: n,
|
|
1444
|
+
uri: "xmpp" + t + "5222"
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
n(i);
|
|
1448
|
+
});
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
function ft(e, { service: t, protocol: n }) {
|
|
1452
|
+
return new Promise((r, i) => {
|
|
1453
|
+
I.default.resolveSrv(`_${t}._${n}.${e}`, (e, a) => {
|
|
1454
|
+
e && ut.includes(e.code) ? r([]) : e ? i(e) : r(a.map((e) => Object.assign(e, {
|
|
1455
|
+
service: t,
|
|
1456
|
+
protocol: n
|
|
1457
|
+
})));
|
|
1458
|
+
});
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
function pt(e) {
|
|
1462
|
+
return e.toSorted((e, t) => {
|
|
1463
|
+
let n = e.priority - t.priority;
|
|
1464
|
+
if (n !== 0) return n;
|
|
1465
|
+
let r = t.weight - e.weight;
|
|
1466
|
+
return r === 0 ? 0 : r;
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
function mt(e, t) {
|
|
1470
|
+
let n = [];
|
|
1471
|
+
return Promise.all(e.map(async (e) => {
|
|
1472
|
+
let r = await dt(e.name, t);
|
|
1473
|
+
for (let t of r) {
|
|
1474
|
+
let { port: r, service: i } = e, a = t.address;
|
|
1475
|
+
n.push({
|
|
1476
|
+
...t,
|
|
1477
|
+
...e,
|
|
1478
|
+
uri: `${i.split("-")[0]}://${t.family === 6 ? "[" + a + "]" : a}:${r}`
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
})).then(() => n);
|
|
1482
|
+
}
|
|
1483
|
+
function ht(e, t = {}) {
|
|
1484
|
+
t.srv ||= [
|
|
1485
|
+
{
|
|
1486
|
+
service: "xmpps-client",
|
|
1487
|
+
protocol: "tcp"
|
|
1488
|
+
},
|
|
1489
|
+
{
|
|
1490
|
+
service: "xmpp-client",
|
|
1491
|
+
protocol: "tcp"
|
|
1492
|
+
},
|
|
1493
|
+
{
|
|
1494
|
+
service: "xmpps-server",
|
|
1495
|
+
protocol: "tcp"
|
|
1496
|
+
},
|
|
1497
|
+
{
|
|
1498
|
+
service: "xmpp-server",
|
|
1499
|
+
protocol: "tcp"
|
|
1500
|
+
},
|
|
1501
|
+
{
|
|
1502
|
+
service: "stun",
|
|
1503
|
+
protocol: "tcp"
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
service: "stun",
|
|
1507
|
+
protocol: "udp"
|
|
1508
|
+
},
|
|
1509
|
+
{
|
|
1510
|
+
service: "stuns ",
|
|
1511
|
+
protcol: "tcp"
|
|
1512
|
+
},
|
|
1513
|
+
{
|
|
1514
|
+
service: "turn",
|
|
1515
|
+
protocol: "tcp"
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
service: "turn",
|
|
1519
|
+
protocol: "udp"
|
|
1520
|
+
},
|
|
1521
|
+
{
|
|
1522
|
+
service: "turns",
|
|
1523
|
+
protcol: "tcp"
|
|
1524
|
+
}
|
|
1525
|
+
];
|
|
1526
|
+
let n = { options: t };
|
|
1527
|
+
return dt(e, t).then((r) => Promise.all(t.srv.map((r) => ft(e, {
|
|
1528
|
+
...r,
|
|
1529
|
+
family: n
|
|
1530
|
+
}).then((e) => mt(e, t)))).then((e) => [...pt(e.flat()), ...r]));
|
|
1531
|
+
}
|
|
1532
|
+
//#endregion
|
|
1533
|
+
//#region node_modules/@xmpp/xml/lib/parse.js
|
|
1534
|
+
function gt(e) {
|
|
1535
|
+
let t = new me(), n = null, r = null;
|
|
1536
|
+
if (t.on("start", (e) => {
|
|
1537
|
+
n = e;
|
|
1538
|
+
}), t.on("element", (e) => {
|
|
1539
|
+
n.append(e);
|
|
1540
|
+
}), t.on("error", (e) => {
|
|
1541
|
+
r = e;
|
|
1542
|
+
}), t.write(e), t.end(), r) throw r;
|
|
1543
|
+
return n;
|
|
1544
|
+
}
|
|
1545
|
+
//#endregion
|
|
1546
|
+
//#region node_modules/@xmpp/resolve/lib/alt-connections.js
|
|
1547
|
+
function _t(e) {
|
|
1548
|
+
return e.startsWith("https") || e.startsWith("wss");
|
|
1549
|
+
}
|
|
1550
|
+
function vt(e, t) {
|
|
1551
|
+
let n;
|
|
1552
|
+
if (n = _t(e.uri) && !_t(t.uri) ? -1 : !_t(e.uri) && _t(t.uri) ? 1 : 0, n !== 0) return n;
|
|
1553
|
+
let r;
|
|
1554
|
+
return r = e.method === t.method ? 0 : e.method === "websocket" ? -1 : t.method === "websocket" ? 1 : e.method === "xbosh" ? -1 : t.method === "xbosh" ? 1 : e.method === "httppoll" ? -1 : +(t.method === "httppoll"), r === 0 ? 0 : r;
|
|
1555
|
+
}
|
|
1556
|
+
//#endregion
|
|
1557
|
+
//#region node_modules/@xmpp/resolve/lib/http.js
|
|
1558
|
+
function yt(e) {
|
|
1559
|
+
return fetch(`https://${e}/.well-known/host-meta`).then((e) => e.text()).then((e) => gt(e).getChildren("Link").filter((e) => [
|
|
1560
|
+
"urn:xmpp:alt-connections:websocket",
|
|
1561
|
+
"urn:xmpp:alt-connections:httppoll",
|
|
1562
|
+
"urn:xmpp:alt-connections:xbosh"
|
|
1563
|
+
].includes(e.attrs.rel)).map(({ attrs: e }) => ({
|
|
1564
|
+
rel: e.rel,
|
|
1565
|
+
href: e.href,
|
|
1566
|
+
method: e.rel.split(":").pop(),
|
|
1567
|
+
uri: e.href
|
|
1568
|
+
})).toSorted(vt)).catch(() => []);
|
|
1569
|
+
}
|
|
1570
|
+
//#endregion
|
|
1571
|
+
//#region node_modules/@xmpp/resolve/resolve.js
|
|
1572
|
+
function bt(...e) {
|
|
1573
|
+
return Promise.all([ht ? ht(...e) : Promise.resolve([]), yt(...e)]).then(([e, t]) => [...e, ...t]);
|
|
1574
|
+
}
|
|
1575
|
+
//#endregion
|
|
1576
|
+
//#region node_modules/@xmpp/resolve/index.js
|
|
1577
|
+
async function xt(e) {
|
|
1578
|
+
let t = await bt(e, { srv: [{
|
|
1579
|
+
service: "xmpps-client",
|
|
1580
|
+
protocol: "tcp"
|
|
1581
|
+
}, {
|
|
1582
|
+
service: "xmpp-client",
|
|
1583
|
+
protocol: "tcp"
|
|
1584
|
+
}] });
|
|
1585
|
+
return [...new Set(t.map((e) => e.uri))];
|
|
1586
|
+
}
|
|
1587
|
+
function St(e, t) {
|
|
1588
|
+
return t.filter((t) => e._findTransport(t));
|
|
1589
|
+
}
|
|
1590
|
+
async function Ct(e, t) {
|
|
1591
|
+
if (t.length === 0) throw Error("Couldn't connect");
|
|
1592
|
+
let n = t.shift(), r = e._findTransport(n);
|
|
1593
|
+
if (!r) return Ct(e, t);
|
|
1594
|
+
e._status("connecting", n);
|
|
1595
|
+
let i = r.prototype.socketParameters(n), a = new r.prototype.Socket();
|
|
1596
|
+
try {
|
|
1597
|
+
a.connect(i), await M(a, "connect");
|
|
1598
|
+
} catch {
|
|
1599
|
+
return Ct(e, t);
|
|
1600
|
+
}
|
|
1601
|
+
e._attachSocket(a), a.emit("connect"), e.Transport = r, e.Socket = r.prototype.Socket, e.Parser = r.prototype.Parser;
|
|
1602
|
+
}
|
|
1603
|
+
function wt({ entity: e }) {
|
|
1604
|
+
let t = e.connect;
|
|
1605
|
+
e.connect = async function(n) {
|
|
1606
|
+
if (!n || /:\/\//.test(n)) return t.call(this, n);
|
|
1607
|
+
let r = St(e, await xt(n));
|
|
1608
|
+
if (r.length === 0) throw Error("No compatible transport found.");
|
|
1609
|
+
try {
|
|
1610
|
+
await Ct(e, r);
|
|
1611
|
+
} catch (t) {
|
|
1612
|
+
throw await e.disconnect(), e._status("disconnect"), t;
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
//#endregion
|
|
1617
|
+
//#region node_modules/@xmpp/base64/index.js
|
|
1618
|
+
function Tt(e) {
|
|
1619
|
+
return globalThis.btoa(e);
|
|
1620
|
+
}
|
|
1621
|
+
function Et(e) {
|
|
1622
|
+
return globalThis.atob(e);
|
|
1623
|
+
}
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region node_modules/@xmpp/sasl/lib/SASLError.js
|
|
1626
|
+
var L = class extends xe {
|
|
1627
|
+
constructor(...e) {
|
|
1628
|
+
super(...e), this.name = "SASLError";
|
|
1629
|
+
}
|
|
1630
|
+
}, R = "urn:ietf:params:xml:ns:xmpp-sasl";
|
|
1631
|
+
function Dt(e, t, n) {
|
|
1632
|
+
let r = new Set(e.getChildren("mechanism", t).map((e) => e.text()));
|
|
1633
|
+
return n._mechs.map(({ name: e }) => e).filter((e) => r.has(e));
|
|
1634
|
+
}
|
|
1635
|
+
async function Ot({ saslFactory: e, entity: t, mechanism: n, credentials: r }) {
|
|
1636
|
+
let i = e.create([n]);
|
|
1637
|
+
if (!i) throw Error(`SASL: Mechanism ${n} not found.`);
|
|
1638
|
+
let { domain: a } = t.options, o = {
|
|
1639
|
+
username: null,
|
|
1640
|
+
password: null,
|
|
1641
|
+
server: a,
|
|
1642
|
+
host: a,
|
|
1643
|
+
realm: a,
|
|
1644
|
+
serviceType: "xmpp",
|
|
1645
|
+
serviceName: a,
|
|
1646
|
+
...r
|
|
1647
|
+
};
|
|
1648
|
+
await de(t, i.clientFirst && N("auth", {
|
|
1649
|
+
xmlns: R,
|
|
1650
|
+
mechanism: i.name
|
|
1651
|
+
}, Tt(await i.response(o))), async (e, n) => {
|
|
1652
|
+
if (e.getNS() === R) {
|
|
1653
|
+
if (e.name === "challenge") {
|
|
1654
|
+
await i.challenge(Et(e.text()));
|
|
1655
|
+
let n = await i.response(o);
|
|
1656
|
+
await t.send(N("response", {
|
|
1657
|
+
xmlns: R,
|
|
1658
|
+
mechanism: i.name
|
|
1659
|
+
}, typeof n == "string" ? Tt(n) : ""));
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
if (e.name === "failure") throw L.fromElement(e);
|
|
1663
|
+
if (e.name === "success") return n();
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
function kt({ streamFeatures: e, saslFactory: t }, n) {
|
|
1668
|
+
e.use("mechanisms", R, async ({ entity: e }, r, i) => {
|
|
1669
|
+
let a = Dt(i, R, t);
|
|
1670
|
+
if (a.length === 0) throw new L("SASL: No compatible mechanism available.");
|
|
1671
|
+
async function o(n, r) {
|
|
1672
|
+
await Ot({
|
|
1673
|
+
saslFactory: t,
|
|
1674
|
+
entity: e,
|
|
1675
|
+
mechanism: r,
|
|
1676
|
+
credentials: n
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
await n(o, a, null, e), await e.restart();
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
//#endregion
|
|
1683
|
+
//#region node_modules/@xmpp/sasl2/index.js
|
|
1684
|
+
var At = "urn:xmpp:sasl:2";
|
|
1685
|
+
async function jt({ saslFactory: e, entity: t, mechanism: n, credentials: r, userAgent: i, streamFeatures: a, features: o }) {
|
|
1686
|
+
let s = e.create([n]);
|
|
1687
|
+
if (!s) throw Error(`SASL: Mechanism ${n} not found.`);
|
|
1688
|
+
let { domain: c } = t.options, l = {
|
|
1689
|
+
username: null,
|
|
1690
|
+
password: null,
|
|
1691
|
+
server: c,
|
|
1692
|
+
host: c,
|
|
1693
|
+
realm: c,
|
|
1694
|
+
serviceType: "xmpp",
|
|
1695
|
+
serviceName: c,
|
|
1696
|
+
...r
|
|
1697
|
+
};
|
|
1698
|
+
await de(t, N("authenticate", {
|
|
1699
|
+
xmlns: At,
|
|
1700
|
+
mechanism: s.name
|
|
1701
|
+
}, [
|
|
1702
|
+
s.clientFirst && N("initial-response", {}, Tt(await s.response(l))),
|
|
1703
|
+
i,
|
|
1704
|
+
...a
|
|
1705
|
+
]), async (e, n) => {
|
|
1706
|
+
if (e.getNS() === At) {
|
|
1707
|
+
if (e.name === "challenge") {
|
|
1708
|
+
await s.challenge(Et(e.text()));
|
|
1709
|
+
let n = await s.response(l);
|
|
1710
|
+
await t.send(N("response", {
|
|
1711
|
+
xmlns: At,
|
|
1712
|
+
mechanism: s.name
|
|
1713
|
+
}, typeof n == "string" ? Tt(n) : ""));
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
if (e.name === "failure") throw L.fromElement(e);
|
|
1717
|
+
if (e.name === "continue") throw Error("SASL continue is not supported yet");
|
|
1718
|
+
if (e.name === "success") {
|
|
1719
|
+
let r = e.getChild("additional-data")?.text();
|
|
1720
|
+
r && s.final && await s.final(Et(r));
|
|
1721
|
+
let i = e.getChildText("authorization-identifier");
|
|
1722
|
+
i && t._jid(i);
|
|
1723
|
+
for (let t of e.getChildElements()) o.get(t.getNS())?.[1]?.(t);
|
|
1724
|
+
return n();
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
function Mt({ streamFeatures: e, saslFactory: t }, n) {
|
|
1730
|
+
let r = /* @__PURE__ */ new Map(), i;
|
|
1731
|
+
return e.use("authentication", At, async ({ entity: e }, a, o) => {
|
|
1732
|
+
let s = Dt(o, At, t), c = await Nt({
|
|
1733
|
+
element: o,
|
|
1734
|
+
features: r
|
|
1735
|
+
}), l = !!i?.mechanism;
|
|
1736
|
+
if (s.length === 0 && !l) throw new L("SASL: No compatible mechanism available.");
|
|
1737
|
+
await n(u, s, l ? i : null, e);
|
|
1738
|
+
async function u(n, a, o) {
|
|
1739
|
+
await i.auth({
|
|
1740
|
+
authenticate: jt,
|
|
1741
|
+
entity: e,
|
|
1742
|
+
userAgent: o,
|
|
1743
|
+
streamFeatures: c,
|
|
1744
|
+
features: r,
|
|
1745
|
+
credentials: n
|
|
1746
|
+
}) || await jt({
|
|
1747
|
+
entity: e,
|
|
1748
|
+
userAgent: o,
|
|
1749
|
+
streamFeatures: c,
|
|
1750
|
+
features: r,
|
|
1751
|
+
saslFactory: t,
|
|
1752
|
+
mechanism: a,
|
|
1753
|
+
credentials: n
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
}), {
|
|
1757
|
+
use(e, t, n) {
|
|
1758
|
+
r.set(e, [t, n]);
|
|
1759
|
+
},
|
|
1760
|
+
setup({ fast: e }) {
|
|
1761
|
+
i = e;
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
async function Nt({ element: e, features: t }) {
|
|
1766
|
+
let n = [], r = e.getChild("inline");
|
|
1767
|
+
if (!r) return n;
|
|
1768
|
+
for (let e of r.getChildElements()) {
|
|
1769
|
+
let r = e.getNS(), i = t.get(r);
|
|
1770
|
+
i && n.push(i[0](e));
|
|
1771
|
+
}
|
|
1772
|
+
return Promise.all(n);
|
|
1773
|
+
}
|
|
1774
|
+
//#endregion
|
|
1775
|
+
//#region node_modules/@xmpp/resource-binding/index.js
|
|
1776
|
+
var Pt = "urn:ietf:params:xml:ns:xmpp-bind";
|
|
1777
|
+
function Ft(e) {
|
|
1778
|
+
return N("bind", { xmlns: Pt }, e && N("resource", {}, e));
|
|
1779
|
+
}
|
|
1780
|
+
async function It(e, t, n) {
|
|
1781
|
+
let r = (await t.set(Ft(n))).getChildText("jid");
|
|
1782
|
+
return e._jid(r), e._ready(!1), r;
|
|
1783
|
+
}
|
|
1784
|
+
function Lt({ iqCaller: e }, t) {
|
|
1785
|
+
return async ({ entity: n }, r) => {
|
|
1786
|
+
t = typeof t == "function" ? await t() : t, await It(n, e, t), r();
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
function Rt({ streamFeatures: e, iqCaller: t }, n) {
|
|
1790
|
+
e.use("bind", Pt, Lt({ iqCaller: t }, n));
|
|
1791
|
+
}
|
|
1792
|
+
//#endregion
|
|
1793
|
+
//#region node_modules/@xmpp/time/index.js
|
|
1794
|
+
function zt(e = /* @__PURE__ */ new Date()) {
|
|
1795
|
+
return typeof e == "string" && (e = new Date(e)), new Date(e).toISOString().split(".")[0] + "Z";
|
|
1796
|
+
}
|
|
1797
|
+
//#endregion
|
|
1798
|
+
//#region node_modules/@xmpp/stream-management/bind2.js
|
|
1799
|
+
function Bt({ bind2: e, sm: t, failed: n, enabled: r }) {
|
|
1800
|
+
e.use(z, (e) => Gt({ sm: t }), async (e) => {
|
|
1801
|
+
e.is("enabled") ? r(e.attrs) : e.is("failed") && n();
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
//#endregion
|
|
1805
|
+
//#region node_modules/@xmpp/stream-management/sasl2.js
|
|
1806
|
+
function Vt({ sasl2: e, sm: t, failed: n, resumed: r }) {
|
|
1807
|
+
e.use(z, (e) => {
|
|
1808
|
+
if (e.is("sm") && t.id) return Kt({ sm: t });
|
|
1809
|
+
}, (e) => {
|
|
1810
|
+
e.is("resumed") ? r(e) : e.is("failed") && n();
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
//#endregion
|
|
1814
|
+
//#region node_modules/@xmpp/stream-management/stream-feature.js
|
|
1815
|
+
function Ht({ streamFeatures: e, sm: t, entity: n, resumed: r, failed: i, enabled: a }) {
|
|
1816
|
+
e.use("sm", z, async (e, o) => {
|
|
1817
|
+
if (t.id) try {
|
|
1818
|
+
await r(await Wt(n, t));
|
|
1819
|
+
return;
|
|
1820
|
+
} catch {
|
|
1821
|
+
i();
|
|
1822
|
+
}
|
|
1823
|
+
await o();
|
|
1824
|
+
let s = Ut(n, t);
|
|
1825
|
+
if (t.outbound_q.length > 0) throw Error("Stream Management assertion failure, queue should be empty after enable");
|
|
1826
|
+
t.outbound = 0;
|
|
1827
|
+
try {
|
|
1828
|
+
a((await s).attrs);
|
|
1829
|
+
} catch {
|
|
1830
|
+
t.enabled = !1, t.enableSent = !1;
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
function Ut(e, t) {
|
|
1835
|
+
return de(e, Gt({ sm: t }), (e, t) => {
|
|
1836
|
+
if (e.is("enabled", "urn:xmpp:sm:3")) return t(e);
|
|
1837
|
+
if (e.is("failed", "urn:xmpp:sm:3")) throw xe.fromElement(e);
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
async function Wt(e, t) {
|
|
1841
|
+
return de(e, Kt({ sm: t }), (e, t) => {
|
|
1842
|
+
if (e.is("resumed", "urn:xmpp:sm:3")) return t(e);
|
|
1843
|
+
if (e.is("failed", "urn:xmpp:sm:3")) throw xe.fromElement(e);
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
//#endregion
|
|
1847
|
+
//#region node_modules/@xmpp/stream-management/index.js
|
|
1848
|
+
var z = "urn:xmpp:sm:3";
|
|
1849
|
+
function Gt({ sm: e }) {
|
|
1850
|
+
return N("enable", {
|
|
1851
|
+
xmlns: z,
|
|
1852
|
+
max: e.preferredMaximum,
|
|
1853
|
+
resume: "true"
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
function Kt({ sm: e }) {
|
|
1857
|
+
return N("resume", {
|
|
1858
|
+
xmlns: z,
|
|
1859
|
+
h: e.inbound,
|
|
1860
|
+
previd: e.id
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
function qt({ streamFeatures: e, entity: t, middleware: n, bind2: r, sasl2: i }) {
|
|
1864
|
+
let a = null, o = null, s = null, c = new j.EventEmitter();
|
|
1865
|
+
Object.assign(c, {
|
|
1866
|
+
preferredMaximum: null,
|
|
1867
|
+
enabled: !1,
|
|
1868
|
+
enableSent: !1,
|
|
1869
|
+
id: "",
|
|
1870
|
+
outbound_q: [],
|
|
1871
|
+
outbound: 0,
|
|
1872
|
+
inbound: 0,
|
|
1873
|
+
max: null,
|
|
1874
|
+
timeout: 6e4,
|
|
1875
|
+
requestAckInterval: 3e4,
|
|
1876
|
+
requestAckDebounce: 250
|
|
1877
|
+
});
|
|
1878
|
+
async function l() {
|
|
1879
|
+
try {
|
|
1880
|
+
await t.send(N("a", {
|
|
1881
|
+
xmlns: z,
|
|
1882
|
+
h: c.inbound
|
|
1883
|
+
}));
|
|
1884
|
+
} catch {}
|
|
1885
|
+
}
|
|
1886
|
+
t.on("disconnect", () => {
|
|
1887
|
+
clearTimeout(a), clearTimeout(o), clearTimeout(s), c.enabled = !1, c.enableSent = !1;
|
|
1888
|
+
}), t.hook("close", async () => {
|
|
1889
|
+
c.enabled && await l();
|
|
1890
|
+
});
|
|
1891
|
+
async function u(e) {
|
|
1892
|
+
c.enabled = !0, f(+e.attrs.h);
|
|
1893
|
+
let n = c.outbound_q;
|
|
1894
|
+
c.outbound_q = [], await t.sendMany(n.map((e) => Jt({
|
|
1895
|
+
entity: t,
|
|
1896
|
+
item: e
|
|
1897
|
+
}))), c.emit("resumed"), t._ready(!0), h();
|
|
1898
|
+
}
|
|
1899
|
+
function d() {
|
|
1900
|
+
c.enabled = !1, c.enableSent = !1, c.id = "", p();
|
|
1901
|
+
}
|
|
1902
|
+
function f(e) {
|
|
1903
|
+
let t = c.outbound;
|
|
1904
|
+
for (let n = 0; n < +e - t; n++) {
|
|
1905
|
+
let e = c.outbound_q.shift();
|
|
1906
|
+
c.outbound++, c.emit("ack", e.stanza);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
function p() {
|
|
1910
|
+
let e;
|
|
1911
|
+
for (; e = c.outbound_q.shift();) c.emit("fail", e.stanza);
|
|
1912
|
+
c.outbound = 0;
|
|
1913
|
+
}
|
|
1914
|
+
function m({ id: e, max: t }) {
|
|
1915
|
+
c.enabled = !0, c.id = e, c.max = t, c.inbound = 0, h();
|
|
1916
|
+
}
|
|
1917
|
+
t.on("offline", () => {
|
|
1918
|
+
p(), c.inbound = 0, c.enabled = !1, c.enableSent = !1, c.id = "";
|
|
1919
|
+
}), n.use(async (e, t) => {
|
|
1920
|
+
let { stanza: n } = e;
|
|
1921
|
+
return clearTimeout(a), a = null, [
|
|
1922
|
+
"presence",
|
|
1923
|
+
"message",
|
|
1924
|
+
"iq"
|
|
1925
|
+
].includes(n.name) ? c.inbound += 1 : n.is("r", "urn:xmpp:sm:3") ? await l() : n.is("a", "urn:xmpp:sm:3") && f(+n.attrs.h), h(), t();
|
|
1926
|
+
}), r && Bt({
|
|
1927
|
+
bind2: r,
|
|
1928
|
+
sm: c,
|
|
1929
|
+
failed: d,
|
|
1930
|
+
enabled: m
|
|
1931
|
+
}), i && Vt({
|
|
1932
|
+
sasl2: i,
|
|
1933
|
+
sm: c,
|
|
1934
|
+
failed: d,
|
|
1935
|
+
resumed: u
|
|
1936
|
+
});
|
|
1937
|
+
function h(e = c.requestAckInterval) {
|
|
1938
|
+
clearTimeout(o), c.enabled && e && (o = setTimeout(g, e));
|
|
1939
|
+
}
|
|
1940
|
+
function g() {
|
|
1941
|
+
clearTimeout(o), clearTimeout(s), c.enabled && (c.timeout && !a && (a = setTimeout(() => {
|
|
1942
|
+
clearTimeout(o), t.disconnect().catch(() => {});
|
|
1943
|
+
}, c.timeout)), t.send(N("r", { xmlns: z })).catch(() => {}), h());
|
|
1944
|
+
}
|
|
1945
|
+
return n.filter((e, t) => {
|
|
1946
|
+
let { stanza: n } = e;
|
|
1947
|
+
return n.is("enable", "urn:xmpp:sm:3") && (c.enableSent = !0), !c.enabled && !c.enableSent || ![
|
|
1948
|
+
"presence",
|
|
1949
|
+
"message",
|
|
1950
|
+
"iq"
|
|
1951
|
+
].includes(n.name) ? t() : (c.outbound_q.push({
|
|
1952
|
+
stanza: n,
|
|
1953
|
+
stamp: zt()
|
|
1954
|
+
}), clearTimeout(o), clearTimeout(s), s = setTimeout(g, c.requestAckDebounce), t());
|
|
1955
|
+
}), e && Ht({
|
|
1956
|
+
streamFeatures: e,
|
|
1957
|
+
sm: c,
|
|
1958
|
+
entity: t,
|
|
1959
|
+
resumed: u,
|
|
1960
|
+
failed: d,
|
|
1961
|
+
enabled: m
|
|
1962
|
+
}), c;
|
|
1963
|
+
}
|
|
1964
|
+
function Jt({ entity: e, item: t }) {
|
|
1965
|
+
let { stanza: n, stamp: r } = t;
|
|
1966
|
+
return n.name === "message" && !n.getChild("delay", "urn:xmpp:delay") && n.append(N("delay", {
|
|
1967
|
+
xmlns: "urn:xmpp:delay",
|
|
1968
|
+
from: e.jid.toString(),
|
|
1969
|
+
stamp: r
|
|
1970
|
+
})), n;
|
|
1971
|
+
}
|
|
1972
|
+
//#endregion
|
|
1973
|
+
//#region node_modules/@xmpp/client-core/src/bind2/bind2.js
|
|
1974
|
+
var Yt = "urn:xmpp:bind:0";
|
|
1975
|
+
function Xt({ sasl2: e, entity: t }, n) {
|
|
1976
|
+
let r = /* @__PURE__ */ new Map();
|
|
1977
|
+
return e.use(Yt, async (e) => {
|
|
1978
|
+
if (!e.is("bind", Yt)) return;
|
|
1979
|
+
n = typeof n == "function" ? await n() : n;
|
|
1980
|
+
let t = await Zt({
|
|
1981
|
+
element: e,
|
|
1982
|
+
features: r
|
|
1983
|
+
});
|
|
1984
|
+
return N("bind", { xmlns: "urn:xmpp:bind:0" }, n && N("tag", null, n), ...t);
|
|
1985
|
+
}, (e) => {
|
|
1986
|
+
if (e.is("bound")) {
|
|
1987
|
+
t._ready(!1);
|
|
1988
|
+
for (let t of e.getChildElements()) r.get(t.getNS())?.[1]?.(t);
|
|
1989
|
+
}
|
|
1990
|
+
}), { use(e, t, n) {
|
|
1991
|
+
r.set(e, [t, n]);
|
|
1992
|
+
} };
|
|
1993
|
+
}
|
|
1994
|
+
function Zt({ element: e, features: t }) {
|
|
1995
|
+
let n = [], r = e.getChild("inline");
|
|
1996
|
+
if (!r) return n;
|
|
1997
|
+
for (let e of r.getChildElements()) {
|
|
1998
|
+
let r = e.attrs.var, i = t.get(r);
|
|
1999
|
+
i && n.push(i[0](e));
|
|
2000
|
+
}
|
|
2001
|
+
return Promise.all(n);
|
|
2002
|
+
}
|
|
2003
|
+
//#endregion
|
|
2004
|
+
//#region node_modules/saslmechanisms/lib/factory.js
|
|
2005
|
+
var Qt = /* @__PURE__ */ y(((e, t) => {
|
|
2006
|
+
(function(n, r) {
|
|
2007
|
+
typeof e == "object" ? r(e, t) : typeof define == "function" && define.amd && define(["exports", "module"], r);
|
|
2008
|
+
})(e, function(e, t) {
|
|
2009
|
+
function n() {
|
|
2010
|
+
this._mechs = [];
|
|
2011
|
+
}
|
|
2012
|
+
n.prototype.use = function(e, t) {
|
|
2013
|
+
return t || (t = e, e = t.prototype.name), this._mechs.push({
|
|
2014
|
+
name: e,
|
|
2015
|
+
mech: t
|
|
2016
|
+
}), this;
|
|
2017
|
+
}, n.prototype.create = function(e) {
|
|
2018
|
+
for (var t = 0, n = this._mechs.length; t < n; t++) for (var r = 0, i = e.length; r < i; r++) {
|
|
2019
|
+
var a = this._mechs[t];
|
|
2020
|
+
if (a.name == e[r]) return new a.mech();
|
|
2021
|
+
}
|
|
2022
|
+
return null;
|
|
2023
|
+
}, e = t.exports = n;
|
|
2024
|
+
});
|
|
2025
|
+
})), $t = /* @__PURE__ */ x((/* @__PURE__ */ y(((e, t) => {
|
|
2026
|
+
(function(n, r) {
|
|
2027
|
+
typeof e == "object" ? r(e, t, Qt()) : typeof define == "function" && define.amd && define([
|
|
2028
|
+
"exports",
|
|
2029
|
+
"module",
|
|
2030
|
+
"./lib/factory"
|
|
2031
|
+
], r);
|
|
2032
|
+
})(e, function(e, t, n) {
|
|
2033
|
+
e = t.exports = n, e.Factory = n;
|
|
2034
|
+
});
|
|
2035
|
+
})))(), 1), B = "urn:xmpp:fast:0";
|
|
2036
|
+
function en({ sasl2: e, entity: t }) {
|
|
2037
|
+
let n = new $t.default(), r, i = new j.EventEmitter();
|
|
2038
|
+
Object.assign(i, {
|
|
2039
|
+
mechanism: null,
|
|
2040
|
+
mechanisms: [],
|
|
2041
|
+
async saveToken(e) {
|
|
2042
|
+
r = e;
|
|
2043
|
+
},
|
|
2044
|
+
async fetchToken() {
|
|
2045
|
+
return r;
|
|
2046
|
+
},
|
|
2047
|
+
async deleteToken() {
|
|
2048
|
+
r = null;
|
|
2049
|
+
},
|
|
2050
|
+
async save(e) {
|
|
2051
|
+
try {
|
|
2052
|
+
await this.saveToken(e);
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
t.emit("error", e);
|
|
2055
|
+
}
|
|
2056
|
+
},
|
|
2057
|
+
async fetch() {
|
|
2058
|
+
try {
|
|
2059
|
+
return this.fetchToken();
|
|
2060
|
+
} catch (e) {
|
|
2061
|
+
t.emit("error", e);
|
|
2062
|
+
}
|
|
2063
|
+
},
|
|
2064
|
+
async delete() {
|
|
2065
|
+
try {
|
|
2066
|
+
await this.deleteToken();
|
|
2067
|
+
} catch (e) {
|
|
2068
|
+
t.emit("error", e);
|
|
2069
|
+
}
|
|
2070
|
+
},
|
|
2071
|
+
saslFactory: n,
|
|
2072
|
+
async auth({ authenticate: e, entity: t, userAgent: n, credentials: r, streamFeatures: o, features: s }) {
|
|
2073
|
+
if (!i.mechanism) return !1;
|
|
2074
|
+
let { token: c } = r;
|
|
2075
|
+
if (!tn(c, i.mechanisms)) return l();
|
|
2076
|
+
try {
|
|
2077
|
+
return await e({
|
|
2078
|
+
saslFactory: i.saslFactory,
|
|
2079
|
+
mechanism: c.mechanism,
|
|
2080
|
+
credentials: {
|
|
2081
|
+
...r,
|
|
2082
|
+
password: c.token
|
|
2083
|
+
},
|
|
2084
|
+
streamFeatures: [...o, N("fast", { xmlns: B })],
|
|
2085
|
+
entity: t,
|
|
2086
|
+
userAgent: n,
|
|
2087
|
+
features: s
|
|
2088
|
+
}), !0;
|
|
2089
|
+
} catch (e) {
|
|
2090
|
+
return e instanceof L && ["not-authorized", "credentials-expired"].includes(e.condition) ? l() : (t.emit("error", e), !1);
|
|
2091
|
+
}
|
|
2092
|
+
async function l() {
|
|
2093
|
+
return await i.delete(), a(o), !1;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
});
|
|
2097
|
+
function a(e) {
|
|
2098
|
+
e.push(N("request-token", {
|
|
2099
|
+
xmlns: B,
|
|
2100
|
+
mechanism: i.mechanism
|
|
2101
|
+
}));
|
|
2102
|
+
}
|
|
2103
|
+
function o() {
|
|
2104
|
+
i.mechanism = null, i.mechanisms = [];
|
|
2105
|
+
}
|
|
2106
|
+
return o(), e.use(B, async (e) => {
|
|
2107
|
+
if (!e.is("fast", B)) return o();
|
|
2108
|
+
i.available = !0;
|
|
2109
|
+
let t = Dt(e, B, n), r = t[0];
|
|
2110
|
+
if (!r) return o();
|
|
2111
|
+
i.mechanisms = t, i.mechanism = r;
|
|
2112
|
+
}, async (e) => {
|
|
2113
|
+
e.is("token", B) && await i.save({
|
|
2114
|
+
mechanism: i.mechanism,
|
|
2115
|
+
token: e.attrs.token,
|
|
2116
|
+
expiry: e.attrs.expiry
|
|
2117
|
+
});
|
|
2118
|
+
}), i;
|
|
2119
|
+
}
|
|
2120
|
+
function tn(e, t) {
|
|
2121
|
+
return !(!e || !t.includes(e.mechanism) || new Date(e.expiry) <= /* @__PURE__ */ new Date());
|
|
2122
|
+
}
|
|
2123
|
+
//#endregion
|
|
2124
|
+
//#region node_modules/sasl-plain/lib/mechanism.js
|
|
2125
|
+
var nn = /* @__PURE__ */ y(((e, t) => {
|
|
2126
|
+
(function(n, r) {
|
|
2127
|
+
typeof e == "object" ? r(e, t) : typeof define == "function" && define.amd && define(["exports", "module"], r);
|
|
2128
|
+
})(e, function(e, t) {
|
|
2129
|
+
function n() {}
|
|
2130
|
+
n.prototype.name = "PLAIN", n.prototype.clientFirst = !0, n.prototype.response = function(e) {
|
|
2131
|
+
var t = "";
|
|
2132
|
+
return t += e.authzid || "", t += "\0", t += e.username, t += "\0", t += e.password, t;
|
|
2133
|
+
}, n.prototype.challenge = function(e) {
|
|
2134
|
+
return this;
|
|
2135
|
+
}, e = t.exports = n;
|
|
2136
|
+
});
|
|
2137
|
+
})), rn = /* @__PURE__ */ x((/* @__PURE__ */ y(((e, t) => {
|
|
2138
|
+
(function(n, r) {
|
|
2139
|
+
typeof e == "object" ? r(e, t, nn()) : typeof define == "function" && define.amd && define([
|
|
2140
|
+
"exports",
|
|
2141
|
+
"module",
|
|
2142
|
+
"./lib/mechanism"
|
|
2143
|
+
], r);
|
|
2144
|
+
})(e, function(e, t, n) {
|
|
2145
|
+
e = t.exports = n, e.Mechanism = n;
|
|
2146
|
+
});
|
|
2147
|
+
})))(), 1);
|
|
2148
|
+
function an(e) {
|
|
2149
|
+
e.use(rn.default);
|
|
2150
|
+
}
|
|
2151
|
+
//#endregion
|
|
2152
|
+
//#region node_modules/sasl-anonymous/lib/mechanism.js
|
|
2153
|
+
var on = /* @__PURE__ */ y(((e, t) => {
|
|
2154
|
+
(function(n, r) {
|
|
2155
|
+
typeof e == "object" ? r(e, t) : typeof define == "function" && define.amd && define(["exports", "module"], r);
|
|
2156
|
+
})(e, function(e, t) {
|
|
2157
|
+
function n() {}
|
|
2158
|
+
n.prototype.name = "ANONYMOUS", n.prototype.clientFirst = !0, n.prototype.response = function(e) {
|
|
2159
|
+
return e.trace || "";
|
|
2160
|
+
}, n.prototype.challenge = function(e) {}, e = t.exports = n;
|
|
2161
|
+
});
|
|
2162
|
+
})), sn = /* @__PURE__ */ x((/* @__PURE__ */ y(((e, t) => {
|
|
2163
|
+
(function(n, r) {
|
|
2164
|
+
typeof e == "object" ? r(e, t, on()) : typeof define == "function" && define.amd && define([
|
|
2165
|
+
"exports",
|
|
2166
|
+
"module",
|
|
2167
|
+
"./lib/mechanism"
|
|
2168
|
+
], r);
|
|
2169
|
+
})(e, function(e, t, n) {
|
|
2170
|
+
e = t.exports = n, e.Mechanism = n;
|
|
2171
|
+
});
|
|
2172
|
+
})))(), 1);
|
|
2173
|
+
function cn(e) {
|
|
2174
|
+
e.use(sn.default);
|
|
2175
|
+
}
|
|
2176
|
+
//#endregion
|
|
2177
|
+
//#region node_modules/@xmpp/sasl-ht-sha-256-none/index.js
|
|
2178
|
+
function V() {}
|
|
2179
|
+
V.prototype.Mechanism = V, V.prototype.name = "HT-SHA-256-NONE", V.prototype.clientFirst = !0, V.prototype.response = async function({ username: e, password: t }) {
|
|
2180
|
+
this.key = await crypto.subtle.importKey("raw", new TextEncoder().encode(t), {
|
|
2181
|
+
name: "HMAC",
|
|
2182
|
+
hash: "SHA-256"
|
|
2183
|
+
}, !1, ["sign", "verify"]);
|
|
2184
|
+
let n = await crypto.subtle.sign("HMAC", this.key, new TextEncoder().encode("Initiator"));
|
|
2185
|
+
return `${e}\0${String.fromCodePoint(...new Uint8Array(n))}`;
|
|
2186
|
+
}, V.prototype.final = async function(e) {
|
|
2187
|
+
let t = Uint8Array.from(e, (e) => e.codePointAt(0));
|
|
2188
|
+
if (await crypto.subtle.verify("HMAC", this.key, t, new TextEncoder().encode("Responder")) !== !0) throw Error("Responder message from server was wrong");
|
|
2189
|
+
};
|
|
2190
|
+
function ln(e) {
|
|
2191
|
+
e.use(V);
|
|
2192
|
+
}
|
|
2193
|
+
//#endregion
|
|
2194
|
+
//#region node_modules/@xmpp/client/lib/createOnAuthenticate.js
|
|
2195
|
+
var un = "ANONYMOUS", dn = "PLAIN";
|
|
2196
|
+
function fn(e, t) {
|
|
2197
|
+
return async function(...n) {
|
|
2198
|
+
if (typeof e == "function") {
|
|
2199
|
+
await e(...n);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
let [r, i, a, o] = n;
|
|
2203
|
+
e.token ??= await a?.fetch(), await r(e, pn({
|
|
2204
|
+
mechanisms: i,
|
|
2205
|
+
entity: o,
|
|
2206
|
+
credentials: e
|
|
2207
|
+
}), t);
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
function pn({ mechanisms: e, entity: t, credentials: n }) {
|
|
2211
|
+
return !n?.username && !n?.password && !n?.token && e.includes(un) ? un : t.isSecure() ? e[0] : e.find((e) => e !== dn);
|
|
2212
|
+
}
|
|
2213
|
+
//#endregion
|
|
2214
|
+
//#region node_modules/@xmpp/client/lib/getDomain.js
|
|
2215
|
+
function mn(e) {
|
|
2216
|
+
return (e.split("://")[1] || e).split(":")[0].split("/")[0];
|
|
2217
|
+
}
|
|
2218
|
+
//#endregion
|
|
2219
|
+
//#region node_modules/@xmpp/client/index.js
|
|
2220
|
+
function hn(e = {}) {
|
|
2221
|
+
let { resource: t, credentials: n, username: r, password: i, userAgent: a, ...o } = e, { domain: s, service: c } = o;
|
|
2222
|
+
!s && c && (o.domain = mn(c));
|
|
2223
|
+
let l = new ke(o);
|
|
2224
|
+
r && o.domain && (l.jid = F(r, o.domain));
|
|
2225
|
+
let u = je({ entity: l }), d = Re({ entity: l }), f = gn(I.default, { entity: l }), p = gn(I.default, { entity: l }), m = qe({ entity: l }), h = Je({ middleware: m }), g = $e({
|
|
2226
|
+
middleware: m,
|
|
2227
|
+
entity: l
|
|
2228
|
+
}), _ = lt({
|
|
2229
|
+
middleware: m,
|
|
2230
|
+
entity: l
|
|
2231
|
+
}), v = wt({ entity: l }), y = new $t.default(), b = Object.entries({
|
|
2232
|
+
...typeof I.default == "function" && { scramsha1: I.default },
|
|
2233
|
+
plain: an,
|
|
2234
|
+
anonymous: cn
|
|
2235
|
+
}).map(([e, t]) => ({ [e]: t(y) }));
|
|
2236
|
+
a ??= N("user-agent", { id: globalThis.crypto.randomUUID() });
|
|
2237
|
+
let x = gn(I.default, { streamFeatures: h }), S = Mt({
|
|
2238
|
+
streamFeatures: h,
|
|
2239
|
+
saslFactory: y
|
|
2240
|
+
}, fn(n ?? {
|
|
2241
|
+
username: r,
|
|
2242
|
+
password: i
|
|
2243
|
+
}, a)), C = en({
|
|
2244
|
+
sasl2: S,
|
|
2245
|
+
entity: l
|
|
2246
|
+
});
|
|
2247
|
+
S.setup({ fast: C });
|
|
2248
|
+
let w = Xt({
|
|
2249
|
+
sasl2: S,
|
|
2250
|
+
entity: l
|
|
2251
|
+
}, t);
|
|
2252
|
+
ln(C.saslFactory);
|
|
2253
|
+
let T = kt({
|
|
2254
|
+
streamFeatures: h,
|
|
2255
|
+
saslFactory: y
|
|
2256
|
+
}, fn(n ?? {
|
|
2257
|
+
username: r,
|
|
2258
|
+
password: i
|
|
2259
|
+
}, a)), E = qt({
|
|
2260
|
+
streamFeatures: h,
|
|
2261
|
+
entity: l,
|
|
2262
|
+
middleware: m,
|
|
2263
|
+
bind2: w,
|
|
2264
|
+
sasl2: S
|
|
2265
|
+
}), D = Rt({
|
|
2266
|
+
iqCaller: g,
|
|
2267
|
+
streamFeatures: h
|
|
2268
|
+
}, t);
|
|
2269
|
+
return _?.get("urn:xmpp:ping", "ping", () => ({})), Object.assign(l, {
|
|
2270
|
+
entity: l,
|
|
2271
|
+
reconnect: u,
|
|
2272
|
+
tcp: f,
|
|
2273
|
+
websocket: d,
|
|
2274
|
+
tls: p,
|
|
2275
|
+
middleware: m,
|
|
2276
|
+
streamFeatures: h,
|
|
2277
|
+
iqCaller: g,
|
|
2278
|
+
iqCallee: _,
|
|
2279
|
+
resolve: v,
|
|
2280
|
+
starttls: x,
|
|
2281
|
+
saslFactory: y,
|
|
2282
|
+
sasl2: S,
|
|
2283
|
+
sasl: T,
|
|
2284
|
+
resourceBinding: D,
|
|
2285
|
+
streamManagement: E,
|
|
2286
|
+
mechanisms: b,
|
|
2287
|
+
bind2: w,
|
|
2288
|
+
fast: C
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
function gn(e, ...t) {
|
|
2292
|
+
if (typeof e == "function") return e(...t);
|
|
2293
|
+
}
|
|
2294
|
+
//#endregion
|
|
2295
|
+
//#region src/xmpp.ts
|
|
2296
|
+
var H = {
|
|
2297
|
+
carbons: "urn:xmpp:carbons:2",
|
|
2298
|
+
forward: "urn:xmpp:forward:0",
|
|
2299
|
+
mam: "urn:xmpp:mam:2",
|
|
2300
|
+
rsm: "http://jabber.org/protocol/rsm",
|
|
2301
|
+
sid: "urn:xmpp:sid:0",
|
|
2302
|
+
hints: "urn:xmpp:hints",
|
|
2303
|
+
chatstates: "http://jabber.org/protocol/chatstates",
|
|
2304
|
+
oob: "jabber:x:oob",
|
|
2305
|
+
upload: "urn:xmpp:http:upload:0",
|
|
2306
|
+
delay: "urn:xmpp:delay",
|
|
2307
|
+
disco: "http://jabber.org/protocol/disco#items",
|
|
2308
|
+
discoInfo: "http://jabber.org/protocol/disco#info",
|
|
2309
|
+
push: "urn:xmpp:push:0",
|
|
2310
|
+
hello: "urn:nethvoice:chat:presence",
|
|
2311
|
+
data: "jabber:x:data",
|
|
2312
|
+
muc: "http://jabber.org/protocol/muc",
|
|
2313
|
+
mucOwner: "http://jabber.org/protocol/muc#owner",
|
|
2314
|
+
mucAdmin: "http://jabber.org/protocol/muc#admin",
|
|
2315
|
+
mucsub: "urn:xmpp:mucsub:0",
|
|
2316
|
+
pubsubEvent: "http://jabber.org/protocol/pubsub#event",
|
|
2317
|
+
mucsubMessages: "urn:xmpp:mucsub:nodes:messages",
|
|
2318
|
+
conference: "jabber:x:conference",
|
|
2319
|
+
vcard: "vcard-temp",
|
|
2320
|
+
ping: "urn:xmpp:ping",
|
|
2321
|
+
reactions: "urn:xmpp:reactions:0"
|
|
2322
|
+
}, _n = 3e4, vn = class {
|
|
2323
|
+
xmpp;
|
|
2324
|
+
me;
|
|
2325
|
+
domain;
|
|
2326
|
+
mucHost;
|
|
2327
|
+
uploadService;
|
|
2328
|
+
mamQueries = /* @__PURE__ */ new Map();
|
|
2329
|
+
mamReactions = /* @__PURE__ */ new Map();
|
|
2330
|
+
stopped = !1;
|
|
2331
|
+
attempt = 0;
|
|
2332
|
+
retryTimer;
|
|
2333
|
+
pingTimer;
|
|
2334
|
+
unauthorized = !1;
|
|
2335
|
+
connected = !1;
|
|
2336
|
+
online = /* @__PURE__ */ new Map();
|
|
2337
|
+
cfg;
|
|
2338
|
+
h;
|
|
2339
|
+
constructor(e, t) {
|
|
2340
|
+
this.cfg = e, this.h = t, this.domain = e.host, this.mucHost = `conference.${e.host}`, this.me = `${e.username}@${e.host}`, this.xmpp = hn({
|
|
2341
|
+
service: `wss://${e.host}/xmpp-websocket`,
|
|
2342
|
+
domain: e.host,
|
|
2343
|
+
username: e.username,
|
|
2344
|
+
password: e.token,
|
|
2345
|
+
resource: "chat-island." + Math.random().toString(36).slice(2, 8)
|
|
2346
|
+
}), this.xmpp.reconnect?.stop(), this.xmpp.on("status", (e) => {
|
|
2347
|
+
this.stopped || this.unauthorized || ((e === "connecting" || e === "opening" || e === "connect") && this.h.status("connecting"), (e === "disconnect" || e === "close") && (this.connected = !1, window.clearInterval(this.pingTimer), this.forgetPresence(), this.h.status("offline")), e === "disconnect" && this.scheduleRetry());
|
|
2348
|
+
}), this.xmpp.on("error", (e) => {
|
|
2349
|
+
if (!this.stopped) {
|
|
2350
|
+
if (yn(e)) {
|
|
2351
|
+
this.unauthorized = !0, window.clearTimeout(this.retryTimer), this.h.status("unauthorized", e.message);
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
this.h.status("error", e.message);
|
|
2355
|
+
}
|
|
2356
|
+
}), this.xmpp.on("online", async () => {
|
|
2357
|
+
if (this.stopped) {
|
|
2358
|
+
await this.xmpp.stop().catch(() => {});
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2361
|
+
this.attempt = 0, this.connected = !0;
|
|
2362
|
+
try {
|
|
2363
|
+
await this.xmpp.send(N("iq", {
|
|
2364
|
+
type: "set",
|
|
2365
|
+
id: "carbons"
|
|
2366
|
+
}, N("enable", { xmlns: H.carbons }))), await this.xmpp.send(N("presence"));
|
|
2367
|
+
} catch {
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
window.clearInterval(this.pingTimer), this.pingTimer = window.setInterval(() => this.ping(), _n), this.h.status("online");
|
|
2371
|
+
}), this.xmpp.on("stanza", (e) => this.onStanza(e));
|
|
2372
|
+
}
|
|
2373
|
+
start() {
|
|
2374
|
+
window.addEventListener("online", this.wake), document.addEventListener("visibilitychange", this.onVisible), this.h.status("connecting"), setTimeout(() => this.connectNow(), 0);
|
|
2375
|
+
}
|
|
2376
|
+
stop() {
|
|
2377
|
+
return this.stopped = !0, window.clearTimeout(this.retryTimer), window.clearInterval(this.pingTimer), window.removeEventListener("online", this.wake), document.removeEventListener("visibilitychange", this.onVisible), this.xmpp.stop().catch(() => {});
|
|
2378
|
+
}
|
|
2379
|
+
wake = () => {
|
|
2380
|
+
if (!(this.stopped || this.unauthorized)) {
|
|
2381
|
+
if (this.connected) {
|
|
2382
|
+
this.ping();
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
window.clearTimeout(this.retryTimer), this.attempt = 0, this.connectNow();
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
onVisible = () => {
|
|
2389
|
+
document.visibilityState === "visible" && this.wake();
|
|
2390
|
+
};
|
|
2391
|
+
ping() {
|
|
2392
|
+
this.connected && this.xmpp.iqCaller.request(N("iq", {
|
|
2393
|
+
type: "get",
|
|
2394
|
+
to: this.domain
|
|
2395
|
+
}, N("ping", { xmlns: H.ping })), 1e4).catch((e) => {
|
|
2396
|
+
!this.stopped && this.connected && e.name !== "StanzaError" && this.xmpp.disconnect().catch(() => {});
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
forgetPresence() {
|
|
2400
|
+
for (let e of this.online.keys()) this.h.presence(e, !1);
|
|
2401
|
+
this.online.clear();
|
|
2402
|
+
}
|
|
2403
|
+
connectNow() {
|
|
2404
|
+
if (this.stopped || this.unauthorized) return;
|
|
2405
|
+
this.retryTimer = void 0;
|
|
2406
|
+
let e = this.xmpp;
|
|
2407
|
+
(e.status === "offline" ? this.xmpp.start() : e.connect(e.options.service).then(() => e.open({ domain: e.options.domain }))).catch((e) => {
|
|
2408
|
+
if (!this.stopped) {
|
|
2409
|
+
if (yn(e)) {
|
|
2410
|
+
this.unauthorized = !0, this.h.status("unauthorized", e.message);
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
this.h.status("error", e.message), this.scheduleRetry();
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
scheduleRetry() {
|
|
2418
|
+
if (this.stopped || this.unauthorized || this.retryTimer !== void 0) return;
|
|
2419
|
+
let e = Math.min(6e4, 1e3 * 2 ** this.attempt) * (.7 + Math.random() * .6);
|
|
2420
|
+
this.attempt++, this.retryTimer = window.setTimeout(() => this.connectNow(), e);
|
|
2421
|
+
}
|
|
2422
|
+
isGroup(e) {
|
|
2423
|
+
return e.endsWith("@" + this.mucHost);
|
|
2424
|
+
}
|
|
2425
|
+
async send(e, t, n) {
|
|
2426
|
+
let r = crypto.randomUUID(), i = [
|
|
2427
|
+
N("body", {}, t),
|
|
2428
|
+
N("origin-id", {
|
|
2429
|
+
xmlns: H.sid,
|
|
2430
|
+
id: r
|
|
2431
|
+
}),
|
|
2432
|
+
N("store", { xmlns: H.hints })
|
|
2433
|
+
];
|
|
2434
|
+
return n && i.push(N("x", { xmlns: H.oob }, N("url", {}, n))), this.isGroup(e) ? (await this.xmpp.send(N("message", {
|
|
2435
|
+
to: e,
|
|
2436
|
+
type: "groupchat",
|
|
2437
|
+
id: r
|
|
2438
|
+
}, ...i)), {
|
|
2439
|
+
id: r,
|
|
2440
|
+
oid: r,
|
|
2441
|
+
from: e,
|
|
2442
|
+
to: this.cfg.username,
|
|
2443
|
+
body: t,
|
|
2444
|
+
ts: Date.now(),
|
|
2445
|
+
mine: !0,
|
|
2446
|
+
oob: n,
|
|
2447
|
+
room: e,
|
|
2448
|
+
nick: this.cfg.username
|
|
2449
|
+
}) : (i.push(N("active", { xmlns: H.chatstates })), await this.xmpp.send(N("message", {
|
|
2450
|
+
to: `${e}@${this.domain}`,
|
|
2451
|
+
type: "chat",
|
|
2452
|
+
id: r
|
|
2453
|
+
}, ...i)), {
|
|
2454
|
+
id: r,
|
|
2455
|
+
oid: r,
|
|
2456
|
+
from: this.cfg.username,
|
|
2457
|
+
to: e,
|
|
2458
|
+
body: t,
|
|
2459
|
+
ts: Date.now(),
|
|
2460
|
+
mine: !0,
|
|
2461
|
+
oob: n
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
async react(e, t, n) {
|
|
2465
|
+
let r = this.isGroup(e), i = N("reactions", {
|
|
2466
|
+
xmlns: H.reactions,
|
|
2467
|
+
id: t
|
|
2468
|
+
}, ...n.map((e) => N("reaction", {}, e)));
|
|
2469
|
+
await this.xmpp.send(N("message", {
|
|
2470
|
+
to: r ? e : `${e}@${this.domain}`,
|
|
2471
|
+
type: r ? "groupchat" : "chat",
|
|
2472
|
+
id: crypto.randomUUID()
|
|
2473
|
+
}, i, N("store", { xmlns: H.hints })));
|
|
2474
|
+
}
|
|
2475
|
+
async announce(e) {
|
|
2476
|
+
for (let t of e) await this.xmpp.send(N("presence", { to: `${t}@${this.domain}` }, N("x", { xmlns: H.hello }))).catch(() => {});
|
|
2477
|
+
}
|
|
2478
|
+
typing(e, t) {
|
|
2479
|
+
return this.isGroup(e) ? Promise.resolve() : this.xmpp.send(N("message", {
|
|
2480
|
+
to: `${e}@${this.domain}`,
|
|
2481
|
+
type: "chat"
|
|
2482
|
+
}, N(t ? "composing" : "paused", { xmlns: H.chatstates })));
|
|
2483
|
+
}
|
|
2484
|
+
enablePush(e, t) {
|
|
2485
|
+
return this.xmpp.iqCaller.request(N("iq", { type: "set" }, N("enable", {
|
|
2486
|
+
xmlns: H.push,
|
|
2487
|
+
jid: e,
|
|
2488
|
+
node: t
|
|
2489
|
+
})), 15e3);
|
|
2490
|
+
}
|
|
2491
|
+
disablePush(e, t) {
|
|
2492
|
+
return this.xmpp.iqCaller.request(N("iq", { type: "set" }, N("disable", {
|
|
2493
|
+
xmlns: H.push,
|
|
2494
|
+
jid: e,
|
|
2495
|
+
node: t
|
|
2496
|
+
})), 5e3);
|
|
2497
|
+
}
|
|
2498
|
+
async recent(e = 200) {
|
|
2499
|
+
return this.mam(void 0, void 0, e);
|
|
2500
|
+
}
|
|
2501
|
+
history(e, t, n = 30) {
|
|
2502
|
+
return this.mam(e, t, n);
|
|
2503
|
+
}
|
|
2504
|
+
async mam(e, t, n) {
|
|
2505
|
+
let r = crypto.randomUUID();
|
|
2506
|
+
this.mamQueries.set(r, []), this.mamReactions.set(r, []);
|
|
2507
|
+
let i = N("set", { xmlns: H.rsm }, N("max", {}, String(n)), N("before", {}, t ?? "")), a = [N("field", {
|
|
2508
|
+
var: "FORM_TYPE",
|
|
2509
|
+
type: "hidden"
|
|
2510
|
+
}, N("value", {}, H.mam))];
|
|
2511
|
+
e && a.push(N("field", { var: "with" }, N("value", {}, this.isGroup(e) ? e : `${e}@${this.domain}`)));
|
|
2512
|
+
let o = N("x", {
|
|
2513
|
+
xmlns: H.data,
|
|
2514
|
+
type: "submit"
|
|
2515
|
+
}, ...a), s, c, l;
|
|
2516
|
+
try {
|
|
2517
|
+
s = await this.xmpp.iqCaller.request(N("iq", {
|
|
2518
|
+
type: "set",
|
|
2519
|
+
id: r
|
|
2520
|
+
}, N("query", {
|
|
2521
|
+
xmlns: H.mam,
|
|
2522
|
+
queryid: r
|
|
2523
|
+
}, o, i)), 3e4);
|
|
2524
|
+
} finally {
|
|
2525
|
+
c = this.mamQueries.get(r) ?? [], l = this.mamReactions.get(r) ?? [], this.mamQueries.delete(r), this.mamReactions.delete(r);
|
|
2526
|
+
}
|
|
2527
|
+
let u = s.getChild("fin", H.mam), d = u?.getChild("set", H.rsm)?.getChildText("first") ?? void 0;
|
|
2528
|
+
return {
|
|
2529
|
+
messages: c,
|
|
2530
|
+
reactions: l,
|
|
2531
|
+
complete: u?.attrs.complete === "true",
|
|
2532
|
+
first: d
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
async createGroup(e, t, n) {
|
|
2536
|
+
let r = `g-${Math.random().toString(36).slice(2, 10)}@${this.mucHost}`, i = this.cfg.username, a = this.waitFor((e) => e.is("presence") && U(e.attrs.from) === r, 1e4);
|
|
2537
|
+
await this.xmpp.send(N("presence", { to: `${r}/${i}` }, N("x", { xmlns: H.muc }))), await a;
|
|
2538
|
+
let o = (e, t) => N("field", { var: e }, N("value", {}, t));
|
|
2539
|
+
await this.xmpp.iqCaller.request(N("iq", {
|
|
2540
|
+
type: "set",
|
|
2541
|
+
to: r
|
|
2542
|
+
}, N("query", { xmlns: H.mucOwner }, N("x", {
|
|
2543
|
+
xmlns: H.data,
|
|
2544
|
+
type: "submit"
|
|
2545
|
+
}, o("FORM_TYPE", "http://jabber.org/protocol/muc#roomconfig"), o("muc#roomconfig_roomname", e), o("muc#roomconfig_persistentroom", "1"), o("muc#roomconfig_membersonly", "1"), o("muc#roomconfig_publicroom", "0"), o("muc#roomconfig_whois", "anyone"), o("allow_subscription", "1"), o("mam", "1")))), 15e3), n && await this.setGroupAvatar(r, n).catch(() => {});
|
|
2546
|
+
let s = t.filter((e) => e && e !== this.cfg.username);
|
|
2547
|
+
await this.xmpp.iqCaller.request(N("iq", {
|
|
2548
|
+
type: "set",
|
|
2549
|
+
to: r
|
|
2550
|
+
}, N("query", { xmlns: H.mucAdmin }, ...s.map((e) => N("item", {
|
|
2551
|
+
affiliation: "member",
|
|
2552
|
+
jid: `${e}@${this.domain}`
|
|
2553
|
+
})))), 15e3);
|
|
2554
|
+
for (let e of s) await this.xmpp.iqCaller.request(N("iq", {
|
|
2555
|
+
type: "set",
|
|
2556
|
+
to: r
|
|
2557
|
+
}, N("subscribe", {
|
|
2558
|
+
xmlns: H.mucsub,
|
|
2559
|
+
jid: `${e}@${this.domain}`,
|
|
2560
|
+
nick: e
|
|
2561
|
+
}, N("event", { node: H.mucsubMessages }))), 15e3).catch(() => {});
|
|
2562
|
+
await this.xmpp.iqCaller.request(N("iq", {
|
|
2563
|
+
type: "set",
|
|
2564
|
+
to: r
|
|
2565
|
+
}, N("subscribe", {
|
|
2566
|
+
xmlns: H.mucsub,
|
|
2567
|
+
nick: i
|
|
2568
|
+
}, N("event", { node: H.mucsubMessages }))), 15e3), await this.xmpp.send(N("presence", {
|
|
2569
|
+
to: `${r}/${i}`,
|
|
2570
|
+
type: "unavailable"
|
|
2571
|
+
}));
|
|
2572
|
+
for (let t of s) await this.xmpp.send(N("message", { to: `${t}@${this.domain}` }, N("x", {
|
|
2573
|
+
xmlns: H.conference,
|
|
2574
|
+
jid: r,
|
|
2575
|
+
reason: e
|
|
2576
|
+
}))).catch(() => {});
|
|
2577
|
+
return r;
|
|
2578
|
+
}
|
|
2579
|
+
async leaveGroup(e, t) {
|
|
2580
|
+
t ? await this.xmpp.iqCaller.request(N("iq", {
|
|
2581
|
+
type: "set",
|
|
2582
|
+
to: e
|
|
2583
|
+
}, N("query", { xmlns: H.mucOwner }, N("destroy", {}))), 1e4) : await this.xmpp.iqCaller.request(N("iq", {
|
|
2584
|
+
type: "set",
|
|
2585
|
+
to: e
|
|
2586
|
+
}, N("unsubscribe", { xmlns: H.mucsub })), 1e4);
|
|
2587
|
+
}
|
|
2588
|
+
async setGroupAvatar(e, t) {
|
|
2589
|
+
let n = /^data:(image\/[a-z+]+);base64,(.+)$/i.exec(t);
|
|
2590
|
+
n && await this.xmpp.iqCaller.request(N("iq", {
|
|
2591
|
+
type: "set",
|
|
2592
|
+
to: e
|
|
2593
|
+
}, N("vCard", { xmlns: H.vcard }, N("PHOTO", {}, N("TYPE", {}, n[1]), N("BINVAL", {}, n[2])))), 15e3);
|
|
2594
|
+
}
|
|
2595
|
+
async groupAvatar(e) {
|
|
2596
|
+
let t = (await this.xmpp.iqCaller.request(N("iq", {
|
|
2597
|
+
type: "get",
|
|
2598
|
+
to: e
|
|
2599
|
+
}, N("vCard", { xmlns: H.vcard })), 1e4)).getChild("vCard", H.vcard)?.getChild("PHOTO"), n = t?.getChildText("BINVAL");
|
|
2600
|
+
return n ? `data:${t?.getChildText("TYPE") || "image/jpeg"};base64,${n.replace(/\s+/g, "")}` : void 0;
|
|
2601
|
+
}
|
|
2602
|
+
async listGroups() {
|
|
2603
|
+
let e = ((await this.xmpp.iqCaller.request(N("iq", {
|
|
2604
|
+
type: "get",
|
|
2605
|
+
to: this.mucHost
|
|
2606
|
+
}, N("subscriptions", { xmlns: H.mucsub })), 15e3)).getChild("subscriptions", H.mucsub)?.getChildren("subscription") ?? []).map((e) => e.attrs.jid);
|
|
2607
|
+
return Promise.all(e.map((e) => this.groupInfo(e)));
|
|
2608
|
+
}
|
|
2609
|
+
async subscribed(e) {
|
|
2610
|
+
return ((await this.xmpp.iqCaller.request(N("iq", {
|
|
2611
|
+
type: "get",
|
|
2612
|
+
to: this.mucHost
|
|
2613
|
+
}, N("subscriptions", { xmlns: H.mucsub })), 15e3)).getChild("subscriptions", H.mucsub)?.getChildren("subscription") ?? []).some((t) => U(t.attrs.jid) === e);
|
|
2614
|
+
}
|
|
2615
|
+
async groupInfo(e) {
|
|
2616
|
+
let t = e.split("@")[0], n = [], r = !1;
|
|
2617
|
+
try {
|
|
2618
|
+
t = (await this.xmpp.iqCaller.request(N("iq", {
|
|
2619
|
+
type: "get",
|
|
2620
|
+
to: e
|
|
2621
|
+
}, N("query", { xmlns: H.discoInfo })), 1e4)).getChild("query", H.discoInfo)?.getChild("identity")?.attrs.name || t;
|
|
2622
|
+
} catch {}
|
|
2623
|
+
try {
|
|
2624
|
+
n = ((await this.xmpp.iqCaller.request(N("iq", {
|
|
2625
|
+
type: "get",
|
|
2626
|
+
to: e
|
|
2627
|
+
}, N("query", { xmlns: H.mucAdmin }, N("item", { affiliation: "member" }))), 1e4)).getChild("query", H.mucAdmin)?.getChildren("item") ?? []).map((e) => W(e.attrs.jid));
|
|
2628
|
+
let t = await this.xmpp.iqCaller.request(N("iq", {
|
|
2629
|
+
type: "get",
|
|
2630
|
+
to: e
|
|
2631
|
+
}, N("query", { xmlns: H.mucAdmin }, N("item", { affiliation: "owner" }))), 1e4);
|
|
2632
|
+
for (let e of t.getChild("query", H.mucAdmin)?.getChildren("item") ?? []) n.push(W(e.attrs.jid)), W(e.attrs.jid) === this.cfg.username && (r = !0);
|
|
2633
|
+
} catch {}
|
|
2634
|
+
let i = await this.groupAvatar(e).catch(() => void 0);
|
|
2635
|
+
return {
|
|
2636
|
+
peer: e,
|
|
2637
|
+
name: t,
|
|
2638
|
+
members: [...new Set(n)],
|
|
2639
|
+
avatar: i,
|
|
2640
|
+
owner: r
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
async upload(e) {
|
|
2644
|
+
let t = await this.findUploadService(), n = (await this.xmpp.iqCaller.request(N("iq", {
|
|
2645
|
+
type: "get",
|
|
2646
|
+
to: t
|
|
2647
|
+
}, N("request", {
|
|
2648
|
+
xmlns: H.upload,
|
|
2649
|
+
filename: e.name,
|
|
2650
|
+
size: String(e.size),
|
|
2651
|
+
"content-type": e.type || "application/octet-stream"
|
|
2652
|
+
})), 3e4)).getChild("slot", H.upload), r = n?.getChild("put"), i = n?.getChild("get")?.attrs.url;
|
|
2653
|
+
if (!r || !i) throw Error("upload: no slot");
|
|
2654
|
+
let a = { "Content-Type": e.type || "application/octet-stream" };
|
|
2655
|
+
for (let e of r.getChildren("header")) a[e.attrs.name] = e.text();
|
|
2656
|
+
let o = await fetch(r.attrs.url, {
|
|
2657
|
+
method: "PUT",
|
|
2658
|
+
headers: a,
|
|
2659
|
+
body: e
|
|
2660
|
+
});
|
|
2661
|
+
if (!o.ok) throw Error(`upload: HTTP ${o.status}`);
|
|
2662
|
+
return i;
|
|
2663
|
+
}
|
|
2664
|
+
async findUploadService() {
|
|
2665
|
+
if (this.uploadService) return this.uploadService;
|
|
2666
|
+
let e = async (e) => {
|
|
2667
|
+
try {
|
|
2668
|
+
return (await this.xmpp.iqCaller.request(N("iq", {
|
|
2669
|
+
type: "get",
|
|
2670
|
+
to: e
|
|
2671
|
+
}, N("query", { xmlns: H.discoInfo })), 1e4)).getChild("query", H.discoInfo)?.getChildren("feature").some((e) => e.attrs.var === H.upload) ?? !1;
|
|
2672
|
+
} catch {
|
|
2673
|
+
return !1;
|
|
2674
|
+
}
|
|
2675
|
+
}, t = [`upload.${this.domain}`];
|
|
2676
|
+
try {
|
|
2677
|
+
let e = await this.xmpp.iqCaller.request(N("iq", {
|
|
2678
|
+
type: "get",
|
|
2679
|
+
to: this.domain
|
|
2680
|
+
}, N("query", { xmlns: H.disco })), 1e4);
|
|
2681
|
+
for (let n of e.getChild("query", H.disco)?.getChildren("item") ?? []) t.includes(n.attrs.jid) || t.push(n.attrs.jid);
|
|
2682
|
+
} catch {}
|
|
2683
|
+
for (let n of t) if (await e(n)) return this.uploadService = n, n;
|
|
2684
|
+
throw Error("upload: service not found");
|
|
2685
|
+
}
|
|
2686
|
+
waiters = [];
|
|
2687
|
+
waitFor(e, t) {
|
|
2688
|
+
return new Promise((n, r) => {
|
|
2689
|
+
let i = {
|
|
2690
|
+
test: e,
|
|
2691
|
+
resolve: n
|
|
2692
|
+
};
|
|
2693
|
+
this.waiters.push(i), setTimeout(() => {
|
|
2694
|
+
let e = this.waiters.indexOf(i);
|
|
2695
|
+
e >= 0 && (this.waiters.splice(e, 1), r(/* @__PURE__ */ Error("timeout")));
|
|
2696
|
+
}, t);
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
onStanza(e) {
|
|
2700
|
+
for (let t of [...this.waiters]) t.test(e) && (this.waiters.splice(this.waiters.indexOf(t), 1), t.resolve());
|
|
2701
|
+
if (e.is("presence")) {
|
|
2702
|
+
let t = e.attrs.from ?? "", n = U(t);
|
|
2703
|
+
if (!n || n === this.me || n.endsWith("@" + this.mucHost) || e.attrs.type === "error" || e.attrs.type?.startsWith("subscribe")) return;
|
|
2704
|
+
let r = W(n), i = this.online.get(r) ?? /* @__PURE__ */ new Set();
|
|
2705
|
+
e.attrs.type === "unavailable" ? i.delete(t) : i.add(t), this.online.set(r, i), this.h.presence(r, i.size > 0);
|
|
2706
|
+
let a = e.getChild("x", H.hello);
|
|
2707
|
+
a && !a.attrs.reply && e.attrs.type !== "unavailable" && this.xmpp.send(N("presence", { to: n }, N("x", {
|
|
2708
|
+
xmlns: H.hello,
|
|
2709
|
+
reply: "1"
|
|
2710
|
+
}))).catch(() => {});
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (!e.is("message")) return;
|
|
2714
|
+
let t = !e.attrs.from || U(e.attrs.from) === this.me, n = e.getChild("result", H.mam);
|
|
2715
|
+
if (n) {
|
|
2716
|
+
if (!t) return;
|
|
2717
|
+
let e = n.getChild("forwarded", H.forward)?.getChild("message"), r = this.mamQueries.get(n.attrs.queryid);
|
|
2718
|
+
if (e && r) {
|
|
2719
|
+
let t = this.reactionOf(e);
|
|
2720
|
+
t && this.mamReactions.get(n.attrs.queryid)?.push(t);
|
|
2721
|
+
let i = t ? void 0 : this.toMessage(e, n.attrs.id, bn(n.getChild("forwarded", H.forward)));
|
|
2722
|
+
i && r.push(i);
|
|
2723
|
+
}
|
|
2724
|
+
return;
|
|
2725
|
+
}
|
|
2726
|
+
let r = e.getChild("received", H.carbons) ?? e.getChild("sent", H.carbons);
|
|
2727
|
+
if (r) {
|
|
2728
|
+
if (!t) return;
|
|
2729
|
+
let e = r.getChild("forwarded", H.forward)?.getChild("message");
|
|
2730
|
+
e && this.deliver(e);
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
let i = e.getChild("x", H.conference);
|
|
2734
|
+
if (i) {
|
|
2735
|
+
let e = U(i.attrs.jid);
|
|
2736
|
+
this.isGroup(e) && this.h.groupInvite(e);
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
this.deliver(e);
|
|
2740
|
+
}
|
|
2741
|
+
deliver(e) {
|
|
2742
|
+
let t = this.reactionOf(e);
|
|
2743
|
+
if (t) {
|
|
2744
|
+
this.h.reaction(t);
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
let n = this.toMessage(e, e.getChild("stanza-id", H.sid)?.attrs.id, bn(e));
|
|
2748
|
+
if (n) {
|
|
2749
|
+
this.h.message(n);
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
if (e.attrs.type !== "chat") return;
|
|
2753
|
+
let r = U(e.attrs.from), i = r === this.me ? U(e.attrs.to) : r, a = e.getChildByAttr("xmlns", H.chatstates);
|
|
2754
|
+
!e.getChild("body") && a && this.h.typing(W(i), a.name === "composing");
|
|
2755
|
+
}
|
|
2756
|
+
reactionOf(e) {
|
|
2757
|
+
let t = e.getChild("event", H.pubsubEvent), n = e, r;
|
|
2758
|
+
if (t && t.getChild("items")?.attrs.node === H.mucsubMessages) {
|
|
2759
|
+
r = U(e.attrs.from);
|
|
2760
|
+
let i = xn(t);
|
|
2761
|
+
if (!this.isGroup(r) || !i || U(i.attrs.from) !== r) return;
|
|
2762
|
+
n = i;
|
|
2763
|
+
} else if (e.attrs.type === "groupchat" && (r = U(e.attrs.from), !this.isGroup(r))) return;
|
|
2764
|
+
let i = n.getChild("reactions", H.reactions), a = i?.attrs.id;
|
|
2765
|
+
if (!i || !a) return;
|
|
2766
|
+
let o = [...new Set(i.getChildren("reaction").map((e) => e.text().trim()).filter((e) => e && e.length <= 16))].slice(0, 5);
|
|
2767
|
+
if (r) {
|
|
2768
|
+
let e = (n.attrs.from ?? "").split("/")[1] ?? "";
|
|
2769
|
+
return e ? {
|
|
2770
|
+
peer: r,
|
|
2771
|
+
target: a,
|
|
2772
|
+
user: e,
|
|
2773
|
+
emojis: o
|
|
2774
|
+
} : void 0;
|
|
2775
|
+
}
|
|
2776
|
+
if (n.attrs.type !== "chat") return;
|
|
2777
|
+
let s = U(n.attrs.from), c = s === this.me || !n.attrs.from, l = W(c ? U(n.attrs.to) : s);
|
|
2778
|
+
return l ? {
|
|
2779
|
+
peer: l,
|
|
2780
|
+
target: a,
|
|
2781
|
+
user: c ? this.cfg.username : W(s),
|
|
2782
|
+
emojis: o
|
|
2783
|
+
} : void 0;
|
|
2784
|
+
}
|
|
2785
|
+
toMessage(e, t, n) {
|
|
2786
|
+
let r = e.getChild("event", H.pubsubEvent);
|
|
2787
|
+
if (r && r.getChild("items")?.attrs.node === H.mucsubMessages) {
|
|
2788
|
+
let i = U(e.attrs.from);
|
|
2789
|
+
if (!this.isGroup(i)) return;
|
|
2790
|
+
let a = xn(r);
|
|
2791
|
+
if (!a || U(a.attrs.from) !== i) return;
|
|
2792
|
+
let o = (a.attrs.from ?? "").split("/")[1] ?? "", s = a.getChildText("body");
|
|
2793
|
+
return s == null ? void 0 : {
|
|
2794
|
+
id: a.getChild("origin-id", H.sid)?.attrs.id ?? t ?? a.getChild("stanza-id", H.sid)?.attrs.id ?? a.attrs.id ?? crypto.randomUUID(),
|
|
2795
|
+
oid: a.getChild("origin-id", H.sid)?.attrs.id ?? a.attrs.id,
|
|
2796
|
+
from: i,
|
|
2797
|
+
to: this.cfg.username,
|
|
2798
|
+
body: s,
|
|
2799
|
+
ts: bn(a) !== n && a.getChild("delay", H.delay) ? bn(a) : n,
|
|
2800
|
+
mine: o === this.cfg.username,
|
|
2801
|
+
oob: a.getChild("x", H.oob)?.getChildText("url") ?? void 0,
|
|
2802
|
+
room: i,
|
|
2803
|
+
nick: o
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2806
|
+
let i = e.getChildText("body");
|
|
2807
|
+
if (i == null) return;
|
|
2808
|
+
let a = U(e.attrs.from);
|
|
2809
|
+
if (e.attrs.type === "groupchat") {
|
|
2810
|
+
if (!this.isGroup(a)) return;
|
|
2811
|
+
let r = (e.attrs.from ?? "").split("/")[1] ?? "";
|
|
2812
|
+
return {
|
|
2813
|
+
id: t ?? e.getChild("origin-id", H.sid)?.attrs.id ?? e.attrs.id ?? crypto.randomUUID(),
|
|
2814
|
+
oid: e.getChild("origin-id", H.sid)?.attrs.id ?? e.attrs.id,
|
|
2815
|
+
from: a,
|
|
2816
|
+
to: this.cfg.username,
|
|
2817
|
+
body: i,
|
|
2818
|
+
ts: n,
|
|
2819
|
+
mine: r === this.cfg.username,
|
|
2820
|
+
oob: e.getChild("x", H.oob)?.getChildText("url") ?? void 0,
|
|
2821
|
+
room: a,
|
|
2822
|
+
nick: r
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
if (e.attrs.type !== "chat") return;
|
|
2826
|
+
let o = a === this.me;
|
|
2827
|
+
return {
|
|
2828
|
+
id: t ?? e.getChild("origin-id", H.sid)?.attrs.id ?? e.attrs.id ?? crypto.randomUUID(),
|
|
2829
|
+
oid: e.getChild("origin-id", H.sid)?.attrs.id ?? e.attrs.id,
|
|
2830
|
+
from: W(a),
|
|
2831
|
+
to: W(U(e.attrs.to)),
|
|
2832
|
+
body: i,
|
|
2833
|
+
ts: n,
|
|
2834
|
+
mine: o,
|
|
2835
|
+
oob: e.getChild("x", H.oob)?.getChildText("url") ?? void 0
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
}, U = (e = "") => e.split("/")[0], yn = (e) => e.name === "SASLError" || e.condition === "not-authorized", W = (e = "") => e.split("@")[0], bn = (e) => {
|
|
2839
|
+
let t = e?.getChild("delay", H.delay)?.attrs.stamp;
|
|
2840
|
+
return t ? Date.parse(t) : Date.now();
|
|
2841
|
+
};
|
|
2842
|
+
function xn(e) {
|
|
2843
|
+
for (let t of e.children) {
|
|
2844
|
+
if (typeof t == "string") continue;
|
|
2845
|
+
if (t.name === "message") return t;
|
|
2846
|
+
let e = xn(t);
|
|
2847
|
+
if (e) return e;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
//#endregion
|
|
2851
|
+
//#region src/sound.ts
|
|
2852
|
+
var G;
|
|
2853
|
+
function Sn() {
|
|
2854
|
+
try {
|
|
2855
|
+
G ??= new AudioContext(), G.state === "suspended" && G.resume();
|
|
2856
|
+
let e = G.currentTime;
|
|
2857
|
+
for (let [t, n, r] of [[
|
|
2858
|
+
880,
|
|
2859
|
+
0,
|
|
2860
|
+
.09
|
|
2861
|
+
], [
|
|
2862
|
+
1174.7,
|
|
2863
|
+
.1,
|
|
2864
|
+
.16
|
|
2865
|
+
]]) {
|
|
2866
|
+
let i = G.createOscillator(), a = G.createGain();
|
|
2867
|
+
i.type = "sine", i.frequency.value = t, a.gain.setValueAtTime(1e-4, e + n), a.gain.exponentialRampToValueAtTime(.12, e + n + .01), a.gain.exponentialRampToValueAtTime(1e-4, e + n + r), i.connect(a).connect(G.destination), i.start(e + n), i.stop(e + n + r + .02);
|
|
2868
|
+
}
|
|
2869
|
+
} catch {}
|
|
2870
|
+
}
|
|
2871
|
+
//#endregion
|
|
2872
|
+
//#region node_modules/zustand/esm/vanilla.mjs
|
|
2873
|
+
var Cn = (e) => {
|
|
2874
|
+
let t, n = /* @__PURE__ */ new Set(), r = (e, r) => {
|
|
2875
|
+
let i = typeof e == "function" ? e(t) : e;
|
|
2876
|
+
if (!Object.is(i, t)) {
|
|
2877
|
+
let e = t;
|
|
2878
|
+
t = r ?? (typeof i != "object" || !i) ? i : Object.assign({}, t, i), n.forEach((n) => n(t, e));
|
|
2879
|
+
}
|
|
2880
|
+
}, i = () => t, a = {
|
|
2881
|
+
setState: r,
|
|
2882
|
+
getState: i,
|
|
2883
|
+
getInitialState: () => o,
|
|
2884
|
+
subscribe: (e) => (n.add(e), () => n.delete(e)),
|
|
2885
|
+
destroy: () => {
|
|
2886
|
+
n.clear();
|
|
2887
|
+
}
|
|
2888
|
+
}, o = t = e(r, i, a);
|
|
2889
|
+
return a;
|
|
2890
|
+
}, wn = (e) => e ? Cn(e) : Cn, { useDebugValue: Tn } = e, { useSyncExternalStoreWithSelector: En } = l, Dn = (e) => e;
|
|
2891
|
+
function On(e, t = Dn, n) {
|
|
2892
|
+
let r = En(e.subscribe, e.getState, e.getServerState || e.getInitialState, t, n);
|
|
2893
|
+
return Tn(r), r;
|
|
2894
|
+
}
|
|
2895
|
+
var kn = (e) => {
|
|
2896
|
+
let t = typeof e == "function" ? wn(e) : e, n = (e, n) => On(t, e, n);
|
|
2897
|
+
return Object.assign(n, t), n;
|
|
2898
|
+
}, An = (e) => e ? kn(e) : kn, jn = (e) => e.room ?? (e.mine ? e.to : e.from), K = (e, t) => ({
|
|
2899
|
+
peer: e,
|
|
2900
|
+
kind: t && e.endsWith("@" + t) ? "group" : "chat",
|
|
2901
|
+
messages: [],
|
|
2902
|
+
unread: 0,
|
|
2903
|
+
typing: !1,
|
|
2904
|
+
loaded: !1,
|
|
2905
|
+
complete: !1
|
|
2906
|
+
}), Mn = (e, t, n, r) => {
|
|
2907
|
+
if (e.includes(t)) return e;
|
|
2908
|
+
let i = [t, ...e];
|
|
2909
|
+
if (i.length <= n) return i;
|
|
2910
|
+
let a = [...i].reverse().find((e) => e !== r);
|
|
2911
|
+
return i.filter((e) => e !== a);
|
|
2912
|
+
}, q = An((e, t) => ({
|
|
2913
|
+
me: "",
|
|
2914
|
+
mucHost: "",
|
|
2915
|
+
status: "connecting",
|
|
2916
|
+
contacts: {},
|
|
2917
|
+
online: {},
|
|
2918
|
+
mobile: {},
|
|
2919
|
+
conversations: {},
|
|
2920
|
+
order: [],
|
|
2921
|
+
open: null,
|
|
2922
|
+
picker: !1,
|
|
2923
|
+
push: "unavailable",
|
|
2924
|
+
enablePush: () => {},
|
|
2925
|
+
maxHeads: 5,
|
|
2926
|
+
newChatButton: !0,
|
|
2927
|
+
setStatus: (t, n) => e({
|
|
2928
|
+
status: t,
|
|
2929
|
+
error: n
|
|
2930
|
+
}),
|
|
2931
|
+
reset: () => e({
|
|
2932
|
+
status: "connecting",
|
|
2933
|
+
error: void 0,
|
|
2934
|
+
contacts: {},
|
|
2935
|
+
online: {},
|
|
2936
|
+
mobile: {},
|
|
2937
|
+
conversations: {},
|
|
2938
|
+
order: [],
|
|
2939
|
+
open: null,
|
|
2940
|
+
picker: !1
|
|
2941
|
+
}),
|
|
2942
|
+
setContacts: (t) => e({ contacts: Object.fromEntries(t.filter((e) => e?.username).map((e) => [e.username, {
|
|
2943
|
+
...e,
|
|
2944
|
+
name: e.name || e.username
|
|
2945
|
+
}])) }),
|
|
2946
|
+
setMobile: (t) => e({ mobile: Object.fromEntries(t.map((e) => [e, !0])) }),
|
|
2947
|
+
setOnline: (t, n) => e((e) => e.online[t] === n ? {} : { online: {
|
|
2948
|
+
...e.online,
|
|
2949
|
+
[t]: n
|
|
2950
|
+
} }),
|
|
2951
|
+
ensure: (n) => {
|
|
2952
|
+
let r = t().conversations[n];
|
|
2953
|
+
if (r) return r;
|
|
2954
|
+
let i = K(n, t().mucHost);
|
|
2955
|
+
return e((e) => ({ conversations: {
|
|
2956
|
+
...e.conversations,
|
|
2957
|
+
[n]: i
|
|
2958
|
+
} })), i;
|
|
2959
|
+
},
|
|
2960
|
+
setGroup: (t, n, r, i, a) => e((e) => {
|
|
2961
|
+
let o = e.conversations[t] ?? K(t, e.mucHost);
|
|
2962
|
+
return { conversations: {
|
|
2963
|
+
...e.conversations,
|
|
2964
|
+
[t]: {
|
|
2965
|
+
...o,
|
|
2966
|
+
kind: "group",
|
|
2967
|
+
name: n,
|
|
2968
|
+
members: r,
|
|
2969
|
+
avatar: i ?? o.avatar,
|
|
2970
|
+
owner: a ?? o.owner
|
|
2971
|
+
}
|
|
2972
|
+
} };
|
|
2973
|
+
}),
|
|
2974
|
+
seed: (t, n) => e((e) => {
|
|
2975
|
+
let r = { ...e.conversations };
|
|
2976
|
+
for (let i of t) {
|
|
2977
|
+
let t = jn(i);
|
|
2978
|
+
if (!t || t === n) continue;
|
|
2979
|
+
let a = r[t] ?? K(t, e.mucHost);
|
|
2980
|
+
if (a.messages.some((e) => e.id === i.id)) continue;
|
|
2981
|
+
if (a.loaded) {
|
|
2982
|
+
r[t] = {
|
|
2983
|
+
...a,
|
|
2984
|
+
messages: [...a.messages, i].sort((e, t) => e.ts - t.ts)
|
|
2985
|
+
};
|
|
2986
|
+
continue;
|
|
2987
|
+
}
|
|
2988
|
+
let o = a.messages[a.messages.length - 1];
|
|
2989
|
+
r[t] = {
|
|
2990
|
+
...a,
|
|
2991
|
+
messages: !o || o.ts <= i.ts ? [i] : a.messages
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
return { conversations: r };
|
|
2995
|
+
}),
|
|
2996
|
+
addMessage: (t, n, r) => e((e) => {
|
|
2997
|
+
let i = e.conversations[t] ?? K(t, e.mucHost), a = i.messages.filter((e) => e.id !== n.id && !(e.pending && n.mine && e.body === n.body && e.oob === n.oob)), o = a.length;
|
|
2998
|
+
for (; o > 0 && a[o - 1].ts > n.ts;) o--;
|
|
2999
|
+
a.splice(o, 0, n);
|
|
3000
|
+
let s = e.open === t, c = r?.live && !n.mine && !s ? i.unread + 1 : i.unread, l = Mn(e.order, t, e.maxHeads, e.open);
|
|
3001
|
+
return {
|
|
3002
|
+
conversations: {
|
|
3003
|
+
...e.conversations,
|
|
3004
|
+
[t]: {
|
|
3005
|
+
...i,
|
|
3006
|
+
messages: a,
|
|
3007
|
+
unread: c,
|
|
3008
|
+
typing: n.mine ? i.typing : !1
|
|
3009
|
+
}
|
|
3010
|
+
},
|
|
3011
|
+
order: l
|
|
3012
|
+
};
|
|
3013
|
+
}),
|
|
3014
|
+
prependHistory: (t, n, r, i) => e((e) => {
|
|
3015
|
+
let a = e.conversations[t] ?? K(t, e.mucHost), o = new Set(a.messages.map((e) => e.id)), s = [...n.filter((e) => !o.has(e.id)), ...a.messages].sort((e, t) => e.ts - t.ts);
|
|
3016
|
+
return { conversations: {
|
|
3017
|
+
...e.conversations,
|
|
3018
|
+
[t]: {
|
|
3019
|
+
...a,
|
|
3020
|
+
messages: s,
|
|
3021
|
+
loaded: !0,
|
|
3022
|
+
complete: r,
|
|
3023
|
+
oldest: i ?? a.oldest
|
|
3024
|
+
}
|
|
3025
|
+
} };
|
|
3026
|
+
}),
|
|
3027
|
+
applyReactions: (t) => e((e) => {
|
|
3028
|
+
if (!t.length) return {};
|
|
3029
|
+
let n = { ...e.conversations };
|
|
3030
|
+
for (let r of t) {
|
|
3031
|
+
let t = n[r.peer] ?? K(r.peer, e.mucHost), i = { ...t.reactions ?? {} }, a = { ...i[r.target] ?? {} };
|
|
3032
|
+
r.emojis.length ? a[r.user] = r.emojis : delete a[r.user], i[r.target] = a, n[r.peer] = {
|
|
3033
|
+
...t,
|
|
3034
|
+
reactions: i
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
return { conversations: n };
|
|
3038
|
+
}),
|
|
3039
|
+
setTyping: (t, n) => e((e) => e.conversations[t] ? { conversations: {
|
|
3040
|
+
...e.conversations,
|
|
3041
|
+
[t]: {
|
|
3042
|
+
...e.conversations[t],
|
|
3043
|
+
typing: n
|
|
3044
|
+
}
|
|
3045
|
+
} } : {}),
|
|
3046
|
+
openChat: (t) => e((e) => ({
|
|
3047
|
+
conversations: e.conversations[t] ? e.conversations : {
|
|
3048
|
+
...e.conversations,
|
|
3049
|
+
[t]: K(t, e.mucHost)
|
|
3050
|
+
},
|
|
3051
|
+
order: Mn(e.order, t, e.maxHeads, e.open),
|
|
3052
|
+
open: t,
|
|
3053
|
+
picker: !1
|
|
3054
|
+
})),
|
|
3055
|
+
closeChat: () => e({ open: null }),
|
|
3056
|
+
removeConversation: (t) => e((e) => {
|
|
3057
|
+
let n = { ...e.conversations };
|
|
3058
|
+
return delete n[t], {
|
|
3059
|
+
conversations: n,
|
|
3060
|
+
order: e.order.filter((e) => e !== t),
|
|
3061
|
+
open: e.open === t ? null : e.open
|
|
3062
|
+
};
|
|
3063
|
+
}),
|
|
3064
|
+
removeHead: (t) => e((e) => ({
|
|
3065
|
+
order: e.order.filter((e) => e !== t),
|
|
3066
|
+
open: e.open === t ? null : e.open
|
|
3067
|
+
})),
|
|
3068
|
+
markRead: (t) => e((e) => e.conversations[t] && e.conversations[t].unread ? { conversations: {
|
|
3069
|
+
...e.conversations,
|
|
3070
|
+
[t]: {
|
|
3071
|
+
...e.conversations[t],
|
|
3072
|
+
unread: 0
|
|
3073
|
+
}
|
|
3074
|
+
} } : {}),
|
|
3075
|
+
setPicker: (t) => e({ picker: t }),
|
|
3076
|
+
totalUnread: () => Object.values(t().conversations).reduce((e, t) => e + t.unread, 0)
|
|
3077
|
+
}));
|
|
3078
|
+
//#endregion
|
|
3079
|
+
//#region src/api.ts
|
|
3080
|
+
async function Nn(e, t, n) {
|
|
3081
|
+
let r = await fetch(`https://${e}/api${n}`, { headers: { Authorization: `Bearer ${t}` } });
|
|
3082
|
+
if (!r.ok) throw Error(`${n}: HTTP ${r.status}`);
|
|
3083
|
+
return await r.json();
|
|
3084
|
+
}
|
|
3085
|
+
async function Pn(e, t, n) {
|
|
3086
|
+
let r = await Nn(e, t, "/user/endpoints/all"), i = {};
|
|
3087
|
+
try {
|
|
3088
|
+
i = await Nn(e, t, "/user/all_avatars");
|
|
3089
|
+
} catch {}
|
|
3090
|
+
return Object.values(r).filter((e) => e.username && e.username !== n).map((e) => ({
|
|
3091
|
+
username: e.username,
|
|
3092
|
+
name: e.name || e.username,
|
|
3093
|
+
avatar: i[e.username],
|
|
3094
|
+
presence: e.mainPresence
|
|
3095
|
+
})).sort((e, t) => e.name.localeCompare(t.name));
|
|
3096
|
+
}
|
|
3097
|
+
async function Fn(e, t) {
|
|
3098
|
+
let n = await fetch(`https://${e}/chat-gw/push/mobile`, { headers: { Authorization: `Bearer ${t}` } });
|
|
3099
|
+
if (!n.ok) throw Error(`push/mobile: HTTP ${n.status}`);
|
|
3100
|
+
return (await n.json()).users;
|
|
3101
|
+
}
|
|
3102
|
+
async function In(e, t, n) {
|
|
3103
|
+
let r = await fetch(`https://${e}/chat-gw/conversations/${encodeURIComponent(n)}`, {
|
|
3104
|
+
method: "DELETE",
|
|
3105
|
+
headers: { Authorization: `Bearer ${t}` }
|
|
3106
|
+
});
|
|
3107
|
+
if (!r.ok) throw Error(`delete: HTTP ${r.status}`);
|
|
3108
|
+
}
|
|
3109
|
+
//#endregion
|
|
3110
|
+
//#region src/push.ts
|
|
3111
|
+
var Ln = (e) => {
|
|
3112
|
+
let t = atob((e + "=".repeat((4 - e.length % 4) % 4)).replace(/-/g, "+").replace(/_/g, "/"));
|
|
3113
|
+
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
3114
|
+
}, Rn = !1;
|
|
3115
|
+
function zn() {
|
|
3116
|
+
Rn || (Rn = !0, navigator.serviceWorker.addEventListener("message", (e) => {
|
|
3117
|
+
e.data?.type === "chat-island-open" && typeof e.data.username == "string" && window.dispatchEvent(new CustomEvent("chat-island-open", { detail: { username: e.data.username } }));
|
|
3118
|
+
}));
|
|
3119
|
+
}
|
|
3120
|
+
async function Bn(e, t) {
|
|
3121
|
+
if (!("serviceWorker" in navigator) || !("PushManager" in window)) throw Error("push not supported by this browser");
|
|
3122
|
+
if (Notification.permission === "denied" || Notification.permission !== "granted" && await Notification.requestPermission() !== "granted") return null;
|
|
3123
|
+
let n = `https://${e.host}/chat-gw`, r = await fetch(`${n}/push/vapid`);
|
|
3124
|
+
if (!r.ok) throw Error(`vapid: HTTP ${r.status}`);
|
|
3125
|
+
let i = await r.json(), a = await navigator.serviceWorker.register(t);
|
|
3126
|
+
await navigator.serviceWorker.ready;
|
|
3127
|
+
let o = await a.pushManager.getSubscription() ?? await a.pushManager.subscribe({
|
|
3128
|
+
userVisibleOnly: !0,
|
|
3129
|
+
applicationServerKey: Ln(i.publicKey)
|
|
3130
|
+
}), s = await fetch(`${n}/push/web`, {
|
|
3131
|
+
method: "POST",
|
|
3132
|
+
headers: {
|
|
3133
|
+
"Content-Type": "application/json",
|
|
3134
|
+
Authorization: `Bearer ${e.token}`
|
|
3135
|
+
},
|
|
3136
|
+
body: JSON.stringify(o.toJSON())
|
|
3137
|
+
});
|
|
3138
|
+
if (!s.ok) throw Error(`push/web: HTTP ${s.status} ${(await s.text()).slice(0, 120)}`);
|
|
3139
|
+
let c = await s.json();
|
|
3140
|
+
return zn(), {
|
|
3141
|
+
node: c.node,
|
|
3142
|
+
service: c.service
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
//#endregion
|
|
3146
|
+
//#region src/events.ts
|
|
3147
|
+
function J(e, t) {
|
|
3148
|
+
window.dispatchEvent(new CustomEvent(e, { detail: t }));
|
|
3149
|
+
}
|
|
3150
|
+
function Y(e, t) {
|
|
3151
|
+
let n = (e) => t(e.detail);
|
|
3152
|
+
return window.addEventListener(e, n), () => window.removeEventListener(e, n);
|
|
3153
|
+
}
|
|
3154
|
+
//#endregion
|
|
3155
|
+
//#region src/components/Avatar.tsx
|
|
3156
|
+
var Vn = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
|
|
3157
|
+
function X({ contact: e, username: t, size: n = 40 }) {
|
|
3158
|
+
let r = e?.name || t, i = {
|
|
3159
|
+
width: n,
|
|
3160
|
+
height: n,
|
|
3161
|
+
fontSize: n / 2.6
|
|
3162
|
+
};
|
|
3163
|
+
return e?.avatar ? /* @__PURE__ */ d("img", {
|
|
3164
|
+
src: e.avatar,
|
|
3165
|
+
alt: r,
|
|
3166
|
+
style: i,
|
|
3167
|
+
className: "ci-rounded-full ci-object-cover ci-shrink-0"
|
|
3168
|
+
}) : /* @__PURE__ */ d("div", {
|
|
3169
|
+
style: i,
|
|
3170
|
+
className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900",
|
|
3171
|
+
children: Vn(r)
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
function Hn({ online: e, presence: t, mobile: n }) {
|
|
3175
|
+
return /* @__PURE__ */ d("span", { className: `ci-absolute ci-bottom-0 ci-right-0 ci-w-3 ci-h-3 ci-rounded-full ci-ring-2 ci-ring-gray-50 dark:ci-ring-gray-950 ${t === "dnd" || t === "busy" ? "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark" : e || n ? "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark" : "ci-bg-gray-400 dark:ci-bg-gray-600"}` });
|
|
3176
|
+
}
|
|
3177
|
+
function Un({ name: e, size: t = 40, avatar: n }) {
|
|
3178
|
+
let r = {
|
|
3179
|
+
width: t,
|
|
3180
|
+
height: t,
|
|
3181
|
+
fontSize: t / 2.8
|
|
3182
|
+
};
|
|
3183
|
+
return n ? /* @__PURE__ */ d("img", {
|
|
3184
|
+
src: n,
|
|
3185
|
+
alt: e,
|
|
3186
|
+
style: r,
|
|
3187
|
+
className: "ci-rounded-full ci-object-cover ci-shrink-0"
|
|
3188
|
+
}) : /* @__PURE__ */ d("div", {
|
|
3189
|
+
style: r,
|
|
3190
|
+
className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-iconSecondary dark:ci-bg-iconSecondaryDark ci-text-white",
|
|
3191
|
+
children: Vn(e || "G")
|
|
3192
|
+
});
|
|
3193
|
+
}
|
|
3194
|
+
//#endregion
|
|
3195
|
+
//#region src/components/Button.tsx
|
|
3196
|
+
var Wn = "ci-flex ci-content-center ci-items-center ci-justify-center ci-tracking-wide ci-duration-200 ci-transform ci-outline-none focus:ci-ring-2 focus:ci-z-20 focus:ci-ring-offset-2 disabled:ci-opacity-40 disabled:ci-cursor-not-allowed ci-border ci-border-transparent focus:ci-ring-offset-white dark:focus:ci-ring-offset-black ci-text-sm ci-leading-4 ci-transition-colors ci-shrink-0 ci-font-light", Gn = {
|
|
3197
|
+
default: "ci-bg-phoneIslandActive dark:ci-bg-phoneIslandActiveDark hover:ci-bg-gray-500 dark:hover:ci-bg-gray-50 focus:ci-ring-emerald-500 dark:focus:ci-ring-emerald-300 ci-text-primaryInvert dark:ci-text-primaryInvertDark ci-h-12 ci-w-12 ci-rounded-full",
|
|
3198
|
+
green: "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark hover:ci-bg-phoneIslandCallHover dark:hover:ci-bg-phoneIslandCallHoverDark focus:ci-ring-green-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
|
|
3199
|
+
red: "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark hover:ci-bg-phoneIslandCloseHover dark:hover:ci-bg-phoneIslandCloseHoverDark focus:ci-ring-emerald-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
|
|
3200
|
+
neutral: "ci-bg-transparent enabled:hover:ci-bg-gray-500 enabled:hover:ci-border-gray-500 ci-border ci-border-gray-700 focus:ci-ring-0 ci-text-secondaryNeutral dark:ci-text-secondaryNeutralDark ci-h-12 ci-w-12 ci-rounded-full",
|
|
3201
|
+
transparent: "ci-bg-transparent dark:enabled:hover:ci-bg-gray-700/30 enabled:hover:ci-bg-gray-300/70 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500 ci-text-secondaryNeutral dark:ci-text-secondaryNeutralDark ci-h-12 ci-w-12 ci-rounded-full",
|
|
3202
|
+
call: "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark hover:ci-bg-phoneIslandCallHover dark:hover:ci-bg-phoneIslandCallHoverDark focus:ci-ring-green-500 ci-text-white dark:ci-text-gray-950 ci-h-8 ci-w-8 ci-rounded-full",
|
|
3203
|
+
small: "ci-bg-transparent dark:hover:ci-bg-gray-600 hover:ci-bg-gray-300 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500 ci-text-gray-700 dark:ci-text-white ci-h-8 ci-w-8 ci-rounded"
|
|
3204
|
+
};
|
|
3205
|
+
function Z({ variant: e, className: t = "", children: n, ...r }) {
|
|
3206
|
+
return /* @__PURE__ */ d("button", {
|
|
3207
|
+
type: "button",
|
|
3208
|
+
"aria-label": r["aria-label"] ?? r.title,
|
|
3209
|
+
className: `${Wn} ${Gn[e]} ${t}`,
|
|
3210
|
+
...r,
|
|
3211
|
+
children: n
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
var Q = {
|
|
3215
|
+
chat: /* @__PURE__ */ d("svg", {
|
|
3216
|
+
width: "22",
|
|
3217
|
+
height: "22",
|
|
3218
|
+
viewBox: "0 0 24 24",
|
|
3219
|
+
fill: "none",
|
|
3220
|
+
stroke: "currentColor",
|
|
3221
|
+
strokeWidth: "2",
|
|
3222
|
+
strokeLinecap: "round",
|
|
3223
|
+
strokeLinejoin: "round",
|
|
3224
|
+
children: /* @__PURE__ */ d("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
|
|
3225
|
+
}),
|
|
3226
|
+
bell: /* @__PURE__ */ d("svg", {
|
|
3227
|
+
width: "18",
|
|
3228
|
+
height: "18",
|
|
3229
|
+
viewBox: "0 0 24 24",
|
|
3230
|
+
fill: "none",
|
|
3231
|
+
stroke: "currentColor",
|
|
3232
|
+
strokeWidth: "2",
|
|
3233
|
+
strokeLinecap: "round",
|
|
3234
|
+
strokeLinejoin: "round",
|
|
3235
|
+
children: /* @__PURE__ */ d("path", { d: "M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9M13.73 21a2 2 0 0 1-3.46 0" })
|
|
3236
|
+
}),
|
|
3237
|
+
clip: /* @__PURE__ */ d("svg", {
|
|
3238
|
+
width: "20",
|
|
3239
|
+
height: "20",
|
|
3240
|
+
viewBox: "0 0 24 24",
|
|
3241
|
+
fill: "none",
|
|
3242
|
+
stroke: "currentColor",
|
|
3243
|
+
strokeWidth: "2",
|
|
3244
|
+
strokeLinecap: "round",
|
|
3245
|
+
strokeLinejoin: "round",
|
|
3246
|
+
children: /* @__PURE__ */ d("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
|
|
3247
|
+
}),
|
|
3248
|
+
send: /* @__PURE__ */ d("svg", {
|
|
3249
|
+
width: "20",
|
|
3250
|
+
height: "20",
|
|
3251
|
+
viewBox: "0 0 24 24",
|
|
3252
|
+
fill: "none",
|
|
3253
|
+
stroke: "currentColor",
|
|
3254
|
+
strokeWidth: "2",
|
|
3255
|
+
strokeLinecap: "round",
|
|
3256
|
+
strokeLinejoin: "round",
|
|
3257
|
+
children: /* @__PURE__ */ d("path", { d: "M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" })
|
|
3258
|
+
}),
|
|
3259
|
+
phone: /* @__PURE__ */ d("svg", {
|
|
3260
|
+
width: "15",
|
|
3261
|
+
height: "15",
|
|
3262
|
+
viewBox: "0 0 24 24",
|
|
3263
|
+
fill: "none",
|
|
3264
|
+
stroke: "currentColor",
|
|
3265
|
+
strokeWidth: "2",
|
|
3266
|
+
strokeLinecap: "round",
|
|
3267
|
+
strokeLinejoin: "round",
|
|
3268
|
+
children: /* @__PURE__ */ d("path", { d: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z" })
|
|
3269
|
+
}),
|
|
3270
|
+
mic: /* @__PURE__ */ f("svg", {
|
|
3271
|
+
width: "20",
|
|
3272
|
+
height: "20",
|
|
3273
|
+
viewBox: "0 0 24 24",
|
|
3274
|
+
fill: "none",
|
|
3275
|
+
stroke: "currentColor",
|
|
3276
|
+
strokeWidth: "2",
|
|
3277
|
+
strokeLinecap: "round",
|
|
3278
|
+
strokeLinejoin: "round",
|
|
3279
|
+
children: [/* @__PURE__ */ d("path", { d: "M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z" }), /* @__PURE__ */ d("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2M12 19v4M8 23h8" })]
|
|
3280
|
+
}),
|
|
3281
|
+
camera: /* @__PURE__ */ f("svg", {
|
|
3282
|
+
width: "18",
|
|
3283
|
+
height: "18",
|
|
3284
|
+
viewBox: "0 0 24 24",
|
|
3285
|
+
fill: "none",
|
|
3286
|
+
stroke: "currentColor",
|
|
3287
|
+
strokeWidth: "2",
|
|
3288
|
+
strokeLinecap: "round",
|
|
3289
|
+
strokeLinejoin: "round",
|
|
3290
|
+
children: [/* @__PURE__ */ d("path", { d: "M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" }), /* @__PURE__ */ d("circle", {
|
|
3291
|
+
cx: "12",
|
|
3292
|
+
cy: "13",
|
|
3293
|
+
r: "4"
|
|
3294
|
+
})]
|
|
3295
|
+
}),
|
|
3296
|
+
trash: /* @__PURE__ */ d("svg", {
|
|
3297
|
+
width: "16",
|
|
3298
|
+
height: "16",
|
|
3299
|
+
viewBox: "0 0 24 24",
|
|
3300
|
+
fill: "none",
|
|
3301
|
+
stroke: "currentColor",
|
|
3302
|
+
strokeWidth: "2",
|
|
3303
|
+
strokeLinecap: "round",
|
|
3304
|
+
strokeLinejoin: "round",
|
|
3305
|
+
children: /* @__PURE__ */ d("path", { d: "M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6" })
|
|
3306
|
+
}),
|
|
3307
|
+
minus: /* @__PURE__ */ d("svg", {
|
|
3308
|
+
width: "16",
|
|
3309
|
+
height: "16",
|
|
3310
|
+
viewBox: "0 0 24 24",
|
|
3311
|
+
fill: "none",
|
|
3312
|
+
stroke: "currentColor",
|
|
3313
|
+
strokeWidth: "2",
|
|
3314
|
+
strokeLinecap: "round",
|
|
3315
|
+
children: /* @__PURE__ */ d("path", { d: "M5 12h14" })
|
|
3316
|
+
}),
|
|
3317
|
+
close: /* @__PURE__ */ d("svg", {
|
|
3318
|
+
width: "16",
|
|
3319
|
+
height: "16",
|
|
3320
|
+
viewBox: "0 0 24 24",
|
|
3321
|
+
fill: "none",
|
|
3322
|
+
stroke: "currentColor",
|
|
3323
|
+
strokeWidth: "2",
|
|
3324
|
+
strokeLinecap: "round",
|
|
3325
|
+
children: /* @__PURE__ */ d("path", { d: "M18 6L6 18M6 6l12 12" })
|
|
3326
|
+
}),
|
|
3327
|
+
smile: /* @__PURE__ */ f("svg", {
|
|
3328
|
+
width: "20",
|
|
3329
|
+
height: "20",
|
|
3330
|
+
viewBox: "0 0 24 24",
|
|
3331
|
+
fill: "none",
|
|
3332
|
+
stroke: "currentColor",
|
|
3333
|
+
strokeWidth: "2",
|
|
3334
|
+
strokeLinecap: "round",
|
|
3335
|
+
strokeLinejoin: "round",
|
|
3336
|
+
children: [/* @__PURE__ */ d("circle", {
|
|
3337
|
+
cx: "12",
|
|
3338
|
+
cy: "12",
|
|
3339
|
+
r: "10"
|
|
3340
|
+
}), /* @__PURE__ */ d("path", { d: "M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01" })]
|
|
3341
|
+
}),
|
|
3342
|
+
react: /* @__PURE__ */ f("svg", {
|
|
3343
|
+
width: "16",
|
|
3344
|
+
height: "16",
|
|
3345
|
+
viewBox: "0 0 24 24",
|
|
3346
|
+
fill: "none",
|
|
3347
|
+
stroke: "currentColor",
|
|
3348
|
+
strokeWidth: "2",
|
|
3349
|
+
strokeLinecap: "round",
|
|
3350
|
+
strokeLinejoin: "round",
|
|
3351
|
+
children: [/* @__PURE__ */ d("path", { d: "M20.5 11A8.5 8.5 0 1 1 13 3.5" }), /* @__PURE__ */ d("path", { d: "M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01M19 2v6M16 5h6" })]
|
|
3352
|
+
}),
|
|
3353
|
+
search: /* @__PURE__ */ f("svg", {
|
|
3354
|
+
width: "16",
|
|
3355
|
+
height: "16",
|
|
3356
|
+
viewBox: "0 0 24 24",
|
|
3357
|
+
fill: "none",
|
|
3358
|
+
stroke: "currentColor",
|
|
3359
|
+
strokeWidth: "2",
|
|
3360
|
+
strokeLinecap: "round",
|
|
3361
|
+
children: [/* @__PURE__ */ d("circle", {
|
|
3362
|
+
cx: "11",
|
|
3363
|
+
cy: "11",
|
|
3364
|
+
r: "8"
|
|
3365
|
+
}), /* @__PURE__ */ d("path", { d: "M21 21l-4.35-4.35" })]
|
|
3366
|
+
})
|
|
3367
|
+
};
|
|
3368
|
+
//#endregion
|
|
3369
|
+
//#region src/components/Dock.tsx
|
|
3370
|
+
function Kn({ onDragStart: e, pushButton: t = !0 }) {
|
|
3371
|
+
let { order: n, open: r, conversations: i, contacts: a, online: o, mobile: s, openChat: c, removeHead: l, picker: p, setPicker: m, status: h, push: g, enablePush: _, newChatButton: v } = q(w((e) => ({
|
|
3372
|
+
order: e.order,
|
|
3373
|
+
open: e.open,
|
|
3374
|
+
conversations: e.conversations,
|
|
3375
|
+
contacts: e.contacts,
|
|
3376
|
+
online: e.online,
|
|
3377
|
+
mobile: e.mobile,
|
|
3378
|
+
openChat: e.openChat,
|
|
3379
|
+
removeHead: e.removeHead,
|
|
3380
|
+
picker: e.picker,
|
|
3381
|
+
setPicker: e.setPicker,
|
|
3382
|
+
status: e.status,
|
|
3383
|
+
push: e.push,
|
|
3384
|
+
enablePush: e.enablePush,
|
|
3385
|
+
newChatButton: e.newChatButton
|
|
3386
|
+
})));
|
|
3387
|
+
return /* @__PURE__ */ f("div", {
|
|
3388
|
+
className: "ci-flex ci-flex-col-reverse ci-items-center ci-gap-3 ci-mb-3 ci-cursor-grab active:ci-cursor-grabbing ci-touch-none",
|
|
3389
|
+
onPointerDown: e,
|
|
3390
|
+
children: [
|
|
3391
|
+
n.map((e) => {
|
|
3392
|
+
let t = i[e], n = r === e;
|
|
3393
|
+
return /* @__PURE__ */ f("div", {
|
|
3394
|
+
className: "ci-relative ci-group",
|
|
3395
|
+
children: [/* @__PURE__ */ f("button", {
|
|
3396
|
+
type: "button",
|
|
3397
|
+
title: t?.kind === "group" ? t.name ?? e : a[e]?.name ?? e,
|
|
3398
|
+
onClick: () => n ? q.getState().closeChat() : c(e),
|
|
3399
|
+
className: `ci-relative ci-rounded-full ci-shadow-lg ci-transition-transform hover:ci-scale-105 ci-ring-2 ci-border-0 ci-p-0 ci-bg-transparent ${n ? "ci-ring-iconSecondary dark:ci-ring-iconSecondaryDark" : "ci-ring-gray-50 dark:ci-ring-gray-950"}`,
|
|
3400
|
+
children: [t?.kind === "group" ? /* @__PURE__ */ d(Un, {
|
|
3401
|
+
name: t.name ?? e,
|
|
3402
|
+
size: 48,
|
|
3403
|
+
avatar: t.avatar
|
|
3404
|
+
}) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(X, {
|
|
3405
|
+
contact: a[e],
|
|
3406
|
+
username: e,
|
|
3407
|
+
size: 48
|
|
3408
|
+
}), /* @__PURE__ */ d(Hn, {
|
|
3409
|
+
online: o[e],
|
|
3410
|
+
presence: a[e]?.presence,
|
|
3411
|
+
mobile: s[e]
|
|
3412
|
+
})] }), t?.unread > 0 && /* @__PURE__ */ d("span", {
|
|
3413
|
+
className: "ci-absolute ci--top-1 ci--right-1 ci-min-w-5 ci-h-5 ci-px-1 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-text-white dark:ci-text-gray-950 ci-text-xs ci-font-medium ci-flex ci-items-center ci-justify-center",
|
|
3414
|
+
children: t.unread > 99 ? "99+" : t.unread
|
|
3415
|
+
})]
|
|
3416
|
+
}), /* @__PURE__ */ d("button", {
|
|
3417
|
+
type: "button",
|
|
3418
|
+
"aria-label": `Remove ${t?.kind === "group" ? t.name ?? e : a[e]?.name ?? e} from the dock`,
|
|
3419
|
+
onClick: () => l(e),
|
|
3420
|
+
className: "ci-absolute ci--top-1 ci--left-1 ci-hidden group-hover:ci-flex group-focus-within:ci-flex ci-w-5 ci-h-5 ci-rounded-full ci-border-0 ci-p-0 ci-bg-gray-700 dark:ci-bg-gray-300 ci-text-gray-50 dark:ci-text-gray-900 ci-items-center ci-justify-center",
|
|
3421
|
+
children: Q.close
|
|
3422
|
+
})]
|
|
3423
|
+
}, e);
|
|
3424
|
+
}),
|
|
3425
|
+
v && /* @__PURE__ */ f(Z, {
|
|
3426
|
+
variant: "default",
|
|
3427
|
+
title: h === "online" ? "New chat" : `Chat ${h}`,
|
|
3428
|
+
onClick: () => m(!p),
|
|
3429
|
+
className: "ci-relative ci-shadow-lg",
|
|
3430
|
+
children: [Q.chat, h !== "online" && /* @__PURE__ */ d("span", { className: "ci-absolute ci-bottom-0 ci-right-0 ci-w-3 ci-h-3 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-ring-2 ci-ring-gray-50 dark:ci-ring-gray-950" })]
|
|
3431
|
+
}),
|
|
3432
|
+
t && g === "ask" && h === "online" && /* @__PURE__ */ d(Z, {
|
|
3433
|
+
variant: "neutral",
|
|
3434
|
+
title: "Enable notifications when the tab is closed",
|
|
3435
|
+
onClick: _,
|
|
3436
|
+
className: "ci-shadow-lg ci-bg-gray-50 dark:ci-bg-gray-950",
|
|
3437
|
+
children: Q.bell
|
|
3438
|
+
})
|
|
3439
|
+
]
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
//#endregion
|
|
3443
|
+
//#region src/shortcodes.ts
|
|
3444
|
+
var qn = {
|
|
3445
|
+
"+1": "👍",
|
|
3446
|
+
thumbsup: "👍",
|
|
3447
|
+
"-1": "👎",
|
|
3448
|
+
thumbsdown: "👎",
|
|
3449
|
+
ok_hand: "👌",
|
|
3450
|
+
clap: "👏",
|
|
3451
|
+
pray: "🙏",
|
|
3452
|
+
wave: "👋",
|
|
3453
|
+
raised_hands: "🙌",
|
|
3454
|
+
muscle: "💪",
|
|
3455
|
+
point_up: "☝️",
|
|
3456
|
+
point_right: "👉",
|
|
3457
|
+
point_left: "👈",
|
|
3458
|
+
point_down: "👇",
|
|
3459
|
+
v: "✌️",
|
|
3460
|
+
crossed_fingers: "🤞",
|
|
3461
|
+
handshake: "🤝",
|
|
3462
|
+
eyes: "👀",
|
|
3463
|
+
facepalm: "🤦",
|
|
3464
|
+
shrug: "🤷",
|
|
3465
|
+
raising_hand: "🙋",
|
|
3466
|
+
heart: "❤️",
|
|
3467
|
+
broken_heart: "💔",
|
|
3468
|
+
orange_heart: "🧡",
|
|
3469
|
+
yellow_heart: "💛",
|
|
3470
|
+
green_heart: "💚",
|
|
3471
|
+
blue_heart: "💙",
|
|
3472
|
+
purple_heart: "💜",
|
|
3473
|
+
black_heart: "🖤",
|
|
3474
|
+
white_heart: "🤍",
|
|
3475
|
+
sparkling_heart: "💖",
|
|
3476
|
+
two_hearts: "💕",
|
|
3477
|
+
100: "💯",
|
|
3478
|
+
fire: "🔥",
|
|
3479
|
+
star: "⭐",
|
|
3480
|
+
star2: "🌟",
|
|
3481
|
+
sparkles: "✨",
|
|
3482
|
+
zap: "⚡",
|
|
3483
|
+
boom: "💥",
|
|
3484
|
+
tada: "🎉",
|
|
3485
|
+
confetti_ball: "🎊",
|
|
3486
|
+
balloon: "🎈",
|
|
3487
|
+
gift: "🎁",
|
|
3488
|
+
birthday: "🎂",
|
|
3489
|
+
cake: "🍰",
|
|
3490
|
+
trophy: "🏆",
|
|
3491
|
+
medal: "🏅",
|
|
3492
|
+
rocket: "🚀",
|
|
3493
|
+
white_check_mark: "✅",
|
|
3494
|
+
heavy_check_mark: "✔️",
|
|
3495
|
+
x: "❌",
|
|
3496
|
+
warning: "⚠️",
|
|
3497
|
+
question: "❓",
|
|
3498
|
+
exclamation: "❗",
|
|
3499
|
+
no_entry: "⛔",
|
|
3500
|
+
ok: "🆗",
|
|
3501
|
+
new: "🆕",
|
|
3502
|
+
sos: "🆘",
|
|
3503
|
+
heavy_plus_sign: "➕",
|
|
3504
|
+
heavy_minus_sign: "➖",
|
|
3505
|
+
smile: "😄",
|
|
3506
|
+
smiley: "😃",
|
|
3507
|
+
grinning: "😀",
|
|
3508
|
+
grin: "😁",
|
|
3509
|
+
laughing: "😆",
|
|
3510
|
+
satisfied: "😆",
|
|
3511
|
+
sweat_smile: "😅",
|
|
3512
|
+
joy: "😂",
|
|
3513
|
+
rofl: "🤣",
|
|
3514
|
+
slightly_smiling_face: "🙂",
|
|
3515
|
+
upside_down_face: "🙃",
|
|
3516
|
+
wink: "😉",
|
|
3517
|
+
blush: "😊",
|
|
3518
|
+
innocent: "😇",
|
|
3519
|
+
heart_eyes: "😍",
|
|
3520
|
+
star_struck: "🤩",
|
|
3521
|
+
kissing_heart: "😘",
|
|
3522
|
+
yum: "😋",
|
|
3523
|
+
stuck_out_tongue: "😛",
|
|
3524
|
+
stuck_out_tongue_winking_eye: "😜",
|
|
3525
|
+
zany_face: "🤪",
|
|
3526
|
+
money_mouth_face: "🤑",
|
|
3527
|
+
hugs: "🤗",
|
|
3528
|
+
hugging_face: "🤗",
|
|
3529
|
+
shushing_face: "🤫",
|
|
3530
|
+
thinking: "🤔",
|
|
3531
|
+
thinking_face: "🤔",
|
|
3532
|
+
zipper_mouth_face: "🤐",
|
|
3533
|
+
raised_eyebrow: "🤨",
|
|
3534
|
+
neutral_face: "😐",
|
|
3535
|
+
expressionless: "😑",
|
|
3536
|
+
no_mouth: "😶",
|
|
3537
|
+
smirk: "😏",
|
|
3538
|
+
unamused: "😒",
|
|
3539
|
+
roll_eyes: "🙄",
|
|
3540
|
+
grimacing: "😬",
|
|
3541
|
+
relieved: "😌",
|
|
3542
|
+
pensive: "😔",
|
|
3543
|
+
sleepy: "😪",
|
|
3544
|
+
sleeping: "😴",
|
|
3545
|
+
mask: "😷",
|
|
3546
|
+
face_with_thermometer: "🤒",
|
|
3547
|
+
nauseated_face: "🤢",
|
|
3548
|
+
sneezing_face: "🤧",
|
|
3549
|
+
hot_face: "🥵",
|
|
3550
|
+
cold_face: "🥶",
|
|
3551
|
+
dizzy_face: "😵",
|
|
3552
|
+
exploding_head: "🤯",
|
|
3553
|
+
cowboy_hat_face: "🤠",
|
|
3554
|
+
partying_face: "🥳",
|
|
3555
|
+
sunglasses: "😎",
|
|
3556
|
+
nerd_face: "🤓",
|
|
3557
|
+
confused: "😕",
|
|
3558
|
+
worried: "😟",
|
|
3559
|
+
slightly_frowning_face: "🙁",
|
|
3560
|
+
open_mouth: "😮",
|
|
3561
|
+
astonished: "😲",
|
|
3562
|
+
flushed: "😳",
|
|
3563
|
+
pleading_face: "🥺",
|
|
3564
|
+
fearful: "😨",
|
|
3565
|
+
cold_sweat: "😰",
|
|
3566
|
+
cry: "😢",
|
|
3567
|
+
sob: "😭",
|
|
3568
|
+
scream: "😱",
|
|
3569
|
+
disappointed: "😞",
|
|
3570
|
+
weary: "😩",
|
|
3571
|
+
tired_face: "😫",
|
|
3572
|
+
yawning_face: "🥱",
|
|
3573
|
+
triumph: "😤",
|
|
3574
|
+
rage: "😡",
|
|
3575
|
+
angry: "😠",
|
|
3576
|
+
cursing_face: "🤬",
|
|
3577
|
+
smiling_imp: "😈",
|
|
3578
|
+
skull: "💀",
|
|
3579
|
+
poop: "💩",
|
|
3580
|
+
hankey: "💩",
|
|
3581
|
+
clown_face: "🤡",
|
|
3582
|
+
ghost: "👻",
|
|
3583
|
+
alien: "👽",
|
|
3584
|
+
robot: "🤖",
|
|
3585
|
+
see_no_evil: "🙈",
|
|
3586
|
+
hear_no_evil: "🙉",
|
|
3587
|
+
speak_no_evil: "🙊",
|
|
3588
|
+
coffee: "☕",
|
|
3589
|
+
tea: "🍵",
|
|
3590
|
+
beer: "🍺",
|
|
3591
|
+
beers: "🍻",
|
|
3592
|
+
wine_glass: "🍷",
|
|
3593
|
+
clinking_glasses: "🥂",
|
|
3594
|
+
pizza: "🍕",
|
|
3595
|
+
hamburger: "🍔",
|
|
3596
|
+
sunny: "☀️",
|
|
3597
|
+
cloud: "☁️",
|
|
3598
|
+
rainbow: "🌈",
|
|
3599
|
+
snowflake: "❄️",
|
|
3600
|
+
umbrella: "☔",
|
|
3601
|
+
phone: "☎️",
|
|
3602
|
+
telephone_receiver: "📞",
|
|
3603
|
+
iphone: "📱",
|
|
3604
|
+
computer: "💻",
|
|
3605
|
+
email: "📧",
|
|
3606
|
+
calendar: "📅",
|
|
3607
|
+
memo: "📝",
|
|
3608
|
+
pencil2: "✏️",
|
|
3609
|
+
paperclip: "📎",
|
|
3610
|
+
pushpin: "📌",
|
|
3611
|
+
lock: "🔒",
|
|
3612
|
+
key: "🔑",
|
|
3613
|
+
bulb: "💡",
|
|
3614
|
+
hourglass: "⌛",
|
|
3615
|
+
hourglass_flowing_sand: "⏳",
|
|
3616
|
+
alarm_clock: "⏰",
|
|
3617
|
+
stopwatch: "⏱️",
|
|
3618
|
+
bell: "🔔",
|
|
3619
|
+
mega: "📣",
|
|
3620
|
+
loudspeaker: "📢",
|
|
3621
|
+
speech_balloon: "💬",
|
|
3622
|
+
thought_balloon: "💭",
|
|
3623
|
+
moneybag: "💰",
|
|
3624
|
+
car: "🚗",
|
|
3625
|
+
airplane: "✈️",
|
|
3626
|
+
house: "🏠",
|
|
3627
|
+
office: "🏢",
|
|
3628
|
+
earth_africa: "🌍",
|
|
3629
|
+
globe_with_meridians: "🌐",
|
|
3630
|
+
arrow_right: "➡️",
|
|
3631
|
+
arrow_left: "⬅️",
|
|
3632
|
+
arrow_up: "⬆️",
|
|
3633
|
+
arrow_down: "⬇️",
|
|
3634
|
+
recycle: "♻️",
|
|
3635
|
+
zzz: "💤",
|
|
3636
|
+
sweat_drops: "💦",
|
|
3637
|
+
dash: "💨"
|
|
3638
|
+
}, Jn = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, Yn = /:([a-z0-9_+-]+):/g, Xn = (e) => e.replace(Yn, (e, t) => qn[t] ?? e);
|
|
3639
|
+
function $(e) {
|
|
3640
|
+
return e.includes(":") ? e.split(Jn).map((e, t) => t % 2 ? e : Xn(e)).join("") : e;
|
|
3641
|
+
}
|
|
3642
|
+
//#endregion
|
|
3643
|
+
//#region src/components/EmojiPicker.tsx
|
|
3644
|
+
var Zn = [
|
|
3645
|
+
{
|
|
3646
|
+
label: "Smileys",
|
|
3647
|
+
icon: "😀",
|
|
3648
|
+
emojis: "😀 😃 😄 😁 😆 😅 🤣 😂 🙂 🙃 😉 😊 😇 🥰 😍 🤩 😘 😗 😚 😙 😋 😛 😜 🤪 😝 🤑 🤗 🤭 🤫 🤔 🤐 🤨 😐 😑 😶 😏 😒 🙄 😬 😌 😔 😪 🤤 😴 😷 🤒 🤕 🤢 🤮 🤧 🥵 🥶 🥴 😵 🤯 🤠 🥳 😎 🤓 🧐 😕 😟 🙁 ☹️ 😮 😯 😲 😳 🥺 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 🥱 😤 😡 😠 🤬 😈 💀 💩 🤡 👻 👽 🤖"
|
|
3649
|
+
},
|
|
3650
|
+
{
|
|
3651
|
+
label: "Gestures",
|
|
3652
|
+
icon: "👍",
|
|
3653
|
+
emojis: "👍 👎 👌 🤌 🤏 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐️ 🖖 👋 👏 🙌 👐 🤲 🤝 🙏 ✍️ 💪 🫶 👀 🧠 🙋 🙆 🙅 🤷 🤦 🙇"
|
|
3654
|
+
},
|
|
3655
|
+
{
|
|
3656
|
+
label: "Hearts and symbols",
|
|
3657
|
+
icon: "❤️",
|
|
3658
|
+
emojis: "❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 💔 ❣️ 💕 💞 💓 💗 💖 💘 💝 💯 💢 💥 💫 💦 💨 🔥 ✨ ⭐ 🌟 ✅ ❌ ⚠️ ❓ ❗ ➕ ➖ 🆗 🆕 🔴 🟢 🟡 🔵"
|
|
3659
|
+
},
|
|
3660
|
+
{
|
|
3661
|
+
label: "Celebrations",
|
|
3662
|
+
icon: "🎉",
|
|
3663
|
+
emojis: "🎉 🎊 🎈 🎁 🎂 🍰 🥂 🍾 🍻 🍺 🍷 🏆 🥇 🥈 🥉 🏅 🎯 🎮 ⚽ 🏀 🎾 🚴 🏃 🎵 🎶 📸 🎬"
|
|
3664
|
+
},
|
|
3665
|
+
{
|
|
3666
|
+
label: "Work",
|
|
3667
|
+
icon: "💼",
|
|
3668
|
+
emojis: "💼 📞 ☎️ 📱 💻 🖥️ ⌨️ 🖨️ 📧 📨 📩 📅 📆 🗓️ 📌 📍 📎 ✂️ 📝 ✏️ 📁 📂 🗂️ 📊 📈 📉 🔒 🔓 🔑 🔧 🛠️ ⚙️ 💡 🔋 ⏰ ⏳ ⌛ 🧾 💶 💰"
|
|
3669
|
+
},
|
|
3670
|
+
{
|
|
3671
|
+
label: "Food and places",
|
|
3672
|
+
icon: "☕",
|
|
3673
|
+
emojis: "☕ 🍵 🥤 🍕 🍔 🍟 🌭 🥪 🌮 🍝 🍣 🍩 🍪 🍫 🍎 🍌 🍓 🥐 🚗 🚕 🚌 🚆 ✈️ 🚀 🏠 🏢 🏖️ 🌍 ☀️ 🌤️ 🌧️ ⛈️ ❄️ ⚡ 🌈 🌙"
|
|
3674
|
+
}
|
|
3675
|
+
], Qn = [
|
|
3676
|
+
"👍",
|
|
3677
|
+
"❤️",
|
|
3678
|
+
"😂",
|
|
3679
|
+
"😮",
|
|
3680
|
+
"😢",
|
|
3681
|
+
"🙏"
|
|
3682
|
+
];
|
|
3683
|
+
function $n({ onPick: e, onClose: t, className: n = "" }) {
|
|
3684
|
+
let [r, a] = c(0), o = s(null);
|
|
3685
|
+
return i(() => {
|
|
3686
|
+
let e = (e) => o.current && !o.current.contains(e.target) && t(), n = (e) => {
|
|
3687
|
+
e.key === "Escape" && (e.stopPropagation(), t());
|
|
3688
|
+
};
|
|
3689
|
+
return document.addEventListener("pointerdown", e, !0), document.addEventListener("keydown", n, !0), () => {
|
|
3690
|
+
document.removeEventListener("pointerdown", e, !0), document.removeEventListener("keydown", n, !0);
|
|
3691
|
+
};
|
|
3692
|
+
}, [t]), /* @__PURE__ */ f("div", {
|
|
3693
|
+
ref: o,
|
|
3694
|
+
role: "dialog",
|
|
3695
|
+
"aria-label": "Emoji",
|
|
3696
|
+
className: `ci-z-30 ci-w-[21rem] ci-max-w-full ci-rounded-2xl ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-2xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ci-select-none ${n}`,
|
|
3697
|
+
children: [/* @__PURE__ */ d("div", {
|
|
3698
|
+
className: "ci-flex ci-gap-1 ci-px-2 ci-pt-2 ci-border-b ci-border-gray-300 dark:ci-border-gray-700",
|
|
3699
|
+
children: Zn.map((e, t) => /* @__PURE__ */ d("button", {
|
|
3700
|
+
type: "button",
|
|
3701
|
+
title: e.label,
|
|
3702
|
+
"aria-label": e.label,
|
|
3703
|
+
onClick: () => a(t),
|
|
3704
|
+
style: {
|
|
3705
|
+
fontSize: 20,
|
|
3706
|
+
lineHeight: "28px"
|
|
3707
|
+
},
|
|
3708
|
+
className: `ci-flex-1 ci-pb-1.5 ci-border-0 ci-bg-transparent ci-border-b-2 ci-border-solid ${t === r ? "ci-border-iconSecondary dark:ci-border-iconSecondaryDark" : "ci-border-transparent ci-opacity-60 hover:ci-opacity-100"}`,
|
|
3709
|
+
children: e.icon
|
|
3710
|
+
}, e.label))
|
|
3711
|
+
}), /* @__PURE__ */ d("div", {
|
|
3712
|
+
className: "ci-grid ci-grid-cols-7 ci-gap-1 ci-p-2 ci-h-64 ci-overflow-y-auto",
|
|
3713
|
+
children: Zn[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
|
|
3714
|
+
type: "button",
|
|
3715
|
+
onClick: () => e(t),
|
|
3716
|
+
style: {
|
|
3717
|
+
fontSize: 26,
|
|
3718
|
+
lineHeight: "36px"
|
|
3719
|
+
},
|
|
3720
|
+
className: "ci-h-10 ci-w-10 ci-flex ci-items-center ci-justify-center ci-rounded-lg ci-border-0 ci-bg-transparent hover:ci-bg-gray-200 dark:hover:ci-bg-gray-800",
|
|
3721
|
+
children: t
|
|
3722
|
+
}, t))
|
|
3723
|
+
})]
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
//#endregion
|
|
3727
|
+
//#region src/components/MessageList.tsx
|
|
3728
|
+
var er = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), tr = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), nr = (e) => {
|
|
3729
|
+
let t = e.split("/").pop() || "file";
|
|
3730
|
+
try {
|
|
3731
|
+
return decodeURIComponent(t);
|
|
3732
|
+
} catch {
|
|
3733
|
+
return t;
|
|
3734
|
+
}
|
|
3735
|
+
}, rr = (e) => {
|
|
3736
|
+
try {
|
|
3737
|
+
return new URL(e).protocol === "https:";
|
|
3738
|
+
} catch {
|
|
3739
|
+
return !1;
|
|
3740
|
+
}
|
|
3741
|
+
}, ir = (e) => new Date(e).toLocaleTimeString([], {
|
|
3742
|
+
hour: "2-digit",
|
|
3743
|
+
minute: "2-digit"
|
|
3744
|
+
}), ar = (e) => new Date(e).toLocaleDateString([], {
|
|
3745
|
+
weekday: "short",
|
|
3746
|
+
day: "numeric",
|
|
3747
|
+
month: "short"
|
|
3748
|
+
}), or = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), sr = (e) => {
|
|
3749
|
+
if (!e.startsWith("{\"")) return null;
|
|
3750
|
+
try {
|
|
3751
|
+
let t = JSON.parse(e);
|
|
3752
|
+
return !Array.isArray(t.attachments) || !t.attachments.length ? null : {
|
|
3753
|
+
text: typeof t.body == "string" && t.body ? t.body : void 0,
|
|
3754
|
+
count: t.attachments.length
|
|
3755
|
+
};
|
|
3756
|
+
} catch {
|
|
3757
|
+
return null;
|
|
3758
|
+
}
|
|
3759
|
+
}, cr = n(function({ url: e }) {
|
|
3760
|
+
return rr(e) ? er(e) ? /* @__PURE__ */ d("a", {
|
|
3761
|
+
href: e,
|
|
3762
|
+
target: "_blank",
|
|
3763
|
+
rel: "noreferrer",
|
|
3764
|
+
children: /* @__PURE__ */ d("img", {
|
|
3765
|
+
src: e,
|
|
3766
|
+
alt: nr(e),
|
|
3767
|
+
className: "ci-max-w-full ci-max-h-60 ci-rounded-2xl ci-block"
|
|
3768
|
+
})
|
|
3769
|
+
}) : tr(e) ? /* @__PURE__ */ d("audio", {
|
|
3770
|
+
controls: !0,
|
|
3771
|
+
src: e,
|
|
3772
|
+
className: "ci-max-w-full"
|
|
3773
|
+
}) : /* @__PURE__ */ f("a", {
|
|
3774
|
+
href: e,
|
|
3775
|
+
target: "_blank",
|
|
3776
|
+
rel: "noreferrer",
|
|
3777
|
+
className: "ci-underline ci-break-all ci-flex ci-items-center ci-gap-1",
|
|
3778
|
+
children: [/* @__PURE__ */ d("svg", {
|
|
3779
|
+
width: "16",
|
|
3780
|
+
height: "16",
|
|
3781
|
+
viewBox: "0 0 24 24",
|
|
3782
|
+
fill: "none",
|
|
3783
|
+
stroke: "currentColor",
|
|
3784
|
+
strokeWidth: "2",
|
|
3785
|
+
children: /* @__PURE__ */ d("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
|
|
3786
|
+
}), nr(e)]
|
|
3787
|
+
}) : /* @__PURE__ */ d("span", {
|
|
3788
|
+
className: "ci-break-all",
|
|
3789
|
+
children: e
|
|
3790
|
+
});
|
|
3791
|
+
}), lr = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
|
|
3792
|
+
function ur({ text: e }) {
|
|
3793
|
+
let t = [], n = 0;
|
|
3794
|
+
for (let r of e.matchAll(lr)) {
|
|
3795
|
+
let i = r[0], a = r.index ?? 0;
|
|
3796
|
+
a > n && t.push($(e.slice(n, a))), r[1] ? t.push(/* @__PURE__ */ d("code", {
|
|
3797
|
+
className: "ci-px-1 ci-py-0.5 ci-rounded ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-[0.85em]",
|
|
3798
|
+
children: i.slice(1, -1)
|
|
3799
|
+
}, a)) : r[2] ? t.push(/* @__PURE__ */ d("strong", { children: i.slice(2, -2) }, a)) : r[3] ? t.push(/* @__PURE__ */ d("s", { children: i.slice(2, -2) }, a)) : r[4] ? t.push(/* @__PURE__ */ d("em", { children: i.slice(1, -1) }, a)) : r[5] ? t.push(/* @__PURE__ */ d("a", {
|
|
3800
|
+
href: r[6],
|
|
3801
|
+
target: "_blank",
|
|
3802
|
+
rel: "noreferrer",
|
|
3803
|
+
className: "ci-underline",
|
|
3804
|
+
children: r[5]
|
|
3805
|
+
}, a)) : t.push(/* @__PURE__ */ d("a", {
|
|
3806
|
+
href: i,
|
|
3807
|
+
target: "_blank",
|
|
3808
|
+
rel: "noreferrer",
|
|
3809
|
+
className: "ci-underline ci-break-all",
|
|
3810
|
+
children: i
|
|
3811
|
+
}, a)), n = a + i.length;
|
|
3812
|
+
}
|
|
3813
|
+
return n < e.length && t.push($(e.slice(n))), /* @__PURE__ */ d(u, { children: t });
|
|
3814
|
+
}
|
|
3815
|
+
var dr = n(function({ text: e }) {
|
|
3816
|
+
let t = e.split(/```[^\n]*\n?([\s\S]*?)```/g);
|
|
3817
|
+
return /* @__PURE__ */ d("span", {
|
|
3818
|
+
className: "ci-whitespace-pre-wrap ci-break-words",
|
|
3819
|
+
children: t.map((e, t) => t % 2 ? /* @__PURE__ */ d("pre", {
|
|
3820
|
+
className: "ci-my-1 ci-p-2 ci-rounded-xl ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-xs ci-overflow-x-auto ci-whitespace-pre",
|
|
3821
|
+
children: e.replace(/\n$/, "")
|
|
3822
|
+
}, t) : /* @__PURE__ */ d(ur, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
|
|
3823
|
+
});
|
|
3824
|
+
});
|
|
3825
|
+
function fr({ text: e, count: t }) {
|
|
3826
|
+
return /* @__PURE__ */ f("span", {
|
|
3827
|
+
className: "ci-italic ci-opacity-80",
|
|
3828
|
+
children: [
|
|
3829
|
+
e && /* @__PURE__ */ d("span", {
|
|
3830
|
+
className: "ci-not-italic ci-block",
|
|
3831
|
+
children: e
|
|
3832
|
+
}),
|
|
3833
|
+
t > 1 ? `${t} attachments` : "Attachment",
|
|
3834
|
+
" from the mobile app, not available here"
|
|
3835
|
+
]
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
function pr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
|
|
3839
|
+
if (!e) return null;
|
|
3840
|
+
let a = /* @__PURE__ */ new Map();
|
|
3841
|
+
for (let [t, n] of Object.entries(e)) for (let e of n) a.set(e, [...a.get(e) ?? [], t]);
|
|
3842
|
+
return a.size ? /* @__PURE__ */ d("div", {
|
|
3843
|
+
className: `ci-flex ci-flex-wrap ci-gap-1 ci--mt-1.5 ci-relative ci-z-[1] ${i ? "ci-justify-end ci-pr-2" : "ci-pl-2"}`,
|
|
3844
|
+
children: [...a.entries()].map(([e, i]) => {
|
|
3845
|
+
let a = i.includes(t);
|
|
3846
|
+
return /* @__PURE__ */ f("button", {
|
|
3847
|
+
type: "button",
|
|
3848
|
+
title: i.map((e) => e === t ? "You" : r(e)).join(", "),
|
|
3849
|
+
"aria-label": `${e} ${i.length}${a ? ", yours: press to remove" : ""}`,
|
|
3850
|
+
onClick: () => n(e),
|
|
3851
|
+
className: `ci-flex ci-items-center ci-gap-0.5 ci-h-6 ci-px-1.5 ci-rounded-full ci-text-xs ci-border ci-border-solid ci-shadow-sm ${a ? "ci-bg-emerald-50 ci-border-emerald-400 dark:ci-bg-emerald-950 dark:ci-border-emerald-600" : "ci-bg-gray-50 ci-border-gray-300 dark:ci-bg-gray-900 dark:ci-border-gray-700"} ci-text-gray-900 dark:ci-text-white`,
|
|
3852
|
+
children: [/* @__PURE__ */ d("span", {
|
|
3853
|
+
style: {
|
|
3854
|
+
fontSize: 16,
|
|
3855
|
+
lineHeight: "20px"
|
|
3856
|
+
},
|
|
3857
|
+
children: e
|
|
3858
|
+
}), i.length > 1 && /* @__PURE__ */ d("span", { children: i.length })]
|
|
3859
|
+
}, e);
|
|
3860
|
+
})
|
|
3861
|
+
}) : null;
|
|
3862
|
+
}
|
|
3863
|
+
function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u }) {
|
|
3864
|
+
let p = q((e) => e.contacts), m = s(null), h = s(!0), [g, _] = c(null), [v, y] = c(null), b = (e) => p[e]?.name ?? e;
|
|
3865
|
+
i(() => {
|
|
3866
|
+
let e = m.current;
|
|
3867
|
+
e && h.current && (e.scrollTop = e.scrollHeight);
|
|
3868
|
+
}, [
|
|
3869
|
+
e.length,
|
|
3870
|
+
t,
|
|
3871
|
+
o
|
|
3872
|
+
]), i(() => {
|
|
3873
|
+
if (!g) return;
|
|
3874
|
+
let e = () => _(null), t = window.setTimeout(() => document.addEventListener("click", e, { once: !0 }), 0);
|
|
3875
|
+
return () => {
|
|
3876
|
+
window.clearTimeout(t), document.removeEventListener("click", e);
|
|
3877
|
+
};
|
|
3878
|
+
}, [g]);
|
|
3879
|
+
let x = () => {
|
|
3880
|
+
let e = m.current;
|
|
3881
|
+
e && (h.current = e.scrollHeight - e.scrollTop - e.clientHeight < 40, e.scrollTop < 30 && r && n());
|
|
3882
|
+
}, S = (e, t) => {
|
|
3883
|
+
_(null), y(null), u?.(e, t);
|
|
3884
|
+
};
|
|
3885
|
+
return /* @__PURE__ */ f("div", {
|
|
3886
|
+
className: "ci-relative ci-flex-1 ci-min-h-0 ci-flex ci-flex-col",
|
|
3887
|
+
children: [/* @__PURE__ */ f("div", {
|
|
3888
|
+
ref: m,
|
|
3889
|
+
onScroll: x,
|
|
3890
|
+
className: "ci-flex-1 ci-overflow-y-auto ci-px-4 ci-py-2 ci-space-y-1",
|
|
3891
|
+
children: [
|
|
3892
|
+
r && /* @__PURE__ */ d("div", {
|
|
3893
|
+
className: "ci-text-center ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-py-1",
|
|
3894
|
+
children: "Scroll up for older messages"
|
|
3895
|
+
}),
|
|
3896
|
+
e.map((t, n) => {
|
|
3897
|
+
let r = e[n - 1], i = !r || !or(r.ts, t.ts), s = r && !i && r.mine === t.mine && r.nick === t.nick && t.ts - r.ts < 12e4, c = a && !t.mine && t.nick ? b(t.nick) : null, m = t.oid, h = !!u && !!m && !t.pending, v = h && /* @__PURE__ */ d("button", {
|
|
3898
|
+
type: "button",
|
|
3899
|
+
title: "React",
|
|
3900
|
+
"aria-label": "React to this message",
|
|
3901
|
+
onClick: (e) => {
|
|
3902
|
+
e.stopPropagation(), _(g === m ? null : m);
|
|
3903
|
+
},
|
|
3904
|
+
className: `ci-self-center ci-h-7 ci-w-7 ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-rounded-full ci-border-0 ci-bg-transparent ci-text-gray-500 dark:ci-text-gray-400 hover:ci-bg-gray-200 dark:hover:ci-bg-gray-800 focus:ci-opacity-100 ${g === m ? "ci-opacity-100" : "ci-opacity-0 group-hover:ci-opacity-100"}`,
|
|
3905
|
+
children: Q.react
|
|
3906
|
+
});
|
|
3907
|
+
return /* @__PURE__ */ f("div", { children: [i && /* @__PURE__ */ d("div", {
|
|
3908
|
+
className: "ci-text-center ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-py-2",
|
|
3909
|
+
children: ar(t.ts)
|
|
3910
|
+
}), /* @__PURE__ */ f("div", {
|
|
3911
|
+
className: `ci-group ci-flex ci-items-start ci-gap-1.5 ${t.mine ? "ci-justify-end" : "ci-justify-start"} ${s ? "ci-mt-0.5" : "ci-mt-2"}`,
|
|
3912
|
+
children: [
|
|
3913
|
+
c && /* @__PURE__ */ d("span", {
|
|
3914
|
+
className: "ci-w-7 ci-shrink-0",
|
|
3915
|
+
title: c,
|
|
3916
|
+
children: !s && /* @__PURE__ */ d(X, {
|
|
3917
|
+
contact: p[t.nick],
|
|
3918
|
+
username: t.nick,
|
|
3919
|
+
size: 28
|
|
3920
|
+
})
|
|
3921
|
+
}),
|
|
3922
|
+
t.mine && v,
|
|
3923
|
+
/* @__PURE__ */ f("div", {
|
|
3924
|
+
className: `ci-relative ci-flex ci-flex-col ci-max-w-[80%] ${t.mine ? "ci-items-end" : "ci-items-start"}`,
|
|
3925
|
+
children: [
|
|
3926
|
+
g === m && m && /* @__PURE__ */ f("div", {
|
|
3927
|
+
role: "menu",
|
|
3928
|
+
onClick: (e) => e.stopPropagation(),
|
|
3929
|
+
className: `ci-absolute ci-bottom-full ci-mb-1 ci-z-20 ci-flex ci-items-center ci-gap-0.5 ci-p-1 ci-rounded-full ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ${t.mine ? "ci-right-0" : "ci-left-0"}`,
|
|
3930
|
+
children: [Qn.map((e) => /* @__PURE__ */ d("button", {
|
|
3931
|
+
type: "button",
|
|
3932
|
+
role: "menuitem",
|
|
3933
|
+
"aria-label": e,
|
|
3934
|
+
onClick: () => S(m, e),
|
|
3935
|
+
style: {
|
|
3936
|
+
fontSize: 22,
|
|
3937
|
+
lineHeight: "32px"
|
|
3938
|
+
},
|
|
3939
|
+
className: `ci-h-9 ci-w-9 ci-flex ci-items-center ci-justify-center ci-rounded-full ci-border-0 hover:ci-scale-125 ci-transition-transform ${o?.[m]?.[l]?.includes(e) ? "ci-bg-gray-200 dark:ci-bg-gray-800" : "ci-bg-transparent"}`,
|
|
3940
|
+
children: e
|
|
3941
|
+
}, e)), /* @__PURE__ */ d("button", {
|
|
3942
|
+
type: "button",
|
|
3943
|
+
role: "menuitem",
|
|
3944
|
+
title: "More emojis",
|
|
3945
|
+
"aria-label": "More emojis",
|
|
3946
|
+
onClick: () => {
|
|
3947
|
+
_(null), y(m);
|
|
3948
|
+
},
|
|
3949
|
+
className: "ci-h-8 ci-w-8 ci-flex ci-items-center ci-justify-center ci-rounded-full ci-border-0 ci-bg-gray-200 dark:ci-bg-gray-800 ci-text-gray-700 dark:ci-text-gray-200 ci-text-lg",
|
|
3950
|
+
children: "+"
|
|
3951
|
+
})]
|
|
3952
|
+
}),
|
|
3953
|
+
/* @__PURE__ */ f("div", {
|
|
3954
|
+
title: ir(t.ts),
|
|
3955
|
+
onDoubleClick: () => h && S(m, Qn[0]),
|
|
3956
|
+
className: `ci-px-3.5 ci-py-2 ci-rounded-3xl ci-text-sm ci-select-text ci-cursor-text ${t.mine ? "ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900 ci-rounded-br-lg" : "ci-bg-elevationL2 ci-text-gray-900 dark:ci-bg-elevationL2Dark dark:ci-text-white ci-rounded-bl-lg"} ${t.pending ? "ci-opacity-60" : ""}`,
|
|
3957
|
+
children: [
|
|
3958
|
+
t.oob ? /* @__PURE__ */ d(cr, { url: t.oob }) : sr(t.body) ? /* @__PURE__ */ d(fr, { ...sr(t.body) }) : /* @__PURE__ */ d(dr, { text: t.body }),
|
|
3959
|
+
t.oob && t.body && t.body !== t.oob && t.body !== nr(t.oob) && /* @__PURE__ */ d("div", {
|
|
3960
|
+
className: "ci-text-xs ci-opacity-80 ci-mt-1",
|
|
3961
|
+
children: t.body
|
|
3962
|
+
}),
|
|
3963
|
+
/* @__PURE__ */ d("span", {
|
|
3964
|
+
className: "ci-block ci-text-right ci-text-[10px] ci-leading-none ci-opacity-60 ci-mt-1",
|
|
3965
|
+
children: ir(t.ts)
|
|
3966
|
+
})
|
|
3967
|
+
]
|
|
3968
|
+
}),
|
|
3969
|
+
m && /* @__PURE__ */ d(pr, {
|
|
3970
|
+
forMsg: o?.[m],
|
|
3971
|
+
me: l,
|
|
3972
|
+
mine: t.mine,
|
|
3973
|
+
nameOf: b,
|
|
3974
|
+
onReact: (e) => h && S(m, e)
|
|
3975
|
+
})
|
|
3976
|
+
]
|
|
3977
|
+
}),
|
|
3978
|
+
!t.mine && v
|
|
3979
|
+
]
|
|
3980
|
+
})] }, t.id);
|
|
3981
|
+
}),
|
|
3982
|
+
t && /* @__PURE__ */ d("div", {
|
|
3983
|
+
className: "ci-flex ci-justify-start ci-mt-2",
|
|
3984
|
+
children: /* @__PURE__ */ d("div", {
|
|
3985
|
+
className: "ci-px-3.5 ci-py-2 ci-rounded-3xl ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-500 dark:ci-text-gray-400 ci-text-xs ci-italic",
|
|
3986
|
+
children: "typing…"
|
|
3987
|
+
})
|
|
3988
|
+
})
|
|
3989
|
+
]
|
|
3990
|
+
}), v && /* @__PURE__ */ d($n, {
|
|
3991
|
+
className: "ci-absolute ci-bottom-2 ci-left-1/2 ci--translate-x-1/2",
|
|
3992
|
+
onPick: (e) => S(v, e),
|
|
3993
|
+
onClose: () => y(null)
|
|
3994
|
+
})]
|
|
3995
|
+
});
|
|
3996
|
+
}
|
|
3997
|
+
//#endregion
|
|
3998
|
+
//#region src/ogg.ts
|
|
3999
|
+
function hr(e, t, n) {
|
|
4000
|
+
let r = e[t];
|
|
4001
|
+
if (r === void 0) return null;
|
|
4002
|
+
let i = 1;
|
|
4003
|
+
for (; i <= 8 && !(r & 128 >> i - 1);) i++;
|
|
4004
|
+
if (i > 8 || t + i > e.length) return null;
|
|
4005
|
+
let a = n ? r : r & 255 >> i, o = a === 255 >> i;
|
|
4006
|
+
for (let n = 1; n < i; n++) a = a * 256 + e[t + n], e[t + n] !== 255 && (o = !1);
|
|
4007
|
+
return {
|
|
4008
|
+
value: a,
|
|
4009
|
+
len: i,
|
|
4010
|
+
unknown: !n && o
|
|
4011
|
+
};
|
|
4012
|
+
}
|
|
4013
|
+
var gr = /* @__PURE__ */ new Set([
|
|
4014
|
+
408125543,
|
|
4015
|
+
524531317,
|
|
4016
|
+
374648427,
|
|
4017
|
+
174,
|
|
4018
|
+
225,
|
|
4019
|
+
160
|
|
4020
|
+
]);
|
|
4021
|
+
function _r(e) {
|
|
4022
|
+
let t = {
|
|
4023
|
+
channels: 1,
|
|
4024
|
+
packets: []
|
|
4025
|
+
}, n = 0;
|
|
4026
|
+
for (; n < e.length;) {
|
|
4027
|
+
let r = hr(e, n, !0);
|
|
4028
|
+
if (!r) break;
|
|
4029
|
+
let i = hr(e, n + r.len, !1);
|
|
4030
|
+
if (!i) break;
|
|
4031
|
+
let a = n + r.len + i.len;
|
|
4032
|
+
if (gr.has(r.value)) {
|
|
4033
|
+
n = a;
|
|
4034
|
+
continue;
|
|
4035
|
+
}
|
|
4036
|
+
if (i.unknown) break;
|
|
4037
|
+
let o = Math.min(e.length, a + i.value);
|
|
4038
|
+
if (r.value === 25506) t.head = e.slice(a, o);
|
|
4039
|
+
else if (r.value === 159) t.channels = e[a] || 1;
|
|
4040
|
+
else if (r.value === 163 || r.value === 161) {
|
|
4041
|
+
let n = hr(e, a, !1);
|
|
4042
|
+
n && (e[a + n.len + 2] >> 1 & 3 || t.packets.push(e.slice(a + n.len + 3, o)));
|
|
4043
|
+
}
|
|
4044
|
+
n = o;
|
|
4045
|
+
}
|
|
4046
|
+
return t;
|
|
4047
|
+
}
|
|
4048
|
+
function vr(e) {
|
|
4049
|
+
if (!e.length) return 0;
|
|
4050
|
+
let t = e[0], n = t >> 3, r;
|
|
4051
|
+
r = n < 12 ? [
|
|
4052
|
+
10,
|
|
4053
|
+
20,
|
|
4054
|
+
40,
|
|
4055
|
+
60
|
|
4056
|
+
][n % 4] : n < 16 ? [10, 20][n % 2] : [
|
|
4057
|
+
2.5,
|
|
4058
|
+
5,
|
|
4059
|
+
10,
|
|
4060
|
+
20
|
|
4061
|
+
][n % 4];
|
|
4062
|
+
let i = t & 3, a = i === 0 ? 1 : i === 3 ? (e[1] ?? 0) & 63 : 2;
|
|
4063
|
+
return Math.round(a * r * 48);
|
|
4064
|
+
}
|
|
4065
|
+
var yr = (() => {
|
|
4066
|
+
let e = /* @__PURE__ */ new Uint32Array(256);
|
|
4067
|
+
for (let t = 0; t < 256; t++) {
|
|
4068
|
+
let n = t << 24;
|
|
4069
|
+
for (let e = 0; e < 8; e++) n = n & 2147483648 ? n << 1 ^ 79764919 : n << 1;
|
|
4070
|
+
e[t] = n >>> 0;
|
|
4071
|
+
}
|
|
4072
|
+
return e;
|
|
4073
|
+
})();
|
|
4074
|
+
function br(e) {
|
|
4075
|
+
let t = 0;
|
|
4076
|
+
for (let n = 0; n < e.length; n++) t = (t << 8 ^ yr[(t >>> 24 ^ e[n]) & 255]) >>> 0;
|
|
4077
|
+
return t;
|
|
4078
|
+
}
|
|
4079
|
+
function xr(e, t, n, r, i) {
|
|
4080
|
+
let a = [];
|
|
4081
|
+
for (let t of e) {
|
|
4082
|
+
let e = t.length;
|
|
4083
|
+
for (; e >= 255;) a.push(255), e -= 255;
|
|
4084
|
+
a.push(e);
|
|
4085
|
+
}
|
|
4086
|
+
let o = e.reduce((e, t) => e + t.length, 0), s = new Uint8Array(27 + a.length + o), c = new DataView(s.buffer);
|
|
4087
|
+
s.set([
|
|
4088
|
+
79,
|
|
4089
|
+
103,
|
|
4090
|
+
103,
|
|
4091
|
+
83
|
|
4092
|
+
], 0), s[5] = i, c.setUint32(6, t % 4294967296, !0), c.setUint32(10, Math.floor(t / 4294967296), !0), c.setUint32(14, n, !0), c.setUint32(18, r, !0), s[26] = a.length, s.set(a, 27);
|
|
4093
|
+
let l = 27 + a.length;
|
|
4094
|
+
for (let t of e) s.set(t, l), l += t.length;
|
|
4095
|
+
return c.setUint32(22, br(s), !0), s;
|
|
4096
|
+
}
|
|
4097
|
+
function Sr(e) {
|
|
4098
|
+
let t = /* @__PURE__ */ new Uint8Array(19), n = new DataView(t.buffer);
|
|
4099
|
+
return t.set(new TextEncoder().encode("OpusHead"), 0), t[8] = 1, t[9] = e, n.setUint16(10, 312, !0), n.setUint32(12, 48e3, !0), t;
|
|
4100
|
+
}
|
|
4101
|
+
function Cr() {
|
|
4102
|
+
let e = new TextEncoder().encode("chat-island"), t = new Uint8Array(12 + e.length + 4);
|
|
4103
|
+
return t.set(new TextEncoder().encode("OpusTags"), 0), new DataView(t.buffer).setUint32(8, e.length, !0), t.set(e, 12), t;
|
|
4104
|
+
}
|
|
4105
|
+
function wr(e) {
|
|
4106
|
+
let { head: t, channels: n, packets: r } = _r(e);
|
|
4107
|
+
if (!r.length) return null;
|
|
4108
|
+
let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [xr([i ? t : Sr(n)], 0, a, 0, 2), xr([Cr()], 0, a, 1, 0)], s = 0, c = 2;
|
|
4109
|
+
for (let e = 0; e < r.length;) {
|
|
4110
|
+
let t = [], n = 0;
|
|
4111
|
+
for (; e < r.length && t.length < 50;) {
|
|
4112
|
+
let i = Math.floor(r[e].length / 255) + 1;
|
|
4113
|
+
if (n + i > 255) break;
|
|
4114
|
+
t.push(r[e]), n += i, s += vr(r[e]), e++;
|
|
4115
|
+
}
|
|
4116
|
+
if (!t.length) return null;
|
|
4117
|
+
o.push(xr(t, s, a, c++, e >= r.length ? 4 : 0));
|
|
4118
|
+
}
|
|
4119
|
+
let l = o.reduce((e, t) => e + t.length, 0), u = new Uint8Array(l), d = 0;
|
|
4120
|
+
for (let e of o) u.set(e, d), d += e.length;
|
|
4121
|
+
return u;
|
|
4122
|
+
}
|
|
4123
|
+
//#endregion
|
|
4124
|
+
//#region src/components/Composer.tsx
|
|
4125
|
+
var Tr = [
|
|
4126
|
+
"audio/ogg;codecs=opus",
|
|
4127
|
+
"audio/webm;codecs=opus",
|
|
4128
|
+
"audio/mp4",
|
|
4129
|
+
"audio/webm"
|
|
4130
|
+
];
|
|
4131
|
+
async function Er(e, t) {
|
|
4132
|
+
let n = Date.now();
|
|
4133
|
+
if (/webm/.test(t) && /opus/.test(t)) try {
|
|
4134
|
+
let t = wr(new Uint8Array(await new Blob(e).arrayBuffer()));
|
|
4135
|
+
if (t) return new File([t], `voice-${n}.ogg`, { type: "audio/ogg" });
|
|
4136
|
+
} catch {}
|
|
4137
|
+
return new File(e, `voice-${n}.${Dr(t)}`, { type: t.split(";")[0] });
|
|
4138
|
+
}
|
|
4139
|
+
var Dr = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", Or = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
|
|
4140
|
+
function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
|
|
4141
|
+
let [o, l] = c(""), [u, p] = c(!1), m = s(null), h = s(null), g = s(null), _ = s(), v = s(!1), [y, b] = c(null), [x, S] = c(0), C = s(!1), w = s(!1), T = s(!1), E = s({});
|
|
4142
|
+
i(() => g.current?.focus(), []), i(() => () => {
|
|
4143
|
+
T.current = !0, C.current = !0, window.clearTimeout(_.current);
|
|
4144
|
+
let { r: e, stream: t } = E.current;
|
|
4145
|
+
e && e.state !== "inactive" && e.stop(), t?.getTracks().forEach((e) => e.stop()), E.current = {};
|
|
4146
|
+
}, []), i(() => {
|
|
4147
|
+
if (!y) return;
|
|
4148
|
+
let e = window.setInterval(() => S(Date.now() - y.since), 250);
|
|
4149
|
+
return () => window.clearInterval(e);
|
|
4150
|
+
}, [y]);
|
|
4151
|
+
let D = (e) => {
|
|
4152
|
+
v.current !== e && (v.current = e, t(e));
|
|
4153
|
+
}, O = (e) => {
|
|
4154
|
+
let t = e.includes(":") ? $(e) : e;
|
|
4155
|
+
t !== e && (m.current = Math.max(0, (g.current?.selectionStart ?? e.length) - (e.length - t.length))), l(t), t ? (D(!0), window.clearTimeout(_.current), _.current = window.setTimeout(() => D(!1), 4e3)) : D(!1);
|
|
4156
|
+
};
|
|
4157
|
+
a(() => {
|
|
4158
|
+
m.current !== null && (g.current?.setSelectionRange(m.current, m.current), m.current = null);
|
|
4159
|
+
}, [o]);
|
|
4160
|
+
let ee = (e) => {
|
|
4161
|
+
let t = g.current, n = t?.selectionStart ?? o.length, r = t?.selectionEnd ?? n;
|
|
4162
|
+
O(o.slice(0, n) + e + o.slice(r)), requestAnimationFrame(() => {
|
|
4163
|
+
t?.focus(), t?.setSelectionRange(n + e.length, n + e.length);
|
|
4164
|
+
});
|
|
4165
|
+
}, k = () => {
|
|
4166
|
+
let t = o.trim();
|
|
4167
|
+
t && (l(""), Promise.resolve(e(t)).catch(() => l((e) => e || t)), window.clearTimeout(_.current), v.current = !1);
|
|
4168
|
+
}, te = async () => {
|
|
4169
|
+
if (w.current || y) return;
|
|
4170
|
+
w.current = !0;
|
|
4171
|
+
let e;
|
|
4172
|
+
try {
|
|
4173
|
+
e = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
4174
|
+
let t = e;
|
|
4175
|
+
if (T.current) {
|
|
4176
|
+
t.getTracks().forEach((e) => e.stop());
|
|
4177
|
+
return;
|
|
4178
|
+
}
|
|
4179
|
+
let r = Tr.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
|
|
4180
|
+
i.ondataavailable = (e) => e.data.size && a.push(e.data), i.onstop = () => {
|
|
4181
|
+
t.getTracks().forEach((e) => e.stop()), E.current = {}, b(null), !C.current && a.length && Er(a, i.mimeType || r || "").then(n);
|
|
4182
|
+
}, C.current = !1, i.start(), E.current = {
|
|
4183
|
+
r: i,
|
|
4184
|
+
stream: t
|
|
4185
|
+
}, S(0), b({
|
|
4186
|
+
r: i,
|
|
4187
|
+
since: Date.now()
|
|
4188
|
+
});
|
|
4189
|
+
} catch {
|
|
4190
|
+
e?.getTracks().forEach((e) => e.stop());
|
|
4191
|
+
} finally {
|
|
4192
|
+
w.current = !1;
|
|
4193
|
+
}
|
|
4194
|
+
}, A = (e) => {
|
|
4195
|
+
C.current = e, y?.r.stop();
|
|
4196
|
+
};
|
|
4197
|
+
return y ? /* @__PURE__ */ f("div", {
|
|
4198
|
+
className: "ci-flex ci-items-center ci-gap-2 ci-px-3 ci-py-3",
|
|
4199
|
+
children: [
|
|
4200
|
+
/* @__PURE__ */ d(Z, {
|
|
4201
|
+
variant: "transparent",
|
|
4202
|
+
title: "Discard",
|
|
4203
|
+
"aria-label": "Discard",
|
|
4204
|
+
onClick: () => A(!0),
|
|
4205
|
+
className: "ci-h-10 ci-w-10",
|
|
4206
|
+
children: Q.close
|
|
4207
|
+
}),
|
|
4208
|
+
/* @__PURE__ */ f("div", {
|
|
4209
|
+
className: "ci-flex-1 ci-flex ci-items-center ci-gap-2 ci-px-4 ci-py-2.5 ci-rounded-3xl ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-sm",
|
|
4210
|
+
children: [/* @__PURE__ */ d("span", { className: "ci-w-2.5 ci-h-2.5 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-animate-pulse" }), /* @__PURE__ */ f("span", { children: ["Recording ", Or(x)] })]
|
|
4211
|
+
}),
|
|
4212
|
+
/* @__PURE__ */ d(Z, {
|
|
4213
|
+
variant: "green",
|
|
4214
|
+
title: "Send voice note",
|
|
4215
|
+
"aria-label": "Send voice note",
|
|
4216
|
+
onClick: () => A(!1),
|
|
4217
|
+
className: "ci-h-10 ci-w-10",
|
|
4218
|
+
children: Q.send
|
|
4219
|
+
})
|
|
4220
|
+
]
|
|
4221
|
+
}) : /* @__PURE__ */ f("div", {
|
|
4222
|
+
className: "ci-relative ci-flex ci-items-center ci-gap-2 ci-px-3 ci-py-3",
|
|
4223
|
+
children: [
|
|
4224
|
+
u && /* @__PURE__ */ d($n, {
|
|
4225
|
+
className: "ci-absolute ci-bottom-full ci-left-3 ci-mb-1",
|
|
4226
|
+
onPick: ee,
|
|
4227
|
+
onClose: () => p(!1)
|
|
4228
|
+
}),
|
|
4229
|
+
/* @__PURE__ */ d("input", {
|
|
4230
|
+
ref: h,
|
|
4231
|
+
type: "file",
|
|
4232
|
+
hidden: !0,
|
|
4233
|
+
onChange: (e) => e.target.files?.[0] && (n(e.target.files[0]), e.target.value = "")
|
|
4234
|
+
}),
|
|
4235
|
+
/* @__PURE__ */ d(Z, {
|
|
4236
|
+
variant: "transparent",
|
|
4237
|
+
disabled: r,
|
|
4238
|
+
title: "Attach a file",
|
|
4239
|
+
onClick: () => h.current?.click(),
|
|
4240
|
+
className: "ci-h-10 ci-w-10",
|
|
4241
|
+
children: Q.clip
|
|
4242
|
+
}),
|
|
4243
|
+
/* @__PURE__ */ f("div", {
|
|
4244
|
+
className: "ci-relative ci-flex-1 ci-min-w-0",
|
|
4245
|
+
children: [/* @__PURE__ */ d("button", {
|
|
4246
|
+
type: "button",
|
|
4247
|
+
disabled: r,
|
|
4248
|
+
title: "Emoji",
|
|
4249
|
+
"aria-label": "Emoji",
|
|
4250
|
+
"aria-expanded": u,
|
|
4251
|
+
onClick: () => p((e) => !e),
|
|
4252
|
+
className: "ci-absolute ci-left-2 ci-bottom-1 ci-z-10 ci-h-8 ci-w-8 ci-flex ci-items-center ci-justify-center ci-rounded-full ci-border-0 ci-bg-transparent ci-text-secondaryNeutral dark:ci-text-secondaryNeutralDark hover:ci-bg-gray-300/70 dark:hover:ci-bg-gray-700/30 disabled:ci-opacity-40",
|
|
4253
|
+
children: Q.smile
|
|
4254
|
+
}), /* @__PURE__ */ d("textarea", {
|
|
4255
|
+
ref: g,
|
|
4256
|
+
value: o,
|
|
4257
|
+
disabled: r,
|
|
4258
|
+
rows: 1,
|
|
4259
|
+
placeholder: r ? "Connecting…" : "Write a message",
|
|
4260
|
+
onChange: (e) => O(e.target.value),
|
|
4261
|
+
onKeyDown: (e) => {
|
|
4262
|
+
let t = (o.match(/```/g) ?? []).length % 2 == 1;
|
|
4263
|
+
e.key === "Enter" && !e.shiftKey && !t && (e.preventDefault(), k());
|
|
4264
|
+
},
|
|
4265
|
+
className: "ci-block ci-w-full ci-resize-none ci-max-h-32 ci-pl-11 ci-pr-4 ci-py-2.5 ci-rounded-3xl ci-border-0 ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-900 dark:ci-text-white placeholder:ci-text-gray-500 dark:placeholder:ci-text-gray-400 ci-outline-none focus:ci-ring-2 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500 ci-text-sm",
|
|
4266
|
+
style: { height: Math.min(128, 40 + 20 * (o.split("\n").length - 1)) }
|
|
4267
|
+
})]
|
|
4268
|
+
}),
|
|
4269
|
+
o.trim() ? /* @__PURE__ */ d(Z, {
|
|
4270
|
+
variant: "default",
|
|
4271
|
+
disabled: r,
|
|
4272
|
+
onClick: k,
|
|
4273
|
+
title: "Send",
|
|
4274
|
+
className: "ci-h-10 ci-w-10",
|
|
4275
|
+
children: Q.send
|
|
4276
|
+
}) : /* @__PURE__ */ d(Z, {
|
|
4277
|
+
variant: "default",
|
|
4278
|
+
disabled: r || typeof MediaRecorder > "u",
|
|
4279
|
+
onClick: te,
|
|
4280
|
+
title: "Record a voice note",
|
|
4281
|
+
"aria-label": "Record a voice note",
|
|
4282
|
+
className: "ci-h-10 ci-w-10",
|
|
4283
|
+
children: Q.mic
|
|
4284
|
+
})
|
|
4285
|
+
]
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4288
|
+
//#endregion
|
|
4289
|
+
//#region src/components/ChatWindow.tsx
|
|
4290
|
+
var Ar = (e) => !!e && ![
|
|
4291
|
+
"offline",
|
|
4292
|
+
"dnd",
|
|
4293
|
+
"busy",
|
|
4294
|
+
"ringing",
|
|
4295
|
+
"onhold"
|
|
4296
|
+
].includes(e);
|
|
4297
|
+
function jr({ peer: e, actions: t, onDragStart: n }) {
|
|
4298
|
+
let { c: r, contacts: a, online: o, mobile: s, status: l, closeChat: p, openChat: m, markRead: h, order: g, me: _ } = q(w((t) => ({
|
|
4299
|
+
c: t.conversations[e],
|
|
4300
|
+
contacts: t.contacts,
|
|
4301
|
+
online: t.online,
|
|
4302
|
+
mobile: t.mobile,
|
|
4303
|
+
status: t.status,
|
|
4304
|
+
closeChat: t.closeChat,
|
|
4305
|
+
openChat: t.openChat,
|
|
4306
|
+
markRead: t.markRead,
|
|
4307
|
+
order: t.order,
|
|
4308
|
+
me: t.me
|
|
4309
|
+
}))), v = Math.max(0, g.indexOf(e)), y = a[e], [b, x] = c(!1), S = (e) => e === _ ? "You" : a[e]?.name ?? e, C = [...r?.members ?? []].sort((e, t) => Number(e === _) - Number(t === _));
|
|
4310
|
+
return i(() => {
|
|
4311
|
+
r && !r.loaded && t.loadOlder(e);
|
|
4312
|
+
}, [e, r?.loaded]), i(() => {
|
|
4313
|
+
h(e);
|
|
4314
|
+
}, [e, r?.messages.length]), i(() => x(!1), [e]), r ? /* @__PURE__ */ f("div", {
|
|
4315
|
+
role: "dialog",
|
|
4316
|
+
"aria-label": r.kind === "group" ? r.name ?? e : y?.name ?? e,
|
|
4317
|
+
onKeyDown: (e) => {
|
|
4318
|
+
e.key === "Escape" && (e.stopPropagation(), b ? x(!1) : p());
|
|
4319
|
+
},
|
|
4320
|
+
className: "ci-relative ci-w-[22rem] ci-h-[30rem] ci-flex ci-flex-col ci-rounded-3xl ci-shadow-2xl ci-bg-gray-50 dark:ci-bg-gray-950 ci-text-gray-900 dark:ci-text-white",
|
|
4321
|
+
children: [
|
|
4322
|
+
/* @__PURE__ */ d("span", {
|
|
4323
|
+
className: "ci-absolute ci--right-1.5 ci-w-3 ci-h-3 ci-rotate-45 ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-2xl ci-transition-all ci-duration-200",
|
|
4324
|
+
style: { bottom: `calc(1.875rem + ${v} * 3.75rem)` },
|
|
4325
|
+
"aria-hidden": "true"
|
|
4326
|
+
}),
|
|
4327
|
+
/* @__PURE__ */ f("div", {
|
|
4328
|
+
className: "ci-flex ci-items-center ci-gap-3 ci-px-4 ci-py-3 ci-cursor-grab active:ci-cursor-grabbing ci-touch-none ci-rounded-t-3xl",
|
|
4329
|
+
onPointerDown: n,
|
|
4330
|
+
children: [
|
|
4331
|
+
r.kind === "group" ? /* @__PURE__ */ d(Un, {
|
|
4332
|
+
name: r.name ?? e,
|
|
4333
|
+
size: 36,
|
|
4334
|
+
avatar: r.avatar
|
|
4335
|
+
}) : /* @__PURE__ */ f("span", {
|
|
4336
|
+
className: "ci-relative",
|
|
4337
|
+
children: [/* @__PURE__ */ d(X, {
|
|
4338
|
+
contact: y,
|
|
4339
|
+
username: e,
|
|
4340
|
+
size: 36
|
|
4341
|
+
}), /* @__PURE__ */ d(Hn, {
|
|
4342
|
+
online: o[e],
|
|
4343
|
+
presence: y?.presence,
|
|
4344
|
+
mobile: s[e]
|
|
4345
|
+
})]
|
|
4346
|
+
}),
|
|
4347
|
+
/* @__PURE__ */ f("div", {
|
|
4348
|
+
className: `ci-flex-1 ci-min-w-0 ${r.kind === "group" ? "ci-cursor-pointer" : ""}`,
|
|
4349
|
+
...r.kind === "group" ? {
|
|
4350
|
+
role: "button",
|
|
4351
|
+
tabIndex: 0,
|
|
4352
|
+
"aria-expanded": b,
|
|
4353
|
+
onKeyDown: (e) => (e.key === "Enter" || e.key === " ") && (e.preventDefault(), x((e) => !e))
|
|
4354
|
+
} : {},
|
|
4355
|
+
onClick: () => r.kind === "group" && x((e) => !e),
|
|
4356
|
+
children: [/* @__PURE__ */ d("div", {
|
|
4357
|
+
className: "ci-font-medium ci-truncate ci-text-sm",
|
|
4358
|
+
children: r.kind === "group" ? r.name ?? e : y?.name ?? e
|
|
4359
|
+
}), /* @__PURE__ */ d("div", {
|
|
4360
|
+
className: "ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-truncate",
|
|
4361
|
+
children: l === "online" ? r.kind === "group" ? C.map(S).join(", ") : r.typing ? "typing…" : o[e] ? "online" : s[e] ? "Mobile" : "offline" : l
|
|
4362
|
+
})]
|
|
4363
|
+
}),
|
|
4364
|
+
r.kind !== "group" && y?.number && Ar(y.presence) && /* @__PURE__ */ d(Z, {
|
|
4365
|
+
variant: "call",
|
|
4366
|
+
title: `Call ${y.number}`,
|
|
4367
|
+
"aria-label": "Call",
|
|
4368
|
+
onClick: () => J("chat-island-call", {
|
|
4369
|
+
username: e,
|
|
4370
|
+
number: y.number
|
|
4371
|
+
}),
|
|
4372
|
+
children: Q.phone
|
|
4373
|
+
}),
|
|
4374
|
+
/* @__PURE__ */ d(Z, {
|
|
4375
|
+
variant: "small",
|
|
4376
|
+
onClick: () => p(),
|
|
4377
|
+
"aria-label": "Close",
|
|
4378
|
+
children: Q.close
|
|
4379
|
+
})
|
|
4380
|
+
]
|
|
4381
|
+
}),
|
|
4382
|
+
/* @__PURE__ */ d("div", { className: "ci-border-t ci-border-gray-300 dark:ci-border-gray-700" }),
|
|
4383
|
+
b && r.kind === "group" && /* @__PURE__ */ d("div", {
|
|
4384
|
+
className: "ci-absolute ci-left-3 ci-right-3 ci-top-16 ci-z-10 ci-max-h-64 ci-overflow-y-auto ci-rounded-2xl ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-2xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ci-p-2",
|
|
4385
|
+
children: C.map((e) => /* @__PURE__ */ f("div", {
|
|
4386
|
+
className: "ci-flex ci-items-center ci-gap-3 ci-px-2 ci-py-1.5 ci-text-sm",
|
|
4387
|
+
children: [
|
|
4388
|
+
/* @__PURE__ */ f("span", {
|
|
4389
|
+
className: "ci-relative",
|
|
4390
|
+
children: [/* @__PURE__ */ d(X, {
|
|
4391
|
+
contact: a[e],
|
|
4392
|
+
username: e,
|
|
4393
|
+
size: 28
|
|
4394
|
+
}), e !== _ && /* @__PURE__ */ d(Hn, {
|
|
4395
|
+
online: o[e],
|
|
4396
|
+
presence: a[e]?.presence,
|
|
4397
|
+
mobile: s[e]
|
|
4398
|
+
})]
|
|
4399
|
+
}),
|
|
4400
|
+
/* @__PURE__ */ d("span", {
|
|
4401
|
+
className: "ci-truncate ci-flex-1",
|
|
4402
|
+
children: S(e)
|
|
4403
|
+
}),
|
|
4404
|
+
e !== _ && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Z, {
|
|
4405
|
+
variant: "small",
|
|
4406
|
+
title: "Chat",
|
|
4407
|
+
"aria-label": "Chat",
|
|
4408
|
+
onClick: () => m(e),
|
|
4409
|
+
children: Q.chat
|
|
4410
|
+
}), a[e]?.number && Ar(a[e]?.presence) && /* @__PURE__ */ d(Z, {
|
|
4411
|
+
variant: "call",
|
|
4412
|
+
title: `Call ${a[e]?.number}`,
|
|
4413
|
+
"aria-label": "Call",
|
|
4414
|
+
onClick: () => J("chat-island-call", {
|
|
4415
|
+
username: e,
|
|
4416
|
+
number: a[e].number
|
|
4417
|
+
}),
|
|
4418
|
+
children: Q.phone
|
|
4419
|
+
})] })
|
|
4420
|
+
]
|
|
4421
|
+
}, e))
|
|
4422
|
+
}),
|
|
4423
|
+
/* @__PURE__ */ f("div", {
|
|
4424
|
+
className: "ci-flex-1 ci-min-h-0 ci-flex ci-flex-col ci-overflow-hidden ci-rounded-b-3xl",
|
|
4425
|
+
children: [/* @__PURE__ */ d(mr, {
|
|
4426
|
+
messages: r.messages,
|
|
4427
|
+
typing: r.typing,
|
|
4428
|
+
group: r.kind === "group",
|
|
4429
|
+
hasOlder: r.loaded && !r.complete,
|
|
4430
|
+
onLoadOlder: () => t.loadOlder(e),
|
|
4431
|
+
reactions: r.reactions,
|
|
4432
|
+
me: _,
|
|
4433
|
+
onReact: (n, r) => t.react(e, n, r)
|
|
4434
|
+
}), /* @__PURE__ */ d(kr, {
|
|
4435
|
+
disabled: l !== "online",
|
|
4436
|
+
onSend: (n) => t.send(e, n),
|
|
4437
|
+
onTyping: (n) => t.typing(e, n),
|
|
4438
|
+
onFile: (n) => t.upload(e, n)
|
|
4439
|
+
}, e)]
|
|
4440
|
+
})
|
|
4441
|
+
]
|
|
4442
|
+
}) : null;
|
|
4443
|
+
}
|
|
4444
|
+
//#endregion
|
|
4445
|
+
//#region src/components/NewChat.tsx
|
|
4446
|
+
async function Mr(e) {
|
|
4447
|
+
let t = await createImageBitmap(e), n = Math.min(t.width, t.height), r = document.createElement("canvas");
|
|
4448
|
+
return r.width = r.height = 128, r.getContext("2d")?.drawImage(t, (t.width - n) / 2, (t.height - n) / 2, n, n, 0, 0, 128, 128), r.toDataURL("image/jpeg", .8);
|
|
4449
|
+
}
|
|
4450
|
+
function Nr({ onOpen: e, onCreateGroup: t }) {
|
|
4451
|
+
let { contacts: n, online: r, mobile: i, setPicker: a } = q(), [l, p] = c(""), [m, h] = c([]), [g, _] = c(""), [v, y] = c(!1), [b, x] = c(), S = s(null), C = o(() => {
|
|
4452
|
+
let e = Object.values(n), t = l.trim().toLowerCase();
|
|
4453
|
+
return t ? e.filter((e) => (e.name ?? "").toLowerCase().includes(t) || e.username.includes(t)) : e;
|
|
4454
|
+
}, [n, l]), w = (e) => h((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]), T = async () => {
|
|
4455
|
+
y(!0);
|
|
4456
|
+
try {
|
|
4457
|
+
await t(g.trim(), m, b);
|
|
4458
|
+
} finally {
|
|
4459
|
+
y(!1);
|
|
4460
|
+
}
|
|
4461
|
+
};
|
|
4462
|
+
return /* @__PURE__ */ f("div", {
|
|
4463
|
+
className: "ci-w-[22rem] ci-max-h-[30rem] ci-flex ci-flex-col ci-rounded-3xl ci-shadow-2xl ci-overflow-hidden ci-bg-gray-50 dark:ci-bg-gray-950 ci-text-gray-900 dark:ci-text-white",
|
|
4464
|
+
children: [
|
|
4465
|
+
/* @__PURE__ */ f("div", {
|
|
4466
|
+
className: "ci-px-4 ci-py-3 ci-flex ci-items-center ci-gap-2",
|
|
4467
|
+
children: [/* @__PURE__ */ f("div", {
|
|
4468
|
+
className: "ci-flex-1 ci-flex ci-items-center ci-gap-2 ci-px-4 ci-py-2 ci-rounded-3xl ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-500 dark:ci-text-gray-400",
|
|
4469
|
+
children: [Q.search, /* @__PURE__ */ d("input", {
|
|
4470
|
+
autoFocus: !0,
|
|
4471
|
+
value: l,
|
|
4472
|
+
onChange: (e) => p(e.target.value),
|
|
4473
|
+
placeholder: "Search colleagues",
|
|
4474
|
+
className: "ci-flex-1 ci-bg-transparent ci-border-0 ci-outline-none ci-text-sm ci-text-gray-900 dark:ci-text-white placeholder:ci-text-gray-500 dark:placeholder:ci-text-gray-400"
|
|
4475
|
+
})]
|
|
4476
|
+
}), /* @__PURE__ */ d(Z, {
|
|
4477
|
+
variant: "small",
|
|
4478
|
+
onClick: () => a(!1),
|
|
4479
|
+
"aria-label": "Close",
|
|
4480
|
+
children: Q.close
|
|
4481
|
+
})]
|
|
4482
|
+
}),
|
|
4483
|
+
m.length > 0 && /* @__PURE__ */ d("div", {
|
|
4484
|
+
className: "ci-px-4 ci-pb-2 ci-flex ci-flex-wrap ci-gap-1.5",
|
|
4485
|
+
children: m.map((e) => /* @__PURE__ */ f("button", {
|
|
4486
|
+
type: "button",
|
|
4487
|
+
onClick: () => w(e),
|
|
4488
|
+
className: "ci-flex ci-items-center ci-gap-1 ci-pl-2.5 ci-pr-1.5 ci-py-1 ci-rounded-full ci-text-xs ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900 ci-border-0",
|
|
4489
|
+
children: [n[e]?.name ?? e, Q.close]
|
|
4490
|
+
}, e))
|
|
4491
|
+
}),
|
|
4492
|
+
/* @__PURE__ */ d("div", { className: "ci-border-t ci-border-gray-300 dark:ci-border-gray-700" }),
|
|
4493
|
+
/* @__PURE__ */ f("ul", {
|
|
4494
|
+
className: "ci-overflow-y-auto ci-py-1 ci-m-0 ci-p-0 ci-list-none ci-flex-1",
|
|
4495
|
+
children: [C.length === 0 && /* @__PURE__ */ d("li", {
|
|
4496
|
+
className: "ci-px-4 ci-py-6 ci-text-center ci-text-sm ci-text-gray-500 dark:ci-text-gray-400",
|
|
4497
|
+
children: "No colleagues found"
|
|
4498
|
+
}), C.map((e) => {
|
|
4499
|
+
let t = m.includes(e.username);
|
|
4500
|
+
return /* @__PURE__ */ d("li", { children: /* @__PURE__ */ f("button", {
|
|
4501
|
+
type: "button",
|
|
4502
|
+
onClick: () => w(e.username),
|
|
4503
|
+
className: "ci-w-full ci-flex ci-items-center ci-gap-3 ci-px-4 ci-py-2 ci-bg-transparent ci-border-0 ci-text-left hover:ci-bg-gray-300/70 dark:hover:ci-bg-gray-700/30 ci-text-inherit",
|
|
4504
|
+
children: [
|
|
4505
|
+
/* @__PURE__ */ f("span", {
|
|
4506
|
+
className: "ci-relative",
|
|
4507
|
+
children: [/* @__PURE__ */ d(X, {
|
|
4508
|
+
contact: e,
|
|
4509
|
+
username: e.username,
|
|
4510
|
+
size: 36
|
|
4511
|
+
}), /* @__PURE__ */ d(Hn, {
|
|
4512
|
+
online: r[e.username],
|
|
4513
|
+
presence: e.presence,
|
|
4514
|
+
mobile: i[e.username]
|
|
4515
|
+
})]
|
|
4516
|
+
}),
|
|
4517
|
+
/* @__PURE__ */ f("span", {
|
|
4518
|
+
className: "ci-flex ci-flex-col ci-min-w-0 ci-flex-1",
|
|
4519
|
+
children: [/* @__PURE__ */ d("span", {
|
|
4520
|
+
className: "ci-text-sm ci-font-medium ci-truncate",
|
|
4521
|
+
children: e.name
|
|
4522
|
+
}), /* @__PURE__ */ d("span", {
|
|
4523
|
+
className: "ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-truncate",
|
|
4524
|
+
children: e.username
|
|
4525
|
+
})]
|
|
4526
|
+
}),
|
|
4527
|
+
/* @__PURE__ */ d("span", {
|
|
4528
|
+
className: `ci-w-5 ci-h-5 ci-rounded-full ci-border ci-flex ci-items-center ci-justify-center ${t ? "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark ci-border-transparent ci-text-white dark:ci-text-gray-950" : "ci-border-gray-400 dark:ci-border-gray-600"}`,
|
|
4529
|
+
children: t && /* @__PURE__ */ d("svg", {
|
|
4530
|
+
width: "12",
|
|
4531
|
+
height: "12",
|
|
4532
|
+
viewBox: "0 0 24 24",
|
|
4533
|
+
fill: "none",
|
|
4534
|
+
stroke: "currentColor",
|
|
4535
|
+
strokeWidth: "3",
|
|
4536
|
+
strokeLinecap: "round",
|
|
4537
|
+
strokeLinejoin: "round",
|
|
4538
|
+
children: /* @__PURE__ */ d("path", { d: "M20 6L9 17l-5-5" })
|
|
4539
|
+
})
|
|
4540
|
+
})
|
|
4541
|
+
]
|
|
4542
|
+
}) }, e.username);
|
|
4543
|
+
})]
|
|
4544
|
+
}),
|
|
4545
|
+
m.length > 0 && /* @__PURE__ */ d("div", {
|
|
4546
|
+
className: "ci-border-t ci-border-gray-300 dark:ci-border-gray-700 ci-px-4 ci-py-3 ci-flex ci-items-center ci-gap-2",
|
|
4547
|
+
children: m.length === 1 ? /* @__PURE__ */ d(Z, {
|
|
4548
|
+
variant: "default",
|
|
4549
|
+
className: "ci-w-auto ci-h-10 ci-px-5",
|
|
4550
|
+
onClick: () => e(m[0]),
|
|
4551
|
+
children: "Open chat"
|
|
4552
|
+
}) : /* @__PURE__ */ f(u, { children: [
|
|
4553
|
+
/* @__PURE__ */ d("input", {
|
|
4554
|
+
ref: S,
|
|
4555
|
+
type: "file",
|
|
4556
|
+
accept: "image/*",
|
|
4557
|
+
hidden: !0,
|
|
4558
|
+
onChange: (e) => e.target.files?.[0] && Mr(e.target.files[0]).then(x).catch(() => {})
|
|
4559
|
+
}),
|
|
4560
|
+
/* @__PURE__ */ d("button", {
|
|
4561
|
+
type: "button",
|
|
4562
|
+
title: "Group picture",
|
|
4563
|
+
onClick: () => S.current?.click(),
|
|
4564
|
+
className: "ci-w-10 ci-h-10 ci-shrink-0 ci-rounded-full ci-border-0 ci-p-0 ci-overflow-hidden ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-500 dark:ci-text-gray-400 ci-flex ci-items-center ci-justify-center",
|
|
4565
|
+
children: b ? /* @__PURE__ */ d("img", {
|
|
4566
|
+
src: b,
|
|
4567
|
+
alt: "",
|
|
4568
|
+
className: "ci-w-full ci-h-full ci-object-cover"
|
|
4569
|
+
}) : Q.camera
|
|
4570
|
+
}),
|
|
4571
|
+
/* @__PURE__ */ d("input", {
|
|
4572
|
+
value: g,
|
|
4573
|
+
onChange: (e) => _(e.target.value),
|
|
4574
|
+
placeholder: "Group name",
|
|
4575
|
+
onKeyDown: (e) => e.key === "Enter" && g.trim() && !v && T(),
|
|
4576
|
+
className: "ci-flex-1 ci-min-w-0 ci-w-0 ci-px-4 ci-py-2 ci-rounded-3xl ci-border-0 ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-sm ci-text-gray-900 dark:ci-text-white placeholder:ci-text-gray-500 dark:placeholder:ci-text-gray-400 ci-outline-none focus:ci-ring-2 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500"
|
|
4577
|
+
}),
|
|
4578
|
+
/* @__PURE__ */ d(Z, {
|
|
4579
|
+
variant: "green",
|
|
4580
|
+
className: "ci-w-auto ci-h-10 ci-px-4 ci-shrink-0 ci-whitespace-nowrap",
|
|
4581
|
+
disabled: !g.trim() || v,
|
|
4582
|
+
onClick: T,
|
|
4583
|
+
children: v ? "…" : "Create group"
|
|
4584
|
+
})
|
|
4585
|
+
] })
|
|
4586
|
+
})
|
|
4587
|
+
]
|
|
4588
|
+
});
|
|
4589
|
+
}
|
|
4590
|
+
//#endregion
|
|
4591
|
+
//#region src/ChatIsland.tsx
|
|
4592
|
+
function Pr() {
|
|
4593
|
+
let e = q.getState();
|
|
4594
|
+
return Object.values(e.conversations).map((t) => {
|
|
4595
|
+
let n = t.messages[t.messages.length - 1], r = e.contacts[t.peer];
|
|
4596
|
+
return {
|
|
4597
|
+
peer: t.peer,
|
|
4598
|
+
kind: t.kind,
|
|
4599
|
+
name: t.kind === "group" ? t.name ?? t.peer.split("@")[0] : r?.name ?? t.peer,
|
|
4600
|
+
avatar: t.kind === "group" ? t.avatar : r?.avatar,
|
|
4601
|
+
online: t.kind !== "group" && !!e.online[t.peer],
|
|
4602
|
+
mobile: t.kind !== "group" && !!e.mobile[t.peer],
|
|
4603
|
+
owner: t.kind === "group" ? !!t.owner : void 0,
|
|
4604
|
+
unread: t.unread,
|
|
4605
|
+
members: t.members,
|
|
4606
|
+
last: n ? {
|
|
4607
|
+
body: Lr(n.body),
|
|
4608
|
+
ts: n.ts,
|
|
4609
|
+
mine: n.mine,
|
|
4610
|
+
oob: n.oob,
|
|
4611
|
+
nick: n.nick
|
|
4612
|
+
} : void 0
|
|
4613
|
+
};
|
|
4614
|
+
}).filter((e) => e.last || e.kind === "group").sort((e, t) => (t.last?.ts ?? 0) - (e.last?.ts ?? 0));
|
|
4615
|
+
}
|
|
4616
|
+
var Fr = class extends t {
|
|
4617
|
+
state = { failed: !1 };
|
|
4618
|
+
failures = [];
|
|
4619
|
+
static getDerivedStateFromError() {
|
|
4620
|
+
return { failed: !0 };
|
|
4621
|
+
}
|
|
4622
|
+
componentDidCatch(e) {
|
|
4623
|
+
J("chat-island-error", {
|
|
4624
|
+
scope: "render",
|
|
4625
|
+
message: e.message
|
|
4626
|
+
});
|
|
4627
|
+
let t = Date.now();
|
|
4628
|
+
this.failures = [...this.failures.filter((e) => t - e < 1e4), t], !(this.failures.length >= 3) && (q.getState().closeChat(), window.setTimeout(() => this.setState({ failed: !1 }), 0));
|
|
4629
|
+
}
|
|
4630
|
+
render() {
|
|
4631
|
+
return this.state.failed ? null : this.props.children;
|
|
4632
|
+
}
|
|
4633
|
+
};
|
|
4634
|
+
function Ir(e) {
|
|
4635
|
+
try {
|
|
4636
|
+
let [t, n, r] = atob(e).split(":");
|
|
4637
|
+
return t && n && r ? {
|
|
4638
|
+
host: t,
|
|
4639
|
+
username: n,
|
|
4640
|
+
token: r
|
|
4641
|
+
} : null;
|
|
4642
|
+
} catch {
|
|
4643
|
+
return null;
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
var Lr = (e) => (sr(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
|
|
4647
|
+
function Rr({ dataConfig: e, position: t = "bottom-right", dark: n, serviceWorker: r, maxHeads: a = 5, newChatButton: l = !0, notifications: u = "click", sound: p = !0 }) {
|
|
4648
|
+
let m = o(() => Ir(e), [e]), h = s(m), g = s(p), _ = s(u);
|
|
4649
|
+
i(() => {
|
|
4650
|
+
h.current = m, g.current = p, _.current = u;
|
|
4651
|
+
}, [
|
|
4652
|
+
m,
|
|
4653
|
+
p,
|
|
4654
|
+
u
|
|
4655
|
+
]), i(() => q.setState({
|
|
4656
|
+
maxHeads: a,
|
|
4657
|
+
newChatButton: l
|
|
4658
|
+
}), [a, l]);
|
|
4659
|
+
let [v, y] = c(0);
|
|
4660
|
+
i(() => {
|
|
4661
|
+
let e = (e) => e.persisted && y((e) => e + 1);
|
|
4662
|
+
return window.addEventListener("pageshow", e), () => window.removeEventListener("pageshow", e);
|
|
4663
|
+
}, []);
|
|
4664
|
+
let b = s(null), x = s(/* @__PURE__ */ new Set()), S = s(!1), C = s(null), T = s(null), D = E(T, `chat-island-pos:${m?.host ?? ""}:${m?.username ?? ""}`), { open: O, picker: ee, status: k } = q(w((e) => ({
|
|
4665
|
+
open: e.open,
|
|
4666
|
+
picker: e.picker,
|
|
4667
|
+
status: e.status
|
|
4668
|
+
}))), te = o(() => ({
|
|
4669
|
+
send: async (e, t) => {
|
|
4670
|
+
let n = b.current;
|
|
4671
|
+
if (!n) throw Error("not connected");
|
|
4672
|
+
try {
|
|
4673
|
+
q.getState().addMessage(e, await n.send(e, $(t)));
|
|
4674
|
+
} catch (e) {
|
|
4675
|
+
throw J("chat-island-error", {
|
|
4676
|
+
scope: "send",
|
|
4677
|
+
message: e.message
|
|
4678
|
+
}), e;
|
|
4679
|
+
}
|
|
4680
|
+
},
|
|
4681
|
+
typing: (e, t) => q.getState().online[e] && b.current?.typing(e, t).catch(() => {}),
|
|
4682
|
+
upload: async (e, t) => {
|
|
4683
|
+
let n = b.current;
|
|
4684
|
+
if (n) try {
|
|
4685
|
+
let r = await n.upload(t);
|
|
4686
|
+
q.getState().addMessage(e, await n.send(e, t.name, r));
|
|
4687
|
+
} catch (e) {
|
|
4688
|
+
J("chat-island-error", {
|
|
4689
|
+
scope: "upload",
|
|
4690
|
+
message: e.message
|
|
4691
|
+
});
|
|
4692
|
+
}
|
|
4693
|
+
},
|
|
4694
|
+
createGroup: async (e, t, n) => {
|
|
4695
|
+
let r = b.current, i = h.current;
|
|
4696
|
+
if (r && i) try {
|
|
4697
|
+
let a = await r.createGroup(e, t, n), o = q.getState();
|
|
4698
|
+
o.setGroup(a, e, [...t, i.username], n), o.openChat(a);
|
|
4699
|
+
} catch (e) {
|
|
4700
|
+
J("chat-island-error", {
|
|
4701
|
+
scope: "group",
|
|
4702
|
+
message: e.message
|
|
4703
|
+
});
|
|
4704
|
+
}
|
|
4705
|
+
},
|
|
4706
|
+
remove: async (e) => {
|
|
4707
|
+
let t = b.current, n = h.current;
|
|
4708
|
+
if (!t || !n) return;
|
|
4709
|
+
let r = q.getState().conversations[e];
|
|
4710
|
+
try {
|
|
4711
|
+
r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await In(n.host, n.token, e), q.getState().removeConversation(e);
|
|
4712
|
+
} catch (e) {
|
|
4713
|
+
J("chat-island-error", {
|
|
4714
|
+
scope: "delete",
|
|
4715
|
+
message: e.message
|
|
4716
|
+
});
|
|
4717
|
+
}
|
|
4718
|
+
},
|
|
4719
|
+
react: async (e, t, n) => {
|
|
4720
|
+
let r = b.current, i = h.current?.username;
|
|
4721
|
+
if (!r || !i) return;
|
|
4722
|
+
let a = (q.getState().conversations[e]?.reactions?.[t]?.[i] ?? []).includes(n) ? [] : [n];
|
|
4723
|
+
try {
|
|
4724
|
+
await r.react(e, t, a), q.getState().applyReactions([{
|
|
4725
|
+
peer: e,
|
|
4726
|
+
target: t,
|
|
4727
|
+
user: i,
|
|
4728
|
+
emojis: a
|
|
4729
|
+
}]);
|
|
4730
|
+
} catch (e) {
|
|
4731
|
+
J("chat-island-error", {
|
|
4732
|
+
scope: "reaction",
|
|
4733
|
+
message: e.message
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
},
|
|
4737
|
+
loadOlder: async (e) => {
|
|
4738
|
+
let t = b.current, n = q.getState().ensure(e);
|
|
4739
|
+
if (!(!t || n.complete || x.current.has(e))) {
|
|
4740
|
+
x.current.add(e);
|
|
4741
|
+
try {
|
|
4742
|
+
let r = await t.history(e, n.oldest);
|
|
4743
|
+
q.getState().prependHistory(e, r.messages, r.complete, r.first), q.getState().applyReactions(r.reactions);
|
|
4744
|
+
} catch (e) {
|
|
4745
|
+
J("chat-island-error", {
|
|
4746
|
+
scope: "history",
|
|
4747
|
+
message: e.message
|
|
4748
|
+
});
|
|
4749
|
+
} finally {
|
|
4750
|
+
x.current.delete(e);
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
}), []);
|
|
4755
|
+
i(() => {
|
|
4756
|
+
if (!m) return;
|
|
4757
|
+
let e = q.getState();
|
|
4758
|
+
e.reset(), q.setState({
|
|
4759
|
+
me: m.username,
|
|
4760
|
+
mucHost: `conference.${m.host}`,
|
|
4761
|
+
maxHeads: a,
|
|
4762
|
+
newChatButton: l
|
|
4763
|
+
});
|
|
4764
|
+
let t = new vn(m, {
|
|
4765
|
+
status: (n, a) => {
|
|
4766
|
+
if (e.setStatus(n, a), J("chat-island-status", {
|
|
4767
|
+
status: n,
|
|
4768
|
+
error: a
|
|
4769
|
+
}), n === "online" && r && !S.current && typeof Notification < "u") {
|
|
4770
|
+
let e = Notification.permission;
|
|
4771
|
+
(e === "granted" || _.current === "auto" && e === "default") && i();
|
|
4772
|
+
}
|
|
4773
|
+
n === "online" && t.listGroups().then((t) => t.forEach((t) => e.setGroup(t.peer, t.name, t.members, t.avatar, t.owner))).catch(() => {}).then(() => t.recent()).then((e) => {
|
|
4774
|
+
e && (q.getState().seed(e.messages, m.username), q.getState().applyReactions(e.reactions));
|
|
4775
|
+
}).catch(() => {});
|
|
4776
|
+
},
|
|
4777
|
+
typing: (t, n) => e.setTyping(t, n),
|
|
4778
|
+
reaction: (t) => e.applyReactions([t]),
|
|
4779
|
+
presence: (t, n) => e.setOnline(t, n),
|
|
4780
|
+
groupInvite: (n) => {
|
|
4781
|
+
t.subscribed(n).then(async (r) => {
|
|
4782
|
+
if (!r) return;
|
|
4783
|
+
let i = await t.groupInfo(n);
|
|
4784
|
+
e.setGroup(i.peer, i.name, i.members, i.avatar, i.owner);
|
|
4785
|
+
}).catch(() => {});
|
|
4786
|
+
},
|
|
4787
|
+
message: (r) => {
|
|
4788
|
+
let i = jn(r);
|
|
4789
|
+
r.room && !q.getState().conversations[r.room]?.name && t.groupInfo(r.room).then((t) => e.setGroup(t.peer, t.name, t.members, t.avatar, t.owner)).catch(() => {}), e.addMessage(i, r, { live: !0 }), J("chat-island-message", {
|
|
4790
|
+
...r,
|
|
4791
|
+
peer: i
|
|
4792
|
+
}), J("chat-island-unread", { total: q.getState().totalUnread() }), r.mine || n(i, r);
|
|
4793
|
+
}
|
|
4794
|
+
}), n = (e, t) => {
|
|
4795
|
+
let n = q.getState(), r = document.visibilityState === "visible";
|
|
4796
|
+
if (r && n.open === e) return;
|
|
4797
|
+
let i = n.conversations[e], a = i?.kind === "group" ? i.name ?? e : n.contacts[e]?.name ?? e, o = t.oob ? "Attachment" : $(t.body), s = i?.kind === "group" && t.nick ? `${n.contacts[t.nick]?.name ?? t.nick}: ${o}` : o;
|
|
4798
|
+
if (g.current && Sn(), J("chat-island-notify", {
|
|
4799
|
+
peer: e,
|
|
4800
|
+
name: a,
|
|
4801
|
+
body: s
|
|
4802
|
+
}), !r && typeof Notification < "u" && Notification.permission === "granted") try {
|
|
4803
|
+
let t = new Notification(a, {
|
|
4804
|
+
body: s,
|
|
4805
|
+
tag: `chat-${e}`
|
|
4806
|
+
});
|
|
4807
|
+
t.onclick = () => {
|
|
4808
|
+
window.focus(), q.getState().openChat(e), t.close();
|
|
4809
|
+
};
|
|
4810
|
+
} catch {}
|
|
4811
|
+
};
|
|
4812
|
+
b.current = t;
|
|
4813
|
+
let i = () => {
|
|
4814
|
+
r && !S.current && (S.current = !0, Bn(m, r).then((e) => {
|
|
4815
|
+
if (!e) {
|
|
4816
|
+
S.current = !1, q.setState({ push: Notification.permission === "denied" ? "denied" : "ask" });
|
|
4817
|
+
return;
|
|
4818
|
+
}
|
|
4819
|
+
return t.enablePush(e.service, e.node).then(() => {
|
|
4820
|
+
C.current = e, q.setState({ push: "enabled" }), J("chat-island-push", { enabled: !0 });
|
|
4821
|
+
});
|
|
4822
|
+
}).catch((e) => {
|
|
4823
|
+
S.current = !1, J("chat-island-error", {
|
|
4824
|
+
scope: "push",
|
|
4825
|
+
message: e.message
|
|
4826
|
+
});
|
|
4827
|
+
}));
|
|
4828
|
+
}, o = !!r && "serviceWorker" in navigator && "PushManager" in window && typeof Notification < "u";
|
|
4829
|
+
q.setState({
|
|
4830
|
+
push: o ? Notification.permission === "denied" ? "denied" : "ask" : "unavailable",
|
|
4831
|
+
enablePush: i
|
|
4832
|
+
});
|
|
4833
|
+
let s = () => t.stop();
|
|
4834
|
+
window.addEventListener("pagehide", s), t.start();
|
|
4835
|
+
let c = () => Fn(m.host, m.token).then(e.setMobile).catch(() => {});
|
|
4836
|
+
c();
|
|
4837
|
+
let u = window.setInterval(c, 12e4);
|
|
4838
|
+
Pn(m.host, m.token, m.username).then(e.setContacts).catch((e) => J("chat-island-error", {
|
|
4839
|
+
scope: "contacts",
|
|
4840
|
+
message: e.message
|
|
4841
|
+
}));
|
|
4842
|
+
let d = Y("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = Y("chat-island-close", () => e.closeChat()), p = Y("chat-island-new", () => e.setPicker(!0)), h = Y("chat-island-delete", ({ username: e }) => e && te.remove(e)), v = Y("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), y = Y("chat-island-conversations-request", () => J("chat-island-conversations", { conversations: Pr() }));
|
|
4843
|
+
return () => {
|
|
4844
|
+
window.removeEventListener("pagehide", s), window.clearInterval(u), y(), p(), h(), d(), f(), v(), C.current && t.disablePush(C.current.service, C.current.node).catch(() => {}), C.current = null, t.stop(), b.current = null, S.current = !1;
|
|
4845
|
+
};
|
|
4846
|
+
}, [
|
|
4847
|
+
m,
|
|
4848
|
+
r,
|
|
4849
|
+
v
|
|
4850
|
+
]);
|
|
4851
|
+
let A = q((e) => Object.keys(e.contacts).join(","));
|
|
4852
|
+
i(() => {
|
|
4853
|
+
k === "online" && A && b.current?.announce(A.split(","));
|
|
4854
|
+
}, [k, A]);
|
|
4855
|
+
let ne = q((e) => Object.values(e.conversations).map((e) => `${e.peer}:${e.kind}:${e.name ?? ""}:${(e.members ?? []).length}:${e.unread}:${e.messages[e.messages.length - 1]?.id ?? ""}`).join("|") + "#" + Object.keys(e.contacts).length + "#" + Object.values(e.online).filter(Boolean).length);
|
|
4856
|
+
i(() => J("chat-island-conversations", { conversations: Pr() }), [ne]);
|
|
4857
|
+
let re = q((e) => Object.values(e.conversations).reduce((e, t) => e + t.unread, 0));
|
|
4858
|
+
if (i(() => J("chat-island-unread", { total: re }), [re]), !m) return null;
|
|
4859
|
+
let j = D.anchor ? {
|
|
4860
|
+
right: D.anchor.right,
|
|
4861
|
+
bottom: D.anchor.bottom
|
|
4862
|
+
} : void 0, ie = j ? "" : t === "bottom-left" ? "ci-left-4 ci-bottom-5" : "ci-right-4 ci-bottom-5";
|
|
4863
|
+
return /* @__PURE__ */ d("div", {
|
|
4864
|
+
ref: T,
|
|
4865
|
+
style: j,
|
|
4866
|
+
onClickCapture: D.onClickCapture,
|
|
4867
|
+
className: `chat-island-root ${n ? "dark" : ""} ci-fixed ${ie} ci-z-[9999] ci-flex ci-items-end ci-gap-3 ci-font-sans ci-select-none`,
|
|
4868
|
+
"data-status": k,
|
|
4869
|
+
children: /* @__PURE__ */ f(Fr, { children: [
|
|
4870
|
+
O && /* @__PURE__ */ d(jr, {
|
|
4871
|
+
peer: O,
|
|
4872
|
+
actions: te,
|
|
4873
|
+
onDragStart: D.start
|
|
4874
|
+
}),
|
|
4875
|
+
ee && /* @__PURE__ */ d(Nr, {
|
|
4876
|
+
onOpen: (e) => q.getState().openChat(e),
|
|
4877
|
+
onCreateGroup: te.createGroup
|
|
4878
|
+
}),
|
|
4879
|
+
/* @__PURE__ */ d(Kn, {
|
|
4880
|
+
onDragStart: D.start,
|
|
4881
|
+
pushButton: u !== "auto"
|
|
4882
|
+
})
|
|
4883
|
+
] })
|
|
4884
|
+
});
|
|
4885
|
+
}
|
|
4886
|
+
//#endregion
|
|
4887
|
+
export { Rr as ChatIsland };
|