From afc37ca3af59124a33f65e80479fb242cf8d394f Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 21 Oct 2021 15:44:27 +0200 Subject: [PATCH 1/3] Add non-reliable websockets support (#1497) * Add non-reliable websockets support * Remove unused properties Co-authored-by: Mattermod Co-authored-by: Scott Bishel --- webapp/src/wsclient.ts | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/webapp/src/wsclient.ts b/webapp/src/wsclient.ts index 8fccb33c5..979d92739 100644 --- a/webapp/src/wsclient.ts +++ b/webapp/src/wsclient.ts @@ -34,10 +34,10 @@ export const ACTION_UPDATE_CLIENT_CONFIG = 'UPDATE_CLIENT_CONFIG' export interface MMWebSocketClient { conn: WebSocket | null; sendMessage(action: string, data: any, responseCallback?: () => void): void /* eslint-disable-line @typescript-eslint/no-explicit-any */ + setFirstConnectCallback(callback: () => void): void setReconnectCallback(callback: () => void): void setErrorCallback(callback: (event: Event) => void): void setCloseCallback(callback: (connectFailCount: number) => void): void - connectionId: string } type OnChangeHandler = (client: WSClient, blocks: Block[]) => void @@ -57,8 +57,6 @@ class WSClient { onChange: OnChangeHandler[] = [] onError: OnErrorHandler[] = [] onConfigChange: OnConfigChangeHandler[] = [] - private mmWSMaxRetries = 100 - private mmWSRetryDelay = 300 private notificationDelay = 100 private reopenDelay = 3000 private updatedBlocks: Block[] = [] @@ -163,10 +161,19 @@ class WSClient { open(): void { if (this.client !== null) { // configure the Mattermost websocket client callbacks + const onConnect = () => { + Utils.log('WSClient in plugin mode, reusing Mattermost WS connection') + + for (const handler of this.onStateChange) { + handler(this, 'open') + } + this.state = 'open' + } + const onReconnect = () => { Utils.logWarn('WSClient reconnected') - this.open() + onConnect() for (const handler of this.onReconnect) { handler(this) } @@ -204,34 +211,11 @@ class WSClient { } } + this.client.setFirstConnectCallback(onConnect) this.client.setErrorCallback(onError) this.client.setCloseCallback(onClose) this.client.setReconnectCallback(onReconnect) - // WSClient needs to ensure that the Mattermost client has - // correctly stablished the connection before opening - let retries = 0 - const setPluginOpen = () => { - if (this.client?.connectionId !== '') { - Utils.log('WSClient in plugin mode, reusing Mattermost WS connection') - - for (const handler of this.onStateChange) { - handler(this, 'open') - } - this.state = 'open' - return - } - - retries++ - if (retries <= this.mmWSMaxRetries) { - Utils.log('WSClient Mattermost Websocket not ready, retrying') - setTimeout(setPluginOpen, this.mmWSRetryDelay) - } else { - Utils.logError('WSClient error on open: Mattermost Websocket client is not ready') - } - } - - setPluginOpen() return } From 9f7428780257bea86f242d1baea7b3d0e02da20d Mon Sep 17 00:00:00 2001 From: Hossein Date: Thu, 21 Oct 2021 10:29:06 -0400 Subject: [PATCH 2/3] fix main (#1619) --- .../__snapshots__/galleryCard.test.tsx.snap | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/webapp/src/components/gallery/__snapshots__/galleryCard.test.tsx.snap b/webapp/src/components/gallery/__snapshots__/galleryCard.test.tsx.snap index f19bb59bc..ca3311994 100644 --- a/webapp/src/components/gallery/__snapshots__/galleryCard.test.tsx.snap +++ b/webapp/src/components/gallery/__snapshots__/galleryCard.test.tsx.snap @@ -38,14 +38,14 @@ exports[`src/components/gallery/GalleryCard with a comment content should match class="MenuWrapper optionsMenu" role="button" > -
-
+