teckos-client 0.2.4 → 0.3.1

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