polfan-server-js-client 0.2.63 → 0.2.65
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.
|
@@ -35,7 +35,7 @@ export declare class WebSocketChatClient extends AbstractChatClient implements O
|
|
|
35
35
|
private onClose;
|
|
36
36
|
private sendFromQueue;
|
|
37
37
|
private triggerConnectionTimeout;
|
|
38
|
-
private
|
|
39
|
-
private
|
|
38
|
+
private isConnectingWsState;
|
|
39
|
+
private isOpenWsState;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
package/package.json
CHANGED
|
@@ -37,6 +37,10 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
public async connect(): Promise<void> {
|
|
40
|
+
if (this.isOpenWsState() || this.isConnectingWsState()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
const params = new URLSearchParams(this.options.queryParams ?? {});
|
|
41
45
|
params.set('token', this.options.token);
|
|
42
46
|
|
|
@@ -63,7 +67,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
63
67
|
const envelope = this.createEnvelope<CommandsMap[CommandType][0]>(commandType, commandData);
|
|
64
68
|
const promise = this.createPromiseFromCommandEnvelope<CommandType>(envelope);
|
|
65
69
|
|
|
66
|
-
if (this.
|
|
70
|
+
if (this.isConnectingWsState() || !this.authenticated && this.isOpenWsState()) {
|
|
67
71
|
this.sendQueue.push(envelope);
|
|
68
72
|
return promise;
|
|
69
73
|
}
|
|
@@ -73,18 +77,18 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
public get isReady(): boolean {
|
|
76
|
-
return this.
|
|
80
|
+
return this.isOpenWsState() && this.authenticated;
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
private sendEnvelope(envelope: Envelope): void {
|
|
80
|
-
if (this.
|
|
84
|
+
if (this.isReady) {
|
|
81
85
|
this.ws.send(JSON.stringify(envelope));
|
|
82
86
|
return;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
this.handleEnvelopeSendError(
|
|
86
90
|
envelope,
|
|
87
|
-
new Error(`Cannot send
|
|
91
|
+
new Error(`Cannot send - client is not ready (state=${this.ws?.readyState ?? '[no connection]'}; authenticated=${this.authenticated})`)
|
|
88
92
|
);
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -134,11 +138,11 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
134
138
|
this.emit(this.Event.error, new Error('Connection timeout'));
|
|
135
139
|
}
|
|
136
140
|
|
|
137
|
-
private
|
|
138
|
-
return this.ws && this.ws.readyState === this.ws.CONNECTING
|
|
141
|
+
private isConnectingWsState(): boolean {
|
|
142
|
+
return this.ws && this.ws.readyState === this.ws.CONNECTING;
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
private
|
|
142
|
-
return this.ws && this.ws.readyState === this.ws.OPEN
|
|
145
|
+
private isOpenWsState(): boolean {
|
|
146
|
+
return this.ws && this.ws.readyState === this.ws.OPEN;
|
|
143
147
|
}
|
|
144
148
|
}
|