Baichuan messages: a header plus the bytes that follow it.

createMessage builds a request with the header fields filled in, and decryptBody turns a received body back into XML text.

Examples

Build a subscribe request and read its header

import { assertEquals } from "@std/assert";
import {
  BAICHUAN_CHANNEL,
  BAICHUAN_CMD,
  createMessage,
} from "@hertzg/reolink-api/protocol/message";

const message = createMessage({
  cmdId: BAICHUAN_CMD.SUBSCRIBE,
  channelId: BAICHUAN_CHANNEL.PUSH,
  messageId: 3,
});

assertEquals(message.header, {
  cmdId: 31,
  bodyLength: 0,
  channelId: 251,
  messageId: 3,
  status: 0,
  messageClass: 0x1464,
  payloadOffset: 0,
});

Functions

f
createMessage(options: CreateMessageOptions): BaichuanMessage

Builds a request message, filling in the header from the options.

f
decryptPayload(
message: BaichuanMessage,
aesKey: Uint8Array
): Uint8Array

Decrypts the binary payload of a received message, such as a snapshot chunk.

f
extensionXml(channel: number): string

Builds the extension XML that addresses a request to one camera channel.

Type Aliases

T
BaichuanMessage = { header: BaichuanHeader; body: Uint8Array; payload: Uint8Array; }

A Baichuan message: a header and the bytes after it, split at header.payloadOffset.

T
CreateMessageOptions = { cmdId: number; channelId: number; messageId: number; messageClass?:
BAICHUAN_MESSAGE_CLASS.LEGACY
| BAICHUAN_MESSAGE_CLASS.MODERN_WITH_OFFSET
; extension?: Uint8Array; body?: Uint8Array; }

Fields for createMessage.

Variables

v
BAICHUAN_CHANNEL: { HOST: number; PUSH: number; }

Channel ids (the header's channelId) for requests that address the device rather than one camera channel. Camera channels are 1-100, the channel number plus one.

v
BAICHUAN_CMD: { LOGIN: number; SUBSCRIBE: number; ALARM_EVENT: number; PING: number; PTZ_CONTROL: number; PTZ_PRESET: number; SNAPSHOT: number; PTZ_PRESETS: number; PTZ_POSITION: number; SIREN: number; PRIVACY_MODE: number; SET_PRIVACY_MODE: number; }

Command ids (the header's cmdId) this package sends or reads.