Skip to content

Commit 635c0af

Browse files
committed
Fixing websocket lost message issue on startup.
1 parent f546f88 commit 635c0af

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/mm-client.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,23 @@ new Promise((resolve, reject) => {
3434
process.exit(-1)
3535
})
3636

37+
/**
38+
* this resolves an issue with lost web messages and the client rebooting endlessly -
39+
* we need to have a listener attached to the client from the start so that it does
40+
* not reconnect infinitely, internally
41+
*/
42+
function workaroundWebsocketPackageLostIssue(webSocketClient: WebSocketClient) {
43+
// after a hundred messages it should be ok to unregister - the actual
44+
// listener should have been added by now.
45+
let messageCount = 100;
46+
const firstMessagesListener = (e: any) => {
47+
if (messageCount-- < 1) {
48+
webSocketClient.removeMessageListener(firstMessagesListener)
49+
}
50+
};
51+
webSocketClient.addMessageListener(firstMessagesListener)
52+
}
53+
54+
workaroundWebsocketPackageLostIssue(wsClient);
55+
3756
wsClient.initialize(wsUrl.toString(), mattermostToken)

0 commit comments

Comments
 (0)