reactor-effect-browser 0.2.0 → 0.3.0-rc.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/README.md +12 -5
- package/dist/_internal/audio-packet.d.ts.map +1 -1
- package/dist/_internal/audio-packet.js +7 -7
- package/dist/_internal/audio-packet.js.map +1 -1
- package/dist/_internal/audio.d.ts +27 -7
- package/dist/_internal/audio.d.ts.map +1 -1
- package/dist/_internal/audio.js +43 -35
- package/dist/_internal/audio.js.map +1 -1
- package/dist/_internal/media.d.ts +17 -3
- package/dist/_internal/media.d.ts.map +1 -1
- package/dist/_internal/media.js +45 -40
- package/dist/_internal/media.js.map +1 -1
- package/dist/_internal/peer.d.ts +1 -1
- package/dist/_internal/peer.d.ts.map +1 -1
- package/dist/_internal/peer.js +24 -24
- package/dist/_internal/peer.js.map +1 -1
- package/dist/_internal/recording.d.ts +13 -21
- package/dist/_internal/recording.d.ts.map +1 -1
- package/dist/_internal/recording.js +8 -109
- package/dist/_internal/recording.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -14,15 +14,20 @@ npm install reactor-effect-client reactor-effect-browser effect@4.0.0-rc.115
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
-
`Browser.
|
|
17
|
+
`Browser.layer` supplies the `PeerFactory` for `Reactor.layer()`. Constructing a factory makes no allocation. Effect HTTP and crypto services remain explicit.
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
|
-
import { Effect } from "effect";
|
|
20
|
+
import { Effect, Layer } from "effect";
|
|
21
|
+
import * as Reactor from "reactor-effect-client";
|
|
21
22
|
import * as Browser from "reactor-effect-browser";
|
|
22
23
|
|
|
24
|
+
const clientLayer = Reactor.layer({ apiUrl: "https://api.reactor.inc" }).pipe(
|
|
25
|
+
Layer.provide(Layer.mergeAll(Reactor.FetchHttp.layer, Browser.layer)),
|
|
26
|
+
);
|
|
27
|
+
|
|
23
28
|
const useTrack = Effect.scoped(
|
|
24
29
|
Effect.gen(function* () {
|
|
25
|
-
const client = yield*
|
|
30
|
+
const client = yield* Reactor.Client;
|
|
26
31
|
const session = yield* client.createConnected({ model: "your-model" });
|
|
27
32
|
const media = yield* Browser.media(session);
|
|
28
33
|
return yield* media.track("main_video");
|
|
@@ -30,11 +35,13 @@ const useTrack = Effect.scoped(
|
|
|
30
35
|
);
|
|
31
36
|
```
|
|
32
37
|
|
|
38
|
+
The application also provides Effect's `Crypto` service, backed by Web Crypto.
|
|
39
|
+
|
|
33
40
|
`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
41
|
|
|
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.
|
|
42
|
+
The entry point also exports `videoFrames`, `audioSamples`, `webAudioSamples`, `audioContext`, `play`, `nextPresentation` and the `Recording` namespace, whose `downloadClip(coordinator, clip, options)` transfers a prepared recording within a caller wall deadline through the portable `Coordinator.Client` from `Coordinator.make()`; it is the same operation as `coordinator.downloadClip(clip, options)`.
|
|
36
43
|
|
|
37
|
-
If the host lacks `RTCPeerConnection`, `Browser.
|
|
44
|
+
If the host lacks `RTCPeerConnection` or `MediaStream`, building `Browser.layer` fails with `UnsupportedHost`, before any coordinator request can be made.
|
|
38
45
|
|
|
39
46
|
## Development
|
|
40
47
|
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -3,7 +3,7 @@ import { record, finite } from "reactor-effect-client/host";
|
|
|
3
3
|
export const decodeAudioPacket = (input, maxBytes) => {
|
|
4
4
|
const p = record(input, "AudioWorklet packet");
|
|
5
5
|
if (p.type !== "pcm")
|
|
6
|
-
throw
|
|
6
|
+
throw ReactorError.fromCode("Protocol", "unexpected AudioWorklet packet");
|
|
7
7
|
const frames = finite(p.frames, "PCM frames");
|
|
8
8
|
const sampleRate = finite(p.sampleRate, "sample rate");
|
|
9
9
|
if (!Number.isSafeInteger(frames) ||
|
|
@@ -12,21 +12,21 @@ export const decodeAudioPacket = (input, maxBytes) => {
|
|
|
12
12
|
!Number.isSafeInteger(sampleRate) ||
|
|
13
13
|
sampleRate < 1 ||
|
|
14
14
|
sampleRate > 384_000) {
|
|
15
|
-
throw
|
|
15
|
+
throw ReactorError.fromCode("Protocol", "invalid PCM frame count or sample rate");
|
|
16
16
|
}
|
|
17
17
|
const frame = finite(p.frame, "context frame"), skipped = finite(p.skipped, "skipped frames");
|
|
18
18
|
if (!Number.isSafeInteger(frame) || frame < 0 || !Number.isSafeInteger(skipped) || skipped < 0)
|
|
19
|
-
throw
|
|
19
|
+
throw ReactorError.fromCode("Protocol", "invalid render-clock frame counter");
|
|
20
20
|
if (!Array.isArray(p.planes) || p.planes.length < 1 || p.planes.length > 32)
|
|
21
|
-
throw
|
|
21
|
+
throw ReactorError.fromCode("Protocol", "invalid PCM channel count");
|
|
22
22
|
if (p.planes.length * frames * 4 > maxBytes)
|
|
23
|
-
throw
|
|
23
|
+
throw ReactorError.fromCode("Overflow", "PCM sample byte bound exceeded");
|
|
24
24
|
const planes = p.planes.map((plane) => {
|
|
25
25
|
if (!(plane instanceof ArrayBuffer) || plane.byteLength !== frames * 4)
|
|
26
|
-
throw
|
|
26
|
+
throw ReactorError.fromCode("Protocol", "PCM plane length/type mismatch");
|
|
27
27
|
const data = new Float32Array(plane);
|
|
28
28
|
if (!data.every(Number.isFinite))
|
|
29
|
-
throw
|
|
29
|
+
throw ReactorError.fromCode("Protocol", "nonfinite PCM sample");
|
|
30
30
|
return data;
|
|
31
31
|
});
|
|
32
32
|
return Object.freeze({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-packet.js","sourceRoot":"","sources":["../../src/_internal/audio-pack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;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,3 +1,4 @@
|
|
|
1
|
+
import * as Duration from "effect/Duration";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import * as Scope from "effect/Scope";
|
|
3
4
|
import type * as Stream from "effect/Stream";
|
|
@@ -6,20 +7,39 @@ import type { WebAudioSample } from "./audio-packet.js";
|
|
|
6
7
|
export type { WebAudioSample } from "./audio-packet.js";
|
|
7
8
|
/** Call from an ordinary start click. No autoplay-policy workaround is attempted.
|
|
8
9
|
* The scope owns this context; audio streams borrow it and own their nodes/track clones. */
|
|
9
|
-
export
|
|
10
|
+
export interface AudioContextOptions {
|
|
10
11
|
readonly sampleRate?: number;
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
/** @deprecated Removed in 0.3.0: use `transitionTimeout` (a bare number is milliseconds). */
|
|
18
|
+
readonly timeoutMs?: never;
|
|
19
|
+
}
|
|
20
|
+
export declare const audioContext: (options?: AudioContextOptions) => Effect.Effect<AudioContext, ReactorError, Scope.Scope>;
|
|
13
21
|
export interface WebAudioOptions {
|
|
14
22
|
/** A running built-in context; caller or audioContext() scope retains ownership. */
|
|
15
23
|
readonly context: AudioContext;
|
|
16
24
|
/** Serve dist/browser/_internal/pcm-worklet.js locally. A bundler must preserve/copy this asset. */
|
|
17
25
|
readonly workletUrl?: string | URL;
|
|
18
26
|
readonly maxSampleBytes?: number;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Each consumption owns a muted HTMLAudioElement and waits for its ordinary
|
|
29
|
+
* play(). This deadline is separate from worklet registration and individual
|
|
30
|
+
* PCM reads; 5 seconds by default and at most 1 minute. A bare number is
|
|
31
|
+
* milliseconds.
|
|
32
|
+
*/
|
|
33
|
+
readonly activationTimeout?: Duration.Input | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* How long registering the worklet, and then each PCM read, may take; 10
|
|
36
|
+
* seconds by default and at most 10 minutes. A bare number is milliseconds.
|
|
37
|
+
*/
|
|
38
|
+
readonly readTimeout?: Duration.Input | undefined;
|
|
39
|
+
/** @deprecated Removed in 0.3.0: use `activationTimeout` (a bare number is milliseconds). */
|
|
40
|
+
readonly activationTimeoutMs?: never;
|
|
41
|
+
/** @deprecated Removed in 0.3.0: use `readTimeout` (a bare number is milliseconds). */
|
|
42
|
+
readonly readTimeoutMs?: never;
|
|
23
43
|
}
|
|
24
44
|
/** Window-realm PCM with OWNED muted playback activation, not a bare Web Audio tap.
|
|
25
45
|
* Each consumption clones the borrowed source once, attaches that clone to an owned muted
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/_internal/audio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ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;;;;;uFAQuF;AACvF,eAAO,MAAM,eAAe,WAClB,gBAAgB,WACf,eAAe,KACvB,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAyMzC,CAAC"}
|
package/dist/_internal/audio.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import * as Duration from "effect/Duration";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import * as Scope from "effect/Scope";
|
|
3
4
|
import { ReactorError } from "reactor-effect-client";
|
|
4
|
-
import { errorOf, fromOwnedReadableStream, positiveLimit } from "reactor-effect-client/host";
|
|
5
|
+
import { duration, errorOf, fromOwnedReadableStream, parsed, positiveLimit, } from "reactor-effect-client/host";
|
|
5
6
|
import { decodeAudioPacket } from "./audio-packet.js";
|
|
6
7
|
const bounded = async (work, timeout, label, signal) => {
|
|
7
8
|
let timer;
|
|
@@ -10,8 +11,8 @@ const bounded = async (work, timeout, label, signal) => {
|
|
|
10
11
|
return await Promise.race([
|
|
11
12
|
work,
|
|
12
13
|
new Promise((_, reject) => {
|
|
13
|
-
timer = setTimeout(() => reject(
|
|
14
|
-
rejectAbort = () => reject(
|
|
14
|
+
timer = setTimeout(() => reject(ReactorError.fromCode("Timeout", label)), timeout);
|
|
15
|
+
rejectAbort = () => reject(ReactorError.fromCode("Aborted", label));
|
|
15
16
|
if (signal?.aborted)
|
|
16
17
|
rejectAbort();
|
|
17
18
|
else
|
|
@@ -26,32 +27,32 @@ const bounded = async (work, timeout, label, signal) => {
|
|
|
26
27
|
signal?.removeEventListener("abort", rejectAbort);
|
|
27
28
|
}
|
|
28
29
|
};
|
|
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
30
|
export const audioContext = (options = {}) => Effect.gen(function* () {
|
|
32
|
-
const timeout = yield*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
31
|
+
const timeout = yield* parsed(() => duration(options.transitionTimeout ?? "5 seconds", "audio context transition timeout", {
|
|
32
|
+
maximum: "1 minute",
|
|
33
|
+
}));
|
|
36
34
|
const context = yield* Effect.acquireRelease(Effect.try({
|
|
37
35
|
try: () => {
|
|
38
36
|
if (typeof AudioContext !== "function" || typeof AudioWorkletNode !== "function")
|
|
39
|
-
throw
|
|
37
|
+
throw ReactorError.fromCode("UnsupportedCapability", "built-in AudioContext and AudioWorkletNode are required");
|
|
40
38
|
return new AudioContext(options.sampleRate === undefined ? {} : { sampleRate: options.sampleRate });
|
|
41
39
|
},
|
|
42
40
|
catch: (e) => errorOf(e, "UnsupportedCapability"),
|
|
43
|
-
}),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
47
|
yield* Effect.tryPromise({
|
|
48
|
-
try: (
|
|
49
|
-
catch: (cause) => cause
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}));
|
|
53
54
|
if (context.state !== "running")
|
|
54
|
-
return yield*
|
|
55
|
+
return yield* ReactorError.fromCode("UnsupportedCapability", `AudioContext is ${context.state}, not running`);
|
|
55
56
|
return context;
|
|
56
57
|
});
|
|
57
58
|
// A worklet is registered once per context and URL. Failed registration is retryable, not cached success.
|
|
@@ -83,23 +84,30 @@ const load = (context, url) => {
|
|
|
83
84
|
* No ScriptProcessorNode, getUserMedia, device permission or native engine is used. */
|
|
84
85
|
export const webAudioSamples = (source, options) => fromOwnedReadableStream({
|
|
85
86
|
evaluate: () => {
|
|
86
|
-
|
|
87
|
-
const
|
|
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
|
+
}));
|
|
88
94
|
const maxBytes = positiveLimit(options.maxSampleBytes ?? 1048576, "PCM sample bound", 64 * 1024 * 1024);
|
|
89
95
|
const context = options.context;
|
|
90
96
|
if (source.kind !== "audio" || source.readyState !== "live")
|
|
91
|
-
throw
|
|
97
|
+
throw ReactorError.fromCode("InvalidState", "expected a live audio track");
|
|
92
98
|
if (typeof AudioWorkletNode !== "function" || context.audioWorklet === undefined)
|
|
93
|
-
throw
|
|
99
|
+
throw ReactorError.fromCode("UnsupportedCapability", "built-in AudioWorklet is unavailable in this realm");
|
|
94
100
|
if (typeof document === "undefined" ||
|
|
101
|
+
// Feature detection reads the method itself, not its deprecated overload.
|
|
102
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
95
103
|
typeof document.createElement !== "function" ||
|
|
96
104
|
typeof MediaStream !== "function")
|
|
97
|
-
throw
|
|
105
|
+
throw ReactorError.fromCode("UnsupportedCapability", "PCM activation requires a Window document and built-in HTML audio playback");
|
|
98
106
|
if (context.state !== "running")
|
|
99
|
-
throw
|
|
107
|
+
throw ReactorError.fromCode("UnsupportedCapability", "PCM requires an explicitly resumed, running AudioContext");
|
|
100
108
|
const url = new URL(options.workletUrl ?? new URL("./pcm-worklet.js", import.meta.url), import.meta.url);
|
|
101
109
|
if (!/^(https?:|file:)$/.test(url.protocol))
|
|
102
|
-
throw
|
|
110
|
+
throw ReactorError.fromCode("Protocol", "serve the PCM worklet as a normal local module, not a data/blob URL");
|
|
103
111
|
const track = source.clone(), lifetime = new AbortController();
|
|
104
112
|
let input, node;
|
|
105
113
|
let sink, watch;
|
|
@@ -122,7 +130,7 @@ export const webAudioSamples = (source, options) => fromOwnedReadableStream({
|
|
|
122
130
|
sink.pause();
|
|
123
131
|
sink.srcObject = null;
|
|
124
132
|
}
|
|
125
|
-
pending?.reject(
|
|
133
|
+
pending?.reject(ReactorError.fromCode("Aborted", "PCM reader closed"));
|
|
126
134
|
pending = undefined;
|
|
127
135
|
input?.disconnect();
|
|
128
136
|
if (node !== undefined) {
|
|
@@ -141,10 +149,10 @@ export const webAudioSamples = (source, options) => fromOwnedReadableStream({
|
|
|
141
149
|
close();
|
|
142
150
|
}
|
|
143
151
|
};
|
|
144
|
-
const ended = () => fail(
|
|
152
|
+
const ended = () => fail(ReactorError.fromCode("Disconnected", "PCM track ended"));
|
|
145
153
|
const state = () => {
|
|
146
154
|
if (context.state !== "running")
|
|
147
|
-
fail(
|
|
155
|
+
fail(ReactorError.fromCode("Disconnected", `PCM context ${context.state}`));
|
|
148
156
|
};
|
|
149
157
|
const live = () => {
|
|
150
158
|
if (source.readyState !== "live" || track.readyState !== "live")
|
|
@@ -190,17 +198,17 @@ export const webAudioSamples = (source, options) => fromOwnedReadableStream({
|
|
|
190
198
|
return;
|
|
191
199
|
try {
|
|
192
200
|
if (pending === undefined)
|
|
193
|
-
throw
|
|
201
|
+
throw ReactorError.fromCode("Protocol", "unsolicited PCM block without a read credit");
|
|
194
202
|
const sample = decodeAudioPacket(event.data, maxBytes), waiter = pending;
|
|
195
203
|
pending = undefined;
|
|
196
204
|
waiter.resolve(sample);
|
|
197
205
|
}
|
|
198
206
|
catch (error) {
|
|
199
|
-
fail(errorOf(error));
|
|
207
|
+
fail(errorOf(error, "Protocol", "PCM block"));
|
|
200
208
|
}
|
|
201
209
|
};
|
|
202
|
-
node.port.onmessageerror = () => fail(
|
|
203
|
-
node.onprocessorerror = () => fail(
|
|
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"));
|
|
204
212
|
input.connect(node);
|
|
205
213
|
node.connect(context.destination);
|
|
206
214
|
};
|
|
@@ -223,7 +231,7 @@ export const webAudioSamples = (source, options) => fromOwnedReadableStream({
|
|
|
223
231
|
c.enqueue(sample);
|
|
224
232
|
}
|
|
225
233
|
catch (error) {
|
|
226
|
-
fail(errorOf(error));
|
|
234
|
+
fail(errorOf(error, "Protocol", "PCM read"));
|
|
227
235
|
}
|
|
228
236
|
},
|
|
229
237
|
cancel: close,
|
|
@@ -1 +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,
|
|
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,EAC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gBACV,IAAI,CAAC;oBACH,MAAM,KAAK,CAAC;oBACZ,IAAI,CAAC,IAAI,EAAE;wBAAE,OAAO;oBACpB,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;wBAC9C,OAAO,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;wBAC9B,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;oBACjC,CAAC,CAAC,EACF,OAAO,EACP,mBAAmB,EACnB,QAAQ,CAAC,MAAM,CAChB,CAAC;oBACF,IAAI,IAAI,EAAE;wBAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAChC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;YACD,MAAM,EAAE,KAAK;SACd,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,CAAC;CAC/E,CAAC,CAAC"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
export { audioContext, webAudioSamples } from "./audio.js";
|
|
2
|
-
export type { WebAudioOptions, WebAudioSample } from "./audio.js";
|
|
2
|
+
export type { AudioContextOptions, WebAudioOptions, WebAudioSample } from "./audio.js";
|
|
3
|
+
import * as Duration from "effect/Duration";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
5
|
import * as Stream from "effect/Stream";
|
|
5
6
|
import type * as Scope from "effect/Scope";
|
|
6
7
|
import { ReactorError } from "reactor-effect-client";
|
|
7
8
|
export interface MediaOptions {
|
|
8
9
|
readonly maxSampleBytes?: number;
|
|
9
|
-
|
|
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
|
+
/** @deprecated Removed in 0.3.0: use `readTimeout` (a bare number is milliseconds). */
|
|
16
|
+
readonly readTimeoutMs?: never;
|
|
10
17
|
}
|
|
11
18
|
export interface VideoSample {
|
|
12
19
|
readonly format: "RGBA";
|
|
@@ -54,7 +61,14 @@ export declare const videoFrames: (track: MediaStreamTrack, options?: MediaOptio
|
|
|
54
61
|
/** Optional native AudioData in the current realm. No worker or Web Audio fallback. */
|
|
55
62
|
export declare const audioSamples: (track: MediaStreamTrack, options?: MediaOptions) => Stream.Stream<AudioSample, ReactorError>;
|
|
56
63
|
/** Scoped local playback. Starting playback does not establish audience output. */
|
|
57
|
-
export
|
|
64
|
+
export interface PlayOptions {
|
|
65
|
+
/**
|
|
66
|
+
* How long starting playback may take; 10 seconds by default and at most 10
|
|
67
|
+
* minutes. A bare number is milliseconds.
|
|
68
|
+
*/
|
|
69
|
+
readonly playTimeout?: Duration.Input | undefined;
|
|
70
|
+
}
|
|
71
|
+
export declare const play: (track: MediaStreamTrack, element: HTMLMediaElement, options?: PlayOptions) => Effect.Effect<void, ReactorError, Scope.Scope>;
|
|
58
72
|
export interface Presentation {
|
|
59
73
|
readonly callbackTimeMs: number;
|
|
60
74
|
readonly mediaTimeSeconds: number;
|
|
@@ -1 +1 @@
|
|
|
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,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/_internal/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,E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