Snapshot requests (cmd 109): a JPEG of the current frame.
The image does not come in the reply. The reply only announces its size, and the image follows in more messages with the same message id:
cmd 109, snapshotXml -> <Snap><pictureSize>48213</pictureSize></Snap> -> payload chunk, payload chunk, ... -> a message with no payload: the image is done
Each chunk may be partly AES-encrypted, see decryptPayload in
@hertzg/reolink-api/protocol/message.
Build a request and read the announced size
Build a request and read the announced size
import { assertEquals, assertStringIncludes } from "@std/assert"; import { parseSnapshotSize, snapshotXml, } from "@hertzg/reolink-api/protocol/snapshot"; assertStringIncludes( snapshotXml({ channel: 0, stream: "main" }), "<streamType>main</streamType>", ); assertEquals( parseSnapshotSize("<body><Snap><pictureSize>48213</pictureSize></Snap></body>"), 48213, );
f
parseSnapshotSize(xml: string): number
Reads the announced image size from the reply to a snapshot request.
f
snapshotXml(request: SnapshotRequest): string
Builds the body of a snapshot request.
T
SnapshotRequest = { channel: number; stream: "main" | "sub"; }
What snapshotXml asks for.
-
channel: number
The zero-based channel number.
-
stream: "main" | "sub"
mainfor full resolution,subfor the smaller stream.
Usage
import * as mod from "protocol/snapshot.ts";