teckos-client 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/dist/index.js +456 -5
  2. package/dist/index.min.js +1 -0
  3. package/es/index.js +459 -0
  4. package/es/index.mjs +1 -0
  5. package/lib/index.js +484 -0
  6. package/package.json +63 -44
  7. package/src/ITeckosClient.js +2 -0
  8. package/src/ITeckosClient.js.map +1 -0
  9. package/src/ITeckosClient.ts +3 -3
  10. package/src/TeckosClient.js +235 -0
  11. package/src/TeckosClient.js.map +1 -0
  12. package/src/TeckosClient.ts +40 -32
  13. package/src/TeckosClientWithJWT.js +63 -0
  14. package/src/TeckosClientWithJWT.js.map +1 -0
  15. package/src/TeckosClientWithJWT.ts +8 -10
  16. package/src/index.js +8 -0
  17. package/src/index.js.map +1 -0
  18. package/src/index.ts +3 -3
  19. package/src/types/ConnectionState.js +9 -0
  20. package/src/types/ConnectionState.js.map +1 -0
  21. package/src/types/Options.js +2 -0
  22. package/src/types/Options.js.map +1 -0
  23. package/src/types/Packet.js +2 -0
  24. package/src/types/Packet.js.map +1 -0
  25. package/src/types/PacketType.js +7 -0
  26. package/src/types/PacketType.js.map +1 -0
  27. package/src/types/SocketEvent.js +2 -0
  28. package/src/types/SocketEvent.js.map +1 -0
  29. package/src/types/index.js +4 -0
  30. package/src/types/index.js.map +1 -0
  31. package/src/util/Converter.js +6 -0
  32. package/src/util/Converter.js.map +1 -0
  33. package/src/util/SocketEventEmitter.js +99 -0
  34. package/src/util/SocketEventEmitter.js.map +1 -0
  35. package/src/util/formatProdErrorMessage.ts +16 -0
  36. package/{dist → types}/ITeckosClient.d.ts +3 -3
  37. package/{dist → types}/TeckosClient.d.ts +6 -6
  38. package/{dist → types}/TeckosClientWithJWT.d.ts +0 -0
  39. package/types/index.d.ts +9 -0
  40. package/{dist → types}/types/ConnectionState.d.ts +0 -0
  41. package/{dist → types}/types/Options.d.ts +0 -0
  42. package/{dist → types}/types/Packet.d.ts +0 -0
  43. package/{dist → types}/types/PacketType.d.ts +0 -0
  44. package/{dist → types}/types/SocketEvent.d.ts +0 -0
  45. package/{dist → types}/types/index.d.ts +0 -0
  46. package/{dist → types}/util/Converter.d.ts +0 -0
  47. package/{dist → types}/util/SocketEventEmitter.d.ts +1 -1
  48. package/types/util/formatProdErrorMessage.d.ts +9 -0
  49. package/dist/index.d.ts +0 -9
  50. package/dist/teckos-client.cjs.development.js +0 -614
  51. package/dist/teckos-client.cjs.development.js.map +0 -1
  52. package/dist/teckos-client.cjs.production.min.js +0 -2
  53. package/dist/teckos-client.cjs.production.min.js.map +0 -1
  54. package/dist/teckos-client.esm.js +0 -611
  55. package/dist/teckos-client.esm.js.map +0 -1
@@ -1,614 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var debug = _interopDefault(require('debug'));
8
- var WebSocket = _interopDefault(require('isomorphic-ws'));
9
-
10
- function _defineProperties(target, props) {
11
- for (var i = 0; i < props.length; i++) {
12
- var descriptor = props[i];
13
- descriptor.enumerable = descriptor.enumerable || false;
14
- descriptor.configurable = true;
15
- if ("value" in descriptor) descriptor.writable = true;
16
- Object.defineProperty(target, descriptor.key, descriptor);
17
- }
18
- }
19
-
20
- function _createClass(Constructor, protoProps, staticProps) {
21
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
22
- if (staticProps) _defineProperties(Constructor, staticProps);
23
- return Constructor;
24
- }
25
-
26
- function _extends() {
27
- _extends = Object.assign || function (target) {
28
- for (var i = 1; i < arguments.length; i++) {
29
- var source = arguments[i];
30
-
31
- for (var key in source) {
32
- if (Object.prototype.hasOwnProperty.call(source, key)) {
33
- target[key] = source[key];
34
- }
35
- }
36
- }
37
-
38
- return target;
39
- };
40
-
41
- return _extends.apply(this, arguments);
42
- }
43
-
44
- function _inheritsLoose(subClass, superClass) {
45
- subClass.prototype = Object.create(superClass.prototype);
46
- subClass.prototype.constructor = subClass;
47
-
48
- _setPrototypeOf(subClass, superClass);
49
- }
50
-
51
- function _setPrototypeOf(o, p) {
52
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
53
- o.__proto__ = p;
54
- return o;
55
- };
56
-
57
- return _setPrototypeOf(o, p);
58
- }
59
-
60
- function _assertThisInitialized(self) {
61
- if (self === void 0) {
62
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
63
- }
64
-
65
- return self;
66
- }
67
-
68
- var enc = /*#__PURE__*/new TextEncoder();
69
- var dec = /*#__PURE__*/new TextDecoder();
70
-
71
- var encodePacket = function encodePacket(packet) {
72
- return enc.encode(JSON.stringify(packet));
73
- };
74
-
75
- var decodePacket = function decodePacket(buffer) {
76
- return JSON.parse(dec.decode(buffer).toString());
77
- };
78
-
79
- (function (PacketType) {
80
- PacketType[PacketType["EVENT"] = 0] = "EVENT";
81
- PacketType[PacketType["ACK"] = 1] = "ACK";
82
- })(exports.PacketType || (exports.PacketType = {}));
83
-
84
- (function (ConnectionState) {
85
- ConnectionState["DISCONNECTED"] = "disconnected";
86
- ConnectionState["CONNECTING"] = "connecting";
87
- ConnectionState["CONNECTED"] = "connected";
88
- ConnectionState["DISCONNECTING"] = "disconnecting";
89
- })(exports.ConnectionState || (exports.ConnectionState = {}));
90
-
91
- var SocketEventEmitter = function SocketEventEmitter() {
92
- var _this = this;
93
-
94
- this.maxListeners = 50;
95
- this.handlers = {};
96
-
97
- this.addListener = function (event, listener) {
98
- if (Object.keys(_this.handlers).length === _this.maxListeners) {
99
- throw new Error('Max listeners reached');
100
- }
101
-
102
- if (typeof listener !== 'function') {
103
- throw new Error('The given listener is not a function');
104
- }
105
-
106
- _this.handlers[event] = _this.handlers[event] || [];
107
-
108
- _this.handlers[event].push(listener);
109
-
110
- return _this;
111
- };
112
-
113
- this.once = function (event, listener) {
114
- if (Object.keys(_this.handlers).length === _this.maxListeners) {
115
- throw new Error('Max listeners reached');
116
- }
117
-
118
- if (typeof listener !== 'function') {
119
- throw new Error('The given listener is not a function');
120
- }
121
-
122
- _this.handlers[event] = _this.handlers[event] || [];
123
-
124
- var onceWrapper = function onceWrapper() {
125
- listener();
126
-
127
- _this.off(event, onceWrapper);
128
- };
129
-
130
- _this.handlers[event].push(onceWrapper);
131
-
132
- return _this;
133
- };
134
-
135
- this.removeListener = function (event, listener) {
136
- if (_this.handlers[event]) {
137
- _this.handlers[event] = _this.handlers[event].filter(function (handler) {
138
- return handler !== listener;
139
- });
140
- }
141
-
142
- return _this;
143
- };
144
-
145
- this.off = function (event, listener) {
146
- return _this.removeListener(event, listener);
147
- };
148
-
149
- this.removeAllListeners = function (event) {
150
- if (event) {
151
- delete _this.handlers[event];
152
- } else {
153
- _this.handlers = {};
154
- }
155
-
156
- return _this;
157
- };
158
-
159
- this.setMaxListeners = function (n) {
160
- _this.maxListeners = n;
161
- return _this;
162
- };
163
-
164
- this.getMaxListeners = function () {
165
- return _this.maxListeners;
166
- };
167
-
168
- this.listeners = function (event) {
169
- if (_this.handlers[event]) {
170
- return [].concat(_this.handlers[event]);
171
- }
172
-
173
- return [];
174
- };
175
-
176
- this.rawListeners = function (event) {
177
- return [].concat(_this.handlers[event]);
178
- };
179
-
180
- this.listenerCount = function (event) {
181
- if (_this.handlers[event]) {
182
- return Object.keys(_this.handlers[event]).length;
183
- }
184
-
185
- return 0;
186
- };
187
-
188
- this.prependListener = function (event, listener) {
189
- if (Object.keys(_this.handlers).length === _this.maxListeners) {
190
- throw new Error('Max listeners reached');
191
- }
192
-
193
- _this.handlers[event] = _this.handlers[event] || [];
194
-
195
- _this.handlers[event].unshift(listener);
196
-
197
- return _this;
198
- };
199
-
200
- this.prependOnceListener = function (event, listener) {
201
- if (Object.keys(_this.handlers).length === _this.maxListeners) {
202
- throw new Error('Max listeners reached');
203
- }
204
-
205
- _this.handlers[event] = _this.handlers[event] || [];
206
-
207
- var onceWrapper = function onceWrapper() {
208
- listener();
209
-
210
- _this.off(event, onceWrapper);
211
- };
212
-
213
- _this.handlers[event].unshift(onceWrapper);
214
-
215
- return _this;
216
- };
217
-
218
- this.eventNames = function () {
219
- return Object.keys(_this.handlers);
220
- };
221
-
222
- this.on = function (event, listener) {
223
- return _this.addListener(event, listener);
224
- };
225
-
226
- this.emit = function (event) {
227
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
228
- args[_key - 1] = arguments[_key];
229
- }
230
-
231
- var listeners = _this.listeners(event);
232
-
233
- if (listeners.length > 0) {
234
- listeners.forEach(function (listener) {
235
- if (listener) listener(args);
236
- });
237
- return true;
238
- }
239
-
240
- return false;
241
- };
242
- };
243
-
244
- var d = /*#__PURE__*/debug('teckos:client');
245
- var DEFAULT_OPTIONS = {
246
- reconnection: true,
247
- reconnectionDelay: 1000,
248
- reconnectionDelayMax: 5000,
249
- reconnectionAttempts: Infinity,
250
- randomizationFactor: 0.5,
251
- timeout: 5000,
252
- debug: false
253
- };
254
-
255
- var TeckosClient = /*#__PURE__*/function (_SocketEventEmitter) {
256
- _inheritsLoose(TeckosClient, _SocketEventEmitter);
257
-
258
- function TeckosClient(url, options) {
259
- var _this;
260
-
261
- _this = _SocketEventEmitter.call(this) || this;
262
- _this.currentReconnectionAttempts = 0;
263
- _this.acks = new Map();
264
- _this.fnId = 0;
265
-
266
- _this.attachHandler = function () {
267
- if (_this.ws) {
268
- _this.ws.onopen = _this.handleOpen;
269
- _this.ws.onerror = _this.handleError;
270
- _this.ws.onclose = _this.handleClose;
271
- _this.ws.onmessage = _this.handleMessage;
272
- }
273
- };
274
-
275
- _this.connect = function () {
276
- if (_this.options.debug) d("Connecting to " + _this.url + "..."); // This will try to connect immediately
277
-
278
- _this.ws = new WebSocket(_this.url); // Attach handlers
279
-
280
- _this.attachHandler(); // Handle timeout
281
-
282
-
283
- _this.connectionTimeout = setTimeout(function () {
284
- if (_this.ws && _this.ws.readyState === WebSocket.CONNECTING) {
285
- _this.ws.close();
286
- }
287
- }, _this.options.timeout);
288
- };
289
-
290
- _this.reconnect = function () {
291
- _this.listeners('reconnect_attempt').forEach(function (listener) {
292
- return listener();
293
- });
294
-
295
- _this.connect();
296
- };
297
-
298
- _this.emit = function (event) {
299
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
300
- args[_key - 1] = arguments[_key];
301
- }
302
-
303
- args.unshift(event);
304
- var packet = {
305
- type: exports.PacketType.EVENT,
306
- data: args
307
- };
308
-
309
- if (typeof args[args.length - 1] === 'function') {
310
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
311
- _this.acks.set(_this.fnId, args.pop());
312
-
313
- packet.id = _this.fnId;
314
- _this.fnId += 1;
315
- }
316
-
317
- return _this.sendPackage(packet);
318
- };
319
-
320
- _this.send = function () {
321
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
322
- args[_key2] = arguments[_key2];
323
- }
324
-
325
- args.unshift('message');
326
- return _this.sendPackage({
327
- type: exports.PacketType.EVENT,
328
- data: args
329
- });
330
- };
331
-
332
- _this.sendPackage = function (packet) {
333
- if (_this.ws !== undefined && _this.ws.readyState === WebSocket.OPEN) {
334
- var buffer = encodePacket(packet);
335
- if (_this.options.debug) d("[" + _this.url + "] Send packet: " + JSON.stringify(packet));
336
-
337
- _this.ws.send(buffer);
338
-
339
- return true;
340
- }
341
-
342
- return false;
343
- };
344
-
345
- _this.handleMessage = function (msg) {
346
- var packet = typeof msg.data === 'string' ? JSON.parse(msg.data) : decodePacket(msg.data);
347
- if (_this.options.debug) d("[" + _this.url + "] Got packet: " + JSON.stringify(packet));
348
-
349
- if (packet.type === exports.PacketType.EVENT) {
350
- var event = packet.data[0];
351
- var args = packet.data.slice(1);
352
-
353
- if (event) {
354
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
355
- _this.listeners(event).forEach(function (listener) {
356
- return listener.apply(void 0, args);
357
- });
358
- } else {
359
- throw new Error("[teckos-client@" + _this.url + "] Got invalid event message: " + JSON.stringify(msg.data));
360
- }
361
- } else if (packet.type === exports.PacketType.ACK && packet.id !== undefined) {
362
- // Call assigned function
363
- var ack = _this.acks.get(packet.id);
364
-
365
- if (typeof ack === 'function') {
366
- ack.apply(_assertThisInitialized(_this), packet.data);
367
-
368
- _this.acks["delete"](packet.id);
369
- }
370
- } else {
371
- throw new Error("[teckos-client@" + _this.url + "] Got invalid message type: " + packet.type);
372
- }
373
- };
374
-
375
- _this.handleOpen = function () {
376
- if (_this.currentReconnectionAttempts > 0) {
377
- // Reset reconnection settings to default
378
- _this.currentReconnectDelay = _this.options.reconnectionDelay;
379
- _this.currentReconnectionAttempts = 0; // Inform listeners
380
-
381
- if (_this.options.debug) d("[" + _this.url + "] Reconnected!"); // eslint-disable-next-line @typescript-eslint/no-unsafe-return
382
-
383
- _this.listeners('reconnect').forEach(function (listener) {
384
- return listener();
385
- });
386
- } // Inform listeners
387
-
388
-
389
- if (_this.options.debug) d("[" + _this.url + "] Connected!");
390
-
391
- _this.listeners('connect').forEach(function (listener) {
392
- return listener();
393
- });
394
- };
395
-
396
- _this.handleError = function (error) {
397
- if (_this.handlers && _this.handlers.error) {
398
- if (_this.options.debug) d("[" + _this.url + "] Got error from server: " + JSON.stringify(error));
399
-
400
- _this.handlers.error.forEach(function (listener) {
401
- return listener(error);
402
- });
403
- }
404
- };
405
-
406
- _this.handleClose = function () {
407
- // Stop connection timeout
408
- if (_this.connectionTimeout) {
409
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
410
- clearTimeout(_this.connectionTimeout);
411
- } // Stop reconnection timeout
412
-
413
-
414
- if (_this.reconnectionTimeout) {
415
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
416
- clearTimeout(_this.reconnectionTimeout);
417
- } // Inform listeners
418
-
419
-
420
- if (_this.currentReconnectionAttempts > 0) {
421
- if (_this.options.debug) d("[" + _this.url + "] Reconnect #" + _this.currentReconnectionAttempts + " failed!");
422
-
423
- _this.listeners('reconnect_error').forEach(function (listener) {
424
- if (listener) listener();
425
- });
426
- } else {
427
- if (_this.options.debug) d("[" + _this.url + "] Disconnected!");
428
-
429
- _this.listeners('disconnect').forEach(function (listener) {
430
- if (listener) listener();
431
- });
432
- }
433
-
434
- if (_this.options.reconnection) {
435
- // Apply reconnection logic
436
- _this.currentReconnectionAttempts += 1;
437
-
438
- if (_this.options.reconnectionAttempts === Infinity || _this.currentReconnectionAttempts <= _this.options.reconnectionAttempts) {
439
- var timeout = Math.min(_this.options.reconnectionDelayMax, _this.currentReconnectDelay); // Increase reconnection delay
440
-
441
- _this.currentReconnectDelay = Math.round(_this.currentReconnectDelay + _this.currentReconnectDelay * _this.options.randomizationFactor);
442
- if (_this.options.debug) d("[" + _this.url + "] Try reconnecting (" + _this.currentReconnectionAttempts + "/" + _this.options.reconnectionAttempts + ") in " + timeout + "ms to " + _this.url + "...");
443
- _this.reconnectionTimeout = setTimeout(function () {
444
- _this.reconnect();
445
- }, timeout);
446
- } else {
447
- if (_this.options.debug) d("[" + _this.url + "] Reconnection maximum of " + _this.options.reconnectionAttempts + " reached");
448
-
449
- _this.listeners('reconnect_failed').forEach(function (listener) {
450
- return listener();
451
- });
452
- }
453
- }
454
- };
455
-
456
- _this.close = function () {
457
- if (_this.options.debug) d("[" + _this.url + "] Closing connection (client-side)");
458
-
459
- if (_this.ws !== undefined) {
460
- _this.ws.onclose = function () {};
461
-
462
- _this.ws.close();
463
-
464
- _this.listeners('disconnect').forEach(function (listener) {
465
- return listener();
466
- });
467
- }
468
- };
469
-
470
- _this.disconnect = function () {
471
- _this.close();
472
- };
473
-
474
- _this.options = _extends({}, DEFAULT_OPTIONS, options);
475
- _this.currentReconnectDelay = _this.options.reconnectionDelay;
476
- _this.url = url;
477
- return _this;
478
- }
479
-
480
- var _proto = TeckosClient.prototype;
481
-
482
- _proto.getConnectionState = function getConnectionState() {
483
- if (this.ws) {
484
- switch (this.ws.readyState) {
485
- case WebSocket.OPEN:
486
- return exports.ConnectionState.CONNECTED;
487
-
488
- case WebSocket.CONNECTING:
489
- return exports.ConnectionState.CONNECTING;
490
-
491
- case WebSocket.CLOSING:
492
- return exports.ConnectionState.DISCONNECTING;
493
-
494
- default:
495
- return exports.ConnectionState.DISCONNECTED;
496
- }
497
- }
498
-
499
- return exports.ConnectionState.DISCONNECTED;
500
- };
501
-
502
- _createClass(TeckosClient, [{
503
- key: "webSocket",
504
- get: function get() {
505
- return this.ws;
506
- }
507
- }, {
508
- key: "state",
509
- get: function get() {
510
- return this.getConnectionState();
511
- }
512
- }, {
513
- key: "connected",
514
- get: function get() {
515
- return this.getConnectionState() === exports.ConnectionState.CONNECTED;
516
- }
517
- }, {
518
- key: "disconnected",
519
- get: function get() {
520
- return this.getConnectionState() === exports.ConnectionState.DISCONNECTED;
521
- }
522
- }]);
523
-
524
- return TeckosClient;
525
- }(SocketEventEmitter);
526
-
527
- var d$1 = /*#__PURE__*/debug('teckos:client');
528
-
529
- var TeckosClientWithJWT = /*#__PURE__*/function (_TeckosClient) {
530
- _inheritsLoose(TeckosClientWithJWT, _TeckosClient);
531
-
532
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
533
- function TeckosClientWithJWT(url, options, token, initialData) {
534
- var _this;
535
-
536
- _this = _TeckosClient.call(this, url, options) || this;
537
- _this.receivedReady = false;
538
-
539
- _this.handleReadyEvent = function () {
540
- if (_this.options.debug) d$1("[" + _this.url + "] Connected!");
541
- _this.receivedReady = true;
542
-
543
- if (_this.currentReconnectionAttempts > 0) {
544
- if (_this.options.debug) d$1("[" + _this.url + "] Reconnected!");
545
-
546
- _this.listeners('reconnect').forEach(function (listener) {
547
- return listener();
548
- }); // Reset reconnection settings to default
549
-
550
-
551
- _this.currentReconnectDelay = _this.options.reconnectionDelay;
552
- _this.currentReconnectionAttempts = 0;
553
- }
554
-
555
- _this.listeners('connect').forEach(function (listener) {
556
- return listener();
557
- });
558
- };
559
-
560
- _this.handleOpen = function () {
561
- _this.receivedReady = false;
562
-
563
- _this.once('ready', _this.handleReadyEvent);
564
-
565
- if (_this.options.debug) d$1('Connection opened, sending token now');
566
-
567
- _this.emit('token', _extends({
568
- token: _this.token
569
- }, _this.initialData));
570
- };
571
-
572
- _this.token = token; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
573
-
574
- _this.initialData = initialData;
575
-
576
- _this.on('disconnect', function () {
577
- _this.receivedReady = false;
578
- });
579
-
580
- return _this;
581
- }
582
-
583
- var _proto = TeckosClientWithJWT.prototype;
584
-
585
- _proto.getConnectionState = function getConnectionState() {
586
- if (this.ws) {
587
- switch (this.ws.readyState) {
588
- case WebSocket.OPEN:
589
- if (this.receivedReady) {
590
- return exports.ConnectionState.CONNECTED;
591
- }
592
-
593
- return exports.ConnectionState.CONNECTING;
594
-
595
- case WebSocket.CONNECTING:
596
- return exports.ConnectionState.CONNECTING;
597
-
598
- case WebSocket.CLOSING:
599
- return exports.ConnectionState.DISCONNECTING;
600
-
601
- default:
602
- return exports.ConnectionState.DISCONNECTED;
603
- }
604
- }
605
-
606
- return exports.ConnectionState.DISCONNECTED;
607
- };
608
-
609
- return TeckosClientWithJWT;
610
- }(TeckosClient);
611
-
612
- exports.TeckosClient = TeckosClient;
613
- exports.TeckosClientWithJWT = TeckosClientWithJWT;
614
- //# sourceMappingURL=teckos-client.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"teckos-client.cjs.development.js","sources":["../src/util/Converter.ts","../src/types/PacketType.ts","../src/types/ConnectionState.ts","../src/util/SocketEventEmitter.ts","../src/TeckosClient.ts","../src/TeckosClientWithJWT.ts"],"sourcesContent":["import { Packet } from '../types'\n\nconst enc = new TextEncoder()\nconst dec = new TextDecoder()\n\nconst encodePacket = (packet: Packet): ArrayBufferLike => enc.encode(JSON.stringify(packet))\nconst decodePacket = (buffer: ArrayBuffer): Packet =>\n JSON.parse(dec.decode(buffer).toString()) as Packet\n\nexport { encodePacket, decodePacket }\n","enum PacketType {\n EVENT,\n ACK,\n}\nexport { PacketType }\n","enum ConnectionState {\n DISCONNECTED = 'disconnected',\n CONNECTING = 'connecting',\n CONNECTED = 'connected',\n DISCONNECTING = 'disconnecting',\n}\nexport { ConnectionState }\n","export type Listener = (...args: any[]) => void\n\nclass SocketEventEmitter<T extends string> {\n protected maxListeners = 50\n\n protected handlers: {\n [event: string]: ((...args: any[]) => void)[]\n } = {}\n\n public addListener = (event: T, listener: (...args: any[]) => void): this => {\n if (Object.keys(this.handlers).length === this.maxListeners) {\n throw new Error('Max listeners reached')\n }\n if (typeof listener !== 'function') {\n throw new Error('The given listener is not a function')\n }\n this.handlers[event] = this.handlers[event] || []\n this.handlers[event].push(listener)\n return this\n }\n\n public once = (event: T, listener: (...args: any[]) => void): this => {\n if (Object.keys(this.handlers).length === this.maxListeners) {\n throw new Error('Max listeners reached')\n }\n if (typeof listener !== 'function') {\n throw new Error('The given listener is not a function')\n }\n this.handlers[event] = this.handlers[event] || []\n const onceWrapper = () => {\n listener()\n this.off(event, onceWrapper)\n }\n this.handlers[event].push(onceWrapper)\n return this\n }\n\n public removeListener = (event: T, listener: (...args: any[]) => void): this => {\n if (this.handlers[event]) {\n this.handlers[event] = this.handlers[event].filter((handler) => handler !== listener)\n }\n return this\n }\n\n public off = (event: T, listener: (...args: any[]) => void): this =>\n this.removeListener(event, listener)\n\n public removeAllListeners = (event?: T): this => {\n if (event) {\n delete this.handlers[event]\n } else {\n this.handlers = {}\n }\n return this\n }\n\n public setMaxListeners = (n: number): this => {\n this.maxListeners = n\n return this\n }\n\n public getMaxListeners = (): number => this.maxListeners\n\n public listeners = (event: T): Listener[] => {\n if (this.handlers[event]) {\n return [...this.handlers[event]]\n }\n return []\n }\n\n public rawListeners = (event: T): Listener[] => [...this.handlers[event]]\n\n public listenerCount = (event: T): number => {\n if (this.handlers[event]) {\n return Object.keys(this.handlers[event]).length\n }\n return 0\n }\n\n public prependListener = (event: T, listener: (...args: any[]) => void): this => {\n if (Object.keys(this.handlers).length === this.maxListeners) {\n throw new Error('Max listeners reached')\n }\n this.handlers[event] = this.handlers[event] || []\n this.handlers[event].unshift(listener)\n return this\n }\n\n public prependOnceListener = (event: T, listener: (...args: any[]) => void): this => {\n if (Object.keys(this.handlers).length === this.maxListeners) {\n throw new Error('Max listeners reached')\n }\n this.handlers[event] = this.handlers[event] || []\n const onceWrapper = () => {\n listener()\n this.off(event, onceWrapper)\n }\n this.handlers[event].unshift(onceWrapper)\n return this\n }\n\n public eventNames = (): T[] => Object.keys(this.handlers) as T[]\n\n public on = (event: T, listener: (...args: any[]) => void): this =>\n this.addListener(event, listener)\n\n public emit = (event: T, ...args: any[]): boolean => {\n const listeners = this.listeners(event)\n if (listeners.length > 0) {\n listeners.forEach((listener) => {\n if (listener) listener(args)\n })\n return true\n }\n return false\n }\n}\n\nexport { SocketEventEmitter }\n","import debug from 'debug'\nimport WebSocket from 'isomorphic-ws'\nimport { decodePacket, encodePacket } from './util/Converter'\nimport { ConnectionState, OptionalOptions, Options, Packet, PacketType, SocketEvent } from './types'\nimport { ITeckosClient } from './ITeckosClient'\nimport { SocketEventEmitter } from './util/SocketEventEmitter'\n\nconst d = debug('teckos:client')\n\nconst DEFAULT_OPTIONS: Options = {\n reconnection: true,\n reconnectionDelay: 1000,\n reconnectionDelayMax: 5000,\n reconnectionAttempts: Infinity,\n randomizationFactor: 0.5,\n timeout: 5000,\n debug: false,\n}\n\nclass TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosClient {\n protected readonly url: string\n\n protected readonly options: Options\n\n ws: WebSocket | undefined\n\n protected currentReconnectDelay: number\n\n protected currentReconnectionAttempts = 0\n\n protected acks: Map<number, (...args: any[]) => void> = new Map()\n\n protected fnId = 0\n\n protected connectionTimeout: any | undefined\n\n protected reconnectionTimeout: any | undefined\n\n constructor(url: string, options?: OptionalOptions) {\n super()\n this.options = {\n ...DEFAULT_OPTIONS,\n ...options,\n }\n this.currentReconnectDelay = this.options.reconnectionDelay\n this.url = url\n }\n\n protected attachHandler = (): void => {\n if (this.ws) {\n this.ws.onopen = this.handleOpen\n this.ws.onerror = this.handleError\n this.ws.onclose = this.handleClose\n this.ws.onmessage = this.handleMessage\n }\n }\n\n public get webSocket(): WebSocket | undefined {\n return this.ws\n }\n\n public connect = (): void => {\n if (this.options.debug) d(`Connecting to ${this.url}...`)\n\n // This will try to connect immediately\n this.ws = new WebSocket(this.url)\n // Attach handlers\n this.attachHandler()\n // Handle timeout\n this.connectionTimeout = setTimeout(() => {\n if (this.ws && this.ws.readyState === WebSocket.CONNECTING) {\n this.ws.close()\n }\n }, this.options.timeout)\n }\n\n protected reconnect = (): void => {\n this.listeners('reconnect_attempt').forEach((listener) => listener())\n this.connect()\n }\n\n protected getConnectionState(): ConnectionState {\n if (this.ws) {\n switch (this.ws.readyState) {\n case WebSocket.OPEN:\n return ConnectionState.CONNECTED\n case WebSocket.CONNECTING:\n return ConnectionState.CONNECTING\n case WebSocket.CLOSING:\n return ConnectionState.DISCONNECTING\n default:\n return ConnectionState.DISCONNECTED\n }\n }\n return ConnectionState.DISCONNECTED\n }\n\n public get state(): ConnectionState {\n return this.getConnectionState()\n }\n\n get connected(): boolean {\n return this.getConnectionState() === ConnectionState.CONNECTED\n }\n\n get disconnected(): boolean {\n return this.getConnectionState() === ConnectionState.DISCONNECTED\n }\n\n public emit = (event: SocketEvent, ...args: any[]): boolean => {\n args.unshift(event)\n\n const packet: Packet = {\n type: PacketType.EVENT,\n data: args,\n }\n\n if (typeof args[args.length - 1] === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n this.acks.set(this.fnId, args.pop())\n packet.id = this.fnId\n this.fnId += 1\n }\n\n return this.sendPackage(packet)\n }\n\n public send = (...args: any[]): boolean => {\n args.unshift('message')\n return this.sendPackage({\n type: PacketType.EVENT,\n data: args,\n })\n }\n\n public sendPackage = (packet: Packet): boolean => {\n if (this.ws !== undefined && this.ws.readyState === WebSocket.OPEN) {\n const buffer = encodePacket(packet)\n if (this.options.debug) d(`[${this.url}] Send packet: ${JSON.stringify(packet)}`)\n this.ws.send(buffer)\n return true\n }\n return false\n }\n\n protected handleMessage = (msg: WebSocket.MessageEvent): void => {\n const packet =\n typeof msg.data === 'string'\n ? (JSON.parse(msg.data) as Packet)\n : decodePacket(msg.data as ArrayBuffer)\n if (this.options.debug) d(`[${this.url}] Got packet: ${JSON.stringify(packet)}`)\n if (packet.type === PacketType.EVENT) {\n const event = packet.data[0] as SocketEvent\n const args = packet.data.slice(1)\n if (event) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n this.listeners(event).forEach((listener) => listener(...args))\n } else {\n throw new Error(\n `[teckos-client@${this.url}] Got invalid event message: ${JSON.stringify(\n msg.data\n )}`\n )\n }\n } else if (packet.type === PacketType.ACK && packet.id !== undefined) {\n // Call assigned function\n const ack = this.acks.get(packet.id)\n if (typeof ack === 'function') {\n ack.apply(this, packet.data)\n this.acks.delete(packet.id)\n }\n } else {\n throw new Error(`[teckos-client@${this.url}] Got invalid message type: ${packet.type}`)\n }\n }\n\n protected handleOpen = (): void => {\n if (this.currentReconnectionAttempts > 0) {\n // Reset reconnection settings to default\n this.currentReconnectDelay = this.options.reconnectionDelay\n this.currentReconnectionAttempts = 0\n\n // Inform listeners\n if (this.options.debug) d(`[${this.url}] Reconnected!`)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n this.listeners('reconnect').forEach((listener) => listener())\n }\n // Inform listeners\n if (this.options.debug) d(`[${this.url}] Connected!`)\n this.listeners('connect').forEach((listener) => listener())\n }\n\n protected handleError = (error: WebSocket.ErrorEvent): void => {\n if (this.handlers && this.handlers.error) {\n if (this.options.debug)\n d(`[${this.url}] Got error from server: ${JSON.stringify(error)}`)\n this.handlers.error.forEach((listener) => listener(error))\n }\n }\n\n protected handleClose = (): void => {\n // Stop connection timeout\n if (this.connectionTimeout) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n clearTimeout(this.connectionTimeout)\n }\n // Stop reconnection timeout\n if (this.reconnectionTimeout) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n clearTimeout(this.reconnectionTimeout)\n }\n\n // Inform listeners\n if (this.currentReconnectionAttempts > 0) {\n if (this.options.debug)\n d(`[${this.url}] Reconnect #${this.currentReconnectionAttempts} failed!`)\n this.listeners('reconnect_error').forEach((listener) => {\n if (listener) listener()\n })\n } else {\n if (this.options.debug) d(`[${this.url}] Disconnected!`)\n this.listeners('disconnect').forEach((listener) => {\n if (listener) listener()\n })\n }\n\n if (this.options.reconnection) {\n // Apply reconnection logic\n this.currentReconnectionAttempts += 1\n\n if (\n this.options.reconnectionAttempts === Infinity ||\n this.currentReconnectionAttempts <= this.options.reconnectionAttempts\n ) {\n const timeout = Math.min(\n this.options.reconnectionDelayMax,\n this.currentReconnectDelay\n )\n // Increase reconnection delay\n this.currentReconnectDelay = Math.round(\n this.currentReconnectDelay +\n this.currentReconnectDelay * this.options.randomizationFactor\n )\n\n if (this.options.debug)\n d(\n `[${this.url}] Try reconnecting (${this.currentReconnectionAttempts}/${this.options.reconnectionAttempts}) in ${timeout}ms to ${this.url}...`\n )\n this.reconnectionTimeout = setTimeout(() => {\n this.reconnect()\n }, timeout)\n } else {\n if (this.options.debug)\n d(\n `[${this.url}] Reconnection maximum of ${this.options.reconnectionAttempts} reached`\n )\n this.listeners('reconnect_failed').forEach((listener) => listener())\n }\n }\n }\n\n public close = (): void => {\n if (this.options.debug) d(`[${this.url}] Closing connection (client-side)`)\n if (this.ws !== undefined) {\n this.ws.onclose = () => {}\n this.ws.close()\n this.listeners('disconnect').forEach((listener) => listener())\n }\n }\n\n public disconnect = (): void => {\n this.close()\n }\n}\n\nexport { TeckosClient }\n","import debug from 'debug'\nimport WebSocket from 'isomorphic-ws'\nimport { TeckosClient } from './TeckosClient'\nimport { OptionalOptions, ConnectionState } from './types'\n\nconst d = debug('teckos:client')\n\nclass TeckosClientWithJWT extends TeckosClient {\n protected readonly token: string\n\n protected readonly initialData: any\n\n protected receivedReady = false\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n constructor(url: string, options: OptionalOptions, token: string, initialData?: any) {\n super(url, options)\n this.token = token\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.initialData = initialData\n this.on('disconnect', () => {\n this.receivedReady = false\n })\n }\n\n protected getConnectionState(): ConnectionState {\n if (this.ws) {\n switch (this.ws.readyState) {\n case WebSocket.OPEN:\n if (this.receivedReady) {\n return ConnectionState.CONNECTED\n }\n return ConnectionState.CONNECTING\n case WebSocket.CONNECTING:\n return ConnectionState.CONNECTING\n case WebSocket.CLOSING:\n return ConnectionState.DISCONNECTING\n default:\n return ConnectionState.DISCONNECTED\n }\n }\n return ConnectionState.DISCONNECTED\n }\n\n protected handleReadyEvent = (): void => {\n if (this.options.debug) d(`[${this.url}] Connected!`)\n this.receivedReady = true\n if (this.currentReconnectionAttempts > 0) {\n if (this.options.debug) d(`[${this.url}] Reconnected!`)\n this.listeners('reconnect').forEach((listener) => listener())\n // Reset reconnection settings to default\n this.currentReconnectDelay = this.options.reconnectionDelay\n this.currentReconnectionAttempts = 0\n }\n this.listeners('connect').forEach((listener) => listener())\n }\n\n protected handleOpen = (): void => {\n this.receivedReady = false\n this.once('ready', this.handleReadyEvent)\n if (this.options.debug) d('Connection opened, sending token now')\n this.emit('token', {\n token: this.token,\n ...this.initialData,\n })\n }\n}\n\nexport { TeckosClientWithJWT }\n"],"names":["enc","TextEncoder","dec","TextDecoder","encodePacket","packet","encode","JSON","stringify","decodePacket","buffer","parse","decode","toString","PacketType","ConnectionState","SocketEventEmitter","event","listener","Object","keys","handlers","length","maxListeners","Error","push","onceWrapper","off","filter","handler","removeListener","n","unshift","addListener","args","listeners","forEach","d","debug","DEFAULT_OPTIONS","reconnection","reconnectionDelay","reconnectionDelayMax","reconnectionAttempts","Infinity","randomizationFactor","timeout","TeckosClient","url","options","Map","ws","onopen","handleOpen","onerror","handleError","onclose","handleClose","onmessage","handleMessage","WebSocket","attachHandler","connectionTimeout","setTimeout","readyState","CONNECTING","close","connect","type","EVENT","data","acks","set","fnId","pop","id","sendPackage","undefined","OPEN","send","msg","slice","ACK","ack","get","apply","currentReconnectionAttempts","currentReconnectDelay","error","clearTimeout","reconnectionTimeout","Math","min","round","reconnect","getConnectionState","CONNECTED","CLOSING","DISCONNECTING","DISCONNECTED","TeckosClientWithJWT","token","initialData","receivedReady","once","handleReadyEvent","emit","on"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,gBAAG,IAAIC,WAAJ,EAAZ;AACA,IAAMC,GAAG,gBAAG,IAAIC,WAAJ,EAAZ;;AAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,MAAD;AAAA,SAAqCL,GAAG,CAACM,MAAJ,CAAWC,IAAI,CAACC,SAAL,CAAeH,MAAf,CAAX,CAArC;AAAA,CAArB;;AACA,IAAMI,YAAY,GAAG,SAAfA,YAAe,CAACC,MAAD;AAAA,SACjBH,IAAI,CAACI,KAAL,CAAWT,GAAG,CAACU,MAAJ,CAAWF,MAAX,EAAmBG,QAAnB,EAAX,CADiB;AAAA,CAArB;;ACNA,WAAKC;AACDA,EAAAA,mCAAA,UAAA;AACAA,EAAAA,iCAAA,QAAA;AACH,CAHD,EAAKA,kBAAU,KAAVA,kBAAU,KAAA,CAAf;;ACAA,WAAKC;AACDA,EAAAA,+BAAA,iBAAA;AACAA,EAAAA,6BAAA,eAAA;AACAA,EAAAA,4BAAA,cAAA;AACAA,EAAAA,gCAAA,kBAAA;AACH,CALD,EAAKA,uBAAe,KAAfA,uBAAe,KAAA,CAApB;;ICEMC,qBAAN;;;AACc,mBAAA,GAAe,EAAf;AAEA,eAAA,GAEN,EAFM;;AAIH,kBAAA,GAAc,UAACC,KAAD,EAAWC,QAAX;AACjB,QAAIC,MAAM,CAACC,IAAP,CAAY,KAAI,CAACC,QAAjB,EAA2BC,MAA3B,KAAsC,KAAI,CAACC,YAA/C,EAA6D;AACzD,YAAM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