diff --git a/doc/lib/js/publish.md b/doc/lib/js/publish.md index f91e8230e3b..c34d26596d8 100644 --- a/doc/lib/js/publish.md +++ b/doc/lib/js/publish.md @@ -31,7 +31,7 @@ WebCodecs, writes the catalog, and publishes a hang broadcast. | `url`, `name` | Relay URL (with `?jwt=` if needed) and broadcast name. | | `versions` | Protocol versions to offer, most preferred first, comma-separated like `moq-transport-18,moq-lite-06`. Every stable version by default. | | `source` | `camera`, `screen`, or `file`. | -| `muted`, `invisible` | Disable audio or video capture. | +| `muted`, `invisible` | Stop publishing audio or video. The microphone and camera stay open, so unmuting or unhiding is instant and the browser's capture indicators stay lit; clear `source` or remove the element to release them. `source` covers both devices, so releasing one while keeping the other takes the library: toggle `Source.Microphone` or `Source.Camera` `enabled`. | | `preview` | What the nested element shows: the raw `source` (default), a decoded copy of the `encoded` stream to see what viewers get, or `none`. | | `backend` | How a `` preview is drawn; see [@moq/video](/lib/js/video). `auto` (default), `webgpu`, or `2d`. | | `announce` | When to advertise: once the `source` is live (default), or `always`. Nobody can see or subscribe to the broadcast until it is announced. To keep it out of discovery, use a hidden name with a `.`-prefixed segment; it is still subscribable by name. | @@ -170,7 +170,7 @@ browsers suspend Web Audio until then. Every input and output is a signal from `out.error` and disables only its rendition; siblings and the broadcast keep running. It does not retry on demand or bandwidth changes, and enable cycles that keep the same capture do not retry. A new capture source (such as the -track a camera or microphone reopens on unmute), changed encoder settings, or +track a camera or microphone reopens after a device swap), changed encoder settings, or a replacement encoder recovers it. Recovery keeps the catalog ID and uses a fresh `track` name. diff --git a/js/publish/MIGRATE.md b/js/publish/MIGRATE.md index 33c54080c1e..d3adb3619a4 100644 --- a/js/publish/MIGRATE.md +++ b/js/publish/MIGRATE.md @@ -4,6 +4,13 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `muted` and `invisible` keep capture open + +`` and `invisible` now stop only the encoder, so the microphone and camera stay open and the browser's capture indicators stay lit. +Unmuting no longer waits on getUserMedia, a new AudioContext, or a camera reopen. +A camera source opens both devices even when it starts muted or hidden. +To release the devices, clear `source` or remove the element; to release one and keep the other, build the pipeline with the library and toggle `Source.Microphone` or `Source.Camera` `enabled`. + ### Element reflection and invalid configuration Property and built-in UI changes now reflect into attributes. Invalid source/preview/backend/announce modes, URLs, and version lists throw instead of selecting defaults; remove an attribute to use its default. diff --git a/js/publish/README.md b/js/publish/README.md index 65a1c79473d..f1f22f3d99a 100644 --- a/js/publish/README.md +++ b/js/publish/README.md @@ -67,8 +67,8 @@ The simplest way to publish a stream: | `name` | string | required | Broadcast name | | `versions` | string | stable versions | Comma-separated protocol versions to offer, most preferred first, like `moq-transport-18,moq-lite-06` | | `source` | string | — | `"camera"`, `"screen"`, `"file"` | -| `muted` | boolean | false | Mute audio capture | -| `invisible` | boolean | false | Disable video capture | +| `muted` | boolean | false | Stop publishing audio; the microphone stays open | +| `invisible` | boolean | false | Stop publishing video; the camera stays open | | `preview` | string | `"source"` | What the preview renders: `"source"`, `"encoded"`, `"none"` | | `backend` | string | `"auto"` | Graphics API for a `` preview: `"auto"`, `"webgpu"`, `"2d"` | | `announce` | string | `"source"` | When to advertise: `"always"` or `"source"` (once media is captured). A camera source waits for every enabled track, and `"source"` waits until each captured track's config resolves or fails, so the first catalog lists every rendition. After its first announcement, a camera stays announced until deselected or disconnected, including mute, hide, device swaps, and capture retries. The broadcast is created while connected either way. To keep it out of discovery, use a hidden name with a `.`-prefixed segment; it is still subscribable by name. | diff --git a/js/publish/src/announce.ts b/js/publish/src/announce.ts index 169dcb07aa2..53fea761622 100644 --- a/js/publish/src/announce.ts +++ b/js/publish/src/announce.ts @@ -32,10 +32,11 @@ export function run(effect: Effect, announcing: Signal, props: Props): effect.run((effect) => { const mode = effect.get(props.mode); const source = effect.get(props.source); - const video = effect.get(props.video.source) !== undefined; - const audio = effect.get(props.audio.source) !== undefined; const videoEnabled = effect.get(props.video.enabled); const audioEnabled = effect.get(props.audio.enabled); + // A muted or hidden track keeps capturing but publishes nothing, so it counts as absent. + const video = videoEnabled && effect.get(props.video.source) !== undefined; + const audio = audioEnabled && effect.get(props.audio.source) !== undefined; // A camera captures video and audio as one publication, so it waits for every enabled track and // denying either permission can't advertise a partial broadcast. @@ -44,9 +45,7 @@ export function run(effect: Effect, announcing: Signal, props: Props): const live = (video || audio) && ready; const active = source !== undefined && (camera || live); - const settled = - (!videoEnabled || !video || !!effect.get(props.video.settled)) && - (!audioEnabled || !audio || !!effect.get(props.audio.settled)); + const settled = (!video || !!effect.get(props.video.settled)) && (!audio || !!effect.get(props.audio.settled)); const announced = mode === "always" || (mode === "source" && active && (latched === source || (live && settled))); diff --git a/js/publish/src/audio/capture.ts b/js/publish/src/audio/capture.ts index ce319c884c4..30f575b884a 100644 --- a/js/publish/src/audio/capture.ts +++ b/js/publish/src/audio/capture.ts @@ -160,7 +160,7 @@ export class Capture { } // Decoded samples need no graph and declare their own format, so this only converts them to the - // planar shape the framer wants. Note it never reads `enabled`: muting must not tear the stream + // planar shape the framer wants. Note it never reads `enabled`: disabling must not tear the stream // down, because a one-shot stream can't be read again. #runSamples(source: SampleSource, effect: Effect): void { const { sampleRate, channelCount } = source; @@ -173,7 +173,7 @@ export class Capture { } #runTrack(source: SourceConfig, effect: Effect): void { - // Releasing the capture device while muted is the whole point of gating on `enabled`. + // Releasing the capture device while disabled is the whole point of gating on `enabled`. if (!effect.get(this.in.enabled)) return; const settings = source.track.getSettings(); diff --git a/js/publish/src/element.ts b/js/publish/src/element.ts index f02e774fcc2..fe2940119e0 100644 --- a/js/publish/src/element.ts +++ b/js/publish/src/element.ts @@ -157,12 +157,13 @@ export default class MoqPublish extends HTMLElement { // The preview element, either a