From 2b138997823fab9ff6e9dac513dde4a226b1d1b3 Mon Sep 17 00:00:00 2001 From: Timur Valiev Date: Thu, 10 Sep 2020 08:16:48 -0700 Subject: [PATCH] websocket connection - make it work with new js sdk Summary: we used to send plugins list with connect command, now we can respond to getPlugins request with new api. we still support old clients Reviewed By: jknoxville Differential Revision: D23625139 fbshipit-source-id: 37a24d0c83cd879d93287dd3a3d4d5d2f9477b34 --- desktop/app/src/server.tsx | 6 ++++-- .../websocketClientFlipperConnection.tsx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/desktop/app/src/server.tsx b/desktop/app/src/server.tsx index 1d0a8310c..66da6a8ce 100644 --- a/desktop/app/src/server.tsx +++ b/desktop/app/src/server.tsx @@ -224,7 +224,8 @@ class Server extends EventEmitter { os: 'JSWebApp', device: 'device', device_id: deviceId, - sdk_version: 1, + // if plugins != null -> we are using old api, where we send the list of plugins with connect message + sdk_version: plugins == null ? 4 : 1, medium: 'FS_ACCESS', }, {}, @@ -233,7 +234,8 @@ class Server extends EventEmitter { ws.on('message', (m: any) => { const parsed = JSON.parse(m.toString()); - if (parsed.app === app) { + // non-null payload id means response to prev request, it's handled in connection + if (parsed.app === app && parsed.payload?.id == null) { const message = JSON.stringify(parsed.payload); if (resolvedClient) { resolvedClient.onMessage(message); diff --git a/desktop/app/src/utils/js-client-server-utils/websocketClientFlipperConnection.tsx b/desktop/app/src/utils/js-client-server-utils/websocketClientFlipperConnection.tsx index c4639ab46..c197f9cc2 100644 --- a/desktop/app/src/utils/js-client-server-utils/websocketClientFlipperConnection.tsx +++ b/desktop/app/src/utils/js-client-server-utils/websocketClientFlipperConnection.tsx @@ -18,7 +18,7 @@ export class WebsocketClientFlipperConnection connStatusSubscribers: Set> = new Set(); connStatus: ConnectionStatus; app: string; - plugins: string[] = []; + plugins: string[] | undefined = undefined; constructor(ws: WebSocket, app: string, plugins: string[]) { this.websocket = ws; @@ -66,7 +66,7 @@ export class WebsocketClientFlipperConnection subscriber.onSubscribe(() => {}); - if (method === 'getPlugins') { + if (method === 'getPlugins' && this.plugins != null) { subscriber.onComplete({ data: JSON.stringify({ success: {plugins: this.plugins},