Extracting utility methods
Summary: Extract the following utility functions from ServerController: transformCertificateExchangeMediumToType appNameWithUpdateHint The functions are not tied to the ServerController and will be used outside of it. Reviewed By: passy Differential Revision: D29938355 fbshipit-source-id: ea489f54a3a6bf46ae4e108579d48ede1f891093
This commit is contained in:
committed by
Facebook GitHub Bot
parent
27eaf4f03d
commit
554f8146d7
@@ -46,6 +46,10 @@ import DummyDevice from '../devices/DummyDevice';
|
||||
import BaseDevice from '../devices/BaseDevice';
|
||||
import {sideEffect} from '../utils/sideEffect';
|
||||
import {destroyDevice} from '../reducers/connections';
|
||||
import {
|
||||
appNameWithUpdateHint,
|
||||
transformCertificateExchangeMediumToType,
|
||||
} from './Utilities';
|
||||
|
||||
type ClientInfo = {
|
||||
connection: ClientConnection | null | undefined;
|
||||
@@ -57,35 +61,12 @@ type ClientCsrQuery = {
|
||||
csr_path?: string | undefined;
|
||||
};
|
||||
|
||||
function transformCertificateExchangeMediumToType(
|
||||
medium: number | undefined,
|
||||
): CertificateExchangeMedium {
|
||||
if (medium == 1) {
|
||||
return 'FS_ACCESS';
|
||||
} else if (medium == 2) {
|
||||
return 'WWW';
|
||||
} else {
|
||||
return 'FS_ACCESS';
|
||||
}
|
||||
}
|
||||
|
||||
declare interface ServerController {
|
||||
on(event: 'new-client', callback: (client: Client) => void): this;
|
||||
on(event: 'error', callback: (err: Error) => void): this;
|
||||
on(event: 'clients-change', callback: () => void): this;
|
||||
}
|
||||
|
||||
function appNameWithUpdateHint(query: ClientQuery): string {
|
||||
// in previous version (before 3), app may not appear in correct device
|
||||
// section because it refers to the name given by client which is not fixed
|
||||
// for android emulators, so it is indicated as outdated so that developers
|
||||
// might want to update SDK to get rid of this connection swap problem
|
||||
if (query.os === 'Android' && (!query.sdk_version || query.sdk_version < 3)) {
|
||||
return query.app + ' (Outdated SDK)';
|
||||
}
|
||||
return query.app;
|
||||
}
|
||||
|
||||
class ServerController extends EventEmitter {
|
||||
connections: Map<string, ClientInfo>;
|
||||
secureServer: Promise<RSocketServer<any, any>> | null;
|
||||
|
||||
46
desktop/app/src/comms/Utilities.tsx
Normal file
46
desktop/app/src/comms/Utilities.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {CertificateExchangeMedium} from '../utils/CertificateProvider';
|
||||
import {ClientQuery} from '../Client';
|
||||
|
||||
/**
|
||||
* Transforms the certificate exchange medium type as number to the
|
||||
* CertificateExchangeMedium type.
|
||||
* @param medium A number representing the certificate exchange medium type.
|
||||
*/
|
||||
export function transformCertificateExchangeMediumToType(
|
||||
medium: number | undefined,
|
||||
): CertificateExchangeMedium {
|
||||
if (medium == 1) {
|
||||
return 'FS_ACCESS';
|
||||
} else if (medium == 2) {
|
||||
return 'WWW';
|
||||
} else {
|
||||
return 'FS_ACCESS';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the app name from a ClientQuery instance. In most cases it should be
|
||||
* the app name as given in the query. On Android, and for old SDK versions (<3) it
|
||||
* will returned the app name suffixed by '(Outdated SDK)'.
|
||||
*
|
||||
* Reason is, in previous version (<3), app may not appear in correct device
|
||||
* section because it refers to the name given by client which is not fixed
|
||||
* for android emulators, so it is indicated as outdated so that developers
|
||||
* might want to update SDK to get rid of this connection swap problem
|
||||
* @param query A ClientQuery object.
|
||||
*/
|
||||
export function appNameWithUpdateHint(query: ClientQuery): string {
|
||||
if (query.os === 'Android' && (!query.sdk_version || query.sdk_version < 3)) {
|
||||
return query.app + ' (Outdated SDK)';
|
||||
}
|
||||
return query.app;
|
||||
}
|
||||
Reference in New Issue
Block a user