Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(calls): choose audio/video (#2439)
Will Hutchinson19c1db6cd935
diff --git a/js/app/packages/channel/Call/CallContext.tsx b/js/app/packages/channel/Call/CallContext.tsxindex 33a13214c9..61bd5073ec 100644--- a/js/app/packages/channel/Call/CallContext.tsx+++ b/js/app/packages/channel/Call/CallContext.tsx@@ -5,6 +5,7 @@ import {Track,type RemoteParticipant,type LocalTrackPublication,+ type LocalTrack,} from 'livekit-client';import {createContext,@@ -23,6 +24,12 @@ export type CallParticipantInfo = {hasVideo: boolean;};+export type MediaDeviceInfo = {+ deviceId: string;+ label: string;+ kind: MediaDeviceKind;+};+type CallStoreState = {connectionState: ConnectionState;activeChannelId: string | null;@@ -32,6 +39,12 @@ type CallStoreState = {isScreenSharing: boolean;trackVersion: number;speakerVersion: number;+ audioInputDevices: MediaDeviceInfo[];+ audioOutputDevices: MediaDeviceInfo[];+ videoInputDevices: MediaDeviceInfo[];+ activeAudioInputDeviceId: string | null;+ activeAudioOutputDeviceId: string | null;+ activeVideoInputDeviceId: string | null;};const initialState: CallStoreState = {@@ -43,6 +56,12 @@ const initialState: CallStoreState = {isScreenSharing: false,trackVersion: 0,speakerVersion: 0,+ audioInputDevices: [],+ audioOutputDevices: [],+ videoInputDevices: [],+ activeAudioInputDeviceId: null,+ activeAudioOutputDeviceId: null,+ activeVideoInputDeviceId: null,};export type CallState = {@@ -68,6 +87,18 @@ export type CallState = {isVideoMuted: () => boolean;/** Whether local screen share is active */isScreenSharing: () => boolean;+ /** Available audio input devices (microphones) */+ audioInputDevices: () => MediaDeviceInfo[];+ /** Available audio output devices (speakers) */+ audioOutputDevices: () => MediaDeviceInfo[];+ /** Available video input devices (cameras) */+ videoInputDevices: () => MediaDeviceInfo[];+ /** Currently active audio input device ID */+ activeAudioInputDeviceId: () => string | null;+ /** Currently active audio output device ID */+ activeAudioOutputDeviceId: () => string | null;+ /** Currently active video input device ID */+ activeVideoInputDeviceId: () => string | null;/** Connect to a call using a token response */connect: (tokenResponse: CallTokenResponse) => Promise<void>;/** Disconnect from the current call */@@ -78,6 +109,12 @@ export type CallState = {toggleVideo: () => Promise<void>;/** Toggle screen sharing */toggleScreenShare: () => Promise<void>;+ /** Switch active audio input device */+ switchAudioInput: (deviceId: string) => Promise<void>;+ /** Switch active audio output device */+ switchAudioOutput: (deviceId: string) => Promise<void>;+ /** Switch active video input device */+ switchVideoInput: (deviceId: string) => Promise<void>;};const CallContext = createContext<CallState>();@@ -152,6 +189,148 @@ function createCallState() {resetState();}+ // --- device enumeration ---++ async function enumerateDevices() {+ try {+ const devices = await Room.getLocalDevices('audioinput');+ setStore(+ 'audioInputDevices',+ devices.map((d) => ({+ deviceId: d.deviceId,+ label: d.label || `Microphone (${d.deviceId.slice(0, 5)})`,+ kind: d.kind,+ }))+ );+ } catch (e) {+ console.error('failed to enumerate audio input devices', e);+ }++ try {+ const devices = await Room.getLocalDevices('audiooutput');+ setStore(+ 'audioOutputDevices',+ devices.map((d) => ({+ deviceId: d.deviceId,+ label: d.label || `Speaker (${d.deviceId.slice(0, 5)})`,+ kind: d.kind,+ }))+ );+ } catch (e) {+ console.error('failed to enumerate audio output devices', e);+ }++ try {+ const devices = await Room.getLocalDevices('videoinput');+ setStore(+ 'videoInputDevices',+ devices.map((d) => ({+ deviceId: d.deviceId,+ label: d.label || `Camera (${d.deviceId.slice(0, 5)})`,+ kind: d.kind,+ }))+ );+ } catch (e) {+ console.error('failed to enumerate video input devices', e);+ }+ }++ function trackActiveDevices(r: Room) {+ const micPub = r.localParticipant.getTrackPublication(+ Track.Source.Microphone+ );+ if (micPub?.track) {+ const settings = (+ micPub.track as LocalTrack+ ).mediaStreamTrack?.getSettings();+ if (settings?.deviceId) {+ setStore('activeAudioInputDeviceId', settings.deviceId);+ }+ }++ // Audio output has no media track — use the room's active device or fall+ // back to the first enumerated output device so the radio is pre-selected.+ const activeOutput = r.getActiveDevice('audiooutput');+ const outputDevices = store.audioOutputDevices;+ if (+ activeOutput &&+ outputDevices.some((d) => d.deviceId === activeOutput)+ ) {+ setStore('activeAudioOutputDeviceId', activeOutput);+ } else if (outputDevices.length > 0) {+ setStore('activeAudioOutputDeviceId', outputDevices[0].deviceId);+ }++ // Only set the active video device when we can read it from a live track.+ // When video is off we leave it null — guessing would show the wrong+ // selection if the browser's default differs from the first enumerated device.+ const camPub = r.localParticipant.getTrackPublication(Track.Source.Camera);+ if (camPub?.track) {+ const settings = (+ camPub.track as LocalTrack+ ).mediaStreamTrack?.getSettings();+ if (settings?.deviceId) {+ setStore('activeVideoInputDeviceId', settings.deviceId);+ }+ }+ }++ async function switchAudioInput(deviceId: string) {+ const r = room();+ if (!r) return;+ try {+ await r.switchActiveDevice('audioinput', deviceId);+ setStore('activeAudioInputDeviceId', deviceId);++ // If mic is currently live, republish with the new device to ensure it+ // actually takes effect (switchActiveDevice alone can be unreliable).+ if (!store.isAudioMuted) {+ await r.localParticipant.setMicrophoneEnabled(false);+ await r.localParticipant.setMicrophoneEnabled(true, {+ deviceId: { exact: deviceId },+ });+ }+ } catch (e) {+ console.error('failed to switch audio input device', e);+ }+ }++ async function switchAudioOutput(deviceId: string) {+ const r = room();+ if (!r) return;+ try {+ await r.switchActiveDevice('audiooutput', deviceId);+ setStore('activeAudioOutputDeviceId', deviceId);+ } catch (e) {+ console.error('failed to switch audio output device', e);+ }+ }++ async function switchVideoInput(deviceId: string) {+ const r = room();+ if (!r) return;+ try {+ await r.switchActiveDevice('videoinput', deviceId);+ setStore('activeVideoInputDeviceId', deviceId);++ // If camera is currently live, republish with the new device.+ if (!store.isVideoMuted) {+ await r.localParticipant.setCameraEnabled(false);+ await r.localParticipant.setCameraEnabled(true, {+ deviceId: { exact: deviceId },+ });+ }+ } catch (e) {+ console.error('failed to switch video input device', e);+ }+ }++ // Re-enumerate when devices change (e.g. headphones plugged in)+ const handleDeviceChange = () => {+ enumerateDevices();+ };+ navigator.mediaDevices?.addEventListener('devicechange', handleDeviceChange);+// --- mutations ---async function connect(tokenResponse: CallTokenResponse) {@@ -195,6 +374,10 @@ function createCallState() {}setStore('isAudioMuted', false);setStore('isVideoMuted', true);++ // Enumerate available devices and track active ones+ await enumerateDevices();+ trackActiveDevices(targetRoom);}async function disconnect() {@@ -213,7 +396,16 @@ function createCallState() {if (!r) return;const newMuted = !store.isAudioMuted;try {- await r.localParticipant.setMicrophoneEnabled(!newMuted);+ if (newMuted) {+ await r.localParticipant.setMicrophoneEnabled(false);+ } else {+ // Re-enable with the user's selected device+ const deviceId = store.activeAudioInputDeviceId;+ await r.localParticipant.setMicrophoneEnabled(+ true,+ deviceId ? { deviceId: { exact: deviceId } } : undefined+ );+ }setStore('isAudioMuted', newMuted);} catch (e) {console.error('failed to toggle audio', e);@@ -225,7 +417,27 @@ function createCallState() {if (!r) return;const newMuted = !store.isVideoMuted;try {- await r.localParticipant.setCameraEnabled(!newMuted);+ if (newMuted) {+ await r.localParticipant.setCameraEnabled(false);+ } else {+ const deviceId = store.activeVideoInputDeviceId;+ await r.localParticipant.setCameraEnabled(+ true,+ deviceId ? { deviceId: { exact: deviceId } } : undefined+ );+ // Read the actual device the browser chose so the dropdown is accurate+ const camPub = r.localParticipant.getTrackPublication(+ Track.Source.Camera+ );+ if (camPub?.track) {+ const settings = (+ camPub.track as LocalTrack+ ).mediaStreamTrack?.getSettings();+ if (settings?.deviceId) {+ setStore('activeVideoInputDeviceId', settings.deviceId);+ }+ }+ }setStore('isVideoMuted', newMuted);} catch (e) {console.error('failed to toggle video', e);@@ -256,6 +468,10 @@ function createCallState() {onCleanup(() => {window.removeEventListener('beforeunload', handleBeforeUnload);+ navigator.mediaDevices?.removeEventListener(+ 'devicechange',+ handleDeviceChange+ );const r = room();if (r) {r.disconnect();@@ -286,6 +502,12 @@ function createCallState() {isAudioMuted: () => store.isAudioMuted,isVideoMuted: () => store.isVideoMuted,isScreenSharing: () => store.isScreenSharing,+ audioInputDevices: () => store.audioInputDevices,+ audioOutputDevices: () => store.audioOutputDevices,+ videoInputDevices: () => store.videoInputDevices,+ activeAudioInputDeviceId: () => store.activeAudioInputDeviceId,+ activeAudioOutputDeviceId: () => store.activeAudioOutputDeviceId,+ activeVideoInputDeviceId: () => store.activeVideoInputDeviceId,// mutationsconnect,@@ -293,6 +515,9 @@ function createCallState() {toggleAudio,toggleVideo,toggleScreenShare,+ switchAudioInput,+ switchAudioOutput,+ switchVideoInput,};return state;diff --git a/js/app/packages/channel/Call/CallOverlay.tsx b/js/app/packages/channel/Call/CallOverlay.tsxindex d578efd986..434e76f7cb 100644--- a/js/app/packages/channel/Call/CallOverlay.tsx+++ b/js/app/packages/channel/Call/CallOverlay.tsx@@ -15,8 +15,17 @@ import MicrophoneSlash from '@icon/regular/microphone-slash.svg';import VideoCamera from '@icon/regular/video-camera.svg';import VideoCameraSlash from '@icon/regular/video-camera-slash.svg';import Screencast from '@icon/regular/screencast.svg';+import CaretDown from '@icon/regular/caret-down.svg';+import { DropdownMenu } from '@kobalte/core/dropdown-menu';+import {+ DropdownMenuContent,+ MenuItem,+ MenuGroup,+ GroupLabel,+ MenuSeparator,+} from '@core/component/Menu';import { tryMacroId, useDisplayName } from '@core/user';-import { useCallContext } from './CallContext';+import { useCallContext, type MediaDeviceInfo } from './CallContext';/*** Generic track view that attaches/detaches a LiveKit track's media element.@@ -155,6 +164,96 @@ const ControlButton: Component<{);};+/**+ * A call control button with a small dropdown chevron for device selection.+ * Similar to Google Meet's mic/camera buttons with a dropdown arrow.+ */+function ControlButtonWithDropdown(props: {+ onClick: () => Promise<void> | void;+ active?: boolean;+ children?: JSX.Element;+ dropdownContent: JSX.Element;+}) {+ const [isPending, setIsPending] = createSignal(false);++ const handleClick = async () => {+ if (isPending()) return;+ setIsPending(true);+ try {+ await props.onClick();+ } catch (e) {+ console.error('ControlButton action failed', e);+ } finally {+ setIsPending(false);+ }+ };++ return (+ <div class="relative flex items-center">+ <button+ onClick={handleClick}+ disabled={isPending()}+ class="w-10 h-10 rounded-l-full flex items-center justify-center transition-colors"+ classList={{+ 'opacity-50 cursor-not-allowed': isPending(),+ 'bg-surface-2 text-ink hover:bg-surface-3':+ !props.active && !isPending(),+ 'bg-accent-2 text-panel hover:bg-accent-3':+ props.active && !isPending(),+ }}+ >+ {props.children}+ </button>+ <DropdownMenu>+ <DropdownMenu.Trigger+ class="h-10 w-5 rounded-r-full flex items-center justify-center transition-colors border-l"+ classList={{+ 'bg-surface-2 text-ink hover:bg-surface-3 border-surface-3':+ !props.active,+ 'bg-accent-2 text-panel hover:bg-accent-3 border-accent-3':+ props.active,+ }}+ >+ <CaretDown class="w-3 h-3" />+ </DropdownMenu.Trigger>+ <DropdownMenu.Portal>+ <DropdownMenuContent class="mb-2" width="lg">+ {props.dropdownContent}+ </DropdownMenuContent>+ </DropdownMenu.Portal>+ </DropdownMenu>+ </div>+ );+}++function DeviceList(props: {+ label: string;+ devices: MediaDeviceInfo[];+ activeDeviceId: string | null;+ onSelect: (deviceId: string) => void;+}) {+ return (+ <MenuGroup>+ <GroupLabel>{props.label}</GroupLabel>+ <DropdownMenu.RadioGroup+ value={props.activeDeviceId ?? ''}+ onChange={(value) => props.onSelect(value)}+ >+ <For each={props.devices}>+ {(device) => (+ <MenuItem+ text={device.label}+ selectorType="radio"+ value={device.deviceId}+ groupValue={props.activeDeviceId ?? ''}+ />+ )}+ </For>+ </DropdownMenu.RadioGroup>+ </MenuGroup>+ );+}+function ScreenShareTile(props: { participant: RemoteParticipant }) {const callCtx = useCallContext();const macroId = () => tryMacroId(props.participant.identity);@@ -272,9 +371,28 @@ export function CallOverlay(props: { onLeave: () => void }) {{/* Controls bar */}<div class="flex items-center justify-center gap-3 p-3 bg-surface-1 border-t border-edge">- <ControlButton+ <ControlButtonWithDropdownonClick={() => callCtx.toggleAudio()}active={!callCtx.isAudioMuted()}+ dropdownContent={+ <>+ <DeviceList+ label="Microphone"+ devices={callCtx.audioInputDevices()}+ activeDeviceId={callCtx.activeAudioInputDeviceId()}+ onSelect={(id) => callCtx.switchAudioInput(id)}+ />+ <Show when={callCtx.audioOutputDevices().length > 0}>+ <MenuSeparator />+ <DeviceList+ label="Speaker"+ devices={callCtx.audioOutputDevices()}+ activeDeviceId={callCtx.activeAudioOutputDeviceId()}+ onSelect={(id) => callCtx.switchAudioOutput(id)}+ />+ </Show>+ </>+ }><Showwhen={!callCtx.isAudioMuted()}@@ -282,11 +400,19 @@ export function CallOverlay(props: { onLeave: () => void }) {><Microphone class="w-5 h-5" /></Show>- </ControlButton>+ </ControlButtonWithDropdown>- <ControlButton+ <ControlButtonWithDropdownonClick={() => callCtx.toggleVideo()}active={!callCtx.isVideoMuted()}+ dropdownContent={+ <DeviceList+ label="Camera"+ devices={callCtx.videoInputDevices()}+ activeDeviceId={callCtx.activeVideoInputDeviceId()}+ onSelect={(id) => callCtx.switchVideoInput(id)}+ />+ }><Showwhen={!callCtx.isVideoMuted()}@@ -294,7 +420,7 @@ export function CallOverlay(props: { onLeave: () => void }) {><VideoCamera class="w-5 h-5" /></Show>- </ControlButton>+ </ControlButtonWithDropdown><ControlButtononClick={() => callCtx.toggleScreenShare()}