Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calls): navigate to the call record after ending a call (#8305)

Eric Hayes3e1c20b470d6
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 2c73cee9ee..a0ee70dbd0 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -100,6 +100,9 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
- Mount the floating mobile AI composer only on the Agents view; other views keep their New action or their own reply/comment composer.
- Keep native booking exit navigation in the route shell, outside page loading boundaries, and use the router so the native hash route stays intact.
- All API/network calls live in service-clients.
+- Route explicit call exits using the server's `callEnded` result: ended calls
+ open their record; ongoing channel and scheduled calls return to the channel
+ and Calendar. Preserve the session ID before disconnecting.
- Keep desktop Gmail and Outlook inbox consent in the system browser with a
`macro:///inbox-link-callback` return; webview origins are not desktop callbacks.
- Draft autosaves preserve active email thread messages; evict inactive legacy
diff --git a/apps/web/src/features/channel/Call/ChannelCallTab.tsx b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
index 35e27a1c14..bf3662f829 100644
--- a/apps/web/src/features/channel/Call/ChannelCallTab.tsx
+++ b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
@@ -1,12 +1,15 @@
import { useChannelTab } from '@channel/Channel/ChannelTabContext';
import { UserGroup } from '@core/component/UserGroup';
import { getDisplayName, tryMacroId } from '@core/user';
+import { Telemetry } from '@macro-inc/observability';
import PhoneIcon from '@phosphor/phone-call.svg';
import { useActiveCallQuery, useCallRecordQuery } from '@queries/call/call';
+import { useLocation, useNavigate } from '@solidjs/router';
import { Button } from '@ui';
import { type Accessor, createMemo, Match, Show, Switch } from 'solid-js';
import { ActiveCallLink } from './ActiveCallLink';
import { CallOverlay } from './CallOverlay';
+import { getCallExitPath } from './call-exit';
import { getCallJoinTab, getCallLeaveTab } from './call-tabs';
import { useCall } from './use-call';
@@ -100,6 +103,9 @@ export function ChannelCallTab(props: {
pendingJoin?: Accessor<boolean>;
}) {
const { setActiveTab } = useChannelTab();
+ const navigate = useNavigate();
+ const location = useLocation();
+ let leaving = false;
// Match ChannelCallButton / ChannelCallAutoJoin so leaving from the
// overlay (or disconnect) switches back to Messages — not only when
@@ -117,6 +123,41 @@ export function ChannelCallTab(props: {
}
}
+ async function handleLeave() {
+ if (leaving) return;
+ leaving = true;
+ const callId = call.callCtx.activeCallId();
+ const channelId = props.channelId;
+ const from = location.key;
+ try {
+ await Telemetry.span('call.leave', async (span) => {
+ if (callId) span.setAttr('call.id', callId);
+ const result = await call.leaveCall();
+ span.setAttr('call.leave.ended', result?.callEnded ?? false);
+ if (
+ props.channelId !== channelId ||
+ location.key !== from ||
+ call.callCtx.isInCall() ||
+ !result?.callEnded
+ )
+ return;
+ // Leaving switches to Messages and unmounts this tab before cleanup
+ // settles. The route key keeps that expected teardown distinct from
+ // the user navigating elsewhere while the server responds.
+ navigate(
+ getCallExitPath({
+ authenticated: true,
+ callId,
+ channelId,
+ callEnded: true,
+ })
+ );
+ });
+ } finally {
+ leaving = false;
+ }
+ }
+
return (
<Switch
fallback={
@@ -133,7 +174,7 @@ export function ChannelCallTab(props: {
<ActiveCallLink />
</div>
<div class="min-h-0 flex-1">
- <CallOverlay onLeave={call.leaveCall} />
+ <CallOverlay onLeave={handleLeave} />
</div>
</div>
</Match>
diff --git a/apps/web/src/features/channel/Call/call-exit.ts b/apps/web/src/features/channel/Call/call-exit.ts
new file mode 100644
index 0000000000..d314dec9a2
--- /dev/null
+++ b/apps/web/src/features/channel/Call/call-exit.ts
@@ -0,0 +1,15 @@
+/** Choose the destination from the server's hangup result, never roster counts. */
+export function getCallExitPath(call: {
+ authenticated: boolean;
+ callId: string | null | undefined;
+ callEnded?: boolean;
+ channelId: string | null | undefined;
+ scheduledStart?: string | null;
+}): string {
+ if (!call.authenticated) return '/';
+ if (call.callEnded && call.callId)
+ return `/calls/call/${encodeURIComponent(call.callId)}`;
+ if (call.channelId) return `/channel/${encodeURIComponent(call.channelId)}`;
+ if (call.scheduledStart) return '/component/calendar';
+ return '/calls';
+}
diff --git a/apps/web/src/features/channel/Call/call-lifecycle.ts b/apps/web/src/features/channel/Call/call-lifecycle.ts
index e9fdb7aa14..7137b2f919 100644
--- a/apps/web/src/features/channel/Call/call-lifecycle.ts
+++ b/apps/web/src/features/channel/Call/call-lifecycle.ts
@@ -31,21 +31,22 @@ function sameCall(first: CallIdentity | undefined, second: CallIdentity) {
);
}
-function deferred() {
- let resolve!: () => void;
+function deferred<T = void>() {
+ let resolve!: (value: T) => void;
let reject!: (error: unknown) => void;
- const promise = new Promise<void>((yes, no) => {
+ const promise = new Promise<T>((yes, no) => {
resolve = yes;
reject = no;
});
return { promise, resolve, reject };
}
-type Join = ReturnType<typeof deferred> & {
+type Join = ReturnType<typeof deferred<void>> & {
channelId: string;
onJoin?: () => void;
restoredCall?: CallIdentity;
};
-type Leave = ReturnType<typeof deferred> & {
+type LeaveResult = { callEnded: boolean } | void;
+type Leave = ReturnType<typeof deferred<LeaveResult>> & {
channelId: string;
startedAt: number;
options?: CallSessionDisconnectOptions;
@@ -168,7 +169,7 @@ export function createCallLifecycle(options: {
requestToken: (channelId: string) => Promise<CallTokenResponse>;
connect: (token: CallTokenResponse) => Promise<void>;
disconnect: (options?: CallSessionDisconnectOptions) => Promise<void>;
- leave: (channelId: string) => Promise<unknown>;
+ leave: (channelId: string) => Promise<LeaveResult>;
lookup: (channelId: string) => Promise<ActiveCallLookup>;
currentCall: () => CallIdentity | undefined;
beginJoin: (channelId: string) => void;
@@ -189,7 +190,7 @@ export function createCallLifecycle(options: {
const pending = options.leave(channelId);
pendingServerLeaves.add(pending);
try {
- await pending;
+ return await pending;
} finally {
pendingServerLeaves.delete(pending);
}
@@ -461,11 +462,11 @@ export function createCallLifecycle(options: {
notifyLeft(request.channelId);
options.rollbackJoin();
options.setError(null);
- const finish = (error?: unknown) => {
+ const finish = (error?: unknown, result?: LeaveResult) => {
if (!active) return;
settled = true;
if (error) request.reject(error);
- else request.resolve();
+ else request.resolve(result);
dispatch({ t: 'finish' });
};
const timeout = setTimeout(
@@ -473,6 +474,7 @@ export function createCallLifecycle(options: {
LEAVE_TIMEOUT_MS
);
async function disconnect() {
+ let result: LeaveResult = undefined;
try {
try {
await options.disconnect(request.options);
@@ -480,9 +482,9 @@ export function createCallLifecycle(options: {
options.onLeft(request.channelId);
} finally {
if (active && !request.skipServerLeave)
- await leaveServer(request.channelId);
+ result = await leaveServer(request.channelId);
}
- finish();
+ finish(undefined, result);
} catch (error) {
if (active) finish(error);
else options.reportError(error);
@@ -536,7 +538,7 @@ export function createCallLifecycle(options: {
function leave(
channelId: string,
leaveOptions?: CallSessionDisconnectOptions
- ): Promise<void> {
+ ): Promise<LeaveResult> {
if (disposed) return Promise.reject(new Error('Call lifecycle disposed'));
const state = machine.getState();
if (state.t === 'leaving') {
@@ -556,7 +558,7 @@ export function createCallLifecycle(options: {
skipServerLeave = false
) {
const request: Leave = {
- ...deferred(),
+ ...deferred<LeaveResult>(),
channelId,
startedAt: Date.now(),
options: leaveOptions,
diff --git a/apps/web/src/features/channel/Call/tests/call-exit-navigation.test.tsx b/apps/web/src/features/channel/Call/tests/call-exit-navigation.test.tsx
new file mode 100644
index 0000000000..48891420e3
--- /dev/null
+++ b/apps/web/src/features/channel/Call/tests/call-exit-navigation.test.tsx
@@ -0,0 +1,89 @@
+// @vitest-environment jsdom
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@solidjs/testing-library';
+import { createSignal, Show } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import { ChannelCallTab } from '../ChannelCallTab';
+
+const state = vi.hoisted(() => ({
+ navigate: vi.fn(),
+ key: 'channel-route',
+ leave: async (): Promise<{ callEnded: boolean }> => ({ callEnded: false }),
+}));
+vi.mock('@solidjs/router', () => ({
+ useNavigate: () => state.navigate,
+ useLocation: () => ({
+ get key() {
+ return state.key;
+ },
+ }),
+}));
+vi.mock('@channel/Channel/ChannelTabContext', () => ({
+ useChannelTab: () => ({ setActiveTab: () => {} }),
+}));
+vi.mock('../use-call', () => ({
+ useCall: () => ({
+ leaveCall: () => state.leave(),
+ isInThisChannel: () => true,
+ joinError: () => null,
+ callCtx: { activeCallId: () => 'call-1', isInCall: () => false },
+ }),
+}));
+vi.mock('../ActiveCallLink', () => ({ ActiveCallLink: () => null }));
+vi.mock('../CallOverlay', () => ({
+ CallOverlay: (props: { onLeave: () => Promise<void> }) => (
+ <button type="button" onClick={props.onLeave}>
+ Leave call
+ </button>
+ ),
+}));
+vi.mock('@queries/call/call', () => ({}));
+vi.mock('@core/component/UserGroup', () => ({}));
+vi.mock('@core/user', () => ({}));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+it.each([
+ { callEnded: true, navigateAway: false, destination: '/calls/call/call-1' },
+ { callEnded: false, navigateAway: false, destination: undefined },
+ { callEnded: true, navigateAway: true, destination: undefined },
+])(
+ 'handles hangup after the call tab unmounts: $callEnded, moved=$navigateAway',
+ async (test) => {
+ state.key = 'channel-route';
+ const [inCallTab, setInCallTab] = createSignal(true);
+ let finish!: (result: { callEnded: boolean }) => void;
+ const response = new Promise<{ callEnded: boolean }>((resolve) => {
+ finish = resolve;
+ });
+ let leaving: Promise<{ callEnded: boolean }> | undefined;
+ state.leave = () => {
+ setInCallTab(false);
+ leaving = response;
+ return response;
+ };
+ render(() => (
+ <Show when={inCallTab()} fallback={<p>Channel messages</p>}>
+ <ChannelCallTab channelId="channel-1" />
+ </Show>
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'Leave call' }));
+ expect(screen.getByText('Channel messages')).toBeTruthy();
+ if (test.navigateAway) state.key = 'another-route';
+ finish({ callEnded: test.callEnded });
+ await leaving;
+ if (test.destination)
+ await waitFor(() =>
+ expect(state.navigate).toHaveBeenCalledExactlyOnceWith(test.destination)
+ );
+ else expect(state.navigate).not.toHaveBeenCalled();
+ }
+);
diff --git a/apps/web/src/features/channel/Call/tests/call-lifecycle.test.ts b/apps/web/src/features/channel/Call/tests/call-lifecycle.test.ts
index 455f0eeb9a..41fd9ed4ab 100644
--- a/apps/web/src/features/channel/Call/tests/call-lifecycle.test.ts
+++ b/apps/web/src/features/channel/Call/tests/call-lifecycle.test.ts
@@ -72,6 +72,16 @@ function setup(extra: Partial<Parameters<typeof createCallLifecycle>[0]> = {}) {
}
describe('shared call lifecycle', () => {
+ it.each([true, false])(
+ 'returns the server call-ended result: %s',
+ async (callEnded) => {
+ const { lifecycle, join } = setup({ leave: async () => ({ callEnded }) });
+ await join();
+ await expect(lifecycle.leave(call.channelId)).resolves.toEqual({
+ callEnded,
+ });
+ }
+ );
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(1_700_000_000_000);
diff --git a/apps/web/src/features/meetings/context/meeting-navigation.ts b/apps/web/src/features/meetings/context/meeting-navigation.ts
index 3158118592..898ffc36f7 100644
--- a/apps/web/src/features/meetings/context/meeting-navigation.ts
+++ b/apps/web/src/features/meetings/context/meeting-navigation.ts
@@ -6,7 +6,7 @@ export type MeetingNavigationCapabilities = {
replace: (
target: Extract<MeetingRouteTarget, { shareToken: string }>
) => void;
- returnToApp: () => void;
+ returnToApp: (path: string) => void;
};
/** Stable owner across the setup and connected URLs of a single meeting. */
diff --git a/apps/web/src/features/meetings/context/meeting-session.ts b/apps/web/src/features/meetings/context/meeting-session.ts
index d95d5f5dbe..998481314b 100644
--- a/apps/web/src/features/meetings/context/meeting-session.ts
+++ b/apps/web/src/features/meetings/context/meeting-session.ts
@@ -40,7 +40,10 @@ export type MeetingSessionCapabilities = {
/** Prepare a draft before requesting credentials; stop side effects if aborted. */
prepare?: (signal: AbortSignal) => Promise<void>;
join: (displayName?: string) => Promise<MeetingCredentials>;
- release: (shareToken: string, token: string) => Promise<unknown>;
+ release: (
+ shareToken: string,
+ token: string
+ ) => Promise<{ callEnded: boolean } | void>;
connect: (
credentials: MeetingCredentials,
preferences: MeetingMediaPreferences
diff --git a/apps/web/src/features/meetings/meeting-route.tsx b/apps/web/src/features/meetings/meeting-route.tsx
index 99f20db483..0f64d28a78 100644
--- a/apps/web/src/features/meetings/meeting-route.tsx
+++ b/apps/web/src/features/meetings/meeting-route.tsx
@@ -24,7 +24,7 @@ import { MeetingPage } from './views/meeting-page';
export function MeetingRouteContent(props: {
shareToken: string;
onCallStateChange: (connected: boolean) => void;
- onLeave: () => void;
+ onLeave: (path: string) => void;
}) {
const [search] = useSearchParams();
const location = useLocation();
diff --git a/apps/web/src/features/meetings/meeting-router.tsx b/apps/web/src/features/meetings/meeting-router.tsx
index 271f271683..1d8a05a9ce 100644
--- a/apps/web/src/features/meetings/meeting-router.tsx
+++ b/apps/web/src/features/meetings/meeting-router.tsx
@@ -39,7 +39,7 @@ function EnabledMeetingRouter() {
: getMeetingPath(target.shareToken),
{ replace: true }
),
- returnToApp: () => navigate('/', { replace: true }),
+ returnToApp: (path) => navigate(path, { replace: true }),
});
return (
<Suspense fallback={<div class="p-6 text-ink-muted">Loading call…</div>}>
@@ -48,7 +48,7 @@ function EnabledMeetingRouter() {
<Switch>
<Match when={entry.kind === 'new'}>
<NewMeetingRoute
- onLeave={() => navigation.leave(entry)}
+ onLeave={(path) => navigation.leave(entry, path)}
onCallStateChange={(connected, shareToken) =>
navigation.setCallState(entry, connected, shareToken)
}
@@ -57,7 +57,7 @@ function EnabledMeetingRouter() {
<Match when={entry.kind === 'existing' ? entry : undefined}>
{(existing) => (
<MeetingRouteContent
- onLeave={() => navigation.leave(entry)}
+ onLeave={(path) => navigation.leave(entry, path)}
shareToken={existing().shareToken}
onCallStateChange={(connected) =>
navigation.setCallState(
diff --git a/apps/web/src/features/meetings/new-meeting-route.tsx b/apps/web/src/features/meetings/new-meeting-route.tsx
index 3f33ea17c4..3ca794d6a0 100644
--- a/apps/web/src/features/meetings/new-meeting-route.tsx
+++ b/apps/web/src/features/meetings/new-meeting-route.tsx
@@ -32,7 +32,7 @@ import { MeetingPage } from './views/meeting-page';
function NewMeetingSetup(props: {
userId: string;
onCallStateChange: (connected: boolean, shareToken: string) => void;
- onLeave: () => void;
+ onLeave: (path: string) => void;
}) {
const call = useCallContext();
const lifecycle = useMeetingSessionLifecycle();
@@ -183,7 +183,7 @@ function NewMeetingSetup(props: {
export function NewMeetingRoute(props: {
onCallStateChange: (connected: boolean, shareToken: string) => void;
- onLeave: () => void;
+ onLeave: (path: string) => void;
}) {
const authenticated = useIsAuthenticated();
const userId = useUserId();
diff --git a/apps/web/src/features/meetings/primitives/meeting-navigation.test.ts b/apps/web/src/features/meetings/primitives/meeting-navigation.test.ts
index b330b9d203..2fa0e8de3b 100644
--- a/apps/web/src/features/meetings/primitives/meeting-navigation.test.ts
+++ b/apps/web/src/features/meetings/primitives/meeting-navigation.test.ts
@@ -54,11 +54,13 @@ describe('meeting route ownership', () => {
navigation.setCallState(owner, true, 'private-token');
navigation.replace.mockClear();
- navigation.leave(owner);
+ navigation.leave(owner, '/calls/call/finished-call');
navigation.setCallState(owner, false, 'private-token');
navigation.leave(owner);
- expect(navigation.returnToApp).toHaveBeenCalledOnce();
+ expect(navigation.returnToApp).toHaveBeenCalledExactlyOnceWith(
+ '/calls/call/finished-call'
+ );
expect(navigation.replace).not.toHaveBeenCalled();
});
diff --git a/apps/web/src/features/meetings/primitives/meeting-navigation.ts b/apps/web/src/features/meetings/primitives/meeting-navigation.ts
index 41ade3d048..f3c11f0845 100644
--- a/apps/web/src/features/meetings/primitives/meeting-navigation.ts
+++ b/apps/web/src/features/meetings/primitives/meeting-navigation.ts
@@ -46,7 +46,7 @@ export function createMeetingNavigation(
setConnection({ owner, connected, shareToken });
}
- function leave(owner: MeetingRouteEntry) {
+ function leave(owner: MeetingRouteEntry, path = '/') {
if (
entry() !== owner ||
owner === leavingOwner ||
@@ -57,7 +57,7 @@ export function createMeetingNavigation(
// Cleanup may report a disconnected session before the router unmounts it.
// Explicit Leave returns to Macro; only unexpected disconnects show setup.
setConnection(undefined);
- capabilities.returnToApp();
+ capabilities.returnToApp(path);
}
// Reflect session state in the URL; visiting an active URL does not join.
diff --git a/apps/web/src/features/meetings/primitives/meeting-session.ts b/apps/web/src/features/meetings/primitives/meeting-session.ts
index ec6f00c503..e4870124d3 100644
--- a/apps/web/src/features/meetings/primitives/meeting-session.ts
+++ b/apps/web/src/features/meetings/primitives/meeting-session.ts
@@ -26,7 +26,10 @@ export function createMeetingSession(capabilities: MeetingSessionCapabilities) {
async function release(session: IssuedMeetingSession) {
try {
- await capabilities.release(session.shareToken, session.credentials.token);
+ return await capabilities.release(
+ session.shareToken,
+ session.credentials.token
+ );
} catch (cause) {
// LiveKit's participant-left webhook also cleans up the session.
console.error('Failed to release meeting participant', cause);
@@ -191,6 +194,7 @@ export function createMeetingSession(capabilities: MeetingSessionCapabilities) {
// Start the keepalive release before awaiting local RTC disconnection:
// navigation or tab closure must not strand server-side participation.
const releasing = session ? release(session) : undefined;
+ let result: { callEnded: boolean } | void;
try {
// Cancellation must not wait for the token request it is cancelling.
// The shared lifecycle still retains that attempt independently.
@@ -205,11 +209,12 @@ export function createMeetingSession(capabilities: MeetingSessionCapabilities) {
console.error('Failed to disconnect meeting', cause);
} finally {
try {
- await releasing;
+ result = await releasing;
} finally {
cleanupLifecycle.complete();
}
}
+ return result;
}
onCleanup(() => {
diff --git a/apps/web/src/features/meetings/views/meeting-page-auth.test.tsx b/apps/web/src/features/meetings/views/meeting-page-auth.test.tsx
index 14bd5a7d31..5c81ffb6e9 100644
--- a/apps/web/src/features/meetings/views/meeting-page-auth.test.tsx
+++ b/apps/web/src/features/meetings/views/meeting-page-auth.test.tsx
@@ -1,5 +1,11 @@
// @vitest-environment jsdom
-import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
import { createMeetingSessionLifecycle } from '../primitives/meeting-session-lifecycle';
@@ -7,6 +13,138 @@ import { MeetingPage } from './meeting-page';
afterEach(cleanup);
+it.each([
+ {
+ authenticated: true,
+ channelId: 'channel-1',
+ scheduledStart: null,
+ callEnded: true,
+ path: '/calls/call/call-1',
+ },
+ {
+ authenticated: true,
+ channelId: 'channel-1',
+ scheduledStart: null,
+ callEnded: false,
+ path: '/channel/channel-1',
+ },
+ {
+ authenticated: true,
+ channelId: null,
+ scheduledStart: '2026-10-19T18:00:00Z',
+ callEnded: false,
+ path: '/component/calendar',
+ },
+ {
+ authenticated: true,
+ channelId: null,
+ scheduledStart: '2026-10-19T18:00:00Z',
+ callEnded: true,
+ path: '/calls/call/call-1',
+ },
+ {
+ authenticated: true,
+ channelId: null,
+ scheduledStart: null,
+ callEnded: false,
+ path: '/calls',
+ },
+ {
+ authenticated: true,
+ channelId: null,
+ scheduledStart: null,
+ callEnded: true,
+ path: '/calls/call/call-1',
+ },
+ {
+ authenticated: false,
+ channelId: null,
+ scheduledStart: null,
+ callEnded: true,
+ path: '/',
+ },
+])(
+ 'leaves for $path (ended=$callEnded, member=$authenticated)',
+ async (test) => {
+ const [activeCallId, setActiveCallId] = createSignal<string | null>(null);
+ let finishRelease!: (value: { callEnded: boolean }) => void;
+ const released = new Promise<{ callEnded: boolean }>((resolve) => {
+ finishRelease = resolve;
+ });
+ const onLeave = vi.fn();
+ const onCallStateChange = vi.fn();
+ render(() => (
+ <MeetingPage
+ source={() => ({
+ kind: 'ready',
+ title: 'Call',
+ channelId: test.channelId,
+ scheduledStart: test.scheduledStart,
+ scheduledEnd: null,
+ })}
+ authenticated={() => test.authenticated}
+ author={() => 'Member'}
+ onCopy={async () => {}}
+ onLeave={onLeave}
+ onCallStateChange={onCallStateChange}
+ mediaAccess={{
+ request: async () => {
+ throw new DOMException('Denied', 'NotAllowedError');
+ },
+ }}
+ session={{
+ lifecycle: createMeetingSessionLifecycle(),
+ shareToken: () => 'token',
+ isInCall: () => activeCallId() !== null,
+ activeCallId,
+ join: async () => ({
+ callId: 'call-1',
+ channelId: test.channelId,
+ roomName: 'room',
+ serverUrl: 'wss://example.com',
+ token: 'token',
+ participantId: 'member',
+ shareToken: 'share',
+ }),
+ release: () => released,
+ connect: async () => {
+ setActiveCallId('call-1');
+ },
+ disconnect: async () => {
+ setActiveCallId(null);
+ },
+ }}
+ renderCall={(leave) => (
+ <button type="button" onClick={leave}>
+ Hang up
+ </button>
+ )}
+ />
+ ));
+ if (!test.authenticated)
+ fireEvent.input(screen.getByRole('textbox', { name: 'Your name' }), {
+ target: { value: 'Guest' },
+ });
+ const joinButton = screen.getByRole('button', { name: 'Join call' });
+ await screen.findByText('Camera unavailable');
+ await waitFor(() =>
+ expect(joinButton.hasAttribute('disabled')).toBe(false)
+ );
+ fireEvent.click(joinButton);
+ await screen.findByRole('button', { name: 'Hang up' });
+ onCallStateChange.mockClear();
+ fireEvent.click(screen.getByRole('button', { name: 'Hang up' }));
+ expect(activeCallId()).toBeNull();
+ expect(screen.getByRole('status').textContent).toBe('Leaving call…');
+ expect(onLeave).not.toHaveBeenCalled();
+ expect(onCallStateChange).not.toHaveBeenCalled();
+ finishRelease({ callEnded: test.callEnded });
+ await waitFor(() =>
+ expect(onLeave).toHaveBeenCalledExactlyOnceWith(test.path)
+ );
+ }
+);
+
it('waits for confirmed membership before rendering setup or requesting devices', async () => {
const [authenticated, setAuthenticated] = createSignal<boolean>();
const request = vi.fn(async () => {
diff --git a/apps/web/src/features/meetings/views/meeting-page.tsx b/apps/web/src/features/meetings/views/meeting-page.tsx
index 6a6596b858..7290465ad6 100644
--- a/apps/web/src/features/meetings/views/meeting-page.tsx
+++ b/apps/web/src/features/meetings/views/meeting-page.tsx
@@ -1,16 +1,18 @@
+import { getCallExitPath } from '@channel/Call/call-exit';
import type { BackgroundEffect } from '@core/media/background-effect';
import { fireAndForget } from '@core/util/fireAndForget';
+import { Telemetry } from '@macro-inc/observability';
import ArrowLeft from '@phosphor/arrow-left.svg';
import Phone from '@phosphor/phone-call.svg';
import { Button } from '@ui';
import {
type Accessor,
- batch,
createEffect,
createSignal,
type JSX,
Match,
on,
+ onCleanup,
Show,
Switch,
} from 'solid-js';
@@ -49,7 +51,7 @@ export function MeetingPage(props: {
/** The host keeps the URL in sync without replacing this session owner. */
onCallStateChange?: (connected: boolean) => void;
/** Explicit hangup, distinct from losing the connection or cancelling setup. */
- onLeave?: () => void;
+ onLeave?: (path: string) => void;
/** Supplied only for the creator's New Call setup flow. */
renderInvite?: (joining: Accessor<boolean>) => JSX.Element;
/** Login redirect for channel-linked calls, which are members-only. */
@@ -63,6 +65,10 @@ export function MeetingPage(props: {
const session = createMeetingSession(props.session);
const [name, setName] = createSignal('');
const [leaving, setLeaving] = createSignal(false);
+ let disposed = false;
+ onCleanup(() => {
+ disposed = true;
+ });
const media = createMeetingMedia(props.mediaAccess, props.initialBackground);
const [uploadingBackground, setUploadingBackground] = createSignal(false);
const ready = () => {
@@ -79,7 +85,11 @@ export function MeetingPage(props: {
props.session.activeCallId() === session.joinedCallId() &&
props.session.isInCall();
- createEffect(on(inCall, (connected) => props.onCallStateChange?.(connected)));
+ createEffect(
+ on(inCall, (connected) => {
+ if (!leaving()) props.onCallStateChange?.(connected);
+ })
+ );
async function warmup() {
try {
@@ -121,13 +131,29 @@ export function MeetingPage(props: {
localTracks: media.handoff(),
});
};
- const leave = () => {
- batch(() => {
- setLeaving(true);
- fireAndForget(session.leave(), 'meetings');
- props.onLeave?.();
+ async function leave() {
+ if (leaving()) return;
+ const callId = session.joinedCallId();
+ const channelId = ready()?.channelId;
+ const scheduledStart = ready()?.scheduledStart;
+ const authenticated = props.authenticated() === true;
+ setLeaving(true);
+ await Telemetry.span('meeting.leave', async (span) => {
+ if (callId) span.setAttr('call.id', callId);
+ const result = await session.leave();
+ if (disposed) return;
+ const path = getCallExitPath({
+ authenticated,
+ callId,
+ channelId,
+ scheduledStart,
+ callEnded: result?.callEnded,
+ });
+ span.setAttr('call.leave.ended', result?.callEnded ?? false);
+ span.setAttr('call.leave.destination', path);
+ props.onLeave?.(path);
});
- };
+ }
return (
<main class="ph-no-capture flex h-dvh min-h-0 flex-col bg-surface p-4 text-ink sm:p-6">
@@ -175,7 +201,11 @@ export function MeetingPage(props: {
</Match>
<Match when={inCall()}>
<div class="min-h-0 flex-1">
- {props.renderCall(leave, displayName, session.credentials)}
+ {props.renderCall(
+ () => fireAndForget(leave(), 'meetings'),
+ displayName,
+ session.credentials
+ )}
</div>
</Match>
<Match when={props.source().kind === 'loading'}>
diff --git a/docs/agent-guide/calls.md b/docs/agent-guide/calls.md
index 4e89a5a850..7b9a3fc3b6 100644
--- a/docs/agent-guide/calls.md
+++ b/docs/agent-guide/calls.md
@@ -75,7 +75,11 @@ created on request via `Get shareable call link`.
New calls use `/app/meet/new`; shared links open setup at
`/app/meet/join/:shareToken`. A successful connection replaces the URL with
-`/app/meet/:shareToken` without restarting the call. Leaving returns to Macro.
+`/app/meet/:shareToken` without restarting the call. For signed-in participants,
+hangup opens the call record when the server confirms the call ended (the last
+participant left). Leaving an ongoing channel call opens its channel; leaving
+an ongoing scheduled call opens Calendar. Ongoing instant calls return to Calls.
+Guests return to Macro without opening a private call record.
An unexpected disconnection returns to setup so the user can retry.
Opening or reloading an in-call URL returns to setup and requires a deliberate
join; existing shared links continue to work.
@@ -109,8 +113,14 @@ viewer is signed out, setup must not request microphone or camera access; the
guest name form is available only for standalone meetings.
The call page shows a recording/transcription notice. It uses the normal call controls
-for audio, video, device selection, screen sharing, and effects. `Leave call` returns
-to Macro. `Copy Meeting Url` is available during the call.
+for audio, video, device selection, screen sharing, and effects. `Leave call` uses
+the destinations above after the server confirms whether the call ended.
+Check channel, scheduled, and instant calls with another participant remaining
+and as the last participant, including at phone width. During a delayed leave,
+the page shows `Leaving call…` without flashing setup; navigating elsewhere must
+not be undone when cleanup finishes. Inline channel call controls return to
+Messages on leave and open the record when that hangup ends the call.
+`Copy Meeting Url` is available during the call.
Rejoining from a new page waits for the prior page's pending leave cleanup before
requesting another connection, so a slow leave cannot disconnect the replacement.
Leaving the last participant archives the session first and tears down its media