polfan-server-js-client 0.2.6 → 0.2.7
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 +88 -83
- package/README.md +22 -2
- package/build/index.cjs.js +85 -28
- 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/AbstractChatClient.d.ts +3 -1
- package/build/types/WebSocketChatClient.d.ts +23 -2
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +0 -1
- package/build/types/types/src/index.d.ts +3 -1
- package/build/types/types/src/schemes/RoomMember.d.ts +3 -0
- package/build/types/types/src/schemes/User.d.ts +1 -1
- package/build/types/types/src/schemes/commands/Ping.d.ts +2 -0
- package/build/types/types/src/schemes/events/Pong.d.ts +2 -0
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +3 -1
- package/src/WebSocketChatClient.ts +80 -10
- package/src/state-tracker/MessagesManager.ts +0 -1
- package/src/state-tracker/RoomsManager.ts +8 -1
- package/src/state-tracker/TopicHistoryWindow.ts +0 -11
- package/src/types/src/index.ts +4 -0
- package/src/types/src/schemes/RoomMember.ts +3 -0
- package/src/types/src/schemes/User.ts +1 -1
- package/src/types/src/schemes/commands/Ping.ts +3 -0
- package/src/types/src/schemes/events/Pong.ts +3 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bye, GetSession, JoinSpace, Session, SpaceJoined, Error as ErrorType, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMemberUpdated, SpaceDeleted, SpaceMembers, SpaceRooms, NewRole, RoomDeleted, RoomJoined, RoomLeft, RoomMemberLeft, RoomMemberJoined, RoomMembers, NewRoom, NewTopic, TopicDeleted, NewMessage, GetPermissionOverwrites, GetComputedPermissions, LeaveSpace, CreateSpace, DeleteSpace, GetSpaceMembers, GetSpaceRooms, CreateRole, DeleteRole, AssignRole, DeassignRole, SetPermissionOverwrites, JoinRoom, LeaveRoom, CreateRoom, DeleteRoom, GetRoomMembers, CreateTopic, DeleteTopic, CreateMessage, Envelope, PermissionOverwrites, PermissionOverwritesUpdated, RoomMemberUpdated, UpdateRole, RoleUpdated, Ack, UserUpdated, UpdateRoom, RoomUpdated, UpdateSpace, SpaceUpdated, PermissionOverwriteTargets, GetPermissionOverwriteTargets, Owners, Ok, GetOwners, CreateOwner, RoleDeleted, FollowedTopicUpdated, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowTopic, UnfollowTopic, GetFollowedTopics, Messages, GetMessages, Topics, GetTopics, TopicUpdated, UpdateTopic, GetDiscoverableSpaces, DiscoverableSpaces, CreateEmoticon, DeleteEmoticon, GetEmoticons, Emoticons, EmoticonDeleted, NewEmoticon, Bans, GetBans, Ban, Unban, Kick, ClientData, GetClientData, SetClientData, GetRoomSummary, GetSpaceSummary, RoomSummaryEvent, SpaceSummaryEvent, UpdateSpaceMember, Relationships, RelationshipDeleted, NewRelationship, DeleteRelationship, CreateRelationship, RoomSummaryUpdated } from "./types/src/index";
|
|
1
|
+
import { Bye, GetSession, JoinSpace, Session, SpaceJoined, Error as ErrorType, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMemberUpdated, SpaceDeleted, SpaceMembers, SpaceRooms, NewRole, RoomDeleted, RoomJoined, RoomLeft, RoomMemberLeft, RoomMemberJoined, RoomMembers, NewRoom, NewTopic, TopicDeleted, NewMessage, GetPermissionOverwrites, GetComputedPermissions, LeaveSpace, CreateSpace, DeleteSpace, GetSpaceMembers, GetSpaceRooms, CreateRole, DeleteRole, AssignRole, DeassignRole, SetPermissionOverwrites, JoinRoom, LeaveRoom, CreateRoom, DeleteRoom, GetRoomMembers, CreateTopic, DeleteTopic, CreateMessage, Envelope, PermissionOverwrites, PermissionOverwritesUpdated, RoomMemberUpdated, UpdateRole, RoleUpdated, Ack, UserUpdated, UpdateRoom, RoomUpdated, UpdateSpace, SpaceUpdated, PermissionOverwriteTargets, GetPermissionOverwriteTargets, Owners, Ok, GetOwners, CreateOwner, RoleDeleted, FollowedTopicUpdated, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowTopic, UnfollowTopic, GetFollowedTopics, Messages, GetMessages, Topics, GetTopics, TopicUpdated, UpdateTopic, GetDiscoverableSpaces, DiscoverableSpaces, CreateEmoticon, DeleteEmoticon, GetEmoticons, Emoticons, EmoticonDeleted, NewEmoticon, Bans, GetBans, Ban, Unban, Kick, ClientData, GetClientData, SetClientData, GetRoomSummary, GetSpaceSummary, RoomSummaryEvent, SpaceSummaryEvent, UpdateSpaceMember, Relationships, RelationshipDeleted, NewRelationship, DeleteRelationship, CreateRelationship, RoomSummaryUpdated, Pong, Ping } from "./types/src/index";
|
|
2
2
|
import { EventTarget } from "./EventTarget";
|
|
3
3
|
import { GetRelationships } from "./types/src/schemes/commands/GetRelationships";
|
|
4
4
|
import { UpdateRoomMember } from "./types/src/schemes/commands/UpdateRoomMember";
|
|
@@ -39,6 +39,7 @@ export type EventsMap = {
|
|
|
39
39
|
NewRelationship: NewRelationship;
|
|
40
40
|
RelationshipDeleted: RelationshipDeleted;
|
|
41
41
|
Relationships: Relationships;
|
|
42
|
+
Pong: Pong;
|
|
42
43
|
DiscoverableSpaces: DiscoverableSpaces;
|
|
43
44
|
SpaceJoined: SpaceJoined;
|
|
44
45
|
SpaceLeft: SpaceLeft;
|
|
@@ -100,6 +101,7 @@ export type CommandsMap = {
|
|
|
100
101
|
DeleteRelationship: [DeleteRelationship, EventsMap['RelationshipDeleted']];
|
|
101
102
|
CreateRelationship: [CreateRelationship, EventsMap['NewRelationship']];
|
|
102
103
|
GetRelationships: [GetRelationships, EventsMap['Relationships']];
|
|
104
|
+
Ping: [Ping, EventsMap['Pong']];
|
|
103
105
|
GetDiscoverableSpaces: [GetDiscoverableSpaces, EventsMap['DiscoverableSpaces']];
|
|
104
106
|
JoinSpace: [JoinSpace, EventsMap['SpaceJoined']];
|
|
105
107
|
LeaveSpace: [LeaveSpace, EventsMap['SpaceLeft']];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ObservableInterface } from "./EventTarget";
|
|
2
3
|
import { AbstractChatClient, CommandResult, CommandsMap } from "./AbstractChatClient";
|
|
3
4
|
import { ChatStateTracker } from "./state-tracker/ChatStateTracker";
|
|
@@ -9,6 +10,20 @@ export interface WebSocketClientOptions {
|
|
|
9
10
|
awaitQueueSendDelayMs?: number;
|
|
10
11
|
stateTracking?: boolean;
|
|
11
12
|
queryParams?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Ping/pong configuration, enabled by default.
|
|
15
|
+
*/
|
|
16
|
+
ping?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Time without activity after which a ping will be sent. Default is 10 seconds.
|
|
20
|
+
*/
|
|
21
|
+
noActivityTimeoutMs?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Time to wait for a pong response before considering the connection dead. Default is 2 seconds.
|
|
24
|
+
*/
|
|
25
|
+
pongBackTimeoutMs?: number;
|
|
26
|
+
};
|
|
12
27
|
}
|
|
13
28
|
declare enum WebSocketChatClientEvent {
|
|
14
29
|
connect = "connect",
|
|
@@ -25,16 +40,22 @@ export declare class WebSocketChatClient extends AbstractChatClient implements O
|
|
|
25
40
|
protected connectingTimeoutId: any;
|
|
26
41
|
protected authenticated: boolean;
|
|
27
42
|
protected authenticatedResolvers: [() => void, (error: Error) => void];
|
|
43
|
+
protected pingIntervalId?: NodeJS.Timeout;
|
|
44
|
+
protected lastReceivedMessageAt?: number;
|
|
45
|
+
protected pingInFlight: boolean;
|
|
28
46
|
constructor(options: WebSocketClientOptions);
|
|
29
47
|
connect(): Promise<void>;
|
|
30
48
|
disconnect(): void;
|
|
31
49
|
send<CommandType extends keyof CommandsMap>(commandType: CommandType, commandData: CommandsMap[CommandType][0]): Promise<CommandResult<CommandsMap[CommandType][1]>>;
|
|
50
|
+
get isReady(): boolean;
|
|
32
51
|
private sendEnvelope;
|
|
33
52
|
private onMessage;
|
|
34
53
|
private onClose;
|
|
35
54
|
private sendFromQueue;
|
|
36
55
|
private triggerConnectionTimeout;
|
|
37
|
-
private
|
|
38
|
-
private
|
|
56
|
+
private isConnectingWsState;
|
|
57
|
+
private isOpenWsState;
|
|
58
|
+
private startConnectionMonitor;
|
|
59
|
+
private stopConnectionMonitor;
|
|
39
60
|
}
|
|
40
61
|
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[]>;
|
|
@@ -126,4 +126,6 @@ import { Relationships } from "./schemes/events/Relationships";
|
|
|
126
126
|
import { CreateRelationship } from "./schemes/commands/CreateRelationship";
|
|
127
127
|
import { RoomSummaryUpdated } from "./schemes/events/RoomSummaryUpdated";
|
|
128
128
|
import { UpdateRoomMember } from "./schemes/commands/UpdateRoomMember";
|
|
129
|
-
|
|
129
|
+
import { Ping } from "./schemes/commands/Ping";
|
|
130
|
+
import { Pong } from "./schemes/events/Pong";
|
|
131
|
+
export { Envelope, Message, MessageType, MessageAuthor, Role, Room, RoomFlag, RoomType, RoomStream, RoomStreamType, RoomHistory, RoomHistoryMode, RoomMember, RoomSummary, RoomSummaryExtras, Space, SpaceFlag, SpaceMember, Topic, FollowedTopic, User, UserState, PermissionOverwritesValue, ChatLocation, SpaceSummary, SpaceDiscoverable, Emoticon, PermissionOverwritesTarget, BanObject, LeaveReason, UserRelationship, UserRelationshipType, CreateTopicInitialMessage, Bye, Error, Messages, NewMessage, NewRole, NewRoom, NewTopic, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowedTopicUpdated, ComputedPermissions, PermissionOverwrites, PermissionOverwritesUpdated, RoleDeleted, RoleUpdated, RoomDeleted, RoomUpdated, RoomJoined, RoomLeft, RoomMemberJoined, RoomMemberLeft, RoomMembers, RoomMemberUpdated, UserUpdated, Session, SpaceDeleted, SpaceUpdated, SpaceJoined, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMembers, SpaceMemberUpdated, SpaceRooms, TopicDeleted, TopicUpdated, PermissionOverwriteTargets, Owners, Ok, DiscoverableSpaces, Emoticons, EmoticonDeleted, NewEmoticon, Bans, ClientData, SpaceSummaryEvent, RoomSummaryEvent, NewRelationship, RelationshipDeleted, Relationships, RoomSummaryUpdated, Pong, AssignRole, GetMessages, CreateMessage, Ack, CreateRole, CreateRoom, CreateSpace, CreateTopic, FollowTopic, UnfollowTopic, GetFollowedTopics, DeassignRole, DeleteRole, DeleteRoom, DeleteSpace, DeleteTopic, SetPermissionOverwrites, GetPermissionOverwrites, GetComputedPermissions, GetRoomMembers, GetSession, GetSpaceMembers, GetSpaceRooms, JoinRoom, JoinSpace, LeaveRoom, LeaveSpace, UpdateRole, UpdateSpace, UpdateRoom, UpdateTopic, GetPermissionOverwriteTargets, CreateOwner, DeleteOwner, GetOwners, Topics, GetTopics, GetDiscoverableSpaces, GetEmoticons, CreateEmoticon, DeleteEmoticon, Ban, Unban, GetBans, Kick, GetClientData, SetClientData, GetSpaceSummary, GetRoomSummary, UpdateSpaceMember, CreateRelationship, DeleteRelationship, UpdateRoomMember, Ping, };
|
package/package.json
CHANGED
|
@@ -101,7 +101,7 @@ import {
|
|
|
101
101
|
NewRelationship,
|
|
102
102
|
DeleteRelationship,
|
|
103
103
|
CreateRelationship,
|
|
104
|
-
RoomSummaryUpdated,
|
|
104
|
+
RoomSummaryUpdated, Pong, Ping,
|
|
105
105
|
} from "./types/src/index";
|
|
106
106
|
import {EventTarget} from "./EventTarget";
|
|
107
107
|
import {GetRelationships} from "./types/src/schemes/commands/GetRelationships";
|
|
@@ -184,6 +184,7 @@ export type EventsMap = {
|
|
|
184
184
|
NewRelationship: NewRelationship,
|
|
185
185
|
RelationshipDeleted: RelationshipDeleted,
|
|
186
186
|
Relationships: Relationships,
|
|
187
|
+
Pong: Pong,
|
|
187
188
|
// Space events
|
|
188
189
|
DiscoverableSpaces: DiscoverableSpaces,
|
|
189
190
|
SpaceJoined: SpaceJoined,
|
|
@@ -250,6 +251,7 @@ export type CommandsMap = {
|
|
|
250
251
|
DeleteRelationship: [DeleteRelationship, EventsMap['RelationshipDeleted']],
|
|
251
252
|
CreateRelationship: [CreateRelationship, EventsMap['NewRelationship']],
|
|
252
253
|
GetRelationships: [GetRelationships, EventsMap['Relationships']],
|
|
254
|
+
Ping: [Ping, EventsMap['Pong']],
|
|
253
255
|
// Space commands
|
|
254
256
|
GetDiscoverableSpaces: [GetDiscoverableSpaces, EventsMap['DiscoverableSpaces']],
|
|
255
257
|
JoinSpace: [JoinSpace, EventsMap['SpaceJoined']],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ObservableInterface} from "./EventTarget";
|
|
2
|
-
import {AbstractChatClient, CommandResult, CommandsMap} from "./AbstractChatClient";
|
|
2
|
+
import {AbstractChatClient, CommandResult, CommandsMap, EventsMap} from "./AbstractChatClient";
|
|
3
3
|
import {ChatStateTracker} from "./state-tracker/ChatStateTracker";
|
|
4
4
|
import {Envelope} from "./types/src";
|
|
5
5
|
|
|
@@ -10,6 +10,20 @@ export interface WebSocketClientOptions {
|
|
|
10
10
|
awaitQueueSendDelayMs?: number;
|
|
11
11
|
stateTracking?: boolean;
|
|
12
12
|
queryParams?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Ping/pong configuration, enabled by default.
|
|
15
|
+
*/
|
|
16
|
+
ping?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Time without activity after which a ping will be sent. Default is 10 seconds.
|
|
20
|
+
*/
|
|
21
|
+
noActivityTimeoutMs?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Time to wait for a pong response before considering the connection dead. Default is 2 seconds.
|
|
24
|
+
*/
|
|
25
|
+
pongBackTimeoutMs?: number;
|
|
26
|
+
},
|
|
13
27
|
}
|
|
14
28
|
|
|
15
29
|
enum WebSocketChatClientEvent {
|
|
@@ -28,15 +42,27 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
28
42
|
protected connectingTimeoutId: any;
|
|
29
43
|
protected authenticated: boolean;
|
|
30
44
|
protected authenticatedResolvers: [() => void, (error: Error) => void];
|
|
45
|
+
protected pingIntervalId?: NodeJS.Timeout;
|
|
46
|
+
protected lastReceivedMessageAt?: number;
|
|
47
|
+
protected pingInFlight: boolean;
|
|
31
48
|
|
|
32
49
|
public constructor(private readonly options: WebSocketClientOptions) {
|
|
33
50
|
super();
|
|
34
51
|
if (this.options.stateTracking ?? true) {
|
|
35
52
|
this.state = new ChatStateTracker(this);
|
|
36
53
|
}
|
|
54
|
+
|
|
55
|
+
options.ping ??= {};
|
|
56
|
+
options.ping.enabled ??= true;
|
|
57
|
+
options.ping.noActivityTimeoutMs ??= 15000;
|
|
58
|
+
options.ping.pongBackTimeoutMs ??= 5000;
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
public async connect(): Promise<void> {
|
|
62
|
+
if (this.isOpenWsState() || this.isConnectingWsState()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
40
66
|
const params = new URLSearchParams(this.options.queryParams ?? {});
|
|
41
67
|
params.set('token', this.options.token);
|
|
42
68
|
|
|
@@ -48,13 +74,12 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
48
74
|
this.options.connectingTimeoutMs ?? 10000
|
|
49
75
|
);
|
|
50
76
|
this.authenticated = false;
|
|
51
|
-
|
|
52
77
|
return new Promise((...args) => this.authenticatedResolvers = args);
|
|
53
78
|
}
|
|
54
79
|
|
|
55
80
|
public disconnect(): void {
|
|
56
81
|
this.sendQueue = [];
|
|
57
|
-
this.ws?.close();
|
|
82
|
+
this.ws?.close(1000); // Normal closure
|
|
58
83
|
this.ws = null;
|
|
59
84
|
}
|
|
60
85
|
|
|
@@ -63,7 +88,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
63
88
|
const envelope = this.createEnvelope<CommandsMap[CommandType][0]>(commandType, commandData);
|
|
64
89
|
const promise = this.createPromiseFromCommandEnvelope<CommandType>(envelope);
|
|
65
90
|
|
|
66
|
-
if (this.
|
|
91
|
+
if (this.isConnectingWsState() || !this.authenticated && this.isOpenWsState()) {
|
|
67
92
|
this.sendQueue.push(envelope);
|
|
68
93
|
return promise;
|
|
69
94
|
}
|
|
@@ -72,19 +97,24 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
72
97
|
return promise;
|
|
73
98
|
}
|
|
74
99
|
|
|
100
|
+
public get isReady(): boolean {
|
|
101
|
+
return this.isOpenWsState() && this.authenticated;
|
|
102
|
+
}
|
|
103
|
+
|
|
75
104
|
private sendEnvelope(envelope: Envelope): void {
|
|
76
|
-
if (this.
|
|
105
|
+
if (this.isReady) {
|
|
77
106
|
this.ws.send(JSON.stringify(envelope));
|
|
78
107
|
return;
|
|
79
108
|
}
|
|
80
109
|
|
|
81
110
|
this.handleEnvelopeSendError(
|
|
82
111
|
envelope,
|
|
83
|
-
new Error(`Cannot send
|
|
112
|
+
new Error(`Cannot send - client is not ready (state=${this.ws?.readyState ?? '[no connection]'}; authenticated=${this.authenticated})`)
|
|
84
113
|
);
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
private onMessage(event: MessageEvent): void {
|
|
117
|
+
this.lastReceivedMessageAt = Date.now();
|
|
88
118
|
const envelope: Envelope = JSON.parse(event.data);
|
|
89
119
|
this.handleIncomingEnvelope(envelope);
|
|
90
120
|
this.emit(envelope.type, envelope.data);
|
|
@@ -95,6 +125,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
95
125
|
const isAuthenticated = envelope.type !== 'Bye';
|
|
96
126
|
this.authenticated = isAuthenticated;
|
|
97
127
|
if (isAuthenticated) {
|
|
128
|
+
this.startConnectionMonitor();
|
|
98
129
|
this.authenticatedResolvers[0]();
|
|
99
130
|
this.emit(this.Event.connect);
|
|
100
131
|
this.sendFromQueue();
|
|
@@ -105,6 +136,7 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
105
136
|
}
|
|
106
137
|
|
|
107
138
|
private onClose(event: CloseEvent): void {
|
|
139
|
+
this.stopConnectionMonitor();
|
|
108
140
|
clearTimeout(this.connectingTimeoutId);
|
|
109
141
|
const reconnect = event.code !== 1000; // Connection was closed because of error
|
|
110
142
|
if (reconnect) {
|
|
@@ -130,11 +162,49 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
|
|
|
130
162
|
this.emit(this.Event.error, new Error('Connection timeout'));
|
|
131
163
|
}
|
|
132
164
|
|
|
133
|
-
private
|
|
134
|
-
return this.ws && this.ws.readyState === this.ws.CONNECTING
|
|
165
|
+
private isConnectingWsState(): boolean {
|
|
166
|
+
return this.ws && this.ws.readyState === this.ws.CONNECTING;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private isOpenWsState(): boolean {
|
|
170
|
+
return this.ws && this.ws.readyState === this.ws.OPEN;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private startConnectionMonitor(): void {
|
|
174
|
+
if (!this.options.ping!.enabled) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this.lastReceivedMessageAt = Date.now();
|
|
179
|
+
|
|
180
|
+
this.pingIntervalId = setInterval(async () => {
|
|
181
|
+
if (!this.isReady || this.pingInFlight) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ((Date.now() - this.lastReceivedMessageAt) < this.options.ping!.noActivityTimeoutMs) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const timeout = setTimeout(() => {
|
|
190
|
+
this.pingInFlight = false;
|
|
191
|
+
this.ws.close(3000); // Service Restart (reconnect)
|
|
192
|
+
}, this.options.ping.pongBackTimeoutMs);
|
|
193
|
+
|
|
194
|
+
this.pingInFlight = true;
|
|
195
|
+
|
|
196
|
+
this.send('Ping', {}).then(() => {
|
|
197
|
+
this.pingInFlight = false;
|
|
198
|
+
clearTimeout(timeout);
|
|
199
|
+
});
|
|
200
|
+
}, 1000);
|
|
135
201
|
}
|
|
136
202
|
|
|
137
|
-
private
|
|
138
|
-
|
|
203
|
+
private stopConnectionMonitor(): void {
|
|
204
|
+
if (this.pingIntervalId) {
|
|
205
|
+
clearInterval(this.pingIntervalId);
|
|
206
|
+
this.pingIntervalId = undefined;
|
|
207
|
+
}
|
|
208
|
+
this.pingInFlight = false;
|
|
139
209
|
}
|
|
140
210
|
}
|
|
@@ -249,7 +249,14 @@ export class RoomsManager {
|
|
|
249
249
|
// because GetMembers are not supported for PM rooms.
|
|
250
250
|
this.handleRoomMembers({
|
|
251
251
|
id: room.id,
|
|
252
|
-
members: room.recipients.map(user => ({
|
|
252
|
+
members: room.recipients.map(user => ({
|
|
253
|
+
user,
|
|
254
|
+
spaceMember: null,
|
|
255
|
+
roles: null,
|
|
256
|
+
customColor: null,
|
|
257
|
+
customNick: null,
|
|
258
|
+
extras: '',
|
|
259
|
+
})),
|
|
253
260
|
});
|
|
254
261
|
this.membersPromises.register(Promise.resolve(), room.id);
|
|
255
262
|
}
|
|
@@ -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
|
|
package/src/types/src/index.ts
CHANGED
|
@@ -126,6 +126,8 @@ import {Relationships} from "./schemes/events/Relationships";
|
|
|
126
126
|
import {CreateRelationship} from "./schemes/commands/CreateRelationship";
|
|
127
127
|
import {RoomSummaryUpdated} from "./schemes/events/RoomSummaryUpdated";
|
|
128
128
|
import {UpdateRoomMember} from "./schemes/commands/UpdateRoomMember";
|
|
129
|
+
import {Ping} from "./schemes/commands/Ping";
|
|
130
|
+
import {Pong} from "./schemes/events/Pong";
|
|
129
131
|
|
|
130
132
|
export {
|
|
131
133
|
// objects
|
|
@@ -215,6 +217,7 @@ export {
|
|
|
215
217
|
RelationshipDeleted,
|
|
216
218
|
Relationships,
|
|
217
219
|
RoomSummaryUpdated,
|
|
220
|
+
Pong,
|
|
218
221
|
// commands
|
|
219
222
|
AssignRole,
|
|
220
223
|
GetMessages,
|
|
@@ -269,4 +272,5 @@ export {
|
|
|
269
272
|
CreateRelationship,
|
|
270
273
|
DeleteRelationship,
|
|
271
274
|
UpdateRoomMember,
|
|
275
|
+
Ping,
|
|
272
276
|
};
|