type alias Client

A Baichuan client bound to one connection.

Properties

login: (options: LoginOptions) => Promise<void>

Logs in with the modern (nonce + MD5) login and keeps the AES session key.

Subscribes to alarm pushes (cmd 31) and returns them as a stream.

While the stream is open the client keeps the connection alive: after keepAliveMs of silence it sends cmd 93 (or repeats cmd 31 if no event has arrived yet), and errors the stream if that gets no answer either. The stream ends when the connection ends.

playSiren: (options?: ChannelOptions & { times?: number; }) => Promise<void>

Plays the siren a number of times, about 5 seconds each. Needs a login.

startSiren: (options?: ChannelOptions) => Promise<void>

Starts the siren until Client.stopSiren. Needs a login.

stopSiren: (options?: ChannelOptions) => Promise<void>

Stops the siren, whether started or played a number of times. Needs a login.

privacyMode: (options?: ChannelOptions) => Promise<boolean>

Reads whether privacy mode (sleep) is on. Needs a login.

setPrivacyMode: (options: ChannelOptions & { enabled: boolean; }) => Promise<void>

Turns privacy mode (sleep) on or off. Needs a login.

snapshot: (options?: ChannelOptions & { stream?: "main" | "sub"; }) => Promise<Uint8Array>

Takes a JPEG snapshot of the main (default) or sub stream. Needs a login.

ptz: (options: ChannelOptions & { command: PtzCommand; speed?: number; }) => Promise<void>

Starts a PTZ move or zoom, which keeps going until PTZ_COMMAND.STOP. Needs a login.

ptzPresets: (options?: ChannelOptions) => Promise<PtzPreset[]>

Lists the saved PTZ presets. Needs a login.

ptzGoToPreset: (options: ChannelOptions & { id: number; }) => Promise<void>

Moves to a saved PTZ preset by its id. Needs a login.

ptzPosition: (options?: ChannelOptions) => Promise<PtzPosition>

Reads where the camera points now. Poll it to tell when a move has finished on cameras that push no PTZ state. Needs a login.

call: <C extends Command>(
command: C,
options?: CallOptions<C>
) => Promise<CallReply<C>>

Sends any Command and reads its reply. Needs a login.

With channel, the request addresses that channel; without it, the device itself. body holds the parameters to send, by element name; leave it out for commands that only read.

Returns every message the camera sends unasked, alarm events included, decoded by the PUSHES table when its id is known and as raw XML otherwise. The camera pushes only after Client.subscribe.

A push the table fails to read errors this stream only; the connection and the alarm event stream carry on. The stream ends with the connection.

close: () => Promise<void>

Stops the keepalive, ends the event stream and closes the writable. The caller still closes the socket.