Separate device in server and client version [2/n]
Summary:
This stack takes care of handling care of moving all device interactions over the (possible) async channel FlipperServer. The FlipperServer interface (see previous diff) allows listening to specific server events using `on`, and emit commands to be executed by the server by using `exec` (e.g. `exec('take-screenshot', serial) => Promise<buffer>`).
FlipperServerImpl implements this interface on the server side.
The device implementations are split as follows
```
server / backend process:
ServerDevice
- iOSDevice
- AndroidDevice
- MetroDevice
- DummyDevice
- Mac/Windows Device
frontend / ui:
BaseDevice: a normal connected, device, implements device apis as they already existed
- ArchivedDevice (note that this doesn't have a server counterpart)
- TestDevice (for unit tests, with stubbed backend communication)
```
All features of devices are for simplicity unified (since the deviations are small), where specific device types might not implement certain features like taking screenshots or running shell commands.
To avoid making this diff unnecessarily big, some open Todo's will be addressed later in this stack, and it shouldn't be landed alone.
Reviewed By: timur-valiev
Differential Revision: D30909346
fbshipit-source-id: cce0bee94fdd5db59bebe3577a6084219a038719
This commit is contained in:
committed by
Facebook GitHub Bot
parent
845d0755f1
commit
2d838efd4d
@@ -69,7 +69,6 @@ export interface RealFlipperDevice {
|
||||
deviceType: DeviceType;
|
||||
addLogListener(callback: DeviceLogListener): Symbol;
|
||||
removeLogListener(id: Symbol): void;
|
||||
addLogEntry(entry: DeviceLogEntry): void;
|
||||
}
|
||||
|
||||
export class SandyDevicePluginInstance extends BasePluginInstance {
|
||||
|
||||
@@ -486,7 +486,9 @@ export function createMockBundledPluginDetails(
|
||||
};
|
||||
}
|
||||
|
||||
function createMockDevice(options?: StartPluginOptions): RealFlipperDevice {
|
||||
function createMockDevice(options?: StartPluginOptions): RealFlipperDevice & {
|
||||
addLogEntry(entry: DeviceLogEntry): void;
|
||||
} {
|
||||
const logListeners: (undefined | DeviceLogListener)[] = [];
|
||||
return {
|
||||
os: 'Android',
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
DeviceSpec,
|
||||
DeviceType as PluginDeviceType,
|
||||
OS as PluginOS,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {DeviceLogEntry} from '../plugin/DevicePlugin';
|
||||
|
||||
// In the future, this file would deserve it's own package, as it doesn't really relate to plugins.
|
||||
// Since flipper-plugin however is currently shared among server, client and defines a lot of base types, leaving it here for now.
|
||||
@@ -31,6 +33,10 @@ export type DeviceDescription = {
|
||||
readonly title: string;
|
||||
readonly deviceType: DeviceType;
|
||||
readonly serial: string;
|
||||
// Android specific information
|
||||
readonly specs?: DeviceSpec[];
|
||||
readonly abiList?: string[];
|
||||
readonly sdkVersion?: string;
|
||||
};
|
||||
|
||||
export type ClientQuery = {
|
||||
@@ -58,8 +64,39 @@ export type FlipperServerEvents = {
|
||||
'device-connected': DeviceDescription;
|
||||
'device-disconnected': DeviceDescription;
|
||||
'client-connected': ClientDescription;
|
||||
'device-log': {
|
||||
serial: string;
|
||||
entry: DeviceLogEntry;
|
||||
};
|
||||
};
|
||||
|
||||
export type FlipperServerCommands = {
|
||||
// TODO
|
||||
'device-start-logging': (serial: string) => Promise<void>;
|
||||
'device-stop-logging': (serial: string) => Promise<void>;
|
||||
'device-supports-screenshot': (serial: string) => Promise<boolean>;
|
||||
'device-supports-screencapture': (serial: string) => Promise<boolean>;
|
||||
'device-take-screenshot': (serial: string) => Promise<string>; // base64 encoded buffer
|
||||
'device-start-screencapture': (
|
||||
serial: string,
|
||||
destination: string,
|
||||
) => Promise<void>;
|
||||
'device-stop-screencapture': (serial: string) => Promise<string>; // file path
|
||||
'device-shell-exec': (serial: string, command: string) => Promise<string>;
|
||||
'metro-command': (serial: string, command: string) => Promise<void>;
|
||||
};
|
||||
|
||||
export interface FlipperServer {
|
||||
on<Event extends keyof FlipperServerEvents>(
|
||||
event: Event,
|
||||
callback: (payload: FlipperServerEvents[Event]) => void,
|
||||
): void;
|
||||
off<Event extends keyof FlipperServerEvents>(
|
||||
event: Event,
|
||||
callback: (payload: FlipperServerEvents[Event]) => void,
|
||||
): void;
|
||||
exec<Event extends keyof FlipperServerCommands>(
|
||||
event: Event,
|
||||
...args: Parameters<FlipperServerCommands[Event]>
|
||||
): ReturnType<FlipperServerCommands[Event]>;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user