Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions app/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ export function Microphone(props: { local: Local }): JSX.Element {

// Handle device selection
const selectDevice = (deviceId: string) => {
if (root() && (deviceId === device.out.active.peek() || deviceId === device.out.requested.peek())) {
if (root() && deviceId === Settings.microphone.device.peek()) {
// Same device selected and mic is enabled - disable it
props.local.core.microphoneEnabled.set(false);
device.preferred.set(undefined);
Settings.microphone.device.set(undefined);
} else {
// Different device or mic is disabled - enable it
device.preferred.set(deviceId);
Settings.microphone.device.set(deviceId);
props.local.core.microphoneEnabled.set(true);
}
};
Expand Down Expand Up @@ -466,6 +466,7 @@ export function Camera(props: { local: Local; room?: Room }): JSX.Element {
props.local.core.cameraEnabled.update((prev: boolean) => !prev);
};
const media = solid(props.local.webcam.out.source);
const enabled = solid(props.local.core.cameraEnabled);

const [showMenu, setShowMenu] = createSignal(false);
const [deviceChangeIndicator, setDeviceChangeIndicator] = createSignal(false);
Expand All @@ -474,6 +475,7 @@ export function Camera(props: { local: Local; room?: Room }): JSX.Element {
// Use device signals from the Device API
const device = props.local.webcam.device;
const available = solid(device.out.available);
const noCamera = createMemo(() => enabled() && available()?.length === 0 && !media());
const requested = createSelector(solid(device.out.requested));
const active = createSelector(solid(device.out.active));

Expand Down Expand Up @@ -525,20 +527,31 @@ export function Camera(props: { local: Local; room?: Room }): JSX.Element {

// Handle device selection
const selectDevice = (deviceId: string) => {
if (media() && (deviceId === device.out.active.peek() || deviceId === device.out.requested.peek())) {
if (media() && deviceId === Settings.camera.device.peek()) {
// Same device selected and camera is enabled - disable it
props.local.core.cameraEnabled.set(false);
device.preferred.set(undefined);
Settings.camera.device.set(undefined);
} else {
// Different device or camera is disabled - enable it
device.preferred.set(deviceId);
Settings.camera.device.set(deviceId);
props.local.core.cameraEnabled.set(true);
}
};

return (
<div class="flex items-start pointer-events-auto relative">
<Tooltip content={media() ? "Disable camera" : "Enable camera"} position="top">
<Show when={noCamera()}>
<div
role="status"
class="absolute bottom-full mb-2 left-0 w-56 rounded border border-white/30 bg-black/90 p-2 text-sm leading-snug text-white shadow-lg"
>
No camera found. Connect a webcam to turn on video.
</div>
</Show>
<Tooltip
content={noCamera() ? "No camera found" : media() ? "Disable camera" : "Enable camera"}
position="top"
>
<button
type="button"
onClick={toggle}
Expand Down
10 changes: 5 additions & 5 deletions app/src/room/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export class Local {
this.#signals.cleanup(() => this.core.close());
this.#signals.run((effect) => {
this.core.webcam.device.preferred.set(effect.get(Settings.camera.device));
this.core.microphone.device.preferred.set(effect.get(Settings.microphone.device));
});
this.#signals.run((effect) => {
Settings.camera.device.set(effect.get(this.core.webcam.device.preferred));
Settings.microphone.device.set(effect.get(this.core.microphone.device.preferred));
// Pin the resolved OS default for the mic so capture matches the user's default input.
// An explicit choice still wins, and an unresolvable default stays browser-managed.
this.core.microphone.device.preferred.set(
effect.get(Settings.microphone.device) ?? effect.get(this.core.microphone.device.out.default),
);
});
this.#signals.run((effect) => {
this.core.cameraAudio.volume.set(effect.get(Settings.microphone.gain));
Expand Down
4 changes: 2 additions & 2 deletions app/src/room/watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as Catalog from "@moq/hang/catalog";
import type * as Moq from "@moq/net";
import * as Moq from "@moq/net";
import { consume } from "@moq/room";
import { Effect, type Getter, Signal } from "@moq/signals";
import * as Watch from "@moq/watch";
Expand Down Expand Up @@ -83,7 +83,7 @@ export class WatchBroadcast {
});

this.#sync = new Watch.Sync({
latency: "real-time",
latency: Moq.Time.Milli(100),
connection: props?.connection,
video: this.#videoSource.out.jitter,
audio: this.#audioSource.out.jitter,
Expand Down
Loading