Files
flipper/desktop/flipper-common/src/transport.tsx
Andrey Goncharov 4f9ceb2e22 Implement subscribing to data updates for Flipper Server Companion
Summary: Allow subscribing to state updates from the plugin in headless mode

Reviewed By: passy

Differential Revision: D36516754

fbshipit-source-id: 14db51243e1d91332a7327c1792412149339f907
2022-05-23 03:38:23 -07:00

66 lines
1.6 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and 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 {FlipperCompanionEvents} from './companion-types';
import {FlipperServerCommands, FlipperServerEvents} from './server-types';
export type GenericWebSocketMessage<E = string, T = unknown> = {
event: E;
payload: T;
};
export type GenericWebSocketError = GenericWebSocketMessage<
'error',
{message: string}
>;
export type ExecWebSocketMessage = GenericWebSocketMessage<
'exec',
{
[K in keyof FlipperServerCommands]: {
id: number;
command: K;
args: Parameters<FlipperServerCommands[K]>;
};
}[keyof FlipperServerCommands]
>;
export type ExecResponseWebSocketMessage = GenericWebSocketMessage<
'exec-response',
{id: number; data: unknown}
>;
export type ExecResponseErrorWebSocketMessage = GenericWebSocketMessage<
'exec-response-error',
{id: number; data: unknown}
>;
export type ServerEventWebSocketMessage = GenericWebSocketMessage<
'server-event',
{
[K in keyof FlipperServerEvents]: {event: K; data: FlipperServerEvents[K]};
}[keyof FlipperServerEvents]
>;
export type CompanionEventWebSocketMessage = GenericWebSocketMessage<
'companion-event',
{
[K in keyof FlipperCompanionEvents]: {
event: K;
data: FlipperCompanionEvents[K];
};
}[keyof FlipperCompanionEvents]
>;
export type ClientWebSocketMessage = ExecWebSocketMessage;
export type ServerWebSocketMessage =
| ExecResponseWebSocketMessage
| ExecResponseErrorWebSocketMessage
| ServerEventWebSocketMessage;