Centralize clientId creation

Summary: One step towards getting away from constructing and destructing clientIds manually everywhere by splitting and joining #'s. Which has been VERY error prone in the past.

Reviewed By: passy

Differential Revision: D18809442

fbshipit-source-id: bd4d89d3eb3d59694aa735b19dbd73d122e59ba0
This commit is contained in:
John Knox
2019-12-04 07:16:13 -08:00
committed by Facebook Github Bot
parent ab5892c60e
commit 15e1b25098
3 changed files with 18 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import net, {Socket} from 'net';
import {Responder, Payload, ReactiveSocket} from 'rsocket-types';
import GK from './fb-stubs/GK';
import {initJsEmulatorIPC} from './utils/js-client/serverUtils';
import {buildClientId} from './utils/clientUtils';
type ClientInfo = {
connection: FlipperClientConnection<any, any> | null | undefined;
@@ -334,7 +335,12 @@ class Server extends EventEmitter {
query.device_id = csrId;
query.app = appNameWithUpdateHint(query);
const id = `${query.app}#${query.os}#${query.device}#${csrId}`;
const id = buildClientId({
app: query.app,
os: query.os,
device: query.device,
device_id: csrId,
});
console.debug(`Device connected: ${id}`, 'server');
const client = new Client(id, query, conn, this.logger, this.store);

View File

@@ -47,3 +47,12 @@ export function getCurrentAppName(client: string | undefined | null): string {
return '';
}
}
export function buildClientId(clientInfo: {
app: string;
os: string;
device: string;
device_id: string;
}): string {
return `${clientInfo.app}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`;
}

View File

@@ -17,6 +17,7 @@ import {Logger} from 'src/fb-interfaces/Logger';
import {Payload, ConnectionStatus, ISubscriber} from 'rsocket-types';
import {Flowable, Single} from 'rsocket-flowable';
import Server from 'src/server';
import {buildClientId} from '../clientUtils';
const connections: Map<number, JSClientFlipperConnection<any>> = new Map();
@@ -59,7 +60,7 @@ export function initJsEmulatorIPC(
device_id: jsDeviceId(windowId),
sdk_version: 2, // hack to bybass callbacks in Client, will be fixed when JS Connection will be fully implemented
};
const clientId = `${query.app}#${query.os}#${query.device}#${query.device_id}`;
const clientId = buildClientId(query);
const client = new Client(
clientId,