chat4app-client-angular 0.0.35 → 0.0.36

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.
@@ -1,10 +1,749 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import * as i0 from '@angular/core';
2
3
  import { Injectable, Component, NgModule } from '@angular/core';
3
- import * as Stomp from 'stompjs';
4
- import * as SockJS from 'sockjs-client';
5
4
  import * as i1 from '@angular/common/http';
6
5
  import { HttpHeaders, HttpClient } from '@angular/common/http';
7
6
 
7
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
+
9
+ function getDefaultExportFromCjs (x) {
10
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
11
+ }
12
+
13
+ function getDefaultExportFromNamespaceIfPresent (n) {
14
+ return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
15
+ }
16
+
17
+ function getDefaultExportFromNamespaceIfNotNamed (n) {
18
+ return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
19
+ }
20
+
21
+ function getAugmentedNamespace(n) {
22
+ if (n.__esModule) return n;
23
+ var a = Object.defineProperty({}, '__esModule', {value: true});
24
+ Object.keys(n).forEach(function (k) {
25
+ var d = Object.getOwnPropertyDescriptor(n, k);
26
+ Object.defineProperty(a, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () {
29
+ return n[k];
30
+ }
31
+ });
32
+ });
33
+ return a;
34
+ }
35
+
36
+ function createCommonjsModule(fn) {
37
+ var module = { exports: {} };
38
+ return fn(module, module.exports), module.exports;
39
+ }
40
+
41
+ function commonjsRequire (target) {
42
+ throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.');
43
+ }
44
+
45
+ /**
46
+ * Skipped minification because the original files appears to be already minified.
47
+ * Original file: /npm/@provide/nats.ws@1.0.6/dist/umd/index.js
48
+ *
49
+ * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
50
+ */
51
+
52
+ var nats_min = createCommonjsModule(function (module, exports) {
53
+ !function (t, e) { "object" == 'object' && "object" == 'object' ? module.exports = e() : "function" == typeof undefined && undefined.amd ? undefined([], e) : "object" == 'object' ? exports.nats = e() : t.nats = e(); }(commonjsGlobal, (function () {
54
+ return function (t) { var e = {}; function r(n) { if (e[n])
55
+ return e[n].exports; var i = e[n] = { i: n, l: !1, exports: {} }; return t[n].call(i.exports, i, i.exports, r), i.l = !0, i.exports; } return r.m = t, r.c = e, r.d = function (t, e, n) { r.o(t, e) || Object.defineProperty(t, e, { enumerable: !0, get: n }); }, r.r = function (t) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(t, "__esModule", { value: !0 }); }, r.t = function (t, e) { if (1 & e && (t = r(t)), 8 & e)
56
+ return t; if (4 & e && "object" == typeof t && t && t.__esModule)
57
+ return t; var n = Object.create(null); if (r.r(n), Object.defineProperty(n, "default", { enumerable: !0, value: t }), 2 & e && "string" != typeof t)
58
+ for (var i in t)
59
+ r.d(n, i, function (e) { return t[e]; }.bind(null, i)); return n; }, r.n = function (t) { var e = t && t.__esModule ? function () { return t.default; } : function () { return t; }; return r.d(e, "a", e), e; }, r.o = function (t, e) { return Object.prototype.hasOwnProperty.call(t, e); }, r.p = "", r(r.s = 12); }([function (t, e, r) {
60
+ "use strict";
61
+ var n;
62
+ r.d(e, "a", (function () { return n; })), r.d(e, "b", (function () { return i; })), r.d(e, "c", (function () { return s; })), function (t) { t.BAD_AUTHENTICATION = "BAD_AUTHENTICATION", t.BAD_SUBJECT = "BAD_SUBJECT", t.CONNECTION_CLOSED = "CONNECTION_CLOSED", t.CONNECTION_DRAINING = "CONNECTION_DRAINING", t.CONNECTION_REFUSED = "CONNECTION_REFUSED", t.CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT", t.INVALID_PAYLOAD_TYPE = "INVALID_PAYLOAD", t.UNKNOWN = "UNKNOWN_ERROR", t.WSS_REQUIRED = "WSS_REQUIRED", t.SUB_CLOSED = "SUB_CLOSED", t.SUB_DRAINING = "SUB_DRAINING", t.PERMISSIONS_VIOLATION = "PERMISSIONS_VIOLATION", t.AUTHORIZATION_VIOLATION = "AUTHORIZATION_VIOLATION", t.NATS_PROTOCOL_ERR = "NATS_PROTOCOL_ERR"; }(n || (n = {}));
63
+ class i {
64
+ constructor() { this.messages = {}, this.messages[n.BAD_AUTHENTICATION] = "User and Token can not both be provided", this.messages[n.BAD_SUBJECT] = "Subject must be supplied", this.messages[n.CONNECTION_CLOSED] = "Connection closed", this.messages[n.CONNECTION_CLOSED] = "Connection closed", this.messages[n.CONNECTION_REFUSED] = "Connection refused", this.messages[n.CONNECTION_TIMEOUT] = "Connection timeout", this.messages[n.CONNECTION_DRAINING] = "Connection draining", this.messages[n.INVALID_PAYLOAD_TYPE] = "Invalid payload type - payloads can be 'binary', 'string', or 'json'", this.messages[n.SUB_CLOSED] = "Subscription closed", this.messages[n.SUB_DRAINING] = "Subscription draining", this.messages[n.WSS_REQUIRED] = "TLS is required, therefore a secure websocket connection is also required"; }
65
+ static getMessage(t) { return i.messages.getMessage(t); }
66
+ getMessage(t) { let e = this.messages[t]; return e || (e = t), e; }
67
+ }
68
+ i.messages = new i;
69
+ class s extends Error {
70
+ constructor(t, e, r) { super(t), this.name = "NatsError", this.message = t, this.code = e, this.chainedError = r; }
71
+ static errorForCode(t, e) { let r = i.getMessage(t); return new s(r, t, e); }
72
+ }
73
+ }, function (t, e, r) {
74
+ "use strict";
75
+ r.d(e, "d", (function () { return u; })), r.d(e, "b", (function () { return a; })), r.d(e, "c", (function () { return h; })), r.d(e, "a", (function () { return c; })), r.d(e, "e", (function () { return f; })), r.d(e, "f", (function () { return l; }));
76
+ var n = r(2);
77
+ let i = n.a.fromAscii("\r\n"), s = new Uint8Array(i)[0], o = new Uint8Array(i)[1];
78
+ function u(t) { return t instanceof ArrayBuffer; }
79
+ function a(t, ...e) { for (let r = 0; r < e.length; r++) {
80
+ let n = e[r];
81
+ Object.keys(n).forEach((function (e) { t[e] = n[e]; }));
82
+ } return t; }
83
+ function h(t) { let e = function (t) { let e = new Uint8Array(t); for (let t = 0; t < e.byteLength; t++) {
84
+ let r = t + 1;
85
+ if (e.byteLength > r && e[t] === s && e[r] === o)
86
+ return r + 1;
87
+ } return -1; }(t); if (e) {
88
+ let r = new Uint8Array(t).slice(0, e);
89
+ return String.fromCharCode.apply(null, r);
90
+ } return ""; }
91
+ function c(t, e) { let r = n.a.fromAscii(t); return e && (r = n.a.concat(r, e, i)), r; }
92
+ function f(t) { return Array.isArray(t) ? Promise.resolve(t).then(d) : Promise.reject(new TypeError("argument requires an array of promises")); }
93
+ function l(t) { const e = t.split(""), r = []; for (var n = 0; n < e.length; n++)
94
+ r.push(e[n].charCodeAt(0)); return new Uint8Array(r); }
95
+ function d(t) { return Promise.all(t.map(t => Promise.resolve(t).then(p, p))); }
96
+ function p(t) { return t; }
97
+ }, function (t, e, r) {
98
+ "use strict";
99
+ r.d(e, "a", (function () { return n; }));
100
+ class n {
101
+ constructor() { this.buffers = [], this.byteLength = 0; }
102
+ static concat(...t) { let e = 0; for (let r = 0; r < t.length; r++)
103
+ e += t[r].byteLength; let r = new Uint8Array(e), n = 0; for (let e = 0; e < t.length; e++)
104
+ r.set(new Uint8Array(t[e]), n), n += t[e].byteLength; return r.buffer; }
105
+ static fromAscii(t) { t || (t = ""); let e = new ArrayBuffer(t.length), r = new Uint8Array(e); for (let e = 0; e < t.length; e++)
106
+ r[e] = t.charCodeAt(e); return e; }
107
+ static toAscii(t) { return String.fromCharCode.apply(null, new Uint8Array(t)); }
108
+ pack() { if (this.buffers.length > 1) {
109
+ let t = this.buffers.splice(0, this.buffers.length);
110
+ this.buffers.push(n.concat(...t));
111
+ } }
112
+ drain(t) { if (this.buffers.length) {
113
+ this.pack();
114
+ let e = this.buffers.pop();
115
+ if (e) {
116
+ let r = this.byteLength;
117
+ (void 0 === t || t > r) && (t = r);
118
+ let n = e.slice(0, t);
119
+ return r > t && this.buffers.push(e.slice(t)), this.byteLength = r - t, n;
120
+ }
121
+ } return new Uint8Array(0).buffer; }
122
+ fill(t) { t && (this.buffers.push(t), this.byteLength += t.byteLength); }
123
+ peek() { return this.buffers.length ? (this.pack(), this.buffers[0]) : new Uint8Array(0).buffer; }
124
+ size() { return this.byteLength; }
125
+ length() { return this.buffers.length; }
126
+ }
127
+ }, function (t, e, r) {
128
+ "use strict";
129
+ var n;
130
+ r.d(e, "a", (function () { return n; })), function (t) { t.STRING = "string", t.JSON = "json", t.BINARY = "binary"; }(n || (n = {}));
131
+ }, function (t, e, r) {
132
+ "use strict";
133
+ (function (t) { r.d(e, "d", (function () { return c; })), r.d(e, "i", (function () { return m; })), r.d(e, "a", (function () { return w; })), r.d(e, "k", (function () { return A; })), r.d(e, "j", (function () { return E; })), r.d(e, "f", (function () { return O; })), r.d(e, "g", (function () { return N; })), r.d(e, "c", (function () { return C; })), r.d(e, "h", (function () { return T; })), r.d(e, "b", (function () { return S; })), r.d(e, "e", (function () { return I; })); var n = r(3), i = r(5), s = r(0), o = r(1), u = r(6), a = r(2); let h; var c; !function (t) { t[t.CLOSED = -1] = "CLOSED", t[t.AWAITING_CONTROL = 0] = "AWAITING_CONTROL", t[t.AWAITING_MSG_PAYLOAD = 1] = "AWAITING_MSG_PAYLOAD"; }(c || (c = {})); const f = /^MSG\s+([^\s\r\n]+)\s+([^\s\r\n]+)\s+(([^\s\r\n]+)[^\S\r\n]+)?(\d+)\r\n/i, l = /^\+OK\s*\r\n/i, d = /^-ERR\s+('.+')?\r\n/i, p = /^PING\r\n/i, g = /^PONG\r\n/i, b = /^INFO\s+([^\r\n]+)\r\n/i, y = "\r\n".length; function m() { return h || (h = new u.a), `_INBOX.${h.next()}`; } class w {
134
+ constructor(t) { this.lang = "javascript", this.pedantic = !1, this.protocol = 1, this.verbose = !1, (t = t || {}).token && (this.auth_token = t.token), t.noEcho && (this.echo = !1), t.userJWT && ("function" == typeof t.userJWT ? this.jwt = t.userJWT() : this.jwt = t.userJWT), Object(o.b)(this, t); }
135
+ } function A() { return { sid: 0, subject: "", received: 0 }; } function E() { return { token: "", subject: "", received: 0, max: 1 }; } class O {
136
+ constructor(t, e) { this.token = t.token, this.protocol = e; }
137
+ cancel() { this.protocol.cancelRequest(this.token, 0); }
138
+ } class N {
139
+ constructor(t, e) { this.sid = t.sid, this.protocol = e; }
140
+ unsubscribe(t) { this.protocol.unsubscribe(this.sid, t); }
141
+ hasTimeout() { let t = this.protocol.subscriptions.get(this.sid); return null !== t && null !== t.timeout; }
142
+ cancelTimeout() { let t = this.protocol.subscriptions.get(this.sid); null !== t && null !== t.timeout && (clearTimeout(t.timeout), t.timeout = null); }
143
+ setTimeout(t, e) { let r = this.protocol.subscriptions.get(this.sid); return null !== r && (r.timeout && (clearTimeout(r.timeout), r.timeout = null), r.timeout = setTimeout(e, t), !0); }
144
+ getReceived() { let t = this.protocol.subscriptions.get(this.sid); return t ? t.received : 0; }
145
+ drain() { return this.protocol.drainSubscription(this.sid); }
146
+ isDraining() { let t = this.protocol.subscriptions.get(this.sid); return !!t && t.draining; }
147
+ isCancelled() { return null === this.protocol.subscriptions.get(this.sid); }
148
+ } class C {
149
+ constructor() { this.reqs = {}, this.length = 0; }
150
+ init() { return this.baseInbox = `${m()}.`, this.baseInbox; }
151
+ add(t) { isNaN(t.received) || (t.received = 0), this.length++, this.reqs[t.token] = t; }
152
+ get(t) { return t in this.reqs ? this.reqs[t] : null; }
153
+ cancel(t) { t && t.timeout && (clearTimeout(t.timeout), t.timeout = null), t.token in this.reqs && (delete this.reqs[t.token], this.length--); }
154
+ getToken(t) { let e = t.subject || ""; return 0 === e.indexOf(this.baseInbox) ? e.substring(this.baseInbox.length) : null; }
155
+ dispatcher() { let t = this; return function (e) { let r = t.getToken(e); if (r) {
156
+ let n = t.get(r);
157
+ n && (n.received++, n.callback(e), n.max && n.received >= n.max && t.cancel(n));
158
+ } }; }
159
+ } class T {
160
+ constructor() { this.subs = {}, this.sidCounter = 0, this.length = 0; }
161
+ add(t) { return this.sidCounter++, this.length++, t.sid = this.sidCounter, this.subs[t.sid] = t, t; }
162
+ setMux(t) { return this.mux = t, t; }
163
+ getMux() { return this.mux; }
164
+ get(t) { return t in this.subs ? this.subs[t] : null; }
165
+ all() { let t = []; for (let e in this.subs) {
166
+ let r = this.subs[e];
167
+ t.push(r);
168
+ } return t; }
169
+ cancel(t) { t && t.timeout && (clearTimeout(t.timeout), t.timeout = null), t.sid in this.subs && (delete this.subs[t.sid], this.length--); }
170
+ } class S {
171
+ constructor(t, e = "string") { this.msg = {}, this.msg.subject = t[1], this.msg.sid = parseInt(t[2], 10), this.msg.reply = t[4], this.msg.size = parseInt(t[5], 10), this.length = this.msg.size + y, this.payload = e; }
172
+ fill(e) { if (this.buf ? this.buf = a.a.concat(this.buf, e) : this.buf = e, this.length -= e.byteLength, 0 === this.length) {
173
+ switch (this.msg.data = this.buf.slice(0, this.buf.byteLength - 2), this.payload) {
174
+ case n.a.JSON:
175
+ this.msg.data = t.from(this.msg.data).toString("utf8"), this.msg.data = JSON.parse(this.msg.data);
176
+ break;
177
+ case n.a.STRING:
178
+ this.msg.data = t.from(this.msg.data).toString("utf8");
179
+ break;
180
+ case n.a.BINARY:
181
+ }
182
+ this.buf = null;
183
+ } }
184
+ } class I {
185
+ constructor(t, e) { this.infoReceived = !1, this.payload = null, this.pongs = [], this.pout = 0, this.state = c.AWAITING_CONTROL, this.noMorePublishing = !1, this.options = t, this.clientHandlers = e, this.subscriptions = new T, this.muxSubscriptions = new C, this.inbound = new a.a, this.outbound = new a.a; }
186
+ static connect(t, e) { return new Promise((r, n) => { let o = new I(t, e); o.connectError = n; let u = t.connectTimeout || 1e4, a = new Promise((t, e) => { let r = setTimeout(() => { e(s.c.errorForCode(s.a.CONNECTION_TIMEOUT)); }, u); o.pongs.push(() => { clearTimeout(r), t(!0); }); }); i.a.connect(t, o, t.debug).then(t => { o.transport = t; }).catch(t => { o.connectError = null, n(t); }), a.then(() => { o.connectError = null, r(o); }).catch(t => { o.connectError = null, n(t); }); }); }
187
+ static toError(t) { let e = t ? t.toLowerCase() : ""; return -1 !== e.indexOf("permissions violation") ? new s.c(t, s.a.PERMISSIONS_VIOLATION) : -1 !== e.indexOf("authorization violation") ? new s.c(t, s.a.AUTHORIZATION_VIOLATION) : new s.c(t, s.a.NATS_PROTOCOL_ERR); }
188
+ processInbound() { let t = null; for (; this.inbound.size();) {
189
+ switch (this.state) {
190
+ case c.CLOSED: return;
191
+ case c.AWAITING_CONTROL:
192
+ let e = this.inbound.peek(), r = Object(o.c)(e);
193
+ if (t = f.exec(r))
194
+ this.payload = new S(t, this.options.payload), this.state = c.AWAITING_MSG_PAYLOAD;
195
+ else if (t = l.exec(r))
196
+ ;
197
+ else {
198
+ if (t = d.exec(r))
199
+ return void this.processError(t[1]);
200
+ if (t = g.exec(r)) {
201
+ this.pout = 0;
202
+ let t = this.pongs.shift();
203
+ t && t();
204
+ }
205
+ else if (t = p.exec(r))
206
+ this.transport.write(Object(o.a)("PONG \r\n"));
207
+ else {
208
+ if (!(t = b.exec(r)))
209
+ return;
210
+ if (!this.infoReceived) {
211
+ if (JSON.parse(t[1]).tls_required && !this.transport.isSecure())
212
+ return void this.handleError(s.c.errorForCode(s.a.WSS_REQUIRED));
213
+ let e = JSON.stringify(new w(this.options));
214
+ this.transport.write(Object(o.a)(`CONNECT ${e}\r\n`)), this.sendSubscriptions(), this.transport.write(Object(o.a)("PING \r\n")), this.infoReceived = !0, this.flushPending();
215
+ }
216
+ }
217
+ }
218
+ break;
219
+ case c.AWAITING_MSG_PAYLOAD:
220
+ if (!this.payload)
221
+ break;
222
+ if (this.inbound.size() < this.payload.length) {
223
+ let t = this.inbound.drain();
224
+ return void this.payload.fill(t);
225
+ }
226
+ let n = this.inbound.drain(this.payload.length);
227
+ this.payload.fill(n);
228
+ try {
229
+ this.processMsg();
230
+ }
231
+ catch (t) { }
232
+ this.state = c.AWAITING_CONTROL, this.payload = null;
233
+ }
234
+ if (t) {
235
+ let e = t[0].length;
236
+ e >= this.inbound.size() ? this.inbound.drain() : this.inbound.drain(e), t = null;
237
+ }
238
+ } }
239
+ processMsg() { if (!this.payload || !this.subscriptions.sidCounter)
240
+ return; let t = this.payload, e = this.subscriptions.get(t.msg.sid); e && (e.received += 1, e.timeout && void 0 === e.max && (clearTimeout(e.timeout), e.timeout = null), e.callback && e.callback(t.msg), void 0 !== e.max && e.received >= e.max && this.unsubscribe(e.sid)); }
241
+ sendCommand(t) { let e; e = "string" == typeof t ? Object(o.f)(t) : t, t && this.outbound.fill(e), 1 === this.outbound.length() ? setTimeout(() => { this.flushPending(); }) : this.outbound.size() > 8192 && this.flushPending(); }
242
+ publish(e, r, n) { if (this.isClosed())
243
+ throw s.c.errorForCode(s.a.CONNECTION_CLOSED); if (this.noMorePublishing)
244
+ throw s.c.errorForCode(s.a.CONNECTION_DRAINING); let i, u = t.byteLength(r); i = (n = n || "") ? `PUB ${e} ${n} ${u}\r\n` : `PUB ${e} ${u}\r\n`, this.sendCommand(Object(o.a)(i, r)); }
245
+ request(t) { return this.initMux(), this.muxSubscriptions.add(t), new O(t, this); }
246
+ subscribe(t) { let e = this.subscriptions.add(t); return e.queue ? this.sendCommand(`SUB ${e.subject} ${e.queue} ${e.sid}\r\n`) : this.sendCommand(`SUB ${e.subject} ${e.sid}\r\n`), new N(e, this); }
247
+ unsubscribe(t, e) { if (!t || this.isClosed())
248
+ return; let r = this.subscriptions.get(t); r && (e ? this.sendCommand(`UNSUB ${t} ${e}\r\n`) : this.sendCommand(`UNSUB ${t}\r\n`), r.max = e, (void 0 === r.max || r.received >= r.max) && this.subscriptions.cancel(r)); }
249
+ cancelRequest(t, e) { if (!t || this.isClosed())
250
+ return; let r = this.muxSubscriptions.get(t); r && (r.max = e, (void 0 === r.max || r.received >= r.max) && this.muxSubscriptions.cancel(r)); }
251
+ flush(t) { this.pongs.push(t), this.sendCommand("PING \r\n"); }
252
+ processError(t) { let e = { error: I.toError(t) }; this.errorHandler(e); }
253
+ sendSubscriptions() { let t = []; this.subscriptions.all().forEach(e => { e.queue ? t.push(`SUB ${e.subject} ${e.queue} ${e.sid} \r\n`) : t.push(`SUB ${e.subject} ${e.sid} \r\n`); }), t.length && this.transport.write(Object(o.a)(t.join(""))); }
254
+ openHandler(t) { }
255
+ closeHandler(t) { this.close(), this.clientHandlers.closeHandler(); }
256
+ errorHandler(t) { let e; t && (e = t.error), this.handleError(e); }
257
+ messageHandler(t) { this.inbound.fill(t.data), this.processInbound(); }
258
+ close() { this.transport.close(), this.state = c.CLOSED; }
259
+ isClosed() { return this.transport.isClosed(); }
260
+ drain() { let t = this.subscriptions.all(), e = []; return t.forEach(t => { let r = this.drainSubscription(t.sid); e.push(r); }), new Promise(t => { Object(o.e)(e).then(e => { this.noMorePublishing = !0, setTimeout(() => { this.close(), t(e); }); }).catch(() => { }); }); }
261
+ drainSubscription(t) { if (this.isClosed())
262
+ return Promise.reject(s.c.errorForCode(s.a.CONNECTION_CLOSED)); if (!t)
263
+ return Promise.reject(s.c.errorForCode(s.a.SUB_CLOSED)); let e = this.subscriptions.get(t); if (!e)
264
+ return Promise.reject(s.c.errorForCode(s.a.SUB_CLOSED)); if (e.draining)
265
+ return Promise.reject(s.c.errorForCode(s.a.SUB_DRAINING)); let r = e; return new Promise(t => { r.draining = !0, this.sendCommand(`UNSUB ${r.sid}\r\n`), this.flush(() => { this.subscriptions.cancel(r), t(r); }); }); }
266
+ flushPending() { if (this.infoReceived && this.outbound.size()) {
267
+ let t = this.outbound.drain();
268
+ this.transport.write(t);
269
+ } }
270
+ initMux() { if (!this.subscriptions.getMux()) {
271
+ let t = this.muxSubscriptions.init(), e = { sid: 0, subject: "", received: 0 };
272
+ e.subject = `${t}*`, e.callback = this.muxSubscriptions.dispatcher(), this.subscriptions.setMux(e), this.subscribe(e);
273
+ } }
274
+ handleError(t) { this.connectError && (this.connectError(t), this.connectError = null), this.close(), this.clientHandlers.errorHandler(t); }
275
+ } }).call(this, r(7).Buffer);
276
+ }, function (t, e, r) {
277
+ "use strict";
278
+ r.d(e, "a", (function () { return i; }));
279
+ var n = r(0);
280
+ class i {
281
+ constructor(t) { this.stream = null, this.closed = !1, this.debug = !1, this.listeners = {}, this.handlers = t; }
282
+ static connect(t, e, r = !1) { return new Promise((s, o) => { let u, a = new i(e); a.debug = r, a.stream = new WebSocket(t.url), a.stream.binaryType = "arraybuffer", a.listeners = {}, a.stream.onclose = function (t) { a.trace("ws closed", t), a.closed || (u ? (a.handlers.closeHandler(t), a.close()) : (clearTimeout(void 0), o(n.c.errorForCode(n.a.CONNECTION_CLOSED)))); }, a.stream.onerror = function (t) { let e; if (t && (e = t.error, !e)) {
283
+ let r = t.message;
284
+ e = r ? new n.c(r, n.a.UNKNOWN) : u ? n.c.errorForCode(n.a.UNKNOWN) : n.c.errorForCode(n.a.CONNECTION_REFUSED);
285
+ } a.trace("ws error", e), a.closed || (a && a.close(), u ? a.handlers.errorHandler(t) : o(e)); }, a.stream.onopen = function () { a.trace("ws open"); }, a.stream.onmessage = function (t) { a.trace(">", [t.data]), u ? a.handlers.messageHandler(t) : (u = !0, s(a), setTimeout((function () { a.handlers.messageHandler(t); }), 100)); }; }); }
286
+ isClosed() { return this.closed; }
287
+ isConnected() { return null !== this.stream && this.stream.readyState === WebSocket.OPEN; }
288
+ write(t) { this.stream && this.isConnected() && (this.trace("<", [t]), this.stream.send(t)); }
289
+ destroy() { this.stream && (this.closed && (this.stream.onclose = null, this.stream.onerror = null, this.stream.onopen = null, this.stream.onmessage = null), this.stream.readyState !== WebSocket.CLOSED && this.stream.readyState !== WebSocket.CLOSING && this.stream.close(1e3), this.stream = null); }
290
+ close() { this.closed = !0, this.stream && this.stream.bufferedAmount > 0 ? setTimeout(this.close.bind(this), 100) : this.destroy(); }
291
+ trace(...t) { this.debug && console.log(t); }
292
+ isSecure() { if (this.stream) {
293
+ return "wss:" === new URL(this.stream.url).protocol.toLowerCase();
294
+ } return !1; }
295
+ }
296
+ }, function (t, e, r) {
297
+ "use strict";
298
+ r.d(e, "a", (function () { return s; }));
299
+ const n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
300
+ let i;
301
+ class s {
302
+ constructor() { this.buf = new Uint8Array(22), this.init(); }
303
+ init() { "crypto" in Object({}) && Object({}).crypto.getRandomValues ? i = Object({}).crypto : "msCrypto" in Object({}) && Object({}).msCrypto.getRandomValues && (i = Object({}).msCrypto), i || (i = { getRandomValues: function (t) { for (let e = 0; e < t.length; e++)
304
+ t[e] = Math.floor(255 * Math.random()); } }), this.setPre(), this.initSeqAndInc(), this.fillSeq(); }
305
+ initSeqAndInc() { this.seq = Math.floor(0xcfd41b9100000 * Math.random()), this.inc = Math.floor(300 * Math.random() + 33); }
306
+ setPre() { let t = new Uint8Array(12); i.getRandomValues(t); for (let e = 0; e < 12; e++) {
307
+ let r = t[e] % 36;
308
+ this.buf[e] = n.charCodeAt(r);
309
+ } }
310
+ fillSeq() { let t = this.seq; for (let e = 21; e >= 12; e--)
311
+ this.buf[e] = n.charCodeAt(t % 36), t = Math.floor(t / 36); }
312
+ next() { return this.seq += this.inc, this.seq > 0xcfd41b9100000 && (this.setPre(), this.initSeqAndInc()), this.fillSeq(), String.fromCharCode.apply(String, this.buf); }
313
+ reset() { this.init(); }
314
+ }
315
+ }, function (t, e, r) {
316
+ "use strict";
317
+ (function (t) {
318
+ /*!
319
+ * The buffer module from node.js, for the browser.
320
+ *
321
+ * @author Feross Aboukhadijeh <http://feross.org>
322
+ * @license MIT
323
+ */
324
+ var n = r(9), i = r(10), s = r(11);
325
+ function o() { return a.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823; }
326
+ function u(t, e) { if (o() < e)
327
+ throw new RangeError("Invalid typed array length"); return a.TYPED_ARRAY_SUPPORT ? (t = new Uint8Array(e)).__proto__ = a.prototype : (null === t && (t = new a(e)), t.length = e), t; }
328
+ function a(t, e, r) { if (!(a.TYPED_ARRAY_SUPPORT || this instanceof a))
329
+ return new a(t, e, r); if ("number" == typeof t) {
330
+ if ("string" == typeof e)
331
+ throw new Error("If encoding is specified then the first argument must be a string");
332
+ return f(this, t);
333
+ } return h(this, t, e, r); }
334
+ function h(t, e, r, n) { if ("number" == typeof e)
335
+ throw new TypeError('"value" argument must not be a number'); return "undefined" != typeof ArrayBuffer && e instanceof ArrayBuffer ? function (t, e, r, n) { if (e.byteLength, r < 0 || e.byteLength < r)
336
+ throw new RangeError("'offset' is out of bounds"); if (e.byteLength < r + (n || 0))
337
+ throw new RangeError("'length' is out of bounds"); e = void 0 === r && void 0 === n ? new Uint8Array(e) : void 0 === n ? new Uint8Array(e, r) : new Uint8Array(e, r, n); a.TYPED_ARRAY_SUPPORT ? (t = e).__proto__ = a.prototype : t = l(t, e); return t; }(t, e, r, n) : "string" == typeof e ? function (t, e, r) { "string" == typeof r && "" !== r || (r = "utf8"); if (!a.isEncoding(r))
338
+ throw new TypeError('"encoding" must be a valid string encoding'); var n = 0 | p(e, r), i = (t = u(t, n)).write(e, r); i !== n && (t = t.slice(0, i)); return t; }(t, e, r) : function (t, e) { if (a.isBuffer(e)) {
339
+ var r = 0 | d(e.length);
340
+ return 0 === (t = u(t, r)).length ? t : (e.copy(t, 0, 0, r), t);
341
+ } if (e) {
342
+ if ("undefined" != typeof ArrayBuffer && e.buffer instanceof ArrayBuffer || "length" in e)
343
+ return "number" != typeof e.length || (n = e.length) != n ? u(t, 0) : l(t, e);
344
+ if ("Buffer" === e.type && s(e.data))
345
+ return l(t, e.data);
346
+ } var n; throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object."); }(t, e); }
347
+ function c(t) { if ("number" != typeof t)
348
+ throw new TypeError('"size" argument must be a number'); if (t < 0)
349
+ throw new RangeError('"size" argument must not be negative'); }
350
+ function f(t, e) { if (c(e), t = u(t, e < 0 ? 0 : 0 | d(e)), !a.TYPED_ARRAY_SUPPORT)
351
+ for (var r = 0; r < e; ++r)
352
+ t[r] = 0; return t; }
353
+ function l(t, e) { var r = e.length < 0 ? 0 : 0 | d(e.length); t = u(t, r); for (var n = 0; n < r; n += 1)
354
+ t[n] = 255 & e[n]; return t; }
355
+ function d(t) { if (t >= o())
356
+ throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + o().toString(16) + " bytes"); return 0 | t; }
357
+ function p(t, e) { if (a.isBuffer(t))
358
+ return t.length; if ("undefined" != typeof ArrayBuffer && "function" == typeof ArrayBuffer.isView && (ArrayBuffer.isView(t) || t instanceof ArrayBuffer))
359
+ return t.byteLength; "string" != typeof t && (t = "" + t); var r = t.length; if (0 === r)
360
+ return 0; for (var n = !1;;)
361
+ switch (e) {
362
+ case "ascii":
363
+ case "latin1":
364
+ case "binary": return r;
365
+ case "utf8":
366
+ case "utf-8":
367
+ case void 0: return k(t).length;
368
+ case "ucs2":
369
+ case "ucs-2":
370
+ case "utf16le":
371
+ case "utf-16le": return 2 * r;
372
+ case "hex": return r >>> 1;
373
+ case "base64": return F(t).length;
374
+ default:
375
+ if (n)
376
+ return k(t).length;
377
+ e = ("" + e).toLowerCase(), n = !0;
378
+ } }
379
+ function g(t, e, r) { var n = !1; if ((void 0 === e || e < 0) && (e = 0), e > this.length)
380
+ return ""; if ((void 0 === r || r > this.length) && (r = this.length), r <= 0)
381
+ return ""; if ((r >>>= 0) <= (e >>>= 0))
382
+ return ""; for (t || (t = "utf8");;)
383
+ switch (t) {
384
+ case "hex": return v(this, e, r);
385
+ case "utf8":
386
+ case "utf-8": return S(this, e, r);
387
+ case "ascii": return I(this, e, r);
388
+ case "latin1":
389
+ case "binary": return _(this, e, r);
390
+ case "base64": return T(this, e, r);
391
+ case "ucs2":
392
+ case "ucs-2":
393
+ case "utf16le":
394
+ case "utf-16le": return R(this, e, r);
395
+ default:
396
+ if (n)
397
+ throw new TypeError("Unknown encoding: " + t);
398
+ t = (t + "").toLowerCase(), n = !0;
399
+ } }
400
+ function b(t, e, r) { var n = t[e]; t[e] = t[r], t[r] = n; }
401
+ function y(t, e, r, n, i) { if (0 === t.length)
402
+ return -1; if ("string" == typeof r ? (n = r, r = 0) : r > 2147483647 ? r = 2147483647 : r < -2147483648 && (r = -2147483648), r = +r, isNaN(r) && (r = i ? 0 : t.length - 1), r < 0 && (r = t.length + r), r >= t.length) {
403
+ if (i)
404
+ return -1;
405
+ r = t.length - 1;
406
+ }
407
+ else if (r < 0) {
408
+ if (!i)
409
+ return -1;
410
+ r = 0;
411
+ } if ("string" == typeof e && (e = a.from(e, n)), a.isBuffer(e))
412
+ return 0 === e.length ? -1 : m(t, e, r, n, i); if ("number" == typeof e)
413
+ return e &= 255, a.TYPED_ARRAY_SUPPORT && "function" == typeof Uint8Array.prototype.indexOf ? i ? Uint8Array.prototype.indexOf.call(t, e, r) : Uint8Array.prototype.lastIndexOf.call(t, e, r) : m(t, [e], r, n, i); throw new TypeError("val must be string, number or Buffer"); }
414
+ function m(t, e, r, n, i) { var s, o = 1, u = t.length, a = e.length; if (void 0 !== n && ("ucs2" === (n = String(n).toLowerCase()) || "ucs-2" === n || "utf16le" === n || "utf-16le" === n)) {
415
+ if (t.length < 2 || e.length < 2)
416
+ return -1;
417
+ o = 2, u /= 2, a /= 2, r /= 2;
418
+ } function h(t, e) { return 1 === o ? t[e] : t.readUInt16BE(e * o); } if (i) {
419
+ var c = -1;
420
+ for (s = r; s < u; s++)
421
+ if (h(t, s) === h(e, -1 === c ? 0 : s - c)) {
422
+ if (-1 === c && (c = s), s - c + 1 === a)
423
+ return c * o;
424
+ }
425
+ else
426
+ -1 !== c && (s -= s - c), c = -1;
427
+ }
428
+ else
429
+ for (r + a > u && (r = u - a), s = r; s >= 0; s--) {
430
+ for (var f = !0, l = 0; l < a; l++)
431
+ if (h(t, s + l) !== h(e, l)) {
432
+ f = !1;
433
+ break;
434
+ }
435
+ if (f)
436
+ return s;
437
+ } return -1; }
438
+ function w(t, e, r, n) { r = Number(r) || 0; var i = t.length - r; n ? (n = Number(n)) > i && (n = i) : n = i; var s = e.length; if (s % 2 != 0)
439
+ throw new TypeError("Invalid hex string"); n > s / 2 && (n = s / 2); for (var o = 0; o < n; ++o) {
440
+ var u = parseInt(e.substr(2 * o, 2), 16);
441
+ if (isNaN(u))
442
+ return o;
443
+ t[r + o] = u;
444
+ } return o; }
445
+ function A(t, e, r, n) { return G(k(e, t.length - r), t, r, n); }
446
+ function E(t, e, r, n) { return G(function (t) { for (var e = [], r = 0; r < t.length; ++r)
447
+ e.push(255 & t.charCodeAt(r)); return e; }(e), t, r, n); }
448
+ function O(t, e, r, n) { return E(t, e, r, n); }
449
+ function N(t, e, r, n) { return G(F(e), t, r, n); }
450
+ function C(t, e, r, n) { return G(function (t, e) { for (var r, n, i, s = [], o = 0; o < t.length && !((e -= 2) < 0); ++o)
451
+ r = t.charCodeAt(o), n = r >> 8, i = r % 256, s.push(i), s.push(n); return s; }(e, t.length - r), t, r, n); }
452
+ function T(t, e, r) { return 0 === e && r === t.length ? n.fromByteArray(t) : n.fromByteArray(t.slice(e, r)); }
453
+ function S(t, e, r) { r = Math.min(t.length, r); for (var n = [], i = e; i < r;) {
454
+ var s, o, u, a, h = t[i], c = null, f = h > 239 ? 4 : h > 223 ? 3 : h > 191 ? 2 : 1;
455
+ if (i + f <= r)
456
+ switch (f) {
457
+ case 1:
458
+ h < 128 && (c = h);
459
+ break;
460
+ case 2:
461
+ 128 == (192 & (s = t[i + 1])) && (a = (31 & h) << 6 | 63 & s) > 127 && (c = a);
462
+ break;
463
+ case 3:
464
+ s = t[i + 1], o = t[i + 2], 128 == (192 & s) && 128 == (192 & o) && (a = (15 & h) << 12 | (63 & s) << 6 | 63 & o) > 2047 && (a < 55296 || a > 57343) && (c = a);
465
+ break;
466
+ case 4: s = t[i + 1], o = t[i + 2], u = t[i + 3], 128 == (192 & s) && 128 == (192 & o) && 128 == (192 & u) && (a = (15 & h) << 18 | (63 & s) << 12 | (63 & o) << 6 | 63 & u) > 65535 && a < 1114112 && (c = a);
467
+ }
468
+ null === c ? (c = 65533, f = 1) : c > 65535 && (c -= 65536, n.push(c >>> 10 & 1023 | 55296), c = 56320 | 1023 & c), n.push(c), i += f;
469
+ } return function (t) { var e = t.length; if (e <= 4096)
470
+ return String.fromCharCode.apply(String, t); var r = "", n = 0; for (; n < e;)
471
+ r += String.fromCharCode.apply(String, t.slice(n, n += 4096)); return r; }(n); }
472
+ e.Buffer = a, e.SlowBuffer = function (t) { +t != t && (t = 0); return a.alloc(+t); }, e.INSPECT_MAX_BYTES = 50, a.TYPED_ARRAY_SUPPORT = void 0 !== t.TYPED_ARRAY_SUPPORT ? t.TYPED_ARRAY_SUPPORT : function () { try {
473
+ var t = new Uint8Array(1);
474
+ return t.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42; } }, 42 === t.foo() && "function" == typeof t.subarray && 0 === t.subarray(1, 1).byteLength;
475
+ }
476
+ catch (t) {
477
+ return !1;
478
+ } }(), e.kMaxLength = o(), a.poolSize = 8192, a._augment = function (t) { return t.__proto__ = a.prototype, t; }, a.from = function (t, e, r) { return h(null, t, e, r); }, a.TYPED_ARRAY_SUPPORT && (a.prototype.__proto__ = Uint8Array.prototype, a.__proto__ = Uint8Array, "undefined" != typeof Symbol && Symbol.species && a[Symbol.species] === a && Object.defineProperty(a, Symbol.species, { value: null, configurable: !0 })), a.alloc = function (t, e, r) { return function (t, e, r, n) { return c(e), e <= 0 ? u(t, e) : void 0 !== r ? "string" == typeof n ? u(t, e).fill(r, n) : u(t, e).fill(r) : u(t, e); }(null, t, e, r); }, a.allocUnsafe = function (t) { return f(null, t); }, a.allocUnsafeSlow = function (t) { return f(null, t); }, a.isBuffer = function (t) { return !(null == t || !t._isBuffer); }, a.compare = function (t, e) { if (!a.isBuffer(t) || !a.isBuffer(e))
479
+ throw new TypeError("Arguments must be Buffers"); if (t === e)
480
+ return 0; for (var r = t.length, n = e.length, i = 0, s = Math.min(r, n); i < s; ++i)
481
+ if (t[i] !== e[i]) {
482
+ r = t[i], n = e[i];
483
+ break;
484
+ } return r < n ? -1 : n < r ? 1 : 0; }, a.isEncoding = function (t) { switch (String(t).toLowerCase()) {
485
+ case "hex":
486
+ case "utf8":
487
+ case "utf-8":
488
+ case "ascii":
489
+ case "latin1":
490
+ case "binary":
491
+ case "base64":
492
+ case "ucs2":
493
+ case "ucs-2":
494
+ case "utf16le":
495
+ case "utf-16le": return !0;
496
+ default: return !1;
497
+ } }, a.concat = function (t, e) { if (!s(t))
498
+ throw new TypeError('"list" argument must be an Array of Buffers'); if (0 === t.length)
499
+ return a.alloc(0); var r; if (void 0 === e)
500
+ for (e = 0, r = 0; r < t.length; ++r)
501
+ e += t[r].length; var n = a.allocUnsafe(e), i = 0; for (r = 0; r < t.length; ++r) {
502
+ var o = t[r];
503
+ if (!a.isBuffer(o))
504
+ throw new TypeError('"list" argument must be an Array of Buffers');
505
+ o.copy(n, i), i += o.length;
506
+ } return n; }, a.byteLength = p, a.prototype._isBuffer = !0, a.prototype.swap16 = function () { var t = this.length; if (t % 2 != 0)
507
+ throw new RangeError("Buffer size must be a multiple of 16-bits"); for (var e = 0; e < t; e += 2)
508
+ b(this, e, e + 1); return this; }, a.prototype.swap32 = function () { var t = this.length; if (t % 4 != 0)
509
+ throw new RangeError("Buffer size must be a multiple of 32-bits"); for (var e = 0; e < t; e += 4)
510
+ b(this, e, e + 3), b(this, e + 1, e + 2); return this; }, a.prototype.swap64 = function () { var t = this.length; if (t % 8 != 0)
511
+ throw new RangeError("Buffer size must be a multiple of 64-bits"); for (var e = 0; e < t; e += 8)
512
+ b(this, e, e + 7), b(this, e + 1, e + 6), b(this, e + 2, e + 5), b(this, e + 3, e + 4); return this; }, a.prototype.toString = function () { var t = 0 | this.length; return 0 === t ? "" : 0 === arguments.length ? S(this, 0, t) : g.apply(this, arguments); }, a.prototype.equals = function (t) { if (!a.isBuffer(t))
513
+ throw new TypeError("Argument must be a Buffer"); return this === t || 0 === a.compare(this, t); }, a.prototype.inspect = function () { var t = "", r = e.INSPECT_MAX_BYTES; return this.length > 0 && (t = this.toString("hex", 0, r).match(/.{2}/g).join(" "), this.length > r && (t += " ... ")), "<Buffer " + t + ">"; }, a.prototype.compare = function (t, e, r, n, i) { if (!a.isBuffer(t))
514
+ throw new TypeError("Argument must be a Buffer"); if (void 0 === e && (e = 0), void 0 === r && (r = t ? t.length : 0), void 0 === n && (n = 0), void 0 === i && (i = this.length), e < 0 || r > t.length || n < 0 || i > this.length)
515
+ throw new RangeError("out of range index"); if (n >= i && e >= r)
516
+ return 0; if (n >= i)
517
+ return -1; if (e >= r)
518
+ return 1; if (this === t)
519
+ return 0; for (var s = (i >>>= 0) - (n >>>= 0), o = (r >>>= 0) - (e >>>= 0), u = Math.min(s, o), h = this.slice(n, i), c = t.slice(e, r), f = 0; f < u; ++f)
520
+ if (h[f] !== c[f]) {
521
+ s = h[f], o = c[f];
522
+ break;
523
+ } return s < o ? -1 : o < s ? 1 : 0; }, a.prototype.includes = function (t, e, r) { return -1 !== this.indexOf(t, e, r); }, a.prototype.indexOf = function (t, e, r) { return y(this, t, e, r, !0); }, a.prototype.lastIndexOf = function (t, e, r) { return y(this, t, e, r, !1); }, a.prototype.write = function (t, e, r, n) { if (void 0 === e)
524
+ n = "utf8", r = this.length, e = 0;
525
+ else if (void 0 === r && "string" == typeof e)
526
+ n = e, r = this.length, e = 0;
527
+ else {
528
+ if (!isFinite(e))
529
+ throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
530
+ e |= 0, isFinite(r) ? (r |= 0, void 0 === n && (n = "utf8")) : (n = r, r = void 0);
531
+ } var i = this.length - e; if ((void 0 === r || r > i) && (r = i), t.length > 0 && (r < 0 || e < 0) || e > this.length)
532
+ throw new RangeError("Attempt to write outside buffer bounds"); n || (n = "utf8"); for (var s = !1;;)
533
+ switch (n) {
534
+ case "hex": return w(this, t, e, r);
535
+ case "utf8":
536
+ case "utf-8": return A(this, t, e, r);
537
+ case "ascii": return E(this, t, e, r);
538
+ case "latin1":
539
+ case "binary": return O(this, t, e, r);
540
+ case "base64": return N(this, t, e, r);
541
+ case "ucs2":
542
+ case "ucs-2":
543
+ case "utf16le":
544
+ case "utf-16le": return C(this, t, e, r);
545
+ default:
546
+ if (s)
547
+ throw new TypeError("Unknown encoding: " + n);
548
+ n = ("" + n).toLowerCase(), s = !0;
549
+ } }, a.prototype.toJSON = function () { return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) }; };
550
+ function I(t, e, r) { var n = ""; r = Math.min(t.length, r); for (var i = e; i < r; ++i)
551
+ n += String.fromCharCode(127 & t[i]); return n; }
552
+ function _(t, e, r) { var n = ""; r = Math.min(t.length, r); for (var i = e; i < r; ++i)
553
+ n += String.fromCharCode(t[i]); return n; }
554
+ function v(t, e, r) { var n = t.length; (!e || e < 0) && (e = 0), (!r || r < 0 || r > n) && (r = n); for (var i = "", s = e; s < r; ++s)
555
+ i += Y(t[s]); return i; }
556
+ function R(t, e, r) { for (var n = t.slice(e, r), i = "", s = 0; s < n.length; s += 2)
557
+ i += String.fromCharCode(n[s] + 256 * n[s + 1]); return i; }
558
+ function P(t, e, r) { if (t % 1 != 0 || t < 0)
559
+ throw new RangeError("offset is not uint"); if (t + e > r)
560
+ throw new RangeError("Trying to access beyond buffer length"); }
561
+ function U(t, e, r, n, i, s) { if (!a.isBuffer(t))
562
+ throw new TypeError('"buffer" argument must be a Buffer instance'); if (e > i || e < s)
563
+ throw new RangeError('"value" argument is out of bounds'); if (r + n > t.length)
564
+ throw new RangeError("Index out of range"); }
565
+ function B(t, e, r, n) { e < 0 && (e = 65535 + e + 1); for (var i = 0, s = Math.min(t.length - r, 2); i < s; ++i)
566
+ t[r + i] = (e & 255 << 8 * (n ? i : 1 - i)) >>> 8 * (n ? i : 1 - i); }
567
+ function L(t, e, r, n) { e < 0 && (e = 4294967295 + e + 1); for (var i = 0, s = Math.min(t.length - r, 4); i < s; ++i)
568
+ t[r + i] = e >>> 8 * (n ? i : 3 - i) & 255; }
569
+ function D(t, e, r, n, i, s) { if (r + n > t.length)
570
+ throw new RangeError("Index out of range"); if (r < 0)
571
+ throw new RangeError("Index out of range"); }
572
+ function x(t, e, r, n, s) { return s || D(t, 0, r, 4), i.write(t, e, r, n, 23, 4), r + 4; }
573
+ function M(t, e, r, n, s) { return s || D(t, 0, r, 8), i.write(t, e, r, n, 52, 8), r + 8; }
574
+ a.prototype.slice = function (t, e) { var r, n = this.length; if ((t = ~~t) < 0 ? (t += n) < 0 && (t = 0) : t > n && (t = n), (e = void 0 === e ? n : ~~e) < 0 ? (e += n) < 0 && (e = 0) : e > n && (e = n), e < t && (e = t), a.TYPED_ARRAY_SUPPORT)
575
+ (r = this.subarray(t, e)).__proto__ = a.prototype;
576
+ else {
577
+ var i = e - t;
578
+ r = new a(i, void 0);
579
+ for (var s = 0; s < i; ++s)
580
+ r[s] = this[s + t];
581
+ } return r; }, a.prototype.readUIntLE = function (t, e, r) { t |= 0, e |= 0, r || P(t, e, this.length); for (var n = this[t], i = 1, s = 0; ++s < e && (i *= 256);)
582
+ n += this[t + s] * i; return n; }, a.prototype.readUIntBE = function (t, e, r) { t |= 0, e |= 0, r || P(t, e, this.length); for (var n = this[t + --e], i = 1; e > 0 && (i *= 256);)
583
+ n += this[t + --e] * i; return n; }, a.prototype.readUInt8 = function (t, e) { return e || P(t, 1, this.length), this[t]; }, a.prototype.readUInt16LE = function (t, e) { return e || P(t, 2, this.length), this[t] | this[t + 1] << 8; }, a.prototype.readUInt16BE = function (t, e) { return e || P(t, 2, this.length), this[t] << 8 | this[t + 1]; }, a.prototype.readUInt32LE = function (t, e) { return e || P(t, 4, this.length), (this[t] | this[t + 1] << 8 | this[t + 2] << 16) + 16777216 * this[t + 3]; }, a.prototype.readUInt32BE = function (t, e) { return e || P(t, 4, this.length), 16777216 * this[t] + (this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3]); }, a.prototype.readIntLE = function (t, e, r) { t |= 0, e |= 0, r || P(t, e, this.length); for (var n = this[t], i = 1, s = 0; ++s < e && (i *= 256);)
584
+ n += this[t + s] * i; return n >= (i *= 128) && (n -= Math.pow(2, 8 * e)), n; }, a.prototype.readIntBE = function (t, e, r) { t |= 0, e |= 0, r || P(t, e, this.length); for (var n = e, i = 1, s = this[t + --n]; n > 0 && (i *= 256);)
585
+ s += this[t + --n] * i; return s >= (i *= 128) && (s -= Math.pow(2, 8 * e)), s; }, a.prototype.readInt8 = function (t, e) { return e || P(t, 1, this.length), 128 & this[t] ? -1 * (255 - this[t] + 1) : this[t]; }, a.prototype.readInt16LE = function (t, e) { e || P(t, 2, this.length); var r = this[t] | this[t + 1] << 8; return 32768 & r ? 4294901760 | r : r; }, a.prototype.readInt16BE = function (t, e) { e || P(t, 2, this.length); var r = this[t + 1] | this[t] << 8; return 32768 & r ? 4294901760 | r : r; }, a.prototype.readInt32LE = function (t, e) { return e || P(t, 4, this.length), this[t] | this[t + 1] << 8 | this[t + 2] << 16 | this[t + 3] << 24; }, a.prototype.readInt32BE = function (t, e) { return e || P(t, 4, this.length), this[t] << 24 | this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3]; }, a.prototype.readFloatLE = function (t, e) { return e || P(t, 4, this.length), i.read(this, t, !0, 23, 4); }, a.prototype.readFloatBE = function (t, e) { return e || P(t, 4, this.length), i.read(this, t, !1, 23, 4); }, a.prototype.readDoubleLE = function (t, e) { return e || P(t, 8, this.length), i.read(this, t, !0, 52, 8); }, a.prototype.readDoubleBE = function (t, e) { return e || P(t, 8, this.length), i.read(this, t, !1, 52, 8); }, a.prototype.writeUIntLE = function (t, e, r, n) { (t = +t, e |= 0, r |= 0, n) || U(this, t, e, r, Math.pow(2, 8 * r) - 1, 0); var i = 1, s = 0; for (this[e] = 255 & t; ++s < r && (i *= 256);)
586
+ this[e + s] = t / i & 255; return e + r; }, a.prototype.writeUIntBE = function (t, e, r, n) { (t = +t, e |= 0, r |= 0, n) || U(this, t, e, r, Math.pow(2, 8 * r) - 1, 0); var i = r - 1, s = 1; for (this[e + i] = 255 & t; --i >= 0 && (s *= 256);)
587
+ this[e + i] = t / s & 255; return e + r; }, a.prototype.writeUInt8 = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 1, 255, 0), a.TYPED_ARRAY_SUPPORT || (t = Math.floor(t)), this[e] = 255 & t, e + 1; }, a.prototype.writeUInt16LE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 2, 65535, 0), a.TYPED_ARRAY_SUPPORT ? (this[e] = 255 & t, this[e + 1] = t >>> 8) : B(this, t, e, !0), e + 2; }, a.prototype.writeUInt16BE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 2, 65535, 0), a.TYPED_ARRAY_SUPPORT ? (this[e] = t >>> 8, this[e + 1] = 255 & t) : B(this, t, e, !1), e + 2; }, a.prototype.writeUInt32LE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 4, 4294967295, 0), a.TYPED_ARRAY_SUPPORT ? (this[e + 3] = t >>> 24, this[e + 2] = t >>> 16, this[e + 1] = t >>> 8, this[e] = 255 & t) : L(this, t, e, !0), e + 4; }, a.prototype.writeUInt32BE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 4, 4294967295, 0), a.TYPED_ARRAY_SUPPORT ? (this[e] = t >>> 24, this[e + 1] = t >>> 16, this[e + 2] = t >>> 8, this[e + 3] = 255 & t) : L(this, t, e, !1), e + 4; }, a.prototype.writeIntLE = function (t, e, r, n) { if (t = +t, e |= 0, !n) {
588
+ var i = Math.pow(2, 8 * r - 1);
589
+ U(this, t, e, r, i - 1, -i);
590
+ } var s = 0, o = 1, u = 0; for (this[e] = 255 & t; ++s < r && (o *= 256);)
591
+ t < 0 && 0 === u && 0 !== this[e + s - 1] && (u = 1), this[e + s] = (t / o >> 0) - u & 255; return e + r; }, a.prototype.writeIntBE = function (t, e, r, n) { if (t = +t, e |= 0, !n) {
592
+ var i = Math.pow(2, 8 * r - 1);
593
+ U(this, t, e, r, i - 1, -i);
594
+ } var s = r - 1, o = 1, u = 0; for (this[e + s] = 255 & t; --s >= 0 && (o *= 256);)
595
+ t < 0 && 0 === u && 0 !== this[e + s + 1] && (u = 1), this[e + s] = (t / o >> 0) - u & 255; return e + r; }, a.prototype.writeInt8 = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 1, 127, -128), a.TYPED_ARRAY_SUPPORT || (t = Math.floor(t)), t < 0 && (t = 255 + t + 1), this[e] = 255 & t, e + 1; }, a.prototype.writeInt16LE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 2, 32767, -32768), a.TYPED_ARRAY_SUPPORT ? (this[e] = 255 & t, this[e + 1] = t >>> 8) : B(this, t, e, !0), e + 2; }, a.prototype.writeInt16BE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 2, 32767, -32768), a.TYPED_ARRAY_SUPPORT ? (this[e] = t >>> 8, this[e + 1] = 255 & t) : B(this, t, e, !1), e + 2; }, a.prototype.writeInt32LE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 4, 2147483647, -2147483648), a.TYPED_ARRAY_SUPPORT ? (this[e] = 255 & t, this[e + 1] = t >>> 8, this[e + 2] = t >>> 16, this[e + 3] = t >>> 24) : L(this, t, e, !0), e + 4; }, a.prototype.writeInt32BE = function (t, e, r) { return t = +t, e |= 0, r || U(this, t, e, 4, 2147483647, -2147483648), t < 0 && (t = 4294967295 + t + 1), a.TYPED_ARRAY_SUPPORT ? (this[e] = t >>> 24, this[e + 1] = t >>> 16, this[e + 2] = t >>> 8, this[e + 3] = 255 & t) : L(this, t, e, !1), e + 4; }, a.prototype.writeFloatLE = function (t, e, r) { return x(this, t, e, !0, r); }, a.prototype.writeFloatBE = function (t, e, r) { return x(this, t, e, !1, r); }, a.prototype.writeDoubleLE = function (t, e, r) { return M(this, t, e, !0, r); }, a.prototype.writeDoubleBE = function (t, e, r) { return M(this, t, e, !1, r); }, a.prototype.copy = function (t, e, r, n) { if (r || (r = 0), n || 0 === n || (n = this.length), e >= t.length && (e = t.length), e || (e = 0), n > 0 && n < r && (n = r), n === r)
596
+ return 0; if (0 === t.length || 0 === this.length)
597
+ return 0; if (e < 0)
598
+ throw new RangeError("targetStart out of bounds"); if (r < 0 || r >= this.length)
599
+ throw new RangeError("sourceStart out of bounds"); if (n < 0)
600
+ throw new RangeError("sourceEnd out of bounds"); n > this.length && (n = this.length), t.length - e < n - r && (n = t.length - e + r); var i, s = n - r; if (this === t && r < e && e < n)
601
+ for (i = s - 1; i >= 0; --i)
602
+ t[i + e] = this[i + r];
603
+ else if (s < 1e3 || !a.TYPED_ARRAY_SUPPORT)
604
+ for (i = 0; i < s; ++i)
605
+ t[i + e] = this[i + r];
606
+ else
607
+ Uint8Array.prototype.set.call(t, this.subarray(r, r + s), e); return s; }, a.prototype.fill = function (t, e, r, n) { if ("string" == typeof t) {
608
+ if ("string" == typeof e ? (n = e, e = 0, r = this.length) : "string" == typeof r && (n = r, r = this.length), 1 === t.length) {
609
+ var i = t.charCodeAt(0);
610
+ i < 256 && (t = i);
611
+ }
612
+ if (void 0 !== n && "string" != typeof n)
613
+ throw new TypeError("encoding must be a string");
614
+ if ("string" == typeof n && !a.isEncoding(n))
615
+ throw new TypeError("Unknown encoding: " + n);
616
+ }
617
+ else
618
+ "number" == typeof t && (t &= 255); if (e < 0 || this.length < e || this.length < r)
619
+ throw new RangeError("Out of range index"); if (r <= e)
620
+ return this; var s; if (e >>>= 0, r = void 0 === r ? this.length : r >>> 0, t || (t = 0), "number" == typeof t)
621
+ for (s = e; s < r; ++s)
622
+ this[s] = t;
623
+ else {
624
+ var o = a.isBuffer(t) ? t : k(new a(t, n).toString()), u = o.length;
625
+ for (s = 0; s < r - e; ++s)
626
+ this[s + e] = o[s % u];
627
+ } return this; };
628
+ var j = /[^+\/0-9A-Za-z-_]/g;
629
+ function Y(t) { return t < 16 ? "0" + t.toString(16) : t.toString(16); }
630
+ function k(t, e) { var r; e = e || 1 / 0; for (var n = t.length, i = null, s = [], o = 0; o < n; ++o) {
631
+ if ((r = t.charCodeAt(o)) > 55295 && r < 57344) {
632
+ if (!i) {
633
+ if (r > 56319) {
634
+ (e -= 3) > -1 && s.push(239, 191, 189);
635
+ continue;
636
+ }
637
+ if (o + 1 === n) {
638
+ (e -= 3) > -1 && s.push(239, 191, 189);
639
+ continue;
640
+ }
641
+ i = r;
642
+ continue;
643
+ }
644
+ if (r < 56320) {
645
+ (e -= 3) > -1 && s.push(239, 191, 189), i = r;
646
+ continue;
647
+ }
648
+ r = 65536 + (i - 55296 << 10 | r - 56320);
649
+ }
650
+ else
651
+ i && (e -= 3) > -1 && s.push(239, 191, 189);
652
+ if (i = null, r < 128) {
653
+ if ((e -= 1) < 0)
654
+ break;
655
+ s.push(r);
656
+ }
657
+ else if (r < 2048) {
658
+ if ((e -= 2) < 0)
659
+ break;
660
+ s.push(r >> 6 | 192, 63 & r | 128);
661
+ }
662
+ else if (r < 65536) {
663
+ if ((e -= 3) < 0)
664
+ break;
665
+ s.push(r >> 12 | 224, r >> 6 & 63 | 128, 63 & r | 128);
666
+ }
667
+ else {
668
+ if (!(r < 1114112))
669
+ throw new Error("Invalid code point");
670
+ if ((e -= 4) < 0)
671
+ break;
672
+ s.push(r >> 18 | 240, r >> 12 & 63 | 128, r >> 6 & 63 | 128, 63 & r | 128);
673
+ }
674
+ } return s; }
675
+ function F(t) { return n.toByteArray(function (t) { if ((t = function (t) { return t.trim ? t.trim() : t.replace(/^\s+|\s+$/g, ""); }(t).replace(j, "")).length < 2)
676
+ return ""; for (; t.length % 4 != 0;)
677
+ t += "="; return t; }(t)); }
678
+ function G(t, e, r, n) { for (var i = 0; i < n && !(i + r >= e.length || i >= t.length); ++i)
679
+ e[i + r] = t[i]; return i; }
680
+ }).call(this, r(8));
681
+ }, function (t, e, r) { var n; n = function () { return this; }(); try {
682
+ n = n || new Function("return this")();
683
+ }
684
+ catch (t) {
685
+ n = Object({});
686
+ } t.exports = n; }, function (t, e, r) {
687
+ "use strict";
688
+ e.byteLength = function (t) { var e = h(t), r = e[0], n = e[1]; return 3 * (r + n) / 4 - n; }, e.toByteArray = function (t) { var e, r, n = h(t), o = n[0], u = n[1], a = new s(function (t, e, r) { return 3 * (e + r) / 4 - r; }(0, o, u)), c = 0, f = u > 0 ? o - 4 : o; for (r = 0; r < f; r += 4)
689
+ e = i[t.charCodeAt(r)] << 18 | i[t.charCodeAt(r + 1)] << 12 | i[t.charCodeAt(r + 2)] << 6 | i[t.charCodeAt(r + 3)], a[c++] = e >> 16 & 255, a[c++] = e >> 8 & 255, a[c++] = 255 & e; 2 === u && (e = i[t.charCodeAt(r)] << 2 | i[t.charCodeAt(r + 1)] >> 4, a[c++] = 255 & e); 1 === u && (e = i[t.charCodeAt(r)] << 10 | i[t.charCodeAt(r + 1)] << 4 | i[t.charCodeAt(r + 2)] >> 2, a[c++] = e >> 8 & 255, a[c++] = 255 & e); return a; }, e.fromByteArray = function (t) { for (var e, r = t.length, i = r % 3, s = [], o = 0, u = r - i; o < u; o += 16383)
690
+ s.push(c(t, o, o + 16383 > u ? u : o + 16383)); 1 === i ? (e = t[r - 1], s.push(n[e >> 2] + n[e << 4 & 63] + "==")) : 2 === i && (e = (t[r - 2] << 8) + t[r - 1], s.push(n[e >> 10] + n[e >> 4 & 63] + n[e << 2 & 63] + "=")); return s.join(""); };
691
+ for (var n = [], i = [], s = "undefined" != typeof Uint8Array ? Uint8Array : Array, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", u = 0, a = o.length; u < a; ++u)
692
+ n[u] = o[u], i[o.charCodeAt(u)] = u;
693
+ function h(t) { var e = t.length; if (e % 4 > 0)
694
+ throw new Error("Invalid string. Length must be a multiple of 4"); var r = t.indexOf("="); return -1 === r && (r = e), [r, r === e ? 0 : 4 - r % 4]; }
695
+ function c(t, e, r) { for (var i, s, o = [], u = e; u < r; u += 3)
696
+ i = (t[u] << 16 & 16711680) + (t[u + 1] << 8 & 65280) + (255 & t[u + 2]), o.push(n[(s = i) >> 18 & 63] + n[s >> 12 & 63] + n[s >> 6 & 63] + n[63 & s]); return o.join(""); }
697
+ i["-".charCodeAt(0)] = 62, i["_".charCodeAt(0)] = 63;
698
+ }, function (t, e) { e.read = function (t, e, r, n, i) { var s, o, u = 8 * i - n - 1, a = (1 << u) - 1, h = a >> 1, c = -7, f = r ? i - 1 : 0, l = r ? -1 : 1, d = t[e + f]; for (f += l, s = d & (1 << -c) - 1, d >>= -c, c += u; c > 0; s = 256 * s + t[e + f], f += l, c -= 8)
699
+ ; for (o = s & (1 << -c) - 1, s >>= -c, c += n; c > 0; o = 256 * o + t[e + f], f += l, c -= 8)
700
+ ; if (0 === s)
701
+ s = 1 - h;
702
+ else {
703
+ if (s === a)
704
+ return o ? NaN : 1 / 0 * (d ? -1 : 1);
705
+ o += Math.pow(2, n), s -= h;
706
+ } return (d ? -1 : 1) * o * Math.pow(2, s - n); }, e.write = function (t, e, r, n, i, s) { var o, u, a, h = 8 * s - i - 1, c = (1 << h) - 1, f = c >> 1, l = 23 === i ? Math.pow(2, -24) - Math.pow(2, -77) : 0, d = n ? 0 : s - 1, p = n ? 1 : -1, g = e < 0 || 0 === e && 1 / e < 0 ? 1 : 0; for (e = Math.abs(e), isNaN(e) || e === 1 / 0 ? (u = isNaN(e) ? 1 : 0, o = c) : (o = Math.floor(Math.log(e) / Math.LN2), e * (a = Math.pow(2, -o)) < 1 && (o--, a *= 2), (e += o + f >= 1 ? l / a : l * Math.pow(2, 1 - f)) * a >= 2 && (o++, a /= 2), o + f >= c ? (u = 0, o = c) : o + f >= 1 ? (u = (e * a - 1) * Math.pow(2, i), o += f) : (u = e * Math.pow(2, f - 1) * Math.pow(2, i), o = 0)); i >= 8; t[r + d] = 255 & u, d += p, u /= 256, i -= 8)
707
+ ; for (o = o << i | u, h += i; h > 0; t[r + d] = 255 & o, d += p, o /= 256, h -= 8)
708
+ ; t[r + d - p] |= 128 * g; }; }, function (t, e) { var r = {}.toString; t.exports = Array.isArray || function (t) { return "[object Array]" == r.call(t); }; }, function (t, e, r) {
709
+ "use strict";
710
+ r.r(e);
711
+ var n = r(2), i = r(0), s = r(3), o = r(1), u = r(4), a = r(6);
712
+ function h(t) { return c.connect(t); }
713
+ class c {
714
+ constructor(t) { this.closeListeners = [], this.errorListeners = [], this.draining = !1, this.nuid = new a.a, this.options = { url: "ws://localhost:4222" }, void 0 === t.payload && (t.payload = s.a.STRING); if (!["json", "string", "binary"].includes(t.payload))
715
+ throw i.c.errorForCode(i.a.INVALID_PAYLOAD_TYPE); if (t.user && t.token)
716
+ throw i.c.errorForCode(i.a.BAD_AUTHENTICATION); Object(o.b)(this.options, t); }
717
+ static connect(t) { return new Promise((e, r) => { let n = new c(t); u.e.connect(t, n).then(t => { n.protocol = t, e(n); }).catch(t => { r(t); }); }); }
718
+ close() { this.protocol.close(); }
719
+ publish(t, e, r = "") { return 0 === (t = t || "").length ? (this.errorHandler(i.c.errorForCode(i.a.BAD_SUBJECT)), this) : (Object(o.d)(e) || (this.options.payload !== s.a.JSON ? e = e || "" : (e = void 0 === e ? null : e, e = JSON.stringify(e)), e = Object(o.f)(e)), this.protocol.publish(t, e, r), this); }
720
+ subscribe(t, e, r = {}) { return new Promise((n, s) => { this.isClosed() && s(i.c.errorForCode(i.a.CONNECTION_CLOSED)), this.isDraining() && s(i.c.errorForCode(i.a.CONNECTION_DRAINING)); let a = Object(u.k)(); Object(o.b)(a, r), a.subject = t, a.callback = e, n(this.protocol.subscribe(a)); }); }
721
+ request(t, e = 1e3, r) { return new Promise((n, s) => { this.isClosed() && s(i.c.errorForCode(i.a.CONNECTION_CLOSED)), this.isDraining() && s(i.c.errorForCode(i.a.CONNECTION_DRAINING)); let a = Object(u.j)(); Object(o.b)(a, { max: 1 }), a.token = this.nuid.next(), a.timeout = setTimeout(() => { h.cancel(), s("timeout"); }, e), a.callback = t => { n(t); }; let h = this.protocol.request(a); this.publish(t, r, `${this.protocol.muxSubscriptions.baseInbox}${a.token}`); }); }
722
+ flush(t) { if (void 0 === t)
723
+ return new Promise(t => { this.protocol.flush(() => { t(); }); }); this.protocol.flush(t); }
724
+ drain() { return this.isClosed() ? Promise.reject(i.c.errorForCode(i.a.CONNECTION_CLOSED)) : this.isDraining() ? Promise.reject(i.c.errorForCode(i.a.CONNECTION_DRAINING)) : (this.draining = !0, this.protocol.drain()); }
725
+ errorHandler(t) { this.errorListeners.forEach(e => { try {
726
+ e(t);
727
+ }
728
+ catch (t) { } }); }
729
+ closeHandler() { this.closeListeners.forEach(t => { try {
730
+ t();
731
+ }
732
+ catch (t) { } }); }
733
+ addEventListener(t, e) { "close" === t ? this.closeListeners.push(e) : "error" === t && this.errorListeners.push(e); }
734
+ isClosed() { return this.protocol.isClosed(); }
735
+ isDraining() { return this.draining; }
736
+ }
737
+ var f = r(5);
738
+ r.d(e, "DataBuffer", (function () { return n.a; })), r.d(e, "ErrorCode", (function () { return i.a; })), r.d(e, "Messages", (function () { return i.b; })), r.d(e, "NatsError", (function () { return i.c; })), r.d(e, "connect", (function () { return h; })), r.d(e, "Connection", (function () { return c; })), r.d(e, "ParserState", (function () { return u.d; })), r.d(e, "createInbox", (function () { return u.i; })), r.d(e, "Connect", (function () { return u.a; })), r.d(e, "defaultSub", (function () { return u.k; })), r.d(e, "defaultReq", (function () { return u.j; })), r.d(e, "Request", (function () { return u.f; })), r.d(e, "Subscription", (function () { return u.g; })), r.d(e, "MuxSubscription", (function () { return u.c; })), r.d(e, "Subscriptions", (function () { return u.h; })), r.d(e, "MsgBuffer", (function () { return u.b; })), r.d(e, "ProtocolHandler", (function () { return u.e; })), r.d(e, "WSTransport", (function () { return f.a; })), r.d(e, "isArrayBuffer", (function () { return o.d; })), r.d(e, "extend", (function () { return o.b; })), r.d(e, "extractProtocolMessage", (function () { return o.c; })), r.d(e, "buildWSMessage", (function () { return o.a; })), r.d(e, "settle", (function () { return o.e; })), r.d(e, "stringToUint8Array", (function () { return o.f; }));
739
+ }]);
740
+ }));
741
+
742
+ });
743
+
744
+ var nats_min$1 = /*@__PURE__*/getDefaultExportFromCjs(nats_min);
745
+
746
+ //declare let nats_min: any;
8
747
  class Chat4appClientAngularService {
9
748
  constructor(http) {
10
749
  this.http = http;
@@ -413,86 +1152,102 @@ class Chat4appClientAngularService {
413
1152
  chatCallback.onChatClosed(chat4appMessage);
414
1153
  }
415
1154
  }
416
- connectWebsocket(chatCallback, token) {
417
- this.disconnect();
418
- let securityToken = this.getBearerToken();
419
- this.sock = new SockJS(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
420
- this.stompClient = Stomp.over(this.sock);
421
- const that = this;
422
- this.stompClient.debug = function (msg) {
423
- if (this.debug) {
424
- console.log(msg);
1155
+ ensureConn(chatServer, userId) {
1156
+ return __awaiter(this, void 0, void 0, function* () {
1157
+ console.log(`chatServer: ${this.chatServer}`);
1158
+ console.log(`userId: ${userId}`);
1159
+ console.log(`getBearerToken: ${this.getBearerToken()}`);
1160
+ const that = this;
1161
+ let server = chatServer.replace("https://", "wss://ws");
1162
+ if (!this.nc) {
1163
+ that.nc = yield nats_min.connect({ url: server, user: userId, pass: this.getBearerToken(), reconnect: true });
425
1164
  }
426
- };
427
- let tokenAuth = "";
428
- if (securityToken && securityToken.startsWith("Bearer ")) {
429
- tokenAuth = securityToken;
430
- }
431
- else {
432
- tokenAuth = "Bearer " + securityToken;
433
- }
434
- this.stompClient.connect({ "X-Authorization": tokenAuth }, (frame) => {
435
- //console.log(frame);
436
- that.timeoutReconnect = 500;
437
- this.stompClient.subscribe('/queue/' + token, (msg) => {
438
- //console.log('mensagem', msg);
439
- if (msg.command == "MESSAGE") {
440
- //console.log(msg)
441
- if (!chatCallback.isTokenFirebaseActive()) {
442
- let msgObj = JSON.parse(msg.body);
443
- let datTmp = new Map();
444
- for (let key in msgObj.data) {
445
- datTmp.set(key, msgObj.data[key]);
446
- }
447
- msgObj.data.all = datTmp;
448
- if (msgObj.data.type == "msg") {
449
- chatCallback.onMessage(msgObj);
450
- }
451
- else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
452
- chatCallback.onOffline(msgObj);
453
- }
454
- else if (msgObj.data.type == "read") {
455
- chatCallback.onRead(msgObj);
456
- }
457
- else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
458
- chatCallback.onStartStopTyping(msgObj);
459
- }
460
- else if (msgObj.data.type == "new_user") {
461
- chatCallback.onNewUser(msgObj);
462
- }
463
- else if (msgObj.data.type == "remove_user") {
464
- chatCallback.onRemoveUser(msgObj);
465
- }
466
- else if (msgObj.data.type == "chat_closed") {
467
- chatCallback.onChatClosed(msgObj);
468
- }
1165
+ return that.nc;
1166
+ });
1167
+ }
1168
+ disconnect() {
1169
+ return __awaiter(this, void 0, void 0, function* () {
1170
+ // Check how we can disconnect
1171
+ if (!this.nc) {
1172
+ try {
1173
+ yield this.nc.close();
1174
+ }
1175
+ catch (e) {
1176
+ if (this.debug) {
1177
+ console.error(e);
469
1178
  }
470
- //callback(msg.body);
471
- // ichatcallback.forEach((iChat)=>{
472
- // iChat.onMessage(JSON.parse(msg.body) );
473
- // });
474
1179
  }
475
- });
476
- }, (message) => {
477
- // check message for disconnect
478
- //console.log("Disconnect");
479
- setTimeout(() => {
480
- that.timeoutReconnect *= 100;
481
- this.connectWebsocket(chatCallback, token);
482
- }, that.timeoutReconnect);
1180
+ }
1181
+ if (this.debug) {
1182
+ console.log("disconect");
1183
+ }
483
1184
  });
484
1185
  }
485
- disconnect() {
486
- // console.log("disconnect")
487
- try {
488
- if (this.stompClient) {
489
- this.stompClient.disconnect();
1186
+ processAndCallback(msgObj, chatCallback) {
1187
+ console.log("Msg Received: " + msgObj);
1188
+ if (!chatCallback.isTokenFirebaseActive()) {
1189
+ let datTmp = new Map();
1190
+ for (let key in msgObj.data) {
1191
+ datTmp.set(key, msgObj.data[key]);
1192
+ }
1193
+ msgObj.data.all = datTmp;
1194
+ if (msgObj.data.type == "msg") {
1195
+ chatCallback.onMessage(msgObj);
1196
+ }
1197
+ else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
1198
+ chatCallback.onOffline(msgObj);
1199
+ }
1200
+ else if (msgObj.data.type == "read") {
1201
+ chatCallback.onRead(msgObj);
1202
+ }
1203
+ else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
1204
+ chatCallback.onStartStopTyping(msgObj);
1205
+ }
1206
+ else if (msgObj.data.type == "new_user") {
1207
+ chatCallback.onNewUser(msgObj);
1208
+ }
1209
+ else if (msgObj.data.type == "remove_user") {
1210
+ chatCallback.onRemoveUser(msgObj);
1211
+ }
1212
+ else if (msgObj.data.type == "chat_closed") {
1213
+ chatCallback.onChatClosed(msgObj);
490
1214
  }
491
1215
  }
492
- catch (e) {
493
- console.log(e);
1216
+ }
1217
+ connectWebsocket(chatCallback, userId) {
1218
+ return __awaiter(this, void 0, void 0, function* () {
1219
+ this.disconnect();
1220
+ let securityToken = this.getBearerToken();
1221
+ let tokenAuth = "";
1222
+ if (securityToken && securityToken.startsWith("Bearer ")) {
1223
+ tokenAuth = securityToken;
1224
+ }
1225
+ else {
1226
+ tokenAuth = "Bearer " + securityToken;
1227
+ }
1228
+ const configId = this.chatServer.split("/")[3];
1229
+ const nc = yield this.ensureConn("https://apihomol.chat4app.com", userId);
1230
+ //TODO Get the user id from jwt
1231
+ const subject = `chat4app.config.${configId}.user.${userId}`;
1232
+ const sub = nc.subscribe(subject, (msg) => {
1233
+ console.log(msg);
1234
+ this.processAndCallback(JSON.parse(msg.data), chatCallback);
1235
+ });
1236
+ });
1237
+ }
1238
+ /*
1239
+ disconnect() {
1240
+ // console.log("disconnect")
1241
+ try {
1242
+ if (this.stompClient) {
1243
+ this.stompClient.disconnect();
494
1244
  }
1245
+
1246
+ } catch (e) {
1247
+ console.log(e);
1248
+ }
495
1249
  }
1250
+ */
496
1251
  convertChat4AppMessageReceiveToChatMessage4App(msg) {
497
1252
  var _a;
498
1253
  let message = new ChatMessage4App();