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.

Examples

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);
}

Functions

f
createClient(options: ClientOptions): Client

Creates a Baichuan client over the given connection streams.

Type Aliases

T
CallOptions<C extends Command> = { channel?: number; body?: CommandBody<C>; }

Options for Client.call.

T
CallReply<C extends Command> = { body: CommandBody<C>; payload: Uint8Array; }

The reply to Client.call.

T
ChannelOptions = { channel?: number; }

Which camera a request is about.

  • channel: number

    The zero-based channel number. A standalone camera is 0, the default.

T
Client = { login: (options: LoginOptions) => Promise<void>; subscribe: (options?: SubscribeOptions) => Promise<ReadableStream<AlarmEvent>>; playSiren: (options?: ChannelOptions & { times?: number; }) => Promise<void>; startSiren: (options?: ChannelOptions) => Promise<void>; stopSiren: (options?: ChannelOptions) => Promise<void>; privacyMode: (options?: ChannelOptions) => Promise<boolean>; setPrivacyMode: (options: ChannelOptions & { enabled: boolean; }) => Promise<void>; snapshot: (options?: ChannelOptions & { stream?: "main" | "sub"; }) => Promise<Uint8Array>; ptz: (options: ChannelOptions & { command: PtzCommand; speed?: number; }) => Promise<void>; ptzPresets: (options?: ChannelOptions) => Promise<PtzPreset[]>; ptzGoToPreset: (options: ChannelOptions & { id: number; }) => Promise<void>; ptzPosition: (options?: ChannelOptions) => Promise<PtzPosition>; call: <C extends Command>(
command: C,
options?: CallOptions<C>
) => Promise<CallReply<C>>
; pushes: () => ReadableStream<Push>; close: () => Promise<void>; }

A Baichuan client bound to one connection.

T
SubscribeOptions = { keepAliveMs?: number; }

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.