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): let screen shares include tab or system audio (#9353)
Eric Hayesa6cff0e63e8f
diff --git a/apps/web/src/features/channel/Call/CallAudioSink.tsx b/apps/web/src/features/channel/Call/CallAudioSink.tsxindex a8b072333f..b7791ab02f 100644--- a/apps/web/src/features/channel/Call/CallAudioSink.tsx+++ b/apps/web/src/features/channel/Call/CallAudioSink.tsx@@ -3,12 +3,17 @@ import { useCallContext } from './CallContext';import { LK_TRACK_SOURCE } from './livekit-loader';import { TrackView } from './TrackView';+const REMOTE_AUDIO_SOURCES = [+ LK_TRACK_SOURCE.Microphone,+ LK_TRACK_SOURCE.ScreenShareAudio,+] as const;+/*** Hidden, mount-persistent sink that plays remote participants' microphone- * audio. Must be mounted above the channel tab <Switch> so that audio keeps- * playing when the user navigates away from the Call tab to Messages /- * Attachments / Participants — those tab switches unmount CallOverlay and- * would otherwise tear down every <audio> element.+ * and screen-share audio. Must be mounted above the channel tab <Switch> so+ * that audio keeps playing when the user navigates away from the Call tab to+ * Messages / Attachments / Participants — those tab switches unmount+ * CallOverlay and would otherwise tear down every <audio> element.** This is audio-only on purpose: video tiles / local preview / screen share /* controls stay scoped to CallOverlay since there's no value in running that@@ -17,16 +22,20 @@ import { TrackView } from './TrackView';export function CallAudioSink() {const callCtx = useCallContext();- const remoteMicTracks = () => {- // Subscribe to trackVersion so mic subscribe / unsubscribe / replace events- // propagate (same reactivity pattern as ParticipantTile).+ const remoteAudioTracks = () => {+ // Subscribe to trackVersion so audio subscribe / unsubscribe / replace+ // events propagate (same reactivity pattern as ParticipantTile). <For>+ // keys by the Track itself, so one share starting or stopping leaves the+ // other audio elements mounted.callCtx.trackVersion();return Array.from(callCtx.remoteParticipants().values()).filter((p) => !p.isAgent)- .map((p) => ({- id: p.identity,- track: p.getTrackPublication(LK_TRACK_SOURCE.Microphone)?.track,- }));+ .flatMap((p) =>+ REMOTE_AUDIO_SOURCES.flatMap((source) => {+ const track = p.getTrackPublication(source)?.track;+ return track ? [track] : [];+ })+ );};return (@@ -35,8 +44,8 @@ export function CallAudioSink() {class="absolute size-0 overflow-hidden pointer-events-none"aria-hidden="true">- <For each={remoteMicTracks()}>- {(entry) => <TrackView track={entry.track} />}+ <For each={remoteAudioTracks()}>+ {(track) => <TrackView track={track} />}</For></div></Show>diff --git a/apps/web/src/features/channel/Call/CallContext.tsx b/apps/web/src/features/channel/Call/CallContext.tsxindex 5173b42c60..0a6c875117 100644--- a/apps/web/src/features/channel/Call/CallContext.tsx+++ b/apps/web/src/features/channel/Call/CallContext.tsx@@ -24,6 +24,7 @@ import type {LocalTrack,RemoteParticipant,Room,+ ScreenShareCaptureOptions,} from 'livekit-client';import {createContext,@@ -192,6 +193,23 @@ function microphoneCaptureOptions(};}+function screenShareCaptureOptions(+ includeAudio: boolean+): ScreenShareCaptureOptions {+ if (!includeAudio) return { audio: false };+ return {+ // Shared audio is usually music or video, which voice processing mangles.+ audio: {+ echoCancellation: false,+ noiseSuppression: false,+ autoGainControl: false,+ },+ // Chromium offers system audio only when asked (Windows, ChromeOS); other+ // platforms and browsers capture tab audio or none.+ systemAudio: 'include',+ };+}+function nativeAudioProcessingConstraints(mode: MicNoiseSuppressionMode): NativeAudioProcessingConstraints {@@ -359,6 +377,13 @@ const [persistedNoiseSuppressionMode, setPersistedNoiseSuppressionMode] =},});+// Persisted across reloads. Off by default: shared tab or system audio is heard+// by everyone in the call, so including it is an explicit choice.+const [persistedShareScreenAudio, setPersistedShareScreenAudio] = makePersisted(+ createSignal(false),+ { name: 'call.shareScreenAudio' }+);+export type CallState = {/** Media connection owned by the meeting session; channel calls use callLifecycle. */meetingSession: Pick<@@ -409,6 +434,10 @@ export type CallState = {toggleVideo: () => Promise<void>;/** Toggle screen sharing */toggleScreenShare: () => Promise<void>;+ /** Whether the next screen share captures tab or system audio */+ shareScreenAudio: () => boolean;+ /** Choose whether the next screen share captures tab or system audio */+ setShareScreenAudio: (value: boolean) => void;/** Switch active audio input device */switchAudioInput: (deviceId: string) => Promise<void>;/** Switch active audio output device */@@ -1551,13 +1580,17 @@ function createCallState() {if (!r) return;const newSharing = !store.isScreenSharing;try {- await r.localParticipant.setScreenShareEnabled(newSharing);+ await r.localParticipant.setScreenShareEnabled(+ newSharing,+ screenShareCaptureOptions(persistedShareScreenAudio())+ );setStore('isScreenSharing', newSharing);analytics.track('call_action', {action: 'screen_share_toggled',channelId: store.activeChannelId ?? '',callId: store.activeCallId ?? undefined,enabled: newSharing,+ audio: newSharing ? persistedShareScreenAudio() : undefined,});} catch (e) {console.error('failed to toggle screen share', e);@@ -1799,6 +1832,8 @@ function createCallState() {toggleAudio,toggleVideo,toggleScreenShare,+ shareScreenAudio: persistedShareScreenAudio,+ setShareScreenAudio: (value) => setPersistedShareScreenAudio(value),switchAudioInput,switchAudioOutput,switchVideoInput,diff --git a/apps/web/src/features/channel/Call/CallControls/CallControlBar.tsx b/apps/web/src/features/channel/Call/CallControls/CallControlBar.tsxindex d062e4e114..780b9eb68f 100644--- a/apps/web/src/features/channel/Call/CallControls/CallControlBar.tsx+++ b/apps/web/src/features/channel/Call/CallControls/CallControlBar.tsx@@ -18,6 +18,8 @@ function MediaSplitButton(props: {toggleLabel: string;menuLabel: string;disabled?: boolean;+ /** Set for a toggle whose icon stays the same in both states. */+ pressed?: boolean;onToggle: () => void;icon: JSX.Element;children: JSX.Element;@@ -29,6 +31,7 @@ function MediaSplitButton(props: {<ButtonGroup.Buttonaria-label={props.toggleLabel}tooltip={{ content: props.toggleLabel, placement: 'top' }}+ aria-pressed={props.pressed}disabled={props.disabled}onClick={props.onToggle}>@@ -73,6 +76,8 @@ export function CallControlBar(props: {audioMenu: JSX.Element;/** Dropdown items for the camera and its background effect. */videoMenu: JSX.Element;+ /** Dropdown items for what a screen share captures. */+ screenMenu: JSX.Element;error?: string;}) {return (@@ -114,24 +119,19 @@ export function CallControlBar(props: {>{props.videoMenu}</MediaSplitButton>- <Button- size="icon-lg"- variant="secondary"- aria-label={+ <MediaSplitButton+ label="Screen share"+ toggleLabel={props.screenSharing ? 'Stop sharing screen' : 'Share screen'}- tooltip={{- content: props.screenSharing- ? 'Stop sharing screen'- : 'Share screen',- placement: 'top',- }}- aria-pressed={props.screenSharing}+ menuLabel="Screen share settings"+ pressed={props.screenSharing}disabled={props.disabled}- onClick={props.onToggleScreen}+ onToggle={props.onToggleScreen}+ icon={<Screencast class="size-5" />}>- <Screencast class="size-5" />- </Button>+ {props.screenMenu}+ </MediaSplitButton><Buttonsize="icon-lg"variant="danger"diff --git a/apps/web/src/features/channel/Call/CallControls/CallMediaControls.tsx b/apps/web/src/features/channel/Call/CallControls/CallMediaControls.tsxindex 0d3848e2f7..63ac1699a9 100644--- a/apps/web/src/features/channel/Call/CallControls/CallMediaControls.tsx+++ b/apps/web/src/features/channel/Call/CallControls/CallMediaControls.tsx@@ -20,6 +20,8 @@ export type CallMediaControlsState = Pick<| 'toggleAudio'| 'toggleVideo'| 'toggleScreenShare'+ | 'shareScreenAudio'+ | 'setShareScreenAudio'| 'audioInputDevices'| 'audioOutputDevices'| 'videoInputDevices'@@ -150,6 +152,23 @@ export function CallMediaControls(props: {</Dropdown.Group></>}+ screenMenu={+ <Dropdown.Group>+ <Dropdown.CheckboxItem+ checked={call.shareScreenAudio()}+ disabled={call.isConnecting() || call.isScreenSharing()}+ closeOnSelect={false}+ onChange={(checked) => call.setShareScreenAudio(checked)}+ >+ Share audio+ </Dropdown.CheckboxItem>+ <p class="px-2 pb-1 text-xs text-ink-muted">+ {call.isScreenSharing()+ ? 'Stop sharing to change this.'+ : 'Shares audio from a tab, or from your whole system where the browser supports it.'}+ </p>+ </Dropdown.Group>+ }videoMenu={<><Dropdown.Group>diff --git a/apps/web/src/features/channel/Call/livekit-loader.ts b/apps/web/src/features/channel/Call/livekit-loader.tsindex feb21f292a..19e9f66d3c 100644--- a/apps/web/src/features/channel/Call/livekit-loader.ts+++ b/apps/web/src/features/channel/Call/livekit-loader.ts@@ -75,6 +75,7 @@ export const LK_TRACK_SOURCE = {Camera: 'camera' as Track.Source.Camera,Microphone: 'microphone' as Track.Source.Microphone,ScreenShare: 'screen_share' as Track.Source.ScreenShare,+ ScreenShareAudio: 'screen_share_audio' as Track.Source.ScreenShareAudio,} as const;export const LK_ROOM_EVENT = {diff --git a/apps/web/src/features/channel/Call/tests/call-controls.test.tsx b/apps/web/src/features/channel/Call/tests/call-controls.test.tsxindex 65ba34f5e9..994dd6c757 100644--- a/apps/web/src/features/channel/Call/tests/call-controls.test.tsx+++ b/apps/web/src/features/channel/Call/tests/call-controls.test.tsx@@ -21,6 +21,7 @@ const device = (deviceId: string, label: string) =>function setup() {const [audioMuted, setAudioMuted] = createSignal(false);+ const [shareAudio, setShareAudio] = createSignal(false);const [background, setBackground] = createSignal<BackgroundEffect>({type: 'none',});@@ -34,6 +35,8 @@ function setup() {}),toggleVideo: vi.fn(async () => {}),toggleScreenShare: vi.fn(async () => {}),+ shareScreenAudio: shareAudio,+ setShareScreenAudio: vi.fn(setShareAudio),audioInputDevices: () => [device('mic-1', 'Desk microphone')],audioOutputDevices: () => [],videoInputDevices: () => [device('cam-1', 'Desk camera')],@@ -109,6 +112,23 @@ describe('call controls', () => {);});+ it('shares the screen without opening its settings', () => {+ const { media } = setup();+ fireEvent.click(screen.getByRole('button', { name: 'Share screen' }));+ expect(media.toggleScreenShare).toHaveBeenCalledOnce();+ expect(screen.queryByRole('menu')).toBeNull();+ });++ it('chooses whether a screen share includes audio', async () => {+ const { media } = setup();+ await openMenu('Screen share settings');+ const item = screen.getByRole('menuitemcheckbox', { name: 'Share audio' });+ expect(item.getAttribute('aria-checked')).toBe('false');+ await choose('menuitemcheckbox', 'Share audio');+ expect(media.setShareScreenAudio).toHaveBeenCalledWith(true);+ await waitFor(() => expect(item.getAttribute('aria-checked')).toBe('true'));+ });+it('leaves the call', () => {const { leave } = setup();fireEvent.click(screen.getByRole('button', { name: 'Leave call' }));diff --git a/apps/web/src/features/channel/Call/tests/livekit-loader.test.ts b/apps/web/src/features/channel/Call/tests/livekit-loader.test.tsindex 4041d261e4..a4f4e27a8a 100644--- a/apps/web/src/features/channel/Call/tests/livekit-loader.test.ts+++ b/apps/web/src/features/channel/Call/tests/livekit-loader.test.ts@@ -27,6 +27,7 @@ describe('livekit-loader', () => {Camera: Track.Source.Camera,Microphone: Track.Source.Microphone,ScreenShare: Track.Source.ScreenShare,+ ScreenShareAudio: Track.Source.ScreenShareAudio,});expect(LK_ROOM_EVENT.Disconnected).toBe(RoomEvent.Disconnected);expect(LK_DISCONNECT_REASON).toEqual({diff --git a/docs/agent-guide/calls.md b/docs/agent-guide/calls.mdindex 335fce1677..c79646e569 100644--- a/docs/agent-guide/calls.md+++ b/docs/agent-guide/calls.md@@ -220,8 +220,13 @@ toggles the device (pressed while on), and the caret opens a settings menu abovethe toolbar on click only; hovering opens nothing. **Audio settings** listsmicrophones, speakers (when the browser can choose one), and noise suppression.**Video settings** lists cameras and the background effects as tiles: None,-Light blur, Strong blur, a selected custom image, and Upload. Screen share and-Leave call are separate buttons. Click outside or press Escape to close a menu.+Light blur, Strong blur, a selected custom image, and Upload. Screen share is+the same kind of split button: the left half starts or stops sharing (pressed+while sharing), and **Screen share settings** holds **Share audio**, off by+default, saved per device, and locked while sharing. With it on, the browser+picker offers tab audio (and system audio where Chromium supports it), and other+participants hear it alongside microphones, even away from the Call tab. Leave+call is a separate button. Click outside or press Escape to close a menu.The controls also work by keyboard and touch.### Browser call diagnostics