websocket-ts 1.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +157 -93
- package/dist/cjs/src/backoff/backoff.d.ts +24 -0
- package/dist/cjs/src/backoff/backoff.d.ts.map +1 -0
- package/{lib → dist/cjs/src}/backoff/backoff.js.map +1 -1
- package/dist/cjs/src/backoff/constantbackoff.d.ts +18 -0
- package/dist/cjs/src/backoff/constantbackoff.d.ts.map +1 -0
- package/dist/cjs/src/backoff/constantbackoff.js +43 -0
- package/dist/cjs/src/backoff/constantbackoff.js.map +1 -0
- package/dist/cjs/src/backoff/exponentialbackoff.d.ts +48 -0
- package/dist/cjs/src/backoff/exponentialbackoff.d.ts.map +1 -0
- package/dist/cjs/src/backoff/exponentialbackoff.js +81 -0
- package/dist/cjs/src/backoff/exponentialbackoff.js.map +1 -0
- package/dist/cjs/src/backoff/linearbackoff.d.ts +51 -0
- package/dist/cjs/src/backoff/linearbackoff.d.ts.map +1 -0
- package/dist/cjs/src/backoff/linearbackoff.js +89 -0
- package/dist/cjs/src/backoff/linearbackoff.js.map +1 -0
- package/dist/cjs/src/index.d.ts +14 -0
- package/dist/cjs/src/index.d.ts.map +1 -0
- package/dist/cjs/src/index.js +20 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/queue/array_queue.d.ts +17 -0
- package/dist/cjs/src/queue/array_queue.d.ts.map +1 -0
- package/dist/cjs/src/queue/array_queue.js +36 -0
- package/dist/cjs/src/queue/array_queue.js.map +1 -0
- package/dist/cjs/src/queue/queue.d.ts +41 -0
- package/dist/cjs/src/queue/queue.d.ts.map +1 -0
- package/{lib/buffer/buffer.js → dist/cjs/src/queue/queue.js} +1 -1
- package/dist/cjs/src/queue/queue.js.map +1 -0
- package/dist/cjs/src/queue/ring_queue.d.ts +20 -0
- package/dist/cjs/src/queue/ring_queue.d.ts.map +1 -0
- package/dist/cjs/src/queue/ring_queue.js +57 -0
- package/dist/cjs/src/queue/ring_queue.js.map +1 -0
- package/dist/cjs/src/websocket.d.ts +206 -0
- package/dist/cjs/src/websocket.d.ts.map +1 -0
- package/dist/cjs/src/websocket.js +434 -0
- package/dist/cjs/src/websocket.js.map +1 -0
- package/dist/cjs/src/websocket_buffer.d.ts +16 -0
- package/dist/cjs/src/websocket_buffer.d.ts.map +1 -0
- package/dist/cjs/src/websocket_buffer.js +3 -0
- package/dist/cjs/src/websocket_buffer.js.map +1 -0
- package/dist/cjs/src/websocket_builder.d.ts +147 -0
- package/dist/cjs/src/websocket_builder.d.ts.map +1 -0
- package/dist/cjs/src/websocket_builder.js +263 -0
- package/dist/cjs/src/websocket_builder.js.map +1 -0
- package/dist/cjs/src/websocket_event.d.ts +67 -0
- package/dist/cjs/src/websocket_event.d.ts.map +1 -0
- package/dist/cjs/src/websocket_event.js +22 -0
- package/dist/cjs/src/websocket_event.js.map +1 -0
- package/dist/cjs/src/websocket_options.d.ts +21 -0
- package/dist/cjs/src/websocket_options.d.ts.map +1 -0
- package/dist/cjs/src/websocket_options.js +3 -0
- package/dist/cjs/src/websocket_options.js.map +1 -0
- package/dist/cjs/src/websocket_retry_options.d.ts +20 -0
- package/dist/cjs/src/websocket_retry_options.d.ts.map +1 -0
- package/dist/cjs/src/websocket_retry_options.js +3 -0
- package/dist/cjs/src/websocket_retry_options.js.map +1 -0
- package/dist/esm/src/backoff/backoff.d.ts +24 -0
- package/dist/esm/src/backoff/backoff.d.ts.map +1 -0
- package/dist/esm/src/backoff/backoff.js +2 -0
- package/dist/esm/src/backoff/backoff.js.map +1 -0
- package/dist/esm/src/backoff/constantbackoff.d.ts +18 -0
- package/dist/esm/src/backoff/constantbackoff.d.ts.map +1 -0
- package/dist/esm/src/backoff/constantbackoff.js +30 -0
- package/dist/esm/src/backoff/constantbackoff.js.map +1 -0
- package/dist/esm/src/backoff/exponentialbackoff.d.ts +48 -0
- package/dist/esm/src/backoff/exponentialbackoff.d.ts.map +1 -0
- package/dist/esm/src/backoff/exponentialbackoff.js +68 -0
- package/dist/esm/src/backoff/exponentialbackoff.js.map +1 -0
- package/dist/esm/src/backoff/linearbackoff.d.ts +51 -0
- package/dist/esm/src/backoff/linearbackoff.d.ts.map +1 -0
- package/dist/esm/src/backoff/linearbackoff.js +76 -0
- package/dist/esm/src/backoff/linearbackoff.js.map +1 -0
- package/dist/esm/src/index.d.ts +14 -0
- package/dist/esm/src/index.d.ts.map +1 -0
- package/dist/esm/src/index.js +9 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/queue/array_queue.d.ts +17 -0
- package/dist/esm/src/queue/array_queue.d.ts.map +1 -0
- package/dist/esm/src/queue/array_queue.js +31 -0
- package/dist/esm/src/queue/array_queue.js.map +1 -0
- package/dist/esm/src/queue/queue.d.ts +41 -0
- package/dist/esm/src/queue/queue.d.ts.map +1 -0
- package/dist/esm/src/queue/queue.js +2 -0
- package/dist/esm/src/queue/queue.js.map +1 -0
- package/dist/esm/src/queue/ring_queue.d.ts +20 -0
- package/dist/esm/src/queue/ring_queue.d.ts.map +1 -0
- package/dist/esm/src/queue/ring_queue.js +52 -0
- package/dist/esm/src/queue/ring_queue.js.map +1 -0
- package/dist/esm/src/websocket.d.ts +206 -0
- package/dist/esm/src/websocket.d.ts.map +1 -0
- package/dist/esm/src/websocket.js +356 -0
- package/dist/esm/src/websocket.js.map +1 -0
- package/dist/esm/src/websocket_buffer.d.ts +16 -0
- package/dist/esm/src/websocket_buffer.d.ts.map +1 -0
- package/dist/esm/src/websocket_buffer.js +2 -0
- package/dist/esm/src/websocket_buffer.js.map +1 -0
- package/dist/esm/src/websocket_builder.d.ts +147 -0
- package/dist/esm/src/websocket_builder.d.ts.map +1 -0
- package/dist/esm/src/websocket_builder.js +213 -0
- package/dist/esm/src/websocket_builder.js.map +1 -0
- package/dist/esm/src/websocket_event.d.ts +67 -0
- package/dist/esm/src/websocket_event.d.ts.map +1 -0
- package/dist/esm/src/websocket_event.js +19 -0
- package/dist/esm/src/websocket_event.js.map +1 -0
- package/dist/esm/src/websocket_options.d.ts +21 -0
- package/dist/esm/src/websocket_options.d.ts.map +1 -0
- package/dist/esm/src/websocket_options.js +2 -0
- package/dist/esm/src/websocket_options.js.map +1 -0
- package/dist/esm/src/websocket_retry_options.d.ts +20 -0
- package/dist/esm/src/websocket_retry_options.d.ts.map +1 -0
- package/dist/esm/src/websocket_retry_options.js +2 -0
- package/dist/esm/src/websocket_retry_options.js.map +1 -0
- package/package.json +27 -14
- package/src/backoff/backoff.ts +21 -13
- package/src/backoff/constantbackoff.ts +29 -11
- package/src/backoff/exponentialbackoff.ts +68 -28
- package/src/backoff/linearbackoff.ts +77 -26
- package/src/index.ts +23 -9
- package/src/queue/array_queue.ts +41 -0
- package/src/queue/queue.ts +46 -0
- package/src/queue/ring_queue.ts +69 -0
- package/src/websocket.ts +463 -138
- package/src/websocket_buffer.ts +18 -0
- package/src/websocket_builder.ts +274 -0
- package/src/websocket_event.ts +88 -0
- package/src/websocket_options.ts +23 -0
- package/src/websocket_retry_options.ts +22 -0
- package/{tsconfig.json → tsconfig.cjs.json} +8 -8
- package/tsconfig.esm.json +71 -0
- package/jest.config.js +0 -9
- package/lib/backoff/backoff.d.ts +0 -18
- package/lib/backoff/backoff.d.ts.map +0 -1
- package/lib/backoff/constantbackoff.d.ts +0 -11
- package/lib/backoff/constantbackoff.d.ts.map +0 -1
- package/lib/backoff/constantbackoff.js +0 -20
- package/lib/backoff/constantbackoff.js.map +0 -1
- package/lib/backoff/exponentialbackoff.d.ts +0 -22
- package/lib/backoff/exponentialbackoff.d.ts.map +0 -1
- package/lib/backoff/exponentialbackoff.js +0 -35
- package/lib/backoff/exponentialbackoff.js.map +0 -1
- package/lib/backoff/linearbackoff.d.ts +0 -19
- package/lib/backoff/linearbackoff.d.ts.map +0 -1
- package/lib/backoff/linearbackoff.js +0 -34
- package/lib/backoff/linearbackoff.js.map +0 -1
- package/lib/buffer/buffer.d.ts +0 -41
- package/lib/buffer/buffer.d.ts.map +0 -1
- package/lib/buffer/buffer.js.map +0 -1
- package/lib/buffer/lrubuffer.d.ts +0 -24
- package/lib/buffer/lrubuffer.d.ts.map +0 -1
- package/lib/buffer/lrubuffer.js +0 -76
- package/lib/buffer/lrubuffer.js.map +0 -1
- package/lib/buffer/timebuffer.d.ts +0 -25
- package/lib/buffer/timebuffer.d.ts.map +0 -1
- package/lib/buffer/timebuffer.js +0 -92
- package/lib/buffer/timebuffer.js.map +0 -1
- package/lib/index.d.ts +0 -10
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -22
- package/lib/index.js.map +0 -1
- package/lib/websocket.d.ts +0 -47
- package/lib/websocket.d.ts.map +0 -1
- package/lib/websocket.js +0 -120
- package/lib/websocket.js.map +0 -1
- package/lib/websocketBuilder.d.ts +0 -32
- package/lib/websocketBuilder.d.ts.map +0 -1
- package/lib/websocketBuilder.js +0 -68
- package/lib/websocketBuilder.js.map +0 -1
- package/src/buffer/buffer.ts +0 -45
- package/src/buffer/lrubuffer.ts +0 -80
- package/src/buffer/timebuffer.ts +0 -105
- package/src/websocketBuilder.ts +0 -98
- package/test/backoff/constantbackoff.test.ts +0 -21
- package/test/backoff/exponentialbackoff.test.ts +0 -13
- package/test/backoff/linearbackoff.test.ts +0 -32
- package/test/buffer/common.ts +0 -10
- package/test/buffer/lrubuffer.test.ts +0 -128
- package/test/buffer/timebuffer.test.ts +0 -115
- package/test/websocket.test.ts +0 -341
- package/test/websocketBuilder.test.ts +0 -36
- /package/{lib → dist/cjs/src}/backoff/backoff.js +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinearBackoff = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* LinearBackoff returns a backoff-time that is incremented by a fixed amount
|
|
6
|
+
* with every step/retry. An optional maximum can be provided as an upper bound
|
|
7
|
+
* to the returned backoff.
|
|
8
|
+
*
|
|
9
|
+
* The series can be described as ('i' is the current step/retry):
|
|
10
|
+
* backoff = initial + increment * i | without bound
|
|
11
|
+
* backoff = initial + increment * min(i, max) | with bound
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* 1) Without bound:
|
|
16
|
+
* initial = 1000, increment = 1000
|
|
17
|
+
* backoff = 1000 + 1000 * 0 = 1000 // first retry
|
|
18
|
+
* backoff = 1000 + 1000 * 1 = 2000 // second retry
|
|
19
|
+
* backoff = 1000 + 1000 * 2 = 3000 // ...increases by 'increment' with every retry
|
|
20
|
+
* backoff = 1000 + 1000 * 3 = 4000
|
|
21
|
+
* backoff = 1000 + 1000 * 4 = 5000
|
|
22
|
+
* ... // and so on
|
|
23
|
+
*
|
|
24
|
+
* 2) With bound:
|
|
25
|
+
* initial = 1000, increment = 1000, max = 5000
|
|
26
|
+
* backoff = 1000 + 1000 * 0 = 1000 // first retry
|
|
27
|
+
* backoff = 1000 + 1000 * 1 = 2000 // second retry
|
|
28
|
+
* backoff = 1000 + 1000 * 2 = 3000 // third retry
|
|
29
|
+
* backoff = 1000 + 1000 * 3 = 4000 // fourth retry
|
|
30
|
+
* backoff = 1000 + 1000 * 4 = 5000 // maximum reached, don't increase further
|
|
31
|
+
* backoff = 1000 + 1000 * 4 = 5000
|
|
32
|
+
* backoff = 1000 + 1000 * 4 = 5000
|
|
33
|
+
* ... // and so on
|
|
34
|
+
*/
|
|
35
|
+
var LinearBackoff = /** @class */ (function () {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new LinearBackoff.
|
|
38
|
+
* @param initial the initial backoff-time in milliseconds
|
|
39
|
+
* @param increment the amount to increment the backoff-time with every step (in milliseconds)
|
|
40
|
+
* @param max the maximum backoff-time (in milliseconds), no bound if undefined
|
|
41
|
+
*/
|
|
42
|
+
function LinearBackoff(initial, increment, max) {
|
|
43
|
+
this.i = 0;
|
|
44
|
+
this._retries = 0;
|
|
45
|
+
if (initial < 0) {
|
|
46
|
+
throw new Error("Initial must be a positive number or zero");
|
|
47
|
+
}
|
|
48
|
+
if (increment < 0) {
|
|
49
|
+
throw new Error("Increment must be a positive number or zero");
|
|
50
|
+
}
|
|
51
|
+
if (max !== undefined && max < 0) {
|
|
52
|
+
throw new Error("Max must be undefined, a positive number or zero");
|
|
53
|
+
}
|
|
54
|
+
if (max !== undefined && max < initial) {
|
|
55
|
+
throw new Error("Max must be undefined or greater than or equal to initial");
|
|
56
|
+
}
|
|
57
|
+
this.initial = initial;
|
|
58
|
+
this.increment = increment;
|
|
59
|
+
this.max = max;
|
|
60
|
+
}
|
|
61
|
+
Object.defineProperty(LinearBackoff.prototype, "retries", {
|
|
62
|
+
get: function () {
|
|
63
|
+
return this._retries;
|
|
64
|
+
},
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(LinearBackoff.prototype, "current", {
|
|
69
|
+
get: function () {
|
|
70
|
+
return this.max === undefined
|
|
71
|
+
? this.initial + this.increment * this.i
|
|
72
|
+
: Math.min(this.initial + this.increment * this.i, this.max);
|
|
73
|
+
},
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: true
|
|
76
|
+
});
|
|
77
|
+
LinearBackoff.prototype.next = function () {
|
|
78
|
+
this._retries++;
|
|
79
|
+
this.i++;
|
|
80
|
+
return this.current;
|
|
81
|
+
};
|
|
82
|
+
LinearBackoff.prototype.reset = function () {
|
|
83
|
+
this._retries = 0;
|
|
84
|
+
this.i = 0;
|
|
85
|
+
};
|
|
86
|
+
return LinearBackoff;
|
|
87
|
+
}());
|
|
88
|
+
exports.LinearBackoff = LinearBackoff;
|
|
89
|
+
//# sourceMappingURL=linearbackoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linearbackoff.js","sourceRoot":"","sources":["../../../../src/backoff/linearbackoff.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH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QACE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IACH,oBAAC;AAAD,CAAC,AAtDD,IAsDC;AAtDY,sCAAa"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { Backoff } from "./backoff/backoff";
|
|
2
|
+
export { ConstantBackoff } from "./backoff/constantbackoff";
|
|
3
|
+
export { ExponentialBackoff } from "./backoff/exponentialbackoff";
|
|
4
|
+
export { LinearBackoff } from "./backoff/linearbackoff";
|
|
5
|
+
export { Queue } from "./queue/queue";
|
|
6
|
+
export { ArrayQueue } from "./queue/array_queue";
|
|
7
|
+
export { RingQueue } from "./queue/ring_queue";
|
|
8
|
+
export { Websocket } from "./websocket";
|
|
9
|
+
export { WebsocketBuffer } from "./websocket_buffer";
|
|
10
|
+
export { WebsocketBuilder } from "./websocket_builder";
|
|
11
|
+
export { WebsocketEvent, RetryEventDetail, ReconnectEventDetail, WebsocketEventMap, WebsocketEventListener, WebsocketEventListenerParams, WebsocketEventListenerOptions, WebsocketEventListenerWithOptions, WebsocketEventListeners, } from "./websocket_event";
|
|
12
|
+
export { WebsocketOptions } from "./websocket_options";
|
|
13
|
+
export { WebsocketConnectionRetryOptions } from "./websocket_retry_options";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebsocketEvent = exports.WebsocketBuilder = exports.Websocket = exports.RingQueue = exports.ArrayQueue = exports.LinearBackoff = exports.ExponentialBackoff = exports.ConstantBackoff = void 0;
|
|
4
|
+
var constantbackoff_1 = require("./backoff/constantbackoff");
|
|
5
|
+
Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return constantbackoff_1.ConstantBackoff; } });
|
|
6
|
+
var exponentialbackoff_1 = require("./backoff/exponentialbackoff");
|
|
7
|
+
Object.defineProperty(exports, "ExponentialBackoff", { enumerable: true, get: function () { return exponentialbackoff_1.ExponentialBackoff; } });
|
|
8
|
+
var linearbackoff_1 = require("./backoff/linearbackoff");
|
|
9
|
+
Object.defineProperty(exports, "LinearBackoff", { enumerable: true, get: function () { return linearbackoff_1.LinearBackoff; } });
|
|
10
|
+
var array_queue_1 = require("./queue/array_queue");
|
|
11
|
+
Object.defineProperty(exports, "ArrayQueue", { enumerable: true, get: function () { return array_queue_1.ArrayQueue; } });
|
|
12
|
+
var ring_queue_1 = require("./queue/ring_queue");
|
|
13
|
+
Object.defineProperty(exports, "RingQueue", { enumerable: true, get: function () { return ring_queue_1.RingQueue; } });
|
|
14
|
+
var websocket_1 = require("./websocket");
|
|
15
|
+
Object.defineProperty(exports, "Websocket", { enumerable: true, get: function () { return websocket_1.Websocket; } });
|
|
16
|
+
var websocket_builder_1 = require("./websocket_builder");
|
|
17
|
+
Object.defineProperty(exports, "WebsocketBuilder", { enumerable: true, get: function () { return websocket_builder_1.WebsocketBuilder; } });
|
|
18
|
+
var websocket_event_1 = require("./websocket_event");
|
|
19
|
+
Object.defineProperty(exports, "WebsocketEvent", { enumerable: true, get: function () { return websocket_event_1.WebsocketEvent; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;AACA,6DAA4D;AAAnD,kHAAA,eAAe,OAAA;AACxB,mEAAkE;AAAzD,wHAAA,kBAAkB,OAAA;AAC3B,yDAAwD;AAA/C,8GAAA,aAAa,OAAA;AAEtB,mDAAiD;AAAxC,yGAAA,UAAU,OAAA;AACnB,iDAA+C;AAAtC,uGAAA,SAAS,OAAA;AAClB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAElB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,qDAU2B;AATzB,iHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Queue } from "./queue";
|
|
2
|
+
/**
|
|
3
|
+
* An array queue is a queue that has an unbounded capacity. Reading from an array queue
|
|
4
|
+
* will return the oldest element and effectively remove it from the queue.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ArrayQueue<E> implements Queue<E> {
|
|
7
|
+
private readonly elements;
|
|
8
|
+
constructor();
|
|
9
|
+
add(element: E): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
forEach(fn: (element: E) => unknown): void;
|
|
12
|
+
length(): number;
|
|
13
|
+
isEmpty(): boolean;
|
|
14
|
+
peek(): E | undefined;
|
|
15
|
+
read(): E | undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=array_queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_queue.d.ts","sourceRoot":"","sources":["../../../../src/queue/array_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;GAGG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;;IAM/B,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAIrB,KAAK;IAIL,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO;IAInC,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,IAAI,IAAI,CAAC,GAAG,SAAS;CAGtB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayQueue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An array queue is a queue that has an unbounded capacity. Reading from an array queue
|
|
6
|
+
* will return the oldest element and effectively remove it from the queue.
|
|
7
|
+
*/
|
|
8
|
+
var ArrayQueue = /** @class */ (function () {
|
|
9
|
+
function ArrayQueue() {
|
|
10
|
+
this.elements = [];
|
|
11
|
+
}
|
|
12
|
+
ArrayQueue.prototype.add = function (element) {
|
|
13
|
+
this.elements.push(element);
|
|
14
|
+
};
|
|
15
|
+
ArrayQueue.prototype.clear = function () {
|
|
16
|
+
this.elements.length = 0;
|
|
17
|
+
};
|
|
18
|
+
ArrayQueue.prototype.forEach = function (fn) {
|
|
19
|
+
this.elements.forEach(fn);
|
|
20
|
+
};
|
|
21
|
+
ArrayQueue.prototype.length = function () {
|
|
22
|
+
return this.elements.length;
|
|
23
|
+
};
|
|
24
|
+
ArrayQueue.prototype.isEmpty = function () {
|
|
25
|
+
return this.elements.length === 0;
|
|
26
|
+
};
|
|
27
|
+
ArrayQueue.prototype.peek = function () {
|
|
28
|
+
return this.elements[0];
|
|
29
|
+
};
|
|
30
|
+
ArrayQueue.prototype.read = function () {
|
|
31
|
+
return this.elements.shift();
|
|
32
|
+
};
|
|
33
|
+
return ArrayQueue;
|
|
34
|
+
}());
|
|
35
|
+
exports.ArrayQueue = ArrayQueue;
|
|
36
|
+
//# sourceMappingURL=array_queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_queue.js","sourceRoot":"","sources":["../../../../src/queue/array_queue.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH;IAGE;QACE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,wBAAG,GAAH,UAAI,OAAU;QACZ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,0BAAK,GAAL;QACE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,4BAAO,GAAP,UAAQ,EAA2B;QACjC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,2BAAM,GAAN;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,4BAAO,GAAP;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,yBAAI,GAAJ;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,yBAAI,GAAJ;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,iBAAC;AAAD,CAAC,AAlCD,IAkCC;AAlCY,gCAAU"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A queue holds elements until they are read. The order in which elements are
|
|
3
|
+
* read is determined by the implementation of the queue.
|
|
4
|
+
*/
|
|
5
|
+
export interface Queue<E> {
|
|
6
|
+
/**
|
|
7
|
+
* Adds an element to the queue.
|
|
8
|
+
* @param element the element to add
|
|
9
|
+
*/
|
|
10
|
+
add(element: E): void;
|
|
11
|
+
/**
|
|
12
|
+
* Clears the queue, removing all elements.
|
|
13
|
+
*/
|
|
14
|
+
clear(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Calls the given function for each element in the queue.
|
|
17
|
+
* @param fn the function to call
|
|
18
|
+
*/
|
|
19
|
+
forEach(fn: (element: E) => unknown): void;
|
|
20
|
+
/**
|
|
21
|
+
* Number of elements in the queue.
|
|
22
|
+
* @return the number of elements in the queue
|
|
23
|
+
*/
|
|
24
|
+
length(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the queue is empty.
|
|
27
|
+
* @return true if the queue is empty, false otherwise
|
|
28
|
+
*/
|
|
29
|
+
isEmpty(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the next element in the queue without removing it.
|
|
32
|
+
* @return the next element in the queue, or undefined if the queue is empty
|
|
33
|
+
*/
|
|
34
|
+
peek(): E | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Removes and returns the next element in the queue.
|
|
37
|
+
* @return the next element in the queue, or undefined if the queue is empty
|
|
38
|
+
*/
|
|
39
|
+
read(): E | undefined;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../../src/queue/queue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IAE3C;;;OAGG;IACH,MAAM,IAAI,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC;IAEnB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;IAEtB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/queue/queue.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Queue } from "./queue";
|
|
2
|
+
/**
|
|
3
|
+
* A ring queue is a queue that has a fixed capacity. When the queue is full, the oldest element is
|
|
4
|
+
* removed to make room for the new element. Reading from a ring queue will return the oldest
|
|
5
|
+
* element and effectively remove it from the queue.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RingQueue<E> implements Queue<E> {
|
|
8
|
+
private readonly elements;
|
|
9
|
+
private head;
|
|
10
|
+
private tail;
|
|
11
|
+
constructor(capacity: number);
|
|
12
|
+
add(element: E): void;
|
|
13
|
+
clear(): void;
|
|
14
|
+
forEach(fn: (element: E) => unknown): void;
|
|
15
|
+
length(): number;
|
|
16
|
+
isEmpty(): boolean;
|
|
17
|
+
peek(): E | undefined;
|
|
18
|
+
read(): E | undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ring_queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ring_queue.d.ts","sourceRoot":"","sources":["../../../../src/queue/ring_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;GAIG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;gBAET,QAAQ,EAAE,MAAM;IAU5B,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAQrB,KAAK;IAKL,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO;IAUnC,MAAM,IAAI,MAAM;IAQhB,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,IAAI,IAAI,CAAC,GAAG,SAAS;CAOtB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RingQueue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A ring queue is a queue that has a fixed capacity. When the queue is full, the oldest element is
|
|
6
|
+
* removed to make room for the new element. Reading from a ring queue will return the oldest
|
|
7
|
+
* element and effectively remove it from the queue.
|
|
8
|
+
*/
|
|
9
|
+
var RingQueue = /** @class */ (function () {
|
|
10
|
+
function RingQueue(capacity) {
|
|
11
|
+
if (!Number.isInteger(capacity) || capacity <= 0) {
|
|
12
|
+
throw new Error("Capacity must be a positive integer");
|
|
13
|
+
}
|
|
14
|
+
this.elements = new Array(capacity + 1); // +1 to distinguish between full and empty
|
|
15
|
+
this.head = 0;
|
|
16
|
+
this.tail = 0;
|
|
17
|
+
}
|
|
18
|
+
RingQueue.prototype.add = function (element) {
|
|
19
|
+
this.elements[this.head] = element;
|
|
20
|
+
this.head = (this.head + 1) % this.elements.length;
|
|
21
|
+
if (this.head === this.tail) {
|
|
22
|
+
this.tail = (this.tail + 1) % this.elements.length;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
RingQueue.prototype.clear = function () {
|
|
26
|
+
this.head = 0;
|
|
27
|
+
this.tail = 0;
|
|
28
|
+
};
|
|
29
|
+
RingQueue.prototype.forEach = function (fn) {
|
|
30
|
+
for (var i = this.tail; i !== this.head; i = (i + 1) % this.elements.length) {
|
|
31
|
+
fn(this.elements[i]);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
RingQueue.prototype.length = function () {
|
|
35
|
+
return this.tail === this.head
|
|
36
|
+
? 0
|
|
37
|
+
: this.tail < this.head
|
|
38
|
+
? this.head - this.tail
|
|
39
|
+
: this.elements.length - this.tail + this.head;
|
|
40
|
+
};
|
|
41
|
+
RingQueue.prototype.isEmpty = function () {
|
|
42
|
+
return this.head === this.tail;
|
|
43
|
+
};
|
|
44
|
+
RingQueue.prototype.peek = function () {
|
|
45
|
+
return this.isEmpty() ? undefined : this.elements[this.tail];
|
|
46
|
+
};
|
|
47
|
+
RingQueue.prototype.read = function () {
|
|
48
|
+
var e = this.peek();
|
|
49
|
+
if (e !== undefined) {
|
|
50
|
+
this.tail = (this.tail + 1) % this.elements.length;
|
|
51
|
+
}
|
|
52
|
+
return e;
|
|
53
|
+
};
|
|
54
|
+
return RingQueue;
|
|
55
|
+
}());
|
|
56
|
+
exports.RingQueue = RingQueue;
|
|
57
|
+
//# sourceMappingURL=ring_queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ring_queue.js","sourceRoot":"","sources":["../../../../src/queue/ring_queue.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH;IAKE,mBAAY,QAAgB;QAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,CAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,2CAA2C;QACvF,IAAI,CAAC,IAAI,GAAG,CAAC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AO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,wBAAI,GAAJ;QACE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED,wBAAI,GAAJ;QACE,IAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;SACpD;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IACH,gBAAC;AAAD,CAAC,AA7DD,IA6DC;AA7DY,8BAAS"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Backoff } from "./backoff/backoff";
|
|
2
|
+
import { WebsocketBuffer } from "./websocket_buffer";
|
|
3
|
+
import { WebsocketEvent, WebsocketEventListener, WebsocketEventListenerOptions } from "./websocket_event";
|
|
4
|
+
import { WebsocketOptions } from "./websocket_options";
|
|
5
|
+
/**
|
|
6
|
+
* A websocket wrapper that can be configured to reconnect automatically and buffer messages when the websocket is not connected.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Websocket {
|
|
9
|
+
private readonly _url;
|
|
10
|
+
private readonly _protocols?;
|
|
11
|
+
private _closedByUser;
|
|
12
|
+
private _lastConnection?;
|
|
13
|
+
private _underlyingWebsocket;
|
|
14
|
+
private retryTimeout?;
|
|
15
|
+
private _options;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new websocket.
|
|
18
|
+
*
|
|
19
|
+
* @param url to connect to.
|
|
20
|
+
* @param protocols optional protocols to use.
|
|
21
|
+
* @param options optional options to use.
|
|
22
|
+
*/
|
|
23
|
+
constructor(url: string, protocols?: string | string[], options?: WebsocketOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Getter for the url.
|
|
26
|
+
*
|
|
27
|
+
* @return the url.
|
|
28
|
+
*/
|
|
29
|
+
get url(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Getter for the protocols.
|
|
32
|
+
*
|
|
33
|
+
* @return the protocols, or undefined if none were provided.
|
|
34
|
+
*/
|
|
35
|
+
get protocols(): string | string[] | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Getter for the buffer.
|
|
38
|
+
*
|
|
39
|
+
* @return the buffer, or undefined if none was provided.
|
|
40
|
+
*/
|
|
41
|
+
get buffer(): WebsocketBuffer | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Getter for the maxRetries.
|
|
44
|
+
*
|
|
45
|
+
* @return the maxRetries, or undefined if none was provided (no limit).
|
|
46
|
+
*/
|
|
47
|
+
get maxRetries(): number | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Getter for the instantReconnect.
|
|
50
|
+
*
|
|
51
|
+
* @return the instantReconnect, or undefined if none was provided.
|
|
52
|
+
*/
|
|
53
|
+
get instantReconnect(): boolean | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Getter for the backoff.
|
|
56
|
+
*
|
|
57
|
+
* @return the backoff, or undefined if none was provided.
|
|
58
|
+
*/
|
|
59
|
+
get backoff(): Backoff | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the websocket was closed by the user. A websocket is closed by the user if the close().
|
|
62
|
+
*
|
|
63
|
+
* @return true if the websocket was closed by the user, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
get closedByUser(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Getter for the last 'open' event, e.g. the last time the websocket was connected.
|
|
68
|
+
*
|
|
69
|
+
* @return the last 'open' event, or undefined if the websocket was never connected.
|
|
70
|
+
*/
|
|
71
|
+
get lastConnection(): Date | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Getter for the underlying websocket. This can be used to access the browser's native websocket directly.
|
|
74
|
+
*
|
|
75
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
|
76
|
+
* @return the underlying websocket.
|
|
77
|
+
*/
|
|
78
|
+
get underlyingWebsocket(): WebSocket;
|
|
79
|
+
/**
|
|
80
|
+
* Getter for the readyState of the underlying websocket.
|
|
81
|
+
*
|
|
82
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState
|
|
83
|
+
* @return the readyState of the underlying websocket.
|
|
84
|
+
*/
|
|
85
|
+
get readyState(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Getter for the bufferedAmount of the underlying websocket.
|
|
88
|
+
*
|
|
89
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount
|
|
90
|
+
* @return the bufferedAmount of the underlying websocket.
|
|
91
|
+
*/
|
|
92
|
+
get bufferedAmount(): number;
|
|
93
|
+
/**
|
|
94
|
+
* Getter for the extensions of the underlying websocket.
|
|
95
|
+
*
|
|
96
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions
|
|
97
|
+
* @return the extensions of the underlying websocket.
|
|
98
|
+
*/
|
|
99
|
+
get extensions(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Getter for the binaryType of the underlying websocket.
|
|
102
|
+
*
|
|
103
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType
|
|
104
|
+
* @return the binaryType of the underlying websocket.
|
|
105
|
+
*/
|
|
106
|
+
get binaryType(): BinaryType;
|
|
107
|
+
/**
|
|
108
|
+
* Setter for the binaryType of the underlying websocket.
|
|
109
|
+
*
|
|
110
|
+
* @param value to set, 'blob' or 'arraybuffer'.
|
|
111
|
+
*/
|
|
112
|
+
set binaryType(value: BinaryType);
|
|
113
|
+
/**
|
|
114
|
+
* Sends data over the websocket.
|
|
115
|
+
*
|
|
116
|
+
* If the websocket is not connected and a buffer was provided on creation, the data will be added to the buffer.
|
|
117
|
+
* If no buffer was provided or the websocket was closed by the user, the data will be dropped.
|
|
118
|
+
*
|
|
119
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
120
|
+
* @param data to send.
|
|
121
|
+
*/
|
|
122
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
123
|
+
/**
|
|
124
|
+
* Close the websocket. No connection-retry will be attempted after this.
|
|
125
|
+
*
|
|
126
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
|
|
127
|
+
* @param code optional close code.
|
|
128
|
+
* @param reason optional close reason.
|
|
129
|
+
*/
|
|
130
|
+
close(code?: number, reason?: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Adds an event listener for the given event-type.
|
|
133
|
+
*
|
|
134
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
|
135
|
+
* @param type of the event to add the listener for.
|
|
136
|
+
* @param listener to add.
|
|
137
|
+
* @param options to use when adding the listener.
|
|
138
|
+
*/
|
|
139
|
+
addEventListener<K extends WebsocketEvent>(type: K, listener: WebsocketEventListener<K>, options?: WebsocketEventListenerOptions): void;
|
|
140
|
+
/**
|
|
141
|
+
* Removes one or more event listener for the given event-type that match the given listener and options.
|
|
142
|
+
*
|
|
143
|
+
* @param type of the event to remove the listener for.
|
|
144
|
+
* @param listener to remove.
|
|
145
|
+
* @param options that were used when the listener was added.
|
|
146
|
+
*/
|
|
147
|
+
removeEventListener<K extends WebsocketEvent>(type: K, listener: WebsocketEventListener<K>, options?: WebsocketEventListenerOptions): void;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new browser-native websocket and connects it to the given URL with the given protocols
|
|
150
|
+
* and adds all event listeners to the browser-native websocket.
|
|
151
|
+
*
|
|
152
|
+
* @return the created browser-native websocket which is also stored in the '_underlyingWebsocket' property.
|
|
153
|
+
*/
|
|
154
|
+
private tryConnect;
|
|
155
|
+
/**
|
|
156
|
+
* Removes all event listeners from the browser-native websocket and closes it.
|
|
157
|
+
*/
|
|
158
|
+
private clearWebsocket;
|
|
159
|
+
/**
|
|
160
|
+
* Handles the 'open' event of the browser-native websocket.
|
|
161
|
+
* @param event to handle.
|
|
162
|
+
*/
|
|
163
|
+
private handleOpenEvent;
|
|
164
|
+
/**
|
|
165
|
+
* Handles the 'error' event of the browser-native websocket.
|
|
166
|
+
* @param event to handle.
|
|
167
|
+
*/
|
|
168
|
+
private handleErrorEvent;
|
|
169
|
+
/**
|
|
170
|
+
* Handles the 'close' event of the browser-native websocket.
|
|
171
|
+
* @param event to handle.
|
|
172
|
+
*/
|
|
173
|
+
private handleCloseEvent;
|
|
174
|
+
/**
|
|
175
|
+
* Handles the 'message' event of the browser-native websocket.
|
|
176
|
+
* @param event to handle.
|
|
177
|
+
*/
|
|
178
|
+
private handleMessageEvent;
|
|
179
|
+
/**
|
|
180
|
+
* Dispatch an event to all listeners of the given event-type.
|
|
181
|
+
*
|
|
182
|
+
* @param type of the event to dispatch.
|
|
183
|
+
* @param event to dispatch.
|
|
184
|
+
*/
|
|
185
|
+
private dispatchEvent;
|
|
186
|
+
/**
|
|
187
|
+
* Handles the given event by dispatching it to all listeners of the given event-type.
|
|
188
|
+
*
|
|
189
|
+
* @param type of the event to handle.
|
|
190
|
+
* @param event to handle.
|
|
191
|
+
*/
|
|
192
|
+
private handleEvent;
|
|
193
|
+
/**
|
|
194
|
+
* Sends buffered data if there is a buffer defined.
|
|
195
|
+
*/
|
|
196
|
+
private sendBufferedData;
|
|
197
|
+
/**
|
|
198
|
+
* Schedules a connection-retry if there is a backoff defined and the websocket was not closed by the user.
|
|
199
|
+
*/
|
|
200
|
+
private scheduleConnectionRetryIfNeeded;
|
|
201
|
+
/**
|
|
202
|
+
* Cancels the scheduled connection-retry, if there is one.
|
|
203
|
+
*/
|
|
204
|
+
private cancelScheduledConnectionRetry;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources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