Reolink Baichuan client: login, then a stream of alarm events.
The client takes the readable and writable halves of a TCP connection to the camera's Baichuan port (9000 by default). It never opens, reconnects or closes the socket itself.
Stream doorbell and motion events
Stream doorbell and motion events
import { createClient } from "@hertzg/reolink-api/client"; const conn = await Deno.connect({ hostname: "192.168.1.10", port: 9000 }); const client = createClient({ readable: conn.readable, writable: conn.writable }); await client.login({ username: "admin", password: "secret" }); const events = await client.subscribe(); for await (const event of events) { console.log(event.channel, event.visitor, event.motion, event.ai); }
Creates a Baichuan client over the given connection streams.
Options for Client.call.
-
body: CommandBody<C>
The parameters to send, by element name.
-
channel: number
The zero-based channel to address. Leave it out to address the device.
The reply to Client.call.
-
body: CommandBody<C>
The reply's parameters, by element name.
-
payload: Uint8Array
Binary data after the XML, decrypted; empty for most commands.
Which camera a request is about.
-
channel: number
The zero-based channel number. A standalone camera is
0, the default.
A Baichuan client bound to one connection.
-
call: <C extends Command>() => Promise<CallReply<C>>command: C,options?: CallOptions<C>
Sends any Command and reads its reply. Needs a login.
-
close: () => Promise<void>
Stops the keepalive, ends the event stream and closes the writable. The caller still closes the socket.
-
login: (options: LoginOptions) => Promise<void>
Logs in with the modern (nonce + MD5) login and keeps the AES session key.
-
playSiren: (options?: ChannelOptions & { times?: number; }) => Promise<void>
Plays the siren a number of times, about 5 seconds each. Needs a login.
-
privacyMode: (options?: ChannelOptions) => Promise<boolean>
Reads whether privacy mode (sleep) is on. 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. -
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.
-
ptzPresets: (options?: ChannelOptions) => Promise<PtzPreset[]>
Lists the saved PTZ presets. Needs a login.
-
pushes: () => ReadableStream<Push>
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.
-
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) orsubstream. 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.
-
subscribe: (options?: SubscribeOptions) => Promise<ReadableStream<AlarmEvent>>
Subscribes to alarm pushes (cmd 31) and returns them as a stream.
The two halves of a connection to the camera's Baichuan port.
-
readable: ReadableStream<Uint8Array>
Bytes from the camera.
-
writable: WritableStream<Uint8Array>
Bytes to the camera.
Camera credentials for Client.login.
-
password: string
The camera password.
-
username: string
The camera user name.
| { name: undefined; id: number; xml: string; }
A message the camera sent unasked, from Client.pushes.
Options for Client.subscribe.
-
keepAliveMs: number
How long the connection may stay silent before the client pings the camera, in milliseconds. If a second interval passes with nothing from the camera, the event stream errors. Defaults to
30_000.
Usage
import * as mod from "client.ts";