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.
Build a subscribe request and read its header
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, });
Builds a request message, filling in the header from the options.
Decrypts a received body into XML text.
Decrypts the binary payload of a received message, such as a snapshot chunk.
Builds the extension XML that addresses a request to one camera channel.
A Baichuan message: a header and the bytes after it, split at
header.payloadOffset.
-
body: Uint8Array
Bytes before
payloadOffset, as sent on the wire, still encrypted. -
header: BaichuanHeader
The decoded header.
bodyLengthcoversbodyandpayloadtogether. -
payload: Uint8Array
Bytes after
payloadOffset, empty for most messages.
| BAICHUAN_MESSAGE_CLASS.MODERN_WITH_OFFSET
Fields for createMessage.
-
body: Uint8Array
The already encrypted body. Defaults to empty.
-
channelId: number
Channel id, such as one of BAICHUAN_CHANNEL.
-
cmdId: number
Command id, such as one of BAICHUAN_CMD.
-
extension: Uint8Array
The already encrypted channel extension, from extensionXml. It goes before
body, andpayloadOffsetpoints past it. -
messageClass: BAICHUAN_MESSAGE_CLASS.LEGACY
| BAICHUAN_MESSAGE_CLASS.MODERN_WITH_OFFSETLEGACYonly for the nonce request. Defaults toMODERN_WITH_OFFSET. -
messageId: number
Message id the reply will echo.
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.
-
HOST: number
The device itself: login, ping.
-
PUSH: number
The push channel: subscribe and alarm pushes.
Command ids (the header's cmdId) this package sends or reads.
-
ALARM_EVENT: number
An alarm push: motion, doorbell, tamper or AI state.
-
LOGIN: number
Nonce request and login, both on the host channel.
-
PING: number
Ping, answered by the camera; keeps an idle connection open.
-
PRIVACY_MODE: number
Read the privacy mode (sleep) state.
-
PTZ_CONTROL: number
Move, zoom or stop a PTZ camera.
-
PTZ_POSITION: number
Read the current PTZ pan and tilt position.
-
PTZ_PRESET: number
Move a PTZ camera to a saved preset.
-
PTZ_PRESETS: number
List the saved PTZ presets.
-
SET_PRIVACY_MODE: number
Turn the privacy mode (sleep) on or off.
-
SIREN: number
Play or stop the siren.
-
SNAPSHOT: number
Take a JPEG snapshot, streamed back as payload.
-
SUBSCRIBE: number
Subscribe to alarm pushes.
Usage
import * as mod from "protocol/message.ts";