ota-hub-reactjs
Version:
ReactJS tools for building web apps to flash MCU devices such as esp32, brought to you by OTA Hub.
43 lines (42 loc) • 1.7 kB
TypeScript
export type LogMessage = string | number | boolean | Record<string, any> | any[];
export type LogLine = {
level: number;
message: LogMessage;
timestamp?: string | Date;
};
type PropCreatorProps<T> = (uuid: string) => Partial<T> | undefined;
export interface AddConnectionProps<T> {
uuid?: string;
propCreator?: PropCreatorProps<T>;
}
export type DeviceConnectionState = {
uuid: string;
deviceMac?: string;
name: string;
send: (data: string | Uint8Array) => void | Promise<void>;
onReceive?: (data: string | Uint8Array) => boolean;
onConnect?: () => void | Promise<void>;
onDisconnect?: () => void | Promise<void>;
autoConnect: boolean;
isConnected: boolean;
isConnecting: boolean;
logs: LogLine[];
readBufferLeftover: string;
};
export declare function createDefaultInitialDeviceState<T extends DeviceConnectionState>(uuid: string, props?: any): T;
export type DeviceWhispererProps<T extends DeviceConnectionState> = {
createInitialConnectionState?: (uuid: string) => T;
};
export declare function MultiDeviceWhisperer<T extends DeviceConnectionState>({ createInitialConnectionState, }?: DeviceWhispererProps<T>): {
connections: T[];
connectionsRef: import("react").RefObject<T[]>;
addConnection: ({ uuid, propCreator }: AddConnectionProps<T>) => Promise<string>;
removeConnection: (uuid: string) => void;
connect: (_uuid: string) => void;
disconnect: (_uuid: string) => void;
updateConnection: (uuid: string, updater: (c: T) => T) => void;
reconnectAll: () => void;
updateConnectionName: (uuid: string, name: string) => void;
appendLog: (uuid: string, log: LogLine) => void;
};
export {};