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
fix(call): do not drop audio when moving to messages/attachments (#2527)
Will Hutchinson731b159305fb
diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsxindex f3b5858d2d..f965b0611f 100644--- a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx@@ -27,6 +27,7 @@ import {import { ChannelAttachmentsTab } from '@channel/Attachments/ChannelAttachmentsTab';import { ChannelParticipantsTab } from '@channel/Participants/ChannelParticipantsTab';import {+ CallAudioSink,CallProvider,ChannelCallButton,ChannelCallTab,@@ -143,6 +144,12 @@ export function NewChannelBlockAdapter(props: BlockChannelProps) {<CallProvider><ChannelTabProvider activeTab={activeTab} setActiveTab={setActiveTab}><div class="h-full flex flex-col">+ {/*+ Mounted above <Switch> so remote call audio keeps playing when+ the user switches from the Call tab to Messages / Attachments /+ Participants. See CallAudioSink for details.+ */}+ <CallAudioSink /><Switch><Match when={activeTab() === 'messages'}><NewChanneldiff --git a/js/app/packages/channel/Call/CallAudioSink.tsx b/js/app/packages/channel/Call/CallAudioSink.tsxnew file mode 100644index 0000000000..cba16764ef--- /dev/null+++ b/js/app/packages/channel/Call/CallAudioSink.tsx@@ -0,0 +1,44 @@+import { Track } from 'livekit-client';+import { For, Show } from 'solid-js';+import { useCallContext } from './CallContext';+import { TrackView } from './TrackView';++/**+ * 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.+ *+ * 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+ * pipeline when the user isn't looking at it.+ */+export function CallAudioSink() {+ const callCtx = useCallContext();++ const remoteMicTracks = () => {+ // Subscribe to trackVersion so mic subscribe / unsubscribe / replace events+ // propagate (same reactivity pattern as ParticipantTile).+ callCtx.trackVersion();+ return Array.from(callCtx.remoteParticipants().values())+ .filter((p) => !p.isAgent)+ .map((p) => ({+ id: p.identity,+ track: p.getTrackPublication(Track.Source.Microphone)?.track,+ }));+ };++ return (+ <Show when={callCtx.isInCall()}>+ <div+ class="absolute w-0 h-0 overflow-hidden pointer-events-none"+ aria-hidden="true"+ >+ <For each={remoteMicTracks()}>+ {(entry) => <TrackView track={entry.track} />}+ </For>+ </div>+ </Show>+ );+}diff --git a/js/app/packages/channel/Call/CallOverlay.tsx b/js/app/packages/channel/Call/CallOverlay.tsxindex 434e76f7cb..fadbe5d567 100644--- a/js/app/packages/channel/Call/CallOverlay.tsx+++ b/js/app/packages/channel/Call/CallOverlay.tsx@@ -1,14 +1,6 @@import { Track, type RemoteParticipant } from 'livekit-client';-import {- For,- Show,- createEffect,- createSignal,- onCleanup,- on,- type Component,- type JSX,-} from 'solid-js';+import { For, Show, createSignal, type Component, type JSX } from 'solid-js';+import { TrackView } from './TrackView';import PhoneDisconnect from '@icon/regular/phone-disconnect.svg';import Microphone from '@icon/regular/microphone.svg';import MicrophoneSlash from '@icon/regular/microphone-slash.svg';@@ -27,67 +19,11 @@ import {import { tryMacroId, useDisplayName } from '@core/user';import { useCallContext, type MediaDeviceInfo } from './CallContext';-/**- * Generic track view that attaches/detaches a LiveKit track's media element.- * Callers resolve the track; this component handles the DOM lifecycle.- */-function TrackView(props: {- track: Track | undefined;- fit?: 'cover' | 'contain';- mirror?: boolean;-}) {- let ref!: HTMLDivElement;- let attachedTrack: Track | undefined;- let attachedElement: Element | undefined;-- createEffect(- on(- () => props.track,- (track, prev) => {- if (prev === track) return;-- prev?.detach().forEach((el) => el.remove());- attachedTrack = undefined;- attachedElement = undefined;-- if (!track) return;-- const el = track.attach();- attachedTrack = track;- attachedElement = el;- Object.assign(el.style, {- width: '100%',- height: '100%',- objectFit: props.fit ?? 'cover',- transform: props.mirror ? 'scaleX(-1)' : '',- });- ref.appendChild(el);- }- )- );-- onCleanup(() => {- if (attachedTrack) {- attachedTrack.detach().forEach((el) => el.remove());- } else {- attachedElement?.remove();- }- });-- return <div ref={ref} class="w-full h-full" />;-}-function ParticipantTile(props: { participant: RemoteParticipant }) {const callCtx = useCallContext();const macroId = () => tryMacroId(props.participant.identity);const [displayName] = useDisplayName(macroId());- const micTrack = () => {- callCtx.trackVersion();- return props.participant.getTrackPublication(Track.Source.Microphone)- ?.track;- };-const cameraTrack = () => {callCtx.trackVersion();const pub = props.participant.getTrackPublication(Track.Source.Camera);@@ -101,10 +37,7 @@ function ParticipantTile(props: { participant: RemoteParticipant }) {class="relative flex items-center justify-center rounded-lg overflow-hidden bg-surface-2 min-h-[120px]"classList={{ 'ring-2 ring-accent-2': isSpeaking() }}>- {/* Attach remote audio so we can hear this participant (visually hidden to avoid stealing layout) */}- <div class="absolute w-0 h-0 overflow-hidden">- <TrackView track={micTrack()} />- </div>+ {/* Remote mic audio is attached by <CallAudioSink /> so playback survives tab switches. */}<Showwhen={cameraTrack()}fallback={diff --git a/js/app/packages/channel/Call/TrackView.tsx b/js/app/packages/channel/Call/TrackView.tsxnew file mode 100644index 0000000000..5d2be803ee--- /dev/null+++ b/js/app/packages/channel/Call/TrackView.tsx@@ -0,0 +1,52 @@+import type { Track } from 'livekit-client';+import { createEffect, on, onCleanup } from 'solid-js';++/**+ * Generic track view that attaches/detaches a LiveKit track's media element.+ * Callers resolve the track; this component handles the DOM lifecycle.+ */+export function TrackView(props: {+ track: Track | undefined;+ fit?: 'cover' | 'contain';+ mirror?: boolean;+}) {+ let ref!: HTMLDivElement;+ let attachedTrack: Track | undefined;+ let attachedElement: Element | undefined;++ createEffect(+ on(+ () => props.track,+ (track, prev) => {+ if (prev === track) return;++ prev?.detach().forEach((el) => el.remove());+ attachedTrack = undefined;+ attachedElement = undefined;++ if (!track) return;++ const el = track.attach();+ attachedTrack = track;+ attachedElement = el;+ Object.assign(el.style, {+ width: '100%',+ height: '100%',+ objectFit: props.fit ?? 'cover',+ transform: props.mirror ? 'scaleX(-1)' : '',+ });+ ref.appendChild(el);+ }+ )+ );++ onCleanup(() => {+ if (attachedTrack) {+ attachedTrack.detach().forEach((el) => el.remove());+ } else {+ attachedElement?.remove();+ }+ });++ return <div ref={ref} class="w-full h-full" />;+}diff --git a/js/app/packages/channel/Call/index.ts b/js/app/packages/channel/Call/index.tsindex d40bbf807f..f6d7f43cbe 100644--- a/js/app/packages/channel/Call/index.ts+++ b/js/app/packages/channel/Call/index.ts@@ -6,5 +6,6 @@ export {export type { CallState } from './CallContext';export { useCall } from './useCall';export { CallOverlay } from './CallOverlay';+export { CallAudioSink } from './CallAudioSink';export { ChannelCallButton } from './ChannelCallButton';export { ChannelCallTab } from './ChannelCallTab';