function stream
stream<T>(
device: Device,
resource: Resource<T>,
options?: StreamOptions
): 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.

Examples

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

Type Parameters

The decoded value of one part.

Parameters

device: Device

Where the device is and how to log in.

resource: Resource<T>

What to stream and how to decode each part.

optional
options: StreamOptions

The signal that ends the stream.

Return Type

Promise<ReadableStream<T>>

A stream of decoded parts in the order the device posted them.

Throws

IsapiError

When the request fails: a status outside 2xx, or a failing <ResponseStatus> on any status.

Error

When the reply is neither multipart nor a <ResponseStatus>.