stream<T>(): Promise<ReadableStream<T>>
Opens a streamed resource.
Resolves once the device has answered the request, so a wrong password or an unsupported device fails here, not on the first read.
Read a canned stream through a stubbed fetch
Read a canned stream through a stubbed fetch
import { assertEquals } from "@std/assert"; import { resolvesNext, spy } from "@std/testing/mock"; import { alertStream } from "./event/alert-stream.ts"; import { stream } from "./stream.ts"; const xml = "<EventNotificationAlert><dynChannelID>3</dynChannelID>" + "<dateTime>2026-10-21T20:44:39</dateTime><eventType>VMD</eventType>" + "<eventState>active</eventState></EventNotificationAlert>"; const body = `--boundary\r\nContent-Type: application/xml; charset="UTF-8"\r\n` + `Content-Length: ${xml.length}\r\n\r\n${xml}\r\n`; const fetch = spy(resolvesNext([ new Response(body, { headers: { "content-type": "multipart/mixed;boundary=boundary" } }), ])); const alerts = await stream( { baseUrl: "http://192.0.2.10", username: "admin", password: "hunter2", fetch }, alertStream, ); const [alert] = await Array.fromAsync(alerts); assertEquals(alert.channel, 3); assertEquals(alert.eventType, "VMD");
device: Device
Where the device is and how to log in.
optional
options: StreamOptions
The signal that ends the stream.
Promise<ReadableStream<T>>
A stream of decoded parts in the order the device posted them.