reactor-effect-browser 0.0.0-reserved.0 → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Reactor Technologies, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,15 @@
1
+ reactor-effect-browser
2
+
3
+ This independent SDK is not an official Reactor SDK.
4
+
5
+ The browser-media implementation incorporates the user-supplied
6
+ reactor-effect-client reference source. Protocol material, the canonical
7
+ session implementation and their upstream notices are distributed with the
8
+ reactor-effect-client package this host depends on.
9
+
10
+ Transport uses the browser's built-in RTCPeerConnection and media tracks; no
11
+ WebRTC engine is shipped by this package.
12
+
13
+ Effect is MIT-licensed. The package declares Effect as a peer dependency; its
14
+ license is retained in notices/effect-LICENSE. Development tooling and
15
+ node_modules are excluded from the npm package.
package/README.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # reactor-effect-browser
2
2
 
3
- Namespace-only bootstrap for npm trusted publishing from [mannyc2/reactor-effect-client](https://github.com/mannyc2/reactor-effect-client).
3
+ Browser WebRTC host for [`reactor-effect-client`](https://www.npmjs.com/package/reactor-effect-client). It selects the built-in `RTCPeerConnection` and browser media tracks as the transport for the canonical `Session`, and exposes generation-scoped tracks, track-to-frame/audio conversion, and recording helpers.
4
4
 
5
- This package contains no SDK, executable code, scripts, or dependencies. Wait for the qualified SDK release before installing.
5
+ This is not an official Reactor SDK.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install reactor-effect-client reactor-effect-browser effect@4.0.0-rc.115
11
+ ```
12
+
13
+ `reactor-effect-client` and Effect `4.0.0-rc.115` are exact peer dependencies. The package needs a secure context with WebRTC and Web Crypto. It has no Node dependency: its declarations compile with DOM types and without `@types/node`, and the workspace's installed-package check bundles it for the browser and runs that bundle without the Node `Buffer` global.
14
+
15
+ ## Usage
16
+
17
+ `Browser.make(configuration)` constructs the canonical factory with the browser peer selected; `Browser.layer` supplies the `PeerFactory` for `Reactor.layer()`. Constructing a factory makes no allocation. Effect HTTP and crypto services remain explicit.
18
+
19
+ ```ts
20
+ import { Effect } from "effect";
21
+ import * as Browser from "reactor-effect-browser";
22
+
23
+ const useTrack = Effect.scoped(
24
+ Effect.gen(function* () {
25
+ const client = yield* Browser.make({ apiUrl: "https://api.reactor.inc" });
26
+ const session = yield* client.createConnected({ model: "your-model" });
27
+ const media = yield* Browser.media(session);
28
+ return yield* media.track("main_video");
29
+ }),
30
+ );
31
+ ```
32
+
33
+ `Browser.media(session)` obtains the negotiated generation; `media.track(name)` acquires a scoped `MediaStreamTrack`, and `media.publish(name, track)` publishes through that generation. Media values stay bound to the generation that negotiated them. A reconnect creates a new generation; existing readers end or fail with their source, and applications obtain the new generation explicitly.
34
+
35
+ The entry point also exports `videoFrames`, `audioSamples`, `webAudioSamples`, `audioContext`, `play`, `nextPresentation` and the `Recording` namespace, whose `downloadClip` transfers a prepared recording within a caller wall deadline.
36
+
37
+ If the host lacks `RTCPeerConnection`, `Browser.make` fails with `UnsupportedHost` before any coordinator request is made.
38
+
39
+ ## Development
40
+
41
+ This package is built and tested from the workspace root; see the repository [CONTRIBUTING](https://github.com/mannyc2/reactor-effect-client/blob/main/CONTRIBUTING.md). Its tests are simulated-host policy tests: they do not establish browser WebRTC or codec support. Real Chrome interoperability with the native host is exercised by the workspace's `integration` project.
42
+
43
+ ## License
44
+
45
+ Apache-2.0. See [NOTICE](./NOTICE) and [`notices/`](./notices/).
@@ -0,0 +1,13 @@
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
@@ -0,0 +1 @@
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,cAwCpE,CAAC"}
@@ -0,0 +1,43 @@
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 new ReactorError("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 new ReactorError("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 new ReactorError("Protocol", "invalid render-clock frame counter");
20
+ if (!Array.isArray(p.planes) || p.planes.length < 1 || p.planes.length > 32)
21
+ throw new ReactorError("Protocol", "invalid PCM channel count");
22
+ if (p.planes.length * frames * 4 > maxBytes)
23
+ throw new ReactorError("Overflow", "PCM sample byte bound exceeded");
24
+ const planes = p.planes.map((plane) => {
25
+ if (!(plane instanceof ArrayBuffer) || plane.byteLength !== frames * 4)
26
+ throw new ReactorError("Protocol", "PCM plane length/type mismatch");
27
+ const data = new Float32Array(plane);
28
+ if (!data.every(Number.isFinite))
29
+ throw new ReactorError("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
@@ -0,0 +1 @@
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,IAAI,YAAY,CAAC,UAAU,EAAE,gCAAgC,CAAC,CAAC;IAC3F,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,aAAa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AC,UAAU,EAAE,gCAAgC,CAAC,CAAC;QACvE,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;YAAE,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC;QAC7F,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"}
@@ -0,0 +1,34 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Scope from "effect/Scope";
3
+ import type * as Stream from "effect/Stream";
4
+ import { ReactorError } from "reactor-effect-client";
5
+ import type { WebAudioSample } from "./audio-packet.js";
6
+ export type { WebAudioSample } from "./audio-packet.js";
7
+ /** Call from an ordinary start click. No autoplay-policy workaround is attempted.
8
+ * The scope owns this context; audio streams borrow it and own their nodes/track clones. */
9
+ export declare const audioContext: (options?: {
10
+ readonly sampleRate?: number;
11
+ readonly timeoutMs?: number;
12
+ }) => Effect.Effect<AudioContext, ReactorError, Scope.Scope>;
13
+ export interface WebAudioOptions {
14
+ /** A running built-in context; caller or audioContext() scope retains ownership. */
15
+ readonly context: AudioContext;
16
+ /** Serve dist/browser/_internal/pcm-worklet.js locally. A bundler must preserve/copy this asset. */
17
+ readonly workletUrl?: string | URL;
18
+ readonly maxSampleBytes?: number;
19
+ /** Each consumption owns a muted HTMLAudioElement and waits for its ordinary play().
20
+ * This deadline is separate from worklet registration and individual PCM reads. */
21
+ readonly activationTimeoutMs?: number;
22
+ readonly readTimeoutMs?: number;
23
+ }
24
+ /** Window-realm PCM with OWNED muted playback activation, not a bare Web Audio tap.
25
+ * Each consumption clones the borrowed source once, attaches that clone to an owned muted
26
+ * HTMLAudioElement, awaits ordinary play(), and uses the same MediaStream for Web Audio.
27
+ * Activation rejection/timeout is an error, not silently successful PCM. No extra play()
28
+ * call is required; no autoplay policy is overridden. The caller owns the running context.
29
+ * One JS output slot and one credited worklet block; skipped render frames are reported.
30
+ * Closing/interrupting the stream releases the sink, clone, nodes, ports and timers.
31
+ * A stopped source lease fails Disconnected; reacquire a track/stream after reconnect.
32
+ * No ScriptProcessorNode, getUserMedia, device permission or native engine is used. */
33
+ export declare const webAudioSamples: (source: MediaStreamTrack, options: WebAudioOptions) => Stream.Stream<WebAudioSample, ReactorError>;
34
+ //# sourceMappingURL=audio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/_internal/audio.ts"],"names":[],"mappings":"AAAA,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;AAGrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAyBxD;4FAC4F;AAC5F,eAAO,MAAM,YAAY,aACd;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,KACrE,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,CAAC,KAAK,CAgDpD,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;uFACmF;IACnF,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAkBD;;;;;;;;uFAQuF;AACvF,eAAO,MAAM,eAAe,WAClB,gBAAgB,WACf,eAAe,KACvB,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CA+LzC,CAAC"}
@@ -0,0 +1,234 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Scope from "effect/Scope";
3
+ import { ReactorError } from "reactor-effect-client";
4
+ import { errorOf, fromOwnedReadableStream, positiveLimit } from "reactor-effect-client/host";
5
+ import { decodeAudioPacket } from "./audio-packet.js";
6
+ const bounded = async (work, timeout, label, signal) => {
7
+ let timer;
8
+ let rejectAbort;
9
+ try {
10
+ return await Promise.race([
11
+ work,
12
+ new Promise((_, reject) => {
13
+ timer = setTimeout(() => reject(new ReactorError("Timeout", label)), timeout);
14
+ rejectAbort = () => reject(new ReactorError("Aborted", label));
15
+ if (signal?.aborted)
16
+ rejectAbort();
17
+ else
18
+ signal?.addEventListener("abort", rejectAbort, { once: true });
19
+ }),
20
+ ]);
21
+ }
22
+ finally {
23
+ if (timer !== undefined)
24
+ clearTimeout(timer);
25
+ if (rejectAbort !== undefined)
26
+ signal?.removeEventListener("abort", rejectAbort);
27
+ }
28
+ };
29
+ /** Call from an ordinary start click. No autoplay-policy workaround is attempted.
30
+ * The scope owns this context; audio streams borrow it and own their nodes/track clones. */
31
+ export const audioContext = (options = {}) => Effect.gen(function* () {
32
+ const timeout = yield* Effect.try({
33
+ try: () => positiveLimit(options.timeoutMs ?? 5000, "audio context timeout", 60000),
34
+ catch: errorOf,
35
+ });
36
+ const context = yield* Effect.acquireRelease(Effect.try({
37
+ try: () => {
38
+ if (typeof AudioContext !== "function" || typeof AudioWorkletNode !== "function")
39
+ throw new ReactorError("UnsupportedCapability", "built-in AudioContext and AudioWorkletNode are required");
40
+ return new AudioContext(options.sampleRate === undefined ? {} : { sampleRate: options.sampleRate });
41
+ },
42
+ catch: (e) => errorOf(e, "UnsupportedCapability"),
43
+ }), (context) => Effect.tryPromise({
44
+ try: () => bounded(context.close(), timeout, "AudioContext close deadline"),
45
+ catch: errorOf,
46
+ }).pipe(Effect.ignore));
47
+ yield* Effect.tryPromise({
48
+ try: (signal) => bounded(context.resume(), timeout, "AudioContext resume deadline; supply user activation", signal),
49
+ catch: (cause) => cause instanceof ReactorError
50
+ ? cause
51
+ : new ReactorError("UnsupportedCapability", "AudioContext resume failed; ordinary user activation is required", { detail: cause }),
52
+ });
53
+ if (context.state !== "running")
54
+ return yield* Effect.fail(new ReactorError("UnsupportedCapability", `AudioContext is ${context.state}, not running`));
55
+ return context;
56
+ });
57
+ // A worklet is registered once per context and URL. Failed registration is retryable, not cached success.
58
+ const modules = new WeakMap();
59
+ const load = (context, url) => {
60
+ let cache = modules.get(context);
61
+ if (cache === undefined) {
62
+ cache = new Map();
63
+ modules.set(context, cache);
64
+ }
65
+ const previous = cache.get(url);
66
+ if (previous !== undefined)
67
+ return previous;
68
+ const task = context.audioWorklet.addModule(url, { credentials: "omit" });
69
+ cache.set(url, task);
70
+ task.catch(() => {
71
+ cache?.delete(url);
72
+ });
73
+ return task;
74
+ };
75
+ /** Window-realm PCM with OWNED muted playback activation, not a bare Web Audio tap.
76
+ * Each consumption clones the borrowed source once, attaches that clone to an owned muted
77
+ * HTMLAudioElement, awaits ordinary play(), and uses the same MediaStream for Web Audio.
78
+ * Activation rejection/timeout is an error, not silently successful PCM. No extra play()
79
+ * call is required; no autoplay policy is overridden. The caller owns the running context.
80
+ * One JS output slot and one credited worklet block; skipped render frames are reported.
81
+ * Closing/interrupting the stream releases the sink, clone, nodes, ports and timers.
82
+ * A stopped source lease fails Disconnected; reacquire a track/stream after reconnect.
83
+ * No ScriptProcessorNode, getUserMedia, device permission or native engine is used. */
84
+ export const webAudioSamples = (source, options) => fromOwnedReadableStream({
85
+ evaluate: () => {
86
+ const timeout = positiveLimit(options.readTimeoutMs ?? 10000, "PCM read timeout", 600000);
87
+ const activationTimeout = positiveLimit(options.activationTimeoutMs ?? 5000, "PCM activation timeout", 60000);
88
+ const maxBytes = positiveLimit(options.maxSampleBytes ?? 1048576, "PCM sample bound", 64 * 1024 * 1024);
89
+ const context = options.context;
90
+ if (source.kind !== "audio" || source.readyState !== "live")
91
+ throw new ReactorError("InvalidState", "expected a live audio track");
92
+ if (typeof AudioWorkletNode !== "function" || context.audioWorklet === undefined)
93
+ throw new ReactorError("UnsupportedCapability", "built-in AudioWorklet is unavailable in this realm");
94
+ if (typeof document === "undefined" ||
95
+ typeof document.createElement !== "function" ||
96
+ typeof MediaStream !== "function")
97
+ throw new ReactorError("UnsupportedCapability", "PCM activation requires a Window document and built-in HTML audio playback");
98
+ if (context.state !== "running")
99
+ throw new ReactorError("UnsupportedCapability", "PCM requires an explicitly resumed, running AudioContext");
100
+ const url = new URL(options.workletUrl ?? new URL("./pcm-worklet.js", import.meta.url), import.meta.url);
101
+ if (!/^(https?:|file:)$/.test(url.protocol))
102
+ throw new ReactorError("Protocol", "serve the PCM worklet as a normal local module, not a data/blob URL");
103
+ const track = source.clone(), lifetime = new AbortController();
104
+ let input, node;
105
+ let sink, watch;
106
+ let closed = false, pending;
107
+ let controller;
108
+ const close = () => {
109
+ if (closed)
110
+ return;
111
+ closed = true;
112
+ lifetime.abort();
113
+ if (watch !== undefined) {
114
+ clearInterval(watch);
115
+ watch = undefined;
116
+ }
117
+ source.removeEventListener("ended", ended);
118
+ track.removeEventListener("ended", ended);
119
+ context.removeEventListener("statechange", state);
120
+ // The element was created here and is never offered to another owner.
121
+ if (sink !== undefined) {
122
+ sink.pause();
123
+ sink.srcObject = null;
124
+ }
125
+ pending?.reject(new ReactorError("Aborted", "PCM reader closed"));
126
+ pending = undefined;
127
+ input?.disconnect();
128
+ if (node !== undefined) {
129
+ node.port.onmessage = null;
130
+ node.port.onmessageerror = null;
131
+ node.onprocessorerror = null;
132
+ node.port.postMessage("stop");
133
+ node.port.close();
134
+ node.disconnect();
135
+ }
136
+ track.stop();
137
+ };
138
+ const fail = (error) => {
139
+ if (!closed) {
140
+ controller?.error(error);
141
+ close();
142
+ }
143
+ };
144
+ const ended = () => fail(new ReactorError("Disconnected", "PCM track ended"));
145
+ const state = () => {
146
+ if (context.state !== "running")
147
+ fail(new ReactorError("Disconnected", `PCM context ${context.state}`));
148
+ };
149
+ const live = () => {
150
+ if (source.readyState !== "live" || track.readyState !== "live")
151
+ ended();
152
+ state();
153
+ return !closed;
154
+ };
155
+ const initialize = async () => {
156
+ source.addEventListener("ended", ended);
157
+ track.addEventListener("ended", ended);
158
+ context.addEventListener("statechange", state);
159
+ // MediaStreamTrack.stop() sets readyState without dispatching ended, and does not
160
+ // stop its clones. Session reconnect stops borrowed leases this way. Inspect the
161
+ // lease on each read/message and every 100ms even while a consumer is stalled.
162
+ // Timer throttling can delay this check; it is not a wall-clock termination proof.
163
+ watch = setInterval(live, 100);
164
+ if (!live())
165
+ return;
166
+ const stream = new MediaStream([track]);
167
+ sink = document.createElement("audio");
168
+ sink.muted = true;
169
+ sink.srcObject = stream;
170
+ try {
171
+ await bounded(sink.play(), activationTimeout, "PCM playback activation deadline; supply normal user activation", lifetime.signal);
172
+ }
173
+ catch (error) {
174
+ throw errorOf(error, "UnsupportedCapability", "PCM HTMLAudioElement.play activation");
175
+ }
176
+ if (!live())
177
+ return;
178
+ await bounded(load(context, url.href), timeout, "AudioWorklet module deadline", lifetime.signal);
179
+ // Cancellation while addModule is pending must not create a late graph.
180
+ if (!live())
181
+ return;
182
+ input = context.createMediaStreamSource(stream);
183
+ node = new AudioWorkletNode(context, "reactor-pcm-tap-v1", {
184
+ numberOfInputs: 1,
185
+ numberOfOutputs: 1,
186
+ outputChannelCount: [1],
187
+ });
188
+ node.port.onmessage = (event) => {
189
+ if (!live())
190
+ return;
191
+ try {
192
+ if (pending === undefined)
193
+ throw new ReactorError("Protocol", "unsolicited PCM block without a read credit");
194
+ const sample = decodeAudioPacket(event.data, maxBytes), waiter = pending;
195
+ pending = undefined;
196
+ waiter.resolve(sample);
197
+ }
198
+ catch (error) {
199
+ fail(errorOf(error));
200
+ }
201
+ };
202
+ node.port.onmessageerror = () => fail(new ReactorError("Protocol", "PCM transfer could not be deserialized"));
203
+ node.onprocessorerror = () => fail(new ReactorError("UnsupportedCapability", "PCM AudioWorklet processor failed"));
204
+ input.connect(node);
205
+ node.connect(context.destination);
206
+ };
207
+ let ready;
208
+ return new ReadableStream({
209
+ start(c) {
210
+ controller = c;
211
+ ready = initialize().catch((error) => fail(errorOf(error, "UnsupportedCapability", "open PCM")));
212
+ },
213
+ async pull(c) {
214
+ try {
215
+ await ready;
216
+ if (!live())
217
+ return;
218
+ const sample = await bounded(new Promise((resolve, reject) => {
219
+ pending = { resolve, reject };
220
+ node?.port.postMessage("pull");
221
+ }), timeout, "PCM read deadline", lifetime.signal);
222
+ if (live())
223
+ c.enqueue(sample);
224
+ }
225
+ catch (error) {
226
+ fail(errorOf(error));
227
+ }
228
+ },
229
+ cancel: close,
230
+ }, { highWaterMark: 1 });
231
+ },
232
+ onError: (error) => errorOf(error, "UnsupportedCapability", "webAudioSamples"),
233
+ });
234
+ //# sourceMappingURL=audio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio.js","sourceRoot":"","sources":["../../src/_internal/audio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,iBAA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