Move server add-on interfaces to flipper-common
Reviewed By: antonk52 Differential Revision: D34169419 fbshipit-source-id: 69fcc8da7d98f59818fbb5b486a488f19830cd81
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9294645d3
commit
04eab80c98
@@ -16,6 +16,7 @@ import {
|
||||
BundledPluginDetails,
|
||||
DownloadablePluginDetails,
|
||||
ExecuteMessage,
|
||||
FlipperServerForServerAddOn,
|
||||
InstalledPluginDetails,
|
||||
} from 'flipper-common';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
@@ -32,7 +33,6 @@ import {
|
||||
installPluginFromNpm,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {ServerAddOn} from './ServerAddOn';
|
||||
import {FlipperServerForServerAddOn} from './ServerAddOnDesktopToModuleConnection';
|
||||
|
||||
const maxInstalledPluginVersionsToKeep = 2;
|
||||
|
||||
|
||||
@@ -10,20 +10,15 @@
|
||||
import assert from 'assert';
|
||||
import {assertNotNull} from '../comms/Utilities';
|
||||
import {
|
||||
ServerAddOnDesktopToModuleConnection,
|
||||
FlipperServerForServerAddOn,
|
||||
} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {
|
||||
ServerAddOnModuleToDesktopConnection,
|
||||
ServerAddOnPluginConnection,
|
||||
} from './ServerAddOnModuleToDesktopConnection';
|
||||
ServerAddOnCleanup,
|
||||
ServerAddOn as ServerAddOnFn,
|
||||
} from 'flipper-common';
|
||||
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
|
||||
|
||||
type ServerAddOnCleanup = () => Promise<void>;
|
||||
interface ServerAddOnModule {
|
||||
serverAddOn?: (
|
||||
connection: ServerAddOnPluginConnection,
|
||||
{flipperServer}: {flipperServer: FlipperServerForServerAddOn},
|
||||
) => Promise<ServerAddOnCleanup>;
|
||||
serverAddOn?: ServerAddOnFn;
|
||||
}
|
||||
|
||||
const loadPlugin = (_pluginName: string): ServerAddOnModule => {
|
||||
|
||||
@@ -11,27 +11,13 @@ import assert from 'assert';
|
||||
import {
|
||||
ClientResponseType,
|
||||
ExecuteMessage,
|
||||
FlipperServer,
|
||||
FlipperServerEvents,
|
||||
FlipperServerForServerAddOn,
|
||||
} from 'flipper-common';
|
||||
import {ServerDevice} from '../devices/ServerDevice';
|
||||
import {
|
||||
ServerAddOnModuleToDesktopConnection,
|
||||
ServerAddOnModuleToDesktopConnectionEvents,
|
||||
} from './ServerAddOnModuleToDesktopConnection';
|
||||
|
||||
export interface FlipperServerForServerAddOn extends FlipperServer {
|
||||
emit(
|
||||
event: 'plugins-server-add-on-message',
|
||||
payload: FlipperServerEvents['plugins-server-add-on-message'],
|
||||
): void;
|
||||
registerDevice(device: ServerDevice): void;
|
||||
unregisterDevice(serial: string): void;
|
||||
getDevice(serial: string): ServerDevice;
|
||||
getDeviceSerials(): string[];
|
||||
getDevices(): ServerDevice[];
|
||||
}
|
||||
|
||||
export class ServerAddOnDesktopToModuleConnection {
|
||||
constructor(
|
||||
private readonly moduleToDesktopConnection: ServerAddOnModuleToDesktopConnection,
|
||||
|
||||
@@ -8,32 +8,19 @@
|
||||
*/
|
||||
|
||||
import EventEmitter from 'events';
|
||||
import {ResponseMessage, ClientErrorType, ExecuteMessage} from 'flipper-common';
|
||||
import {
|
||||
ResponseMessage,
|
||||
ClientErrorType,
|
||||
ExecuteMessage,
|
||||
ServerAddOnPluginConnection,
|
||||
FlipperPluginReceiver,
|
||||
} from 'flipper-common';
|
||||
import {safeJSONStringify} from '../utils/safeJSONStringify';
|
||||
|
||||
// TODO: Share with js-flipper? Is it worth it?
|
||||
type FlipperPluginReceiverRes =
|
||||
| object
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| void;
|
||||
|
||||
type FlipperPluginReceiver = (
|
||||
data: any,
|
||||
) => FlipperPluginReceiverRes | Promise<FlipperPluginReceiverRes>;
|
||||
|
||||
export type ServerAddOnModuleToDesktopConnectionEvents = {
|
||||
message: ExecuteMessage;
|
||||
};
|
||||
|
||||
export interface ServerAddOnPluginConnection {
|
||||
send(method: string, params: unknown): void;
|
||||
receive(method: string, receiver: FlipperPluginReceiver): void;
|
||||
}
|
||||
|
||||
export class ServerAddOnModuleToDesktopConnection
|
||||
extends EventEmitter
|
||||
implements ServerAddOnPluginConnection
|
||||
|
||||
Reference in New Issue
Block a user