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
This commit is contained in:
Timur Valiev
2020-09-10 08:16:48 -07:00
committed by Facebook GitHub Bot
parent 1d55b35dfd
commit 2b13899782
2 changed files with 6 additions and 4 deletions

View File

@@ -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);