reactor-effect-browser 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +26 -21
  2. package/dist/BrowserMedia.d.ts +28 -0
  3. package/dist/BrowserMedia.d.ts.map +1 -0
  4. package/dist/BrowserMedia.js +56 -0
  5. package/dist/BrowserMedia.js.map +1 -0
  6. package/dist/BrowserPeer.d.ts +23 -0
  7. package/dist/BrowserPeer.d.ts.map +1 -0
  8. package/dist/BrowserPeer.js +298 -0
  9. package/dist/BrowserPeer.js.map +1 -0
  10. package/dist/index.d.ts +2 -22
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -21
  13. package/dist/index.js.map +1 -1
  14. package/package.json +12 -11
  15. package/dist/_internal/audio-packet.d.ts +0 -13
  16. package/dist/_internal/audio-packet.d.ts.map +0 -1
  17. package/dist/_internal/audio-packet.js +0 -43
  18. package/dist/_internal/audio-packet.js.map +0 -1
  19. package/dist/_internal/audio.d.ts +0 -48
  20. package/dist/_internal/audio.d.ts.map +0 -1
  21. package/dist/_internal/audio.js +0 -242
  22. package/dist/_internal/audio.js.map +0 -1
  23. package/dist/_internal/media.d.ts +0 -78
  24. package/dist/_internal/media.d.ts.map +0 -1
  25. package/dist/_internal/media.js +0 -414
  26. package/dist/_internal/media.js.map +0 -1
  27. package/dist/_internal/pcm-worklet.d.ts +0 -2
  28. package/dist/_internal/pcm-worklet.d.ts.map +0 -1
  29. package/dist/_internal/pcm-worklet.js +0 -51
  30. package/dist/_internal/pcm-worklet.js.map +0 -1
  31. package/dist/_internal/peer.d.ts +0 -30
  32. package/dist/_internal/peer.d.ts.map +0 -1
  33. package/dist/_internal/peer.js +0 -294
  34. package/dist/_internal/peer.js.map +0 -1
  35. package/dist/_internal/recording.d.ts +0 -15
  36. package/dist/_internal/recording.d.ts.map +0 -1
  37. package/dist/_internal/recording.js +0 -9
  38. package/dist/_internal/recording.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactor-effect-browser",
3
- "version": "0.7.1",
4
- "description": "Browser WebRTC host for reactor-effect-client: built-in peer connections, generation-scoped tracks, media conversion and recording",
3
+ "version": "0.8.0",
4
+ "description": "Browser WebRTC host for reactor-effect-client: the Peer port on RTCPeerConnection, and local playback of session tracks",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -18,19 +18,20 @@
18
18
  "README.md"
19
19
  ],
20
20
  "exports": {
21
- ".": {
22
- "types": "./dist/index.d.ts",
23
- "import": "./dist/index.js"
24
- }
21
+ "./package.json": "./package.json",
22
+ ".": "./dist/index.js",
23
+ "./*": "./dist/*.js",
24
+ "./internal/*": null,
25
+ "./index": null
25
26
  },
26
27
  "peerDependencies": {
27
- "effect": "^4.0.0-rc.117",
28
- "reactor-effect-client": "0.7.1"
28
+ "effect": "4.0.0-rc.117",
29
+ "reactor-effect-client": "0.8.0"
29
30
  },
30
31
  "devDependencies": {
31
- "effect": "^4.0.0-rc.117",
32
- "reactor-effect-client": "0.7.1",
33
- "reactor-effect-test-kit": "0.7.1",
32
+ "@effect/vitest": "4.0.0-rc.117",
33
+ "effect": "4.0.0-rc.117",
34
+ "reactor-effect-client": "0.8.0",
34
35
  "vitest": "5.0.0"
35
36
  },
36
37
  "scripts": {
@@ -1,13 +0,0 @@
1
- /** A Web Audio rendering-clock block, not an RTP or capture timestamp. */
2
- export interface WebAudioSample {
3
- readonly format: "f32-planar";
4
- readonly planes: readonly Float32Array<ArrayBuffer>[];
5
- readonly sampleRate: number;
6
- readonly frames: number;
7
- readonly timestampUs: number;
8
- readonly contextFrame: number;
9
- readonly skippedFrames: number;
10
- readonly clock: "audio-context-render";
11
- }
12
- export declare const decodeAudioPacket: (input: unknown, maxBytes: number) => WebAudioSample;
13
- //# sourceMappingURL=audio-packet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audio-packet.d.ts","sourceRoot":"","sources":["../../src/_internal/audio-packet.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;IACtD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;CACxC;AACD,eAAO,MAAM,iBAAiB,UAAW,OAAO,YAAY,MAAM,KAAG,cAyCpE,CAAC"}
@@ -1,43 +0,0 @@
1
- import { ReactorError } from "reactor-effect-client";
2
- import { record, finite } from "reactor-effect-client/host";
3
- export const decodeAudioPacket = (input, maxBytes) => {
4
- const p = record(input, "AudioWorklet packet");
5
- if (p.type !== "pcm")
6
- throw ReactorError.fromCode("Protocol", "unexpected AudioWorklet packet");
7
- const frames = finite(p.frames, "PCM frames");
8
- const sampleRate = finite(p.sampleRate, "sample rate");
9
- if (!Number.isSafeInteger(frames) ||
10
- frames < 1 ||
11
- frames > 16_384 ||
12
- !Number.isSafeInteger(sampleRate) ||
13
- sampleRate < 1 ||
14
- sampleRate > 384_000) {
15
- throw ReactorError.fromCode("Protocol", "invalid PCM frame count or sample rate");
16
- }
17
- const frame = finite(p.frame, "context frame"), skipped = finite(p.skipped, "skipped frames");
18
- if (!Number.isSafeInteger(frame) || frame < 0 || !Number.isSafeInteger(skipped) || skipped < 0)
19
- throw ReactorError.fromCode("Protocol", "invalid render-clock frame counter");
20
- if (!Array.isArray(p.planes) || p.planes.length < 1 || p.planes.length > 32)
21
- throw ReactorError.fromCode("Protocol", "invalid PCM channel count");
22
- if (p.planes.length * frames * 4 > maxBytes)
23
- throw ReactorError.fromCode("Overflow", "PCM sample byte bound exceeded");
24
- const planes = p.planes.map((plane) => {
25
- if (!(plane instanceof ArrayBuffer) || plane.byteLength !== frames * 4)
26
- throw ReactorError.fromCode("Protocol", "PCM plane length/type mismatch");
27
- const data = new Float32Array(plane);
28
- if (!data.every(Number.isFinite))
29
- throw ReactorError.fromCode("Protocol", "nonfinite PCM sample");
30
- return data;
31
- });
32
- return Object.freeze({
33
- format: "f32-planar",
34
- planes: Object.freeze(planes),
35
- frames,
36
- sampleRate,
37
- timestampUs: (frame * 1_000_000) / sampleRate,
38
- contextFrame: frame,
39
- skippedFrames: skipped,
40
- clock: "audio-context-render",
41
- });
42
- };
43
- //# sourceMappingURL=audio-packet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audio-packet.js","sourceRoot":"","sources":["../../src/_internal/audio-packet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAY5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAE,QAAgB,EAAkB,EAAE;IACpF,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;IAC/C,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK;QAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,gCAAgC,CAAC,CAAC;IAChG,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACvD,IACE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;QAC7B,MAAM,GAAG,CAAC;QACV,MAAM,GAAG,MAAM;QACf,CAAC,MAAM,CAA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rC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC9B,MAAM,YAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAC7B,MAAM;QACN,UAAU;QACV,WAAW,EAAE,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,UAAU;QAC7C,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,OAAO;QACtB,KAAK,EAAE,sBAAsB;KAC9B,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,48 +0,0 @@
1
- import * as Duration from "effect/Duration";
2
- import * as Effect from "effect/Effect";
3
- import * as Scope from "effect/Scope";
4
- import type * as Stream from "effect/Stream";
5
- import { ReactorError } from "reactor-effect-client";
6
- import type { WebAudioSample } from "./audio-packet.js";
7
- export type { WebAudioSample } from "./audio-packet.js";
8
- /** Call from an ordinary start click. No autoplay-policy workaround is attempted.
9
- * The scope owns this context; audio streams borrow it and own their nodes/track clones. */
10
- export interface AudioContextOptions {
11
- readonly sampleRate?: number;
12
- /**
13
- * How long resuming the context, and closing it on release, may each take; 5
14
- * seconds by default and at most 1 minute. A bare number is milliseconds.
15
- */
16
- readonly transitionTimeout?: Duration.Input | undefined;
17
- }
18
- export declare const audioContext: (options?: AudioContextOptions) => Effect.Effect<AudioContext, ReactorError, Scope.Scope>;
19
- export interface WebAudioOptions {
20
- /** A running built-in context; caller or audioContext() scope retains ownership. */
21
- readonly context: AudioContext;
22
- /** Serve dist/browser/_internal/pcm-worklet.js locally. A bundler must preserve/copy this asset. */
23
- readonly workletUrl?: string | URL;
24
- readonly maxSampleBytes?: number;
25
- /**
26
- * Each consumption owns a muted HTMLAudioElement and waits for its ordinary
27
- * play(). This deadline is separate from worklet registration and individual
28
- * PCM reads; 5 seconds by default and at most 1 minute. A bare number is
29
- * milliseconds.
30
- */
31
- readonly activationTimeout?: Duration.Input | undefined;
32
- /**
33
- * How long registering the worklet, and then each PCM read, may take; 10
34
- * seconds by default and at most 10 minutes. A bare number is milliseconds.
35
- */
36
- readonly readTimeout?: Duration.Input | undefined;
37
- }
38
- /** Window-realm PCM with OWNED muted playback activation, not a bare Web Audio tap.
39
- * Each consumption clones the borrowed source once, attaches that clone to an owned muted
40
- * HTMLAudioElement, awaits ordinary play(), and uses the same MediaStream for Web Audio.
41
- * Activation rejection/timeout is an error, not silently successful PCM. No extra play()
42
- * call is required; no autoplay policy is overridden. The caller owns the running context.
43
- * One JS output slot and one credited worklet block; skipped render frames are reported.
44
- * Closing/interrupting the stream releases the sink, clone, nodes, ports and timers.
45
- * A stopped source lease fails Disconnected; reacquire a track/stream after reconnect.
46
- * No ScriptProcessorNode, getUserMedia, device permission or native engine is used. */
47
- export declare const webAudioSamples: (source: MediaStreamTrack, options: WebAudioOptions) => Stream.Stream<WebAudioSample, ReactorError>;
48
- //# sourceMappingURL=audio.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/_internal/audio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AASrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAyBxD;4FAC4F;AAC5F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;CACzD;AACD,eAAO,MAAM,YAAY,aACd,mBAAmB,KAC3B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,CAAC,KAAK,CAsDpD,CAAC;AACL,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,oGAAoG;IACpG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;IACxD;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;CACnD;AAkBD;;;;;;;;uFAQuF;AACvF,eAAO,MAAM,eAAe,WAClB,gBAAgB,WACf,eAAe,KACvB,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAyMzC,CAAC"}
@@ -1,242 +0,0 @@
1
- import * as Duration from "effect/Duration";
2
- import * as Effect from "effect/Effect";
3
- import * as Scope from "effect/Scope";
4
- import { ReactorError } from "reactor-effect-client";
5
- import { duration, errorOf, fromOwnedReadableStream, parsed, positiveLimit, } from "reactor-effect-client/host";
6
- import { decodeAudioPacket } from "./audio-packet.js";
7
- const bounded = async (work, timeout, label, signal) => {
8
- let timer;
9
- let rejectAbort;
10
- try {
11
- return await Promise.race([
12
- work,
13
- new Promise((_, reject) => {
14
- timer = setTimeout(() => reject(ReactorError.fromCode("Timeout", label)), timeout);
15
- rejectAbort = () => reject(ReactorError.fromCode("Aborted", label));
16
- if (signal?.aborted)
17
- rejectAbort();
18
- else
19
- signal?.addEventListener("abort", rejectAbort, { once: true });
20
- }),
21
- ]);
22
- }
23
- finally {
24
- if (timer !== undefined)
25
- clearTimeout(timer);
26
- if (rejectAbort !== undefined)
27
- signal?.removeEventListener("abort", rejectAbort);
28
- }
29
- };
30
- export const audioContext = (options = {}) => Effect.gen(function* () {
31
- const timeout = yield* parsed(() => duration(options.transitionTimeout ?? "5 seconds", "audio context transition timeout", {
32
- maximum: "1 minute",
33
- }));
34
- const context = yield* Effect.acquireRelease(Effect.try({
35
- try: () => {
36
- if (typeof AudioContext !== "function" || typeof AudioWorkletNode !== "function")
37
- throw ReactorError.fromCode("UnsupportedCapability", "built-in AudioContext and AudioWorkletNode are required");
38
- return new AudioContext(options.sampleRate === undefined ? {} : { sampleRate: options.sampleRate });
39
- },
40
- catch: (e) => errorOf(e, "UnsupportedCapability"),
41
- }),
42
- // Neither browser promise can be cancelled; each deadline only stops waiting for it.
43
- (context) => Effect.tryPromise({
44
- try: () => context.close(),
45
- catch: (cause) => errorOf(cause, "Shutdown", "AudioContext.close"),
46
- }).pipe(Effect.timeout(timeout), Effect.ignore));
47
- yield* Effect.tryPromise({
48
- try: () => context.resume(),
49
- catch: (cause) => ReactorError.fromCode("UnsupportedCapability", "AudioContext resume failed; ordinary user activation is required", { detail: cause }),
50
- }).pipe(Effect.timeoutOrElse({
51
- duration: timeout,
52
- orElse: () => Effect.fail(ReactorError.fromCode("Timeout", "AudioContext resume deadline; supply user activation")),
53
- }));
54
- if (context.state !== "running")
55
- return yield* ReactorError.fromCode("UnsupportedCapability", `AudioContext is ${context.state}, not running`);
56
- return context;
57
- });
58
- // A worklet is registered once per context and URL. Failed registration is retryable, not cached success.
59
- const modules = new WeakMap();
60
- const load = (context, url) => {
61
- let cache = modules.get(context);
62
- if (cache === undefined) {
63
- cache = new Map();
64
- modules.set(context, cache);
65
- }
66
- const previous = cache.get(url);
67
- if (previous !== undefined)
68
- return previous;
69
- const task = context.audioWorklet.addModule(url, { credentials: "omit" });
70
- cache.set(url, task);
71
- task.catch(() => {
72
- cache?.delete(url);
73
- });
74
- return task;
75
- };
76
- /** Window-realm PCM with OWNED muted playback activation, not a bare Web Audio tap.
77
- * Each consumption clones the borrowed source once, attaches that clone to an owned muted
78
- * HTMLAudioElement, awaits ordinary play(), and uses the same MediaStream for Web Audio.
79
- * Activation rejection/timeout is an error, not silently successful PCM. No extra play()
80
- * call is required; no autoplay policy is overridden. The caller owns the running context.
81
- * One JS output slot and one credited worklet block; skipped render frames are reported.
82
- * Closing/interrupting the stream releases the sink, clone, nodes, ports and timers.
83
- * A stopped source lease fails Disconnected; reacquire a track/stream after reconnect.
84
- * No ScriptProcessorNode, getUserMedia, device permission or native engine is used. */
85
- export const webAudioSamples = (source, options) => fromOwnedReadableStream({
86
- evaluate: () => {
87
- // The deadlines race host promises inside the stream's callbacks, in milliseconds.
88
- const timeout = Duration.toMillis(duration(options.readTimeout ?? "10 seconds", "PCM read timeout", {
89
- maximum: "10 minutes",
90
- }));
91
- const activationTimeout = Duration.toMillis(duration(options.activationTimeout ?? "5 seconds", "PCM activation timeout", {
92
- maximum: "1 minute",
93
- }));
94
- const maxBytes = positiveLimit(options.maxSampleBytes ?? 1048576, "PCM sample bound", 64 * 1024 * 1024);
95
- const context = options.context;
96
- if (source.kind !== "audio" || source.readyState !== "live")
97
- throw ReactorError.fromCode("InvalidState", "expected a live audio track");
98
- if (typeof AudioWorkletNode !== "function" || context.audioWorklet === undefined)
99
- throw ReactorError.fromCode("UnsupportedCapability", "built-in AudioWorklet is unavailable in this realm");
100
- if (typeof document === "undefined" ||
101
- // Feature detection reads the method itself, not its deprecated overload.
102
- // oxlint-disable-next-line typescript/no-deprecated
103
- typeof document.createElement !== "function" ||
104
- typeof MediaStream !== "function")
105
- throw ReactorError.fromCode("UnsupportedCapability", "PCM activation requires a Window document and built-in HTML audio playback");
106
- if (context.state !== "running")
107
- throw ReactorError.fromCode("UnsupportedCapability", "PCM requires an explicitly resumed, running AudioContext");
108
- const url = new URL(options.workletUrl ?? new URL("./pcm-worklet.js", import.meta.url), import.meta.url);
109
- if (!/^(https?:|file:)$/.test(url.protocol))
110
- throw ReactorError.fromCode("Protocol", "serve the PCM worklet as a normal local module, not a data/blob URL");
111
- const track = source.clone(), lifetime = new AbortController();
112
- let input, node;
113
- let sink, watch;
114
- let closed = false, pending;
115
- let controller;
116
- const close = () => {
117
- if (closed)
118
- return;
119
- closed = true;
120
- lifetime.abort();
121
- if (watch !== undefined) {
122
- clearInterval(watch);
123
- watch = undefined;
124
- }
125
- source.removeEventListener("ended", ended);
126
- track.removeEventListener("ended", ended);
127
- context.removeEventListener("statechange", state);
128
- // The element was created here and is never offered to another owner.
129
- if (sink !== undefined) {
130
- sink.pause();
131
- sink.srcObject = null;
132
- }
133
- pending?.reject(ReactorError.fromCode("Aborted", "PCM reader closed"));
134
- pending = undefined;
135
- input?.disconnect();
136
- if (node !== undefined) {
137
- node.port.onmessage = null;
138
- node.port.onmessageerror = null;
139
- node.onprocessorerror = null;
140
- node.port.postMessage("stop");
141
- node.port.close();
142
- node.disconnect();
143
- }
144
- track.stop();
145
- };
146
- const fail = (error) => {
147
- if (!closed) {
148
- controller?.error(error);
149
- close();
150
- }
151
- };
152
- const ended = () => fail(ReactorError.fromCode("Disconnected", "PCM track ended"));
153
- const state = () => {
154
- if (context.state !== "running")
155
- fail(ReactorError.fromCode("Disconnected", `PCM context ${context.state}`));
156
- };
157
- const live = () => {
158
- if (source.readyState !== "live" || track.readyState !== "live")
159
- ended();
160
- state();
161
- return !closed;
162
- };
163
- const initialize = async () => {
164
- source.addEventListener("ended", ended);
165
- track.addEventListener("ended", ended);
166
- context.addEventListener("statechange", state);
167
- // MediaStreamTrack.stop() sets readyState without dispatching ended, and does not
168
- // stop its clones. Session reconnect stops borrowed leases this way. Inspect the
169
- // lease on each read/message and every 100ms even while a consumer is stalled.
170
- // Timer throttling can delay this check; it is not a wall-clock termination proof.
171
- watch = setInterval(live, 100);
172
- if (!live())
173
- return;
174
- const stream = new MediaStream([track]);
175
- sink = document.createElement("audio");
176
- sink.muted = true;
177
- sink.srcObject = stream;
178
- try {
179
- await bounded(sink.play(), activationTimeout, "PCM playback activation deadline; supply normal user activation", lifetime.signal);
180
- }
181
- catch (error) {
182
- throw errorOf(error, "UnsupportedCapability", "PCM HTMLAudioElement.play activation");
183
- }
184
- if (!live())
185
- return;
186
- await bounded(load(context, url.href), timeout, "AudioWorklet module deadline", lifetime.signal);
187
- // Cancellation while addModule is pending must not create a late graph.
188
- if (!live())
189
- return;
190
- input = context.createMediaStreamSource(stream);
191
- node = new AudioWorkletNode(context, "reactor-pcm-tap-v1", {
192
- numberOfInputs: 1,
193
- numberOfOutputs: 1,
194
- outputChannelCount: [1],
195
- });
196
- node.port.onmessage = (event) => {
197
- if (!live())
198
- return;
199
- try {
200
- if (pending === undefined)
201
- throw ReactorError.fromCode("Protocol", "unsolicited PCM block without a read credit");
202
- const sample = decodeAudioPacket(event.data, maxBytes), waiter = pending;
203
- pending = undefined;
204
- waiter.resolve(sample);
205
- }
206
- catch (error) {
207
- fail(errorOf(error, "Protocol", "PCM block"));
208
- }
209
- };
210
- node.port.onmessageerror = () => fail(ReactorError.fromCode("Protocol", "PCM transfer could not be deserialized"));
211
- node.onprocessorerror = () => fail(ReactorError.fromCode("UnsupportedCapability", "PCM AudioWorklet processor failed"));
212
- input.connect(node);
213
- node.connect(context.destination);
214
- };
215
- let ready;
216
- return new ReadableStream({
217
- start(c) {
218
- controller = c;
219
- ready = initialize().catch((error) => fail(errorOf(error, "UnsupportedCapability", "open PCM")));
220
- },
221
- async pull(c) {
222
- try {
223
- await ready;
224
- if (!live())
225
- return;
226
- const sample = await bounded(new Promise((resolve, reject) => {
227
- pending = { resolve, reject };
228
- node?.port.postMessage("pull");
229
- }), timeout, "PCM read deadline", lifetime.signal);
230
- if (live())
231
- c.enqueue(sample);
232
- }
233
- catch (error) {
234
- fail(errorOf(error, "Protocol", "PCM read"));
235
- }
236
- },
237
- cancel: close,
238
- }, { highWaterMark: 1 });
239
- },
240
- onError: (error) => errorOf(error, "UnsupportedCapability", "webAudioSamples"),
241
- });
242
- //# sourceMappingURL=audio.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audio.js","sourceRoot":"","sources":["../../src/_internal/audio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,QAAQ,EACR,OAAO,EACP,uBAAuB,EACvB,MAAM,EACN,aAAa,GACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItD,MAAM,OAAO,GAAG,KAAK,EACnB,IAAgB,EAChB,OAAe,EACf,KAAa,EACb,MAAoB,EACR,EAAE;IACd,IAAI,KAAgD,CAAC;IACrD,IAAI,WAAqC,CAAC;IAC1C,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,IAAI;YACJ,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;gBAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBACnF,WAAW,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;gBACpE,IAAI,MAAM,EAAE,OAAO;oBAAE,WAAW,EAAE,CAAC;;oBAC9B,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,KAAK,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ACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,CAAC;CAC/E,CAAC,CAAC"}
@@ -1,78 +0,0 @@
1
- export { audioContext, webAudioSamples } from "./audio.js";
2
- export type { AudioContextOptions, WebAudioOptions, WebAudioSample } from "./audio.js";
3
- import * as Duration from "effect/Duration";
4
- import * as Effect from "effect/Effect";
5
- import * as Stream from "effect/Stream";
6
- import type * as Scope from "effect/Scope";
7
- import { ReactorError } from "reactor-effect-client";
8
- export interface MediaOptions {
9
- readonly maxSampleBytes?: number;
10
- /**
11
- * How long reading and copying each sample may take; 10 seconds by default
12
- * and at most 10 minutes. A bare number is milliseconds.
13
- */
14
- readonly readTimeout?: Duration.Input | undefined;
15
- }
16
- export interface VideoSample {
17
- readonly format: "RGBA";
18
- readonly width: number;
19
- readonly height: number;
20
- readonly data: Uint8Array<ArrayBuffer>;
21
- readonly timestampUs: number;
22
- readonly clock: "video-track-processor";
23
- }
24
- export interface AudioSample {
25
- readonly format: "f32-planar";
26
- readonly planes: readonly Float32Array<ArrayBuffer>[];
27
- readonly sampleRate: number;
28
- readonly frames: number;
29
- readonly timestampUs: number;
30
- readonly clock: "audio-track-processor";
31
- }
32
- /** Presence is only a hint. Acquiring a processor and copying a sample tests the capability. */
33
- export declare const mediaFacilities: () => Readonly<Record<string, boolean>>;
34
- /** Acquisition, native output and copied output remain separate diagnostic facts. */
35
- export interface NativeMediaFailure {
36
- readonly phase: string;
37
- readonly realm: "Window" | "other";
38
- readonly processorConstructed: boolean;
39
- readonly readerAcquired: boolean;
40
- readonly nativeSamplesRead: number;
41
- readonly copiedSamples: number;
42
- readonly source: Readonly<{
43
- kind: string;
44
- readyState: MediaStreamTrackState;
45
- enabled: boolean;
46
- muted: boolean;
47
- }>;
48
- readonly ownedTrack: Readonly<{
49
- readyState: MediaStreamTrackState;
50
- }>;
51
- readonly nativeErrorName?: string;
52
- readonly cleanupFailures: readonly Readonly<{
53
- phase: string;
54
- message: string;
55
- }>[];
56
- }
57
- /** One native queue slot and one demand-driven copy. No borrowed frame escapes. */
58
- export declare const videoFrames: (track: MediaStreamTrack, options?: MediaOptions) => Stream.Stream<VideoSample, ReactorError>;
59
- /** Optional native AudioData in the current realm. No worker or Web Audio fallback. */
60
- export declare const audioSamples: (track: MediaStreamTrack, options?: MediaOptions) => Stream.Stream<AudioSample, ReactorError>;
61
- /** Scoped local playback. Starting playback does not establish audience output. */
62
- export interface PlayOptions {
63
- /**
64
- * How long starting playback may take; 10 seconds by default and at most 10
65
- * minutes. A bare number is milliseconds.
66
- */
67
- readonly playTimeout?: Duration.Input | undefined;
68
- }
69
- export declare const play: (track: MediaStreamTrack, element: HTMLMediaElement, options?: PlayOptions) => Effect.Effect<void, ReactorError, Scope.Scope>;
70
- export interface Presentation {
71
- readonly callbackTimeMs: number;
72
- readonly mediaTimeSeconds: number;
73
- readonly presentedFrames: number;
74
- readonly width: number;
75
- readonly height: number;
76
- }
77
- export declare const nextPresentation: (element: HTMLVideoElement, timeoutMs?: number) => Effect.Effect<Presentation, ReactorError>;
78
- //# sourceMappingURL=media.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/_internal/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,cAAc,CAAC,EA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