polfan-server-js-client 0.2.64 → 0.2.66
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/.idea/workspace.xml +4 -1
- package/README.md +22 -2
- package/build/index.cjs.js +11 -27
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/WebSocketChatClient.d.ts +2 -2
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +0 -1
- package/package.json +1 -1
- package/src/WebSocketChatClient.ts +9 -9
- package/src/state-tracker/MessagesManager.ts +0 -1
- package/src/state-tracker/TopicHistoryWindow.ts +0 -11
|
@@ -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 {};
|
|
@@ -83,7 +83,6 @@ export declare class TopicHistoryWindow extends TraversableRemoteCollection<Mess
|
|
|
83
83
|
*/
|
|
84
84
|
_updateMessageReference(refTopic: Topic): void;
|
|
85
85
|
private handleNewMessage;
|
|
86
|
-
private handleSession;
|
|
87
86
|
protected fetchItemsAfter(): Promise<Message[] | null>;
|
|
88
87
|
protected fetchItemsBefore(): Promise<Message[] | null>;
|
|
89
88
|
protected fetchLatestItems(): Promise<Message[]>;
|
package/package.json
CHANGED
|
@@ -37,7 +37,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
public async connect(): Promise<void> {
|
|
40
|
-
if (this.
|
|
40
|
+
if (this.isOpenWsState() || this.isConnectingWsState()) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -67,7 +67,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
67
67
|
const envelope = this.createEnvelope<CommandsMap[CommandType][0]>(commandType, commandData);
|
|
68
68
|
const promise = this.createPromiseFromCommandEnvelope<CommandType>(envelope);
|
|
69
69
|
|
|
70
|
-
if (this.
|
|
70
|
+
if (this.isConnectingWsState() || !this.authenticated && this.isOpenWsState()) {
|
|
71
71
|
this.sendQueue.push(envelope);
|
|
72
72
|
return promise;
|
|
73
73
|
}
|
|
@@ -77,18 +77,18 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
public get isReady(): boolean {
|
|
80
|
-
return this.
|
|
80
|
+
return this.isOpenWsState() && this.authenticated;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private sendEnvelope(envelope: Envelope): void {
|
|
84
|
-
if (this.
|
|
84
|
+
if (this.isReady) {
|
|
85
85
|
this.ws.send(JSON.stringify(envelope));
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
this.handleEnvelopeSendError(
|
|
90
90
|
envelope,
|
|
91
|
-
new Error(`Cannot send
|
|
91
|
+
new Error(`Cannot send - client is not ready (state=${this.ws?.readyState ?? '[no connection]'}; authenticated=${this.authenticated})`)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -138,11 +138,11 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
138
138
|
this.emit(this.Event.error, new Error('Connection timeout'));
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
private
|
|
142
|
-
return this.ws && this.ws.readyState === this.ws.CONNECTING
|
|
141
|
+
private isConnectingWsState(): boolean {
|
|
142
|
+
return this.ws && this.ws.readyState === this.ws.CONNECTING;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
private
|
|
146
|
-
return this.ws && this.ws.readyState === this.ws.OPEN
|
|
145
|
+
private isOpenWsState(): boolean {
|
|
146
|
+
return this.ws && this.ws.readyState === this.ws.OPEN;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -222,7 +222,6 @@ export class TopicHistoryWindow extends TraversableRemoteCollection<Message> {
|
|
|
222
222
|
this.internalState.traverseLock = false;
|
|
223
223
|
|
|
224
224
|
if (bindEvents) {
|
|
225
|
-
this.tracker.client.on('Session', ev => this.handleSession(ev));
|
|
226
225
|
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
227
226
|
}
|
|
228
227
|
}
|
|
@@ -291,16 +290,6 @@ export class TopicHistoryWindow extends TraversableRemoteCollection<Message> {
|
|
|
291
290
|
}
|
|
292
291
|
}
|
|
293
292
|
|
|
294
|
-
private handleSession(ev: Session): void {
|
|
295
|
-
const rooms = ev.state.rooms;
|
|
296
|
-
|
|
297
|
-
if (rooms.find(room => room.id === this.roomId)) {
|
|
298
|
-
void this.resetToLatest();
|
|
299
|
-
} else {
|
|
300
|
-
this.deleteAll();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
293
|
protected async fetchItemsAfter(): Promise<Message[] | null> {
|
|
305
294
|
const afterId = this.getAt(this.length - 1)?.id;
|
|
306
295
|
|