teckos-client 0.3.3 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/ITeckosClient.d.ts +18 -0
- package/dist/TeckosClient.d.ts +35 -0
- package/dist/TeckosClientWithJWT.d.ts +12 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +40 -43
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/teckos-client.cjs.development.js +611 -0
- package/dist/teckos-client.cjs.development.js.map +1 -0
- package/dist/teckos-client.cjs.production.min.js +2 -0
- package/dist/teckos-client.cjs.production.min.js.map +1 -0
- package/dist/teckos-client.esm.js +608 -0
- package/dist/teckos-client.esm.js.map +1 -0
- package/dist/types/ConnectionState.d.ts +7 -0
- package/dist/types/Options.d.ts +10 -0
- package/dist/types/Packet.d.ts +6 -0
- package/dist/types/PacketType.d.ts +5 -0
- package/dist/types/SocketEvent.d.ts +10 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/util/Converter.d.ts +4 -0
- package/dist/util/SocketEventEmitter.d.ts +23 -0
- package/es/index.js +34 -39
- package/es/index.mjs +1 -1
- package/lib/index.js +37 -58
- package/package.json +6 -7
- package/src/ITeckosClient.ts +2 -3
- package/src/TeckosClient.ts +29 -29
- package/src/TeckosClientWithJWT.ts +6 -6
- package/src/index.ts +3 -3
- package/types/ITeckosClient.d.ts +2 -3
- package/types/TeckosClient.d.ts +5 -5
- package/types/index.d.ts +3 -3
- package/src/ITeckosClient.js +0 -2
- package/src/ITeckosClient.js.map +0 -1
- package/src/TeckosClient.js +0 -235
- package/src/TeckosClient.js.map +0 -1
- package/src/TeckosClientWithJWT.js +0 -63
- package/src/TeckosClientWithJWT.js.map +0 -1
- package/src/index.js +0 -8
- package/src/index.js.map +0 -1
- package/src/types/ConnectionState.js +0 -9
- package/src/types/ConnectionState.js.map +0 -1
- package/src/types/Options.js +0 -2
- package/src/types/Options.js.map +0 -1
- package/src/types/Packet.js +0 -2
- package/src/types/Packet.js.map +0 -1
- package/src/types/PacketType.js +0 -7
- package/src/types/PacketType.js.map +0 -1
- package/src/types/SocketEvent.js +0 -2
- package/src/types/SocketEvent.js.map +0 -1
- package/src/types/index.js +0 -4
- package/src/types/index.js.map +0 -1
- package/src/util/Converter.js +0 -6
- package/src/util/Converter.js.map +0 -1
- package/src/util/SocketEventEmitter.js +0 -99
- package/src/util/SocketEventEmitter.js.map +0 -1
package/src/TeckosClient.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/* eslint-disable no-console */
|
2
|
-
import
|
2
|
+
import WebSocket from 'isomorphic-ws'
|
3
3
|
import { decodePacket, encodePacket } from './util/Converter'
|
4
4
|
import { ITeckosClient } from './ITeckosClient'
|
5
5
|
import { SocketEventEmitter } from './util/SocketEventEmitter'
|
@@ -20,7 +20,7 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
20
20
|
|
21
21
|
protected readonly options: Options
|
22
22
|
|
23
|
-
|
23
|
+
protected _ws: WebSocket | undefined
|
24
24
|
|
25
25
|
protected currentReconnectDelay: number
|
26
26
|
|
@@ -45,30 +45,26 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
45
45
|
}
|
46
46
|
|
47
47
|
protected attachHandler = (): void => {
|
48
|
-
if (this.
|
49
|
-
this.
|
50
|
-
this.
|
51
|
-
this.
|
52
|
-
this.
|
48
|
+
if (this._ws) {
|
49
|
+
this._ws.onopen = this.handleOpen
|
50
|
+
this._ws.onerror = this.handleError
|
51
|
+
this._ws.onclose = this.handleClose
|
52
|
+
this._ws.onmessage = this.handleMessage
|
53
53
|
}
|
54
54
|
}
|
55
55
|
|
56
|
-
public get webSocket(): IsomorphicWebSocket.WebSocket | undefined {
|
57
|
-
return this.ws
|
58
|
-
}
|
59
|
-
|
60
56
|
public connect = (): void => {
|
61
57
|
if (this.options.debug) console.log(`(teckos:client) Connecting to ${this.url}...`)
|
62
58
|
|
63
59
|
// This will try to connect immediately
|
64
60
|
// eslint-disable-next-line new-cap
|
65
|
-
this.
|
61
|
+
this._ws = new WebSocket(this.url)
|
66
62
|
// Attach handlers
|
67
63
|
this.attachHandler()
|
68
64
|
// Handle timeout
|
69
65
|
this.connectionTimeout = setTimeout(() => {
|
70
|
-
if (this.
|
71
|
-
this.
|
66
|
+
if (this._ws && this._ws.readyState === 0 /* = CONNECTING */) {
|
67
|
+
this._ws.close()
|
72
68
|
}
|
73
69
|
}, this.options.timeout)
|
74
70
|
}
|
@@ -79,25 +75,29 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
79
75
|
}
|
80
76
|
|
81
77
|
protected getConnectionState(): ConnectionState {
|
82
|
-
if (this.
|
83
|
-
switch (this.
|
84
|
-
case
|
85
|
-
return ConnectionState.CONNECTING
|
86
|
-
case 1 /* = OPEN */:
|
78
|
+
if (this._ws) {
|
79
|
+
switch (this._ws.readyState) {
|
80
|
+
case WebSocket.OPEN:
|
87
81
|
return ConnectionState.CONNECTED
|
88
|
-
case
|
82
|
+
case WebSocket.CONNECTING:
|
83
|
+
return ConnectionState.CONNECTING
|
84
|
+
case WebSocket.CLOSING:
|
89
85
|
return ConnectionState.DISCONNECTING
|
90
|
-
default:
|
86
|
+
default:
|
91
87
|
return ConnectionState.DISCONNECTED
|
92
88
|
}
|
93
89
|
}
|
94
90
|
return ConnectionState.DISCONNECTED
|
95
91
|
}
|
96
92
|
|
97
|
-
|
93
|
+
get state(): ConnectionState {
|
98
94
|
return this.getConnectionState()
|
99
95
|
}
|
100
96
|
|
97
|
+
get ws(): WebSocket | undefined {
|
98
|
+
return this._ws
|
99
|
+
}
|
100
|
+
|
101
101
|
get connected(): boolean {
|
102
102
|
return this.getConnectionState() === ConnectionState.CONNECTED
|
103
103
|
}
|
@@ -133,17 +133,17 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
133
133
|
}
|
134
134
|
|
135
135
|
public sendPackage = (packet: Packet): boolean => {
|
136
|
-
if (this.
|
136
|
+
if (this._ws !== undefined && this._ws.readyState === 1 /* = OPEN */) {
|
137
137
|
const buffer = encodePacket(packet)
|
138
138
|
if (this.options.debug)
|
139
139
|
console.log(`(teckos:client) [${this.url}] Send packet: ${JSON.stringify(packet)}`)
|
140
|
-
this.
|
140
|
+
this._ws.send(buffer)
|
141
141
|
return true
|
142
142
|
}
|
143
143
|
return false
|
144
144
|
}
|
145
145
|
|
146
|
-
protected handleMessage = (msg:
|
146
|
+
protected handleMessage = (msg: WebSocket.MessageEvent): void => {
|
147
147
|
const packet =
|
148
148
|
typeof msg.data === 'string'
|
149
149
|
? (JSON.parse(msg.data) as Packet)
|
@@ -193,7 +193,7 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
193
193
|
this.listeners('connect').forEach((listener) => listener())
|
194
194
|
}
|
195
195
|
|
196
|
-
protected handleError = (error:
|
196
|
+
protected handleError = (error: WebSocket.ErrorEvent): void => {
|
197
197
|
if (this.handlers && this.handlers.error) {
|
198
198
|
if (this.options.debug)
|
199
199
|
console.log(
|
@@ -269,9 +269,9 @@ class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosCli
|
|
269
269
|
public close = (): void => {
|
270
270
|
if (this.options.debug)
|
271
271
|
console.log(`(teckos:client) [${this.url}] Closing connection (client-side)`)
|
272
|
-
if (this.
|
273
|
-
this.
|
274
|
-
this.
|
272
|
+
if (this._ws !== undefined) {
|
273
|
+
this._ws.onclose = () => {}
|
274
|
+
this._ws.close()
|
275
275
|
this.listeners('disconnect').forEach((listener) => listener())
|
276
276
|
}
|
277
277
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* eslint-disable no-console */
|
2
|
-
import
|
2
|
+
import WebSocket from 'isomorphic-ws'
|
3
3
|
import { TeckosClient } from './TeckosClient'
|
4
4
|
import { OptionalOptions, ConnectionState } from './types'
|
5
5
|
|
@@ -22,16 +22,16 @@ class TeckosClientWithJWT extends TeckosClient {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
protected getConnectionState(): ConnectionState {
|
25
|
-
if (this.
|
26
|
-
switch (this.
|
27
|
-
case
|
25
|
+
if (this._ws) {
|
26
|
+
switch (this._ws.readyState) {
|
27
|
+
case WebSocket.OPEN:
|
28
28
|
if (this.receivedReady) {
|
29
29
|
return ConnectionState.CONNECTED
|
30
30
|
}
|
31
31
|
return ConnectionState.CONNECTING
|
32
|
-
case
|
32
|
+
case WebSocket.CONNECTING:
|
33
33
|
return ConnectionState.CONNECTING
|
34
|
-
case
|
34
|
+
case WebSocket.CLOSING:
|
35
35
|
return ConnectionState.DISCONNECTING
|
36
36
|
default:
|
37
37
|
return ConnectionState.DISCONNECTED
|
package/src/index.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { TeckosClientWithJWT } from './TeckosClientWithJWT'
|
2
2
|
import { TeckosClient } from './TeckosClient'
|
3
3
|
import { ITeckosClient } from './ITeckosClient'
|
4
|
-
import { ConnectionState, OptionalOptions, Options, Packet, PacketType, SocketEvent } from './types'
|
5
4
|
|
6
5
|
/**
|
7
6
|
* Expose all types
|
8
7
|
*/
|
9
|
-
export
|
8
|
+
export * from './types'
|
9
|
+
export type { ITeckosClient }
|
10
10
|
|
11
|
-
export {
|
11
|
+
export { TeckosClient, TeckosClientWithJWT }
|
package/types/ITeckosClient.d.ts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
/// <reference types="ws" />
|
2
|
-
import
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
3
3
|
import { ConnectionState, Packet, SocketEvent } from './types';
|
4
4
|
import { SocketEventEmitter } from './util/SocketEventEmitter';
|
5
5
|
interface ITeckosClient extends SocketEventEmitter<SocketEvent> {
|
6
|
-
ws:
|
7
|
-
readonly webSocket: IsomorphicWebSocket.WebSocket | undefined;
|
6
|
+
readonly ws: WebSocket | undefined;
|
8
7
|
readonly state: ConnectionState;
|
9
8
|
readonly connected: boolean;
|
10
9
|
readonly disconnected: boolean;
|
package/types/TeckosClient.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
/// <reference types="ws" />
|
2
|
-
import
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
3
3
|
import { ITeckosClient } from './ITeckosClient';
|
4
4
|
import { SocketEventEmitter } from './util/SocketEventEmitter';
|
5
5
|
import { OptionalOptions, Options, SocketEvent, ConnectionState, Packet } from './types';
|
6
6
|
declare class TeckosClient extends SocketEventEmitter<SocketEvent> implements ITeckosClient {
|
7
7
|
protected readonly url: string;
|
8
8
|
protected readonly options: Options;
|
9
|
-
|
9
|
+
protected _ws: WebSocket | undefined;
|
10
10
|
protected currentReconnectDelay: number;
|
11
11
|
protected currentReconnectionAttempts: number;
|
12
12
|
protected acks: Map<number, (...args: any[]) => void>;
|
@@ -15,19 +15,19 @@ declare class TeckosClient extends SocketEventEmitter<SocketEvent> implements IT
|
|
15
15
|
protected reconnectionTimeout: any | undefined;
|
16
16
|
constructor(url: string, options?: OptionalOptions);
|
17
17
|
protected attachHandler: () => void;
|
18
|
-
get webSocket(): IsomorphicWebSocket.WebSocket | undefined;
|
19
18
|
connect: () => void;
|
20
19
|
protected reconnect: () => void;
|
21
20
|
protected getConnectionState(): ConnectionState;
|
22
21
|
get state(): ConnectionState;
|
22
|
+
get ws(): WebSocket | undefined;
|
23
23
|
get connected(): boolean;
|
24
24
|
get disconnected(): boolean;
|
25
25
|
emit: (event: SocketEvent, ...args: any[]) => boolean;
|
26
26
|
send: (...args: any[]) => boolean;
|
27
27
|
sendPackage: (packet: Packet) => boolean;
|
28
|
-
protected handleMessage: (msg:
|
28
|
+
protected handleMessage: (msg: WebSocket.MessageEvent) => void;
|
29
29
|
protected handleOpen: () => void;
|
30
|
-
protected handleError: (error:
|
30
|
+
protected handleError: (error: WebSocket.ErrorEvent) => void;
|
31
31
|
protected handleClose: () => void;
|
32
32
|
close: () => void;
|
33
33
|
disconnect: () => void;
|
package/types/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { TeckosClientWithJWT } from './TeckosClientWithJWT';
|
2
2
|
import { TeckosClient } from './TeckosClient';
|
3
3
|
import { ITeckosClient } from './ITeckosClient';
|
4
|
-
import { ConnectionState, OptionalOptions, Options, Packet, PacketType, SocketEvent } from './types';
|
5
4
|
/**
|
6
5
|
* Expose all types
|
7
6
|
*/
|
8
|
-
export
|
9
|
-
export {
|
7
|
+
export * from './types';
|
8
|
+
export type { ITeckosClient };
|
9
|
+
export { TeckosClient, TeckosClientWithJWT };
|
package/src/ITeckosClient.js
DELETED
package/src/ITeckosClient.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ITeckosClient.js","sourceRoot":"","sources":["ITeckosClient.ts"],"names":[],"mappings":""}
|
package/src/TeckosClient.js
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console */
|
2
|
-
import * as IsomorphicWebSocket from 'isomorphic-ws';
|
3
|
-
import { decodePacket, encodePacket } from './util/Converter';
|
4
|
-
import { SocketEventEmitter } from './util/SocketEventEmitter';
|
5
|
-
import { ConnectionState, PacketType } from './types';
|
6
|
-
const DEFAULT_OPTIONS = {
|
7
|
-
reconnection: true,
|
8
|
-
reconnectionDelay: 1000,
|
9
|
-
reconnectionDelayMax: 5000,
|
10
|
-
reconnectionAttempts: Infinity,
|
11
|
-
randomizationFactor: 0.5,
|
12
|
-
timeout: 5000,
|
13
|
-
debug: false,
|
14
|
-
};
|
15
|
-
class TeckosClient extends SocketEventEmitter {
|
16
|
-
url;
|
17
|
-
options;
|
18
|
-
ws;
|
19
|
-
currentReconnectDelay;
|
20
|
-
currentReconnectionAttempts = 0;
|
21
|
-
acks = new Map();
|
22
|
-
fnId = 0;
|
23
|
-
connectionTimeout;
|
24
|
-
reconnectionTimeout;
|
25
|
-
constructor(url, options) {
|
26
|
-
super();
|
27
|
-
this.options = {
|
28
|
-
...DEFAULT_OPTIONS,
|
29
|
-
...options,
|
30
|
-
};
|
31
|
-
this.currentReconnectDelay = this.options.reconnectionDelay;
|
32
|
-
this.url = url;
|
33
|
-
}
|
34
|
-
attachHandler = () => {
|
35
|
-
if (this.ws) {
|
36
|
-
this.ws.onopen = this.handleOpen;
|
37
|
-
this.ws.onerror = this.handleError;
|
38
|
-
this.ws.onclose = this.handleClose;
|
39
|
-
this.ws.onmessage = this.handleMessage;
|
40
|
-
}
|
41
|
-
};
|
42
|
-
get webSocket() {
|
43
|
-
return this.ws;
|
44
|
-
}
|
45
|
-
connect = () => {
|
46
|
-
if (this.options.debug)
|
47
|
-
console.log(`(teckos:client) Connecting to ${this.url}...`);
|
48
|
-
// This will try to connect immediately
|
49
|
-
// eslint-disable-next-line new-cap
|
50
|
-
this.ws = new IsomorphicWebSocket.WebSocket(this.url);
|
51
|
-
// Attach handlers
|
52
|
-
this.attachHandler();
|
53
|
-
// Handle timeout
|
54
|
-
this.connectionTimeout = setTimeout(() => {
|
55
|
-
if (this.ws && this.ws.readyState === 0 /* = CONNECTING */) {
|
56
|
-
this.ws.close();
|
57
|
-
}
|
58
|
-
}, this.options.timeout);
|
59
|
-
};
|
60
|
-
reconnect = () => {
|
61
|
-
this.listeners('reconnect_attempt').forEach((listener) => listener());
|
62
|
-
this.connect();
|
63
|
-
};
|
64
|
-
getConnectionState() {
|
65
|
-
if (this.ws) {
|
66
|
-
switch (this.ws.readyState) {
|
67
|
-
case 0 /* = CONNECTING */:
|
68
|
-
return ConnectionState.CONNECTING;
|
69
|
-
case 1 /* = OPEN */:
|
70
|
-
return ConnectionState.CONNECTED;
|
71
|
-
case 2 /* = CLOSING */:
|
72
|
-
return ConnectionState.DISCONNECTING;
|
73
|
-
default: /* 3 = CLOSED */
|
74
|
-
return ConnectionState.DISCONNECTED;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
return ConnectionState.DISCONNECTED;
|
78
|
-
}
|
79
|
-
get state() {
|
80
|
-
return this.getConnectionState();
|
81
|
-
}
|
82
|
-
get connected() {
|
83
|
-
return this.getConnectionState() === ConnectionState.CONNECTED;
|
84
|
-
}
|
85
|
-
get disconnected() {
|
86
|
-
return this.getConnectionState() === ConnectionState.DISCONNECTED;
|
87
|
-
}
|
88
|
-
emit = (event, ...args) => {
|
89
|
-
args.unshift(event);
|
90
|
-
const packet = {
|
91
|
-
type: PacketType.EVENT,
|
92
|
-
data: args,
|
93
|
-
};
|
94
|
-
if (typeof args[args.length - 1] === 'function') {
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
96
|
-
this.acks.set(this.fnId, args.pop());
|
97
|
-
packet.id = this.fnId;
|
98
|
-
this.fnId += 1;
|
99
|
-
}
|
100
|
-
return this.sendPackage(packet);
|
101
|
-
};
|
102
|
-
send = (...args) => {
|
103
|
-
args.unshift('message');
|
104
|
-
return this.sendPackage({
|
105
|
-
type: PacketType.EVENT,
|
106
|
-
data: args,
|
107
|
-
});
|
108
|
-
};
|
109
|
-
sendPackage = (packet) => {
|
110
|
-
if (this.ws !== undefined && this.ws.readyState === 1 /* = OPEN */) {
|
111
|
-
const buffer = encodePacket(packet);
|
112
|
-
if (this.options.debug)
|
113
|
-
console.log(`(teckos:client) [${this.url}] Send packet: ${JSON.stringify(packet)}`);
|
114
|
-
this.ws.send(buffer);
|
115
|
-
return true;
|
116
|
-
}
|
117
|
-
return false;
|
118
|
-
};
|
119
|
-
handleMessage = (msg) => {
|
120
|
-
const packet = typeof msg.data === 'string'
|
121
|
-
? JSON.parse(msg.data)
|
122
|
-
: decodePacket(msg.data);
|
123
|
-
if (this.options.debug)
|
124
|
-
console.log(`(teckos:client) [${this.url}] Got packet: ${JSON.stringify(packet)}`);
|
125
|
-
if (packet.type === PacketType.EVENT) {
|
126
|
-
const event = packet.data[0];
|
127
|
-
const args = packet.data.slice(1);
|
128
|
-
if (event) {
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
130
|
-
this.listeners(event).forEach((listener) => listener(...args));
|
131
|
-
}
|
132
|
-
else {
|
133
|
-
throw new Error(`(teckos-client) [${this.url}] Got invalid event message: ${JSON.stringify(msg.data)}`);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
else if (packet.type === PacketType.ACK && packet.id !== undefined) {
|
137
|
-
// Call assigned function
|
138
|
-
const ack = this.acks.get(packet.id);
|
139
|
-
if (typeof ack === 'function') {
|
140
|
-
ack.apply(this, packet.data);
|
141
|
-
this.acks.delete(packet.id);
|
142
|
-
}
|
143
|
-
}
|
144
|
-
else {
|
145
|
-
throw new Error(`(teckos-client) [${this.url}] Got invalid message type: ${packet.type}`);
|
146
|
-
}
|
147
|
-
};
|
148
|
-
handleOpen = () => {
|
149
|
-
if (this.currentReconnectionAttempts > 0) {
|
150
|
-
// Reset reconnection settings to default
|
151
|
-
this.currentReconnectDelay = this.options.reconnectionDelay;
|
152
|
-
this.currentReconnectionAttempts = 0;
|
153
|
-
// Inform listeners
|
154
|
-
if (this.options.debug)
|
155
|
-
console.log(`(teckos:client) [${this.url}] Reconnected!`);
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
157
|
-
this.listeners('reconnect').forEach((listener) => listener());
|
158
|
-
}
|
159
|
-
// Inform listeners
|
160
|
-
if (this.options.debug)
|
161
|
-
console.log(`(teckos:client) [${this.url}] Connected!`);
|
162
|
-
this.listeners('connect').forEach((listener) => listener());
|
163
|
-
};
|
164
|
-
handleError = (error) => {
|
165
|
-
if (this.handlers && this.handlers.error) {
|
166
|
-
if (this.options.debug)
|
167
|
-
console.log(`(teckos:client) [${this.url}] Got error from server: ${JSON.stringify(error)}`);
|
168
|
-
this.handlers.error.forEach((listener) => listener(error));
|
169
|
-
}
|
170
|
-
};
|
171
|
-
handleClose = () => {
|
172
|
-
// Stop connection timeout
|
173
|
-
if (this.connectionTimeout) {
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
175
|
-
clearTimeout(this.connectionTimeout);
|
176
|
-
}
|
177
|
-
// Stop reconnection timeout
|
178
|
-
if (this.reconnectionTimeout) {
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
180
|
-
clearTimeout(this.reconnectionTimeout);
|
181
|
-
}
|
182
|
-
// Inform listeners
|
183
|
-
if (this.currentReconnectionAttempts > 0) {
|
184
|
-
if (this.options.debug)
|
185
|
-
console.log(`(teckos:client) [${this.url}] Reconnect #${this.currentReconnectionAttempts} failed!`);
|
186
|
-
this.listeners('reconnect_error').forEach((listener) => {
|
187
|
-
if (listener)
|
188
|
-
listener();
|
189
|
-
});
|
190
|
-
}
|
191
|
-
else {
|
192
|
-
if (this.options.debug)
|
193
|
-
console.log(`(teckos:client) [${this.url}] Disconnected!`);
|
194
|
-
this.listeners('disconnect').forEach((listener) => {
|
195
|
-
if (listener)
|
196
|
-
listener();
|
197
|
-
});
|
198
|
-
}
|
199
|
-
if (this.options.reconnection) {
|
200
|
-
// Apply reconnection logic
|
201
|
-
this.currentReconnectionAttempts += 1;
|
202
|
-
if (this.options.reconnectionAttempts === Infinity ||
|
203
|
-
this.currentReconnectionAttempts <= this.options.reconnectionAttempts) {
|
204
|
-
const timeout = Math.min(this.options.reconnectionDelayMax, this.currentReconnectDelay);
|
205
|
-
// Increase reconnection delay
|
206
|
-
this.currentReconnectDelay = Math.round(this.currentReconnectDelay +
|
207
|
-
this.currentReconnectDelay * this.options.randomizationFactor);
|
208
|
-
if (this.options.debug)
|
209
|
-
console.log(`(teckos:client) [${this.url}] Try reconnecting (${this.currentReconnectionAttempts}/${this.options.reconnectionAttempts}) in ${timeout}ms to ${this.url}...`);
|
210
|
-
this.reconnectionTimeout = setTimeout(() => {
|
211
|
-
this.reconnect();
|
212
|
-
}, timeout);
|
213
|
-
}
|
214
|
-
else {
|
215
|
-
if (this.options.debug)
|
216
|
-
console.log(`(teckos:client) [${this.url}] Reconnection maximum of ${this.options.reconnectionAttempts} reached`);
|
217
|
-
this.listeners('reconnect_failed').forEach((listener) => listener());
|
218
|
-
}
|
219
|
-
}
|
220
|
-
};
|
221
|
-
close = () => {
|
222
|
-
if (this.options.debug)
|
223
|
-
console.log(`(teckos:client) [${this.url}] Closing connection (client-side)`);
|
224
|
-
if (this.ws !== undefined) {
|
225
|
-
this.ws.onclose = () => { };
|
226
|
-
this.ws.close();
|
227
|
-
this.listeners('disconnect').forEach((listener) => listener());
|
228
|
-
}
|
229
|
-
};
|
230
|
-
disconnect = () => {
|
231
|
-
this.close();
|
232
|
-
};
|
233
|
-
}
|
234
|
-
export { TeckosClient };
|
235
|
-
//# sourceMappingURL=TeckosClient.js.map
|
package/src/TeckosClient.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TeckosClient.js","sourceRoot":"","sources":["TeckosClient.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,KAAK,mBAAmB,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAyC,eAAe,EAAU,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpG,MAAM,eAAe,GAAY;IAC7B,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,IAAI;IACvB,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,QAAQ;IAC9B,mBAAmB,EAAE,GAAG;IACxB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,KAAK;CACf,CAAA;AAED,MAAM,YAAa,SAAQ,kBAA+B;IACnC,GAAG,CAAQ;IAEX,OAAO,CAAS;IAEnC,EAAE,CAA2C;IAEnC,qBAAqB,CAAQ;IAE7B,2BAA2B,GAAG,CAAC,CAAA;IAE/B,IAAI,GAA0C,IAAI,GAAG,EAAE,CAAA;IAEvD,IAAI,GAAG,CAAC,CAAA;IAER,iBAAiB,CAAiB;IAElC,mBAAmB,CAAiB;IAE9C,YAAY,GAAW,EAAE,OAAyB;QAC9C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG;YACX,GAAG,eAAe;YAClB,GAAG,OAAO;SAC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,GAAG,GAAS,EAAE;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC,CAAA;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
@@ -1,63 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console */
|
2
|
-
import * as IsomorphicWebSocket from 'isomorphic-ws';
|
3
|
-
import { TeckosClient } from './TeckosClient';
|
4
|
-
import { ConnectionState } from './types';
|
5
|
-
class TeckosClientWithJWT extends TeckosClient {
|
6
|
-
token;
|
7
|
-
initialData;
|
8
|
-
receivedReady = false;
|
9
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
10
|
-
constructor(url, options, token, initialData) {
|
11
|
-
super(url, options);
|
12
|
-
this.token = token;
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
14
|
-
this.initialData = initialData;
|
15
|
-
this.on('disconnect', () => {
|
16
|
-
this.receivedReady = false;
|
17
|
-
});
|
18
|
-
}
|
19
|
-
getConnectionState() {
|
20
|
-
if (this.ws) {
|
21
|
-
switch (this.ws.readyState) {
|
22
|
-
case IsomorphicWebSocket.WebSocket.OPEN:
|
23
|
-
if (this.receivedReady) {
|
24
|
-
return ConnectionState.CONNECTED;
|
25
|
-
}
|
26
|
-
return ConnectionState.CONNECTING;
|
27
|
-
case IsomorphicWebSocket.WebSocket.CONNECTING:
|
28
|
-
return ConnectionState.CONNECTING;
|
29
|
-
case IsomorphicWebSocket.WebSocket.CLOSING:
|
30
|
-
return ConnectionState.DISCONNECTING;
|
31
|
-
default:
|
32
|
-
return ConnectionState.DISCONNECTED;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
return ConnectionState.DISCONNECTED;
|
36
|
-
}
|
37
|
-
handleReadyEvent = () => {
|
38
|
-
if (this.options.debug)
|
39
|
-
console.log(`(teckos:client) [${this.url}] Connected!`);
|
40
|
-
this.receivedReady = true;
|
41
|
-
if (this.currentReconnectionAttempts > 0) {
|
42
|
-
if (this.options.debug)
|
43
|
-
console.log(`(teckos:client) [${this.url}] Reconnected!`);
|
44
|
-
this.listeners('reconnect').forEach((listener) => listener());
|
45
|
-
// Reset reconnection settings to default
|
46
|
-
this.currentReconnectDelay = this.options.reconnectionDelay;
|
47
|
-
this.currentReconnectionAttempts = 0;
|
48
|
-
}
|
49
|
-
this.listeners('connect').forEach((listener) => listener());
|
50
|
-
};
|
51
|
-
handleOpen = () => {
|
52
|
-
this.receivedReady = false;
|
53
|
-
this.once('ready', this.handleReadyEvent);
|
54
|
-
if (this.options.debug)
|
55
|
-
console.log(`(teckos:client) Connection opened, sending token now`);
|
56
|
-
this.emit('token', {
|
57
|
-
token: this.token,
|
58
|
-
...this.initialData,
|
59
|
-
});
|
60
|
-
};
|
61
|
-
}
|
62
|
-
export { TeckosClientWithJWT };
|
63
|
-
//# sourceMappingURL=TeckosClientWithJWT.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TeckosClientWithJWT.js","sourceRoot":"","sources":["TeckosClientWithJWT.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,KAAK,mBAAmB,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAmB,eAAe,EAAE,MAAM,SAAS,CAAA;AAE1D,MAAM,mBAAoB,SAAQ,YAAY;IACvB,KAAK,CAAQ;IAEb,WAAW,CAAK;IAEzB,aAAa,GAAG,KAAK,CAAA;IAE/B,6EAA6E;IAC7E,YAAY,GAAW,EAAE,OAAwB,EAAE,KAAa,EAAE,WAAiB;QAC/E,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,mEAAmE;QACnE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;YACvB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAA;Q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AO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAA;IAES,UAAU,GAAG,GAAS,EAAE;QAC9B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAA;QAC3F,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,IAAI,CAAC,WAAW;SACtB,CAAC,CAAA;IACN,CAAC,CAAA;CACJ;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
package/src/index.js
DELETED
package/src/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C;;GAEG;AACH,cAAc,SAAS,CAAA;AAGvB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAA"}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
var ConnectionState;
|
2
|
-
(function (ConnectionState) {
|
3
|
-
ConnectionState["DISCONNECTED"] = "disconnected";
|
4
|
-
ConnectionState["CONNECTING"] = "connecting";
|
5
|
-
ConnectionState["CONNECTED"] = "connected";
|
6
|
-
ConnectionState["DISCONNECTING"] = "disconnecting";
|
7
|
-
})(ConnectionState || (ConnectionState = {}));
|
8
|
-
export { ConnectionState };
|
9
|
-
//# sourceMappingURL=ConnectionState.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ConnectionState.js","sourceRoot":"","sources":["ConnectionState.ts"],"names":[],"mappings":"AAAA,IAAK,eAKJ;AALD,WAAK,eAAe;IAChB,gDAA6B,CAAA;IAC7B,4CAAyB,CAAA;IACzB,0CAAuB,CAAA;IACvB,kDAA+B,CAAA;AACnC,CAAC,EALI,eAAe,KAAf,eAAe,QAKnB;AACD,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/src/types/Options.js
DELETED
package/src/types/Options.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Options.js","sourceRoot":"","sources":["Options.ts"],"names":[],"mappings":""}
|
package/src/types/Packet.js
DELETED
package/src/types/Packet.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Packet.js","sourceRoot":"","sources":["Packet.ts"],"names":[],"mappings":""}
|
package/src/types/PacketType.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PacketType.js","sourceRoot":"","sources":["PacketType.ts"],"names":[],"mappings":"AAAA,IAAK,UAGJ;AAHD,WAAK,UAAU;IACX,6CAAK,CAAA;IACL,yCAAG,CAAA;AACP,CAAC,EAHI,UAAU,KAAV,UAAU,QAGd;AACD,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
package/src/types/SocketEvent.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"SocketEvent.js","sourceRoot":"","sources":["SocketEvent.ts"],"names":[],"mappings":""}
|
package/src/types/index.js
DELETED
package/src/types/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,CAAA"}
|