Files
flipper/desktop/flipper-common/src/transport.tsx
Pascal Hartig 9c5d1a32c5 Recover from malformed JSON
Summary: Following up on D34787674 (f85def32fb).

Reviewed By: aigoncharov

Differential Revision: D34930249

fbshipit-source-id: f209a638c1281957fd2b03b6fc50389bd98bc5f6
2022-03-16 16:39:23 -07:00

55 lines
1.3 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 {FlipperServerCommands, FlipperServerEvents} from './server-types';
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 ClientWebSocketMessage = ExecWebSocketMessage;
export type ServerWebSocketMessage =
| ExecResponseWebSocketMessage
| ExecResponseErrorWebSocketMessage
| ServerEventWebSocketMessage;