import { EventEmitter } from "events"; import { MessageSerializer } from "./MessageSerializer"; import { PixelInfo } from "./PixelInfo"; import { PixelInfoNotifierMutableProps, PixelInfoNotifier } from "./PixelInfoNotifier"; import { PixelMessage } from "./PixelMessage"; import { PixelSession, PixelSessionConnectionEventReason } from "./PixelSession"; /** * The different possible connection statuses of a Pixel. * @category Pixels */ export type PixelStatus = "disconnected" | "connecting" | "identifying" | "ready" | "disconnecting"; export type PixelStatusEvent = Readonly<{ status: PixelStatus; lastStatus: PixelStatus; reason?: PixelSessionConnectionEventReason; }>; /** * The mutable properties of {@link PixelConnect} not inherited from parent * class {@link PixelInfoNotifier}. * @category Pixels */ export type PixelConnectOwnMutableProps = { /** Connection status. */ status: PixelStatus; }; /** * The mutable properties of {@link PixelConnect}. * @category Pixels */ export type PixelConnectMutableProps = PixelInfoNotifierMutableProps & PixelConnectOwnMutableProps; /** * {@link PixelInfo} type extend with PixelConnect props. * @category Pixels */ export type PixelInfoWithStatus = PixelInfo & PixelConnectOwnMutableProps; /** * Abstract class that represents a connection to a Pixel device (die, charger, etc.). * @category Pixels */ export declare abstract class PixelConnect extends PixelInfoNotifier { protected readonly _msgEvEmitter: EventEmitter; protected readonly _serializer: MessageSerializer; private _logFunc; private _logMessages; private _logData; private readonly _session; private _status; /** Toggle logging information about each send and received message. */ get logMessages(): boolean; set logMessages(enabled: boolean); /** Toggle logging the serialized (binary) data for each send and received message. */ get logMessagesSerializedData(): boolean; set logMessagesSerializedData(enabled: boolean); /** Set logger to use by this instance. */ get logger(): ((msg: string) => void) | undefined | null; set logger(logger: ((msg: string) => void) | undefined | null); /** Gets the Pixel last known connection status. */ get status(): PixelStatus; protected get sessionDeviceName(): string | undefined; protected constructor(serializer: MessageSerializer, session: PixelSession); /** * /!\ Internal, don't call this function ;) */ private _dispose; /** * Registers a listener function that will be called on receiving * raw messages of a given type from the Pixel. * @param msgType The type of message to watch for. * @param listener The callback function. */ addMessageListener(msgType: MessageType, listener: (this: PixelConnect, message: PixelMessage | MessageType) => void): void; /** * Unregisters a listener from receiving raw messages of a given type. * @param msgType The type of message to watch for. * @param listener The callback function to unregister. */ removeMessageListener(msgType: MessageType, listener: (this: PixelConnect, msg: PixelMessage | MessageType) => void): void; protected abstract _internalDispose(): void; protected abstract _onStatusChanged(ev: PixelStatusEvent): void; protected abstract _internalSetup(): Promise; protected abstract _internalDeserializeMessage(dataView: DataView): PixelMessage | MessageType; protected _internalConnect(timeoutMs?: number): Promise; /** * Immediately disconnects from the die. * @returns A promise that resolves once the disconnect request has been processed. **/ protected _internalDisconnect(): Promise; private _onValueChanged; /** * Waits for a message from the Pixel. * @param expectedMsgType Type of the message to expect. * @param timeoutMs Timeout before aborting the wait. * @returns A promise with the received message of the expected type. */ protected _internalWaitForMessage(expectedMsgType: MessageType, timeoutMs?: number): Promise; /** * Sends a message to the Pixel. * @param msgOrType Message with the data to send or just a message type. * @param withoutAck Whether to request a confirmation that the message was received. * @returns A promise that resolves once the message has been send. */ protected _internalSendMessage(msgOrType: PixelMessage | MessageType, withoutAck?: boolean): Promise; /** * Sends a message to the Pixel and wait for a specific response. * @param msgOrTypeToSend Message with the data to send or just a message type. * @param responseType Expected response type. * @param timeoutMs Timeout in mill-seconds before aborting waiting for the response. * @returns A promise resolving to the response in the form of a message type or a message object. */ protected _internalSendAndWaitForResponse(msgOrTypeToSend: PixelMessage | MessageType, responseType: MessageType, timeoutMs?: number): Promise; /** * Sends a message to the Pixel and wait for a specific response * which is returned casted to the expected type. * @param msgOrTypeToSend Message with the data to send or just a message type. * @param responseType Expected response class type. * @param responseType Expected response type. * @returns A promise resolving to a message object of the expected type. */ protected _internalSendAndWaitForTypedResponse(msgOrTypeToSend: PixelMessage | MessageType, responseType: { new (): T; }, timeoutMs?: number): Promise; private _updateStatus; protected _tagLogString(str: string): string; protected _log(msg: unknown): void; protected _warn(msg: unknown): void; protected _logArray(arr: ArrayBuffer): void; } //# sourceMappingURL=PixelConnect.d.ts.map