@livedigital/client 2.5.0 → 2.6.0
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/dist/engine/network/Socket.d.ts +2 -0
- package/dist/index.es.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/engine/index.ts +3 -2
- package/src/engine/network/Socket.ts +17 -1
package/package.json
CHANGED
package/src/engine/index.ts
CHANGED
|
@@ -116,8 +116,9 @@ class Engine {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
private watchSocketState(): void {
|
|
119
|
-
this.network.socket.observer.on('state', (
|
|
120
|
-
|
|
119
|
+
this.network.socket.observer.on('state', (evt: { state: SocketIOEvents, code?: string }) => {
|
|
120
|
+
const { state, code } = evt;
|
|
121
|
+
this.clientEventEmitter.emit(state, { code });
|
|
121
122
|
|
|
122
123
|
if (state === SocketIOEvents.Reconnecting) {
|
|
123
124
|
this.network.socket.disconnect();
|
|
@@ -21,6 +21,14 @@ class SocketIO {
|
|
|
21
21
|
|
|
22
22
|
private readonly logger: Logger;
|
|
23
23
|
|
|
24
|
+
private readonly knownDisconnectReasonsCodes: Record<string, string> = {
|
|
25
|
+
'io server disconnect': 'server.disconnect',
|
|
26
|
+
'io client disconnect': 'client.disconnect',
|
|
27
|
+
'ping timeout': 'ping.timeout',
|
|
28
|
+
'transport close': 'transport.close',
|
|
29
|
+
'transport error': 'transport.error',
|
|
30
|
+
};
|
|
31
|
+
|
|
24
32
|
constructor() {
|
|
25
33
|
this.logger = new Logger('Socket');
|
|
26
34
|
}
|
|
@@ -62,7 +70,10 @@ class SocketIO {
|
|
|
62
70
|
this.setReconnectingAttempt(0);
|
|
63
71
|
this.disconnectReason = reason;
|
|
64
72
|
this.logger.warn('connection.on(`disconnect`)', reason);
|
|
65
|
-
this.observer.safeEmit('state', {
|
|
73
|
+
this.observer.safeEmit('state', {
|
|
74
|
+
state: SocketIOEvents.Disconnected,
|
|
75
|
+
code: this.getDisconnectReasonCode(reason),
|
|
76
|
+
});
|
|
66
77
|
}));
|
|
67
78
|
|
|
68
79
|
connection.io.on('reconnect_attempt', (attempt: number) => {
|
|
@@ -106,6 +117,11 @@ class SocketIO {
|
|
|
106
117
|
});
|
|
107
118
|
}
|
|
108
119
|
|
|
120
|
+
private getDisconnectReasonCode(reasonSentence: string): string {
|
|
121
|
+
const reason = String(reasonSentence).toLowerCase();
|
|
122
|
+
return this.knownDisconnectReasonsCodes[reason] || reason;
|
|
123
|
+
}
|
|
124
|
+
|
|
109
125
|
private setReconnectingAttempt(attemptNo: number): void {
|
|
110
126
|
this.reconnectingAttempt = attemptNo;
|
|
111
127
|
}
|