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
52 changes: 33 additions & 19 deletions apps/desktop/src/meeting-float/host.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,42 @@ describe("FloatingMeetingWindowHost", () => {
transcriptBubbles: null,
}),
);
expect(mocks.liveCaptionShow).toHaveBeenCalledOnce();
expect(mocks.liveCaptionUpdate).toHaveBeenLastCalledWith(
expect.objectContaining({
text: "we should ship this",
minimized: false,
}),
);
});
expect(mocks.liveCaptionShow).not.toHaveBeenCalled();
expect(mocks.liveCaptionHide).toHaveBeenCalled();
expect(mocks.floatingBarShow).toHaveBeenCalledOnce();
expect(mocks.floatingBarHide).not.toHaveBeenCalled();
});

it("shows the floating bar on Windows and Linux", async () => {
mocks.platform.mockReturnValue("linux");

render(<FloatingMeetingWindowHost />);

await waitFor(() => {
expect(mocks.floatingBarShow).toHaveBeenCalledOnce();
expect(mocks.floatingBarUpdate).toHaveBeenCalled();
});
expect(mocks.liveCaptionHide).toHaveBeenCalled();
expect(mocks.liveCaptionShow).not.toHaveBeenCalled();
});
it.each(["windows", "linux"] as const)(
"uses the floating bar on %s like macOS, without the old caption overlay",
async (currentPlatform) => {
mocks.platform.mockReturnValue(currentPlatform);

const view = render(<FloatingMeetingWindowHost />);

await waitFor(() => {
expect(mocks.floatingBarShow).toHaveBeenCalledOnce();
expect(mocks.floatingBarUpdate).toHaveBeenLastCalledWith(
expect.objectContaining({ liveCaptionMinimized: true }),
);
});

mocks.settings.current = {
...mocks.settings.current,
live_caption_minimized: false,
};
view.rerender(<FloatingMeetingWindowHost />);

await waitFor(() => {
expect(mocks.floatingBarUpdate).toHaveBeenLastCalledWith(
expect.objectContaining({ liveCaptionMinimized: false }),
);
});
expect(mocks.liveCaptionHide).toHaveBeenCalled();
expect(mocks.liveCaptionShow).not.toHaveBeenCalled();
expect(mocks.liveCaptionUpdate).not.toHaveBeenCalled();
expect(mocks.floatingBarHide).not.toHaveBeenCalled();
},
);
});
79 changes: 1 addition & 78 deletions apps/desktop/src/meeting-float/host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
getCurrentFloatingBarColorScheme,
getFloatingLiveCaptionToggleVisible,
getFloatingRouteState,
getLiveCaptionRouteState,
isSameFloatingRouteState,
isSameLiveCaptionRouteState,
type FloatingRouteState,
type ListenerState,
} from "./route-state";
Expand All @@ -31,7 +29,6 @@ import {
import { isFloatingBarSupported } from "./support";
import {
createFloatingMeetingWindowSynchronizer,
createLiveCaptionWindowSynchronizer,
hideFloatingMeetingPanel,
hideLiveCaptionPanel,
showFloatingMeetingWindow,
Expand Down Expand Up @@ -77,11 +74,7 @@ export function FloatingMeetingWindowHost() {
) : (
<FloatingMeetingWindowDisabled />
)}
{floatingOverlaySupported ? (
<LiveCaptionWindowSync settings={overlaySettings} />
) : (
<LiveCaptionWindowDisabled />
)}
<LiveCaptionWindowDisabled />
</>
);
}
Expand Down Expand Up @@ -171,63 +164,6 @@ function LiveCaptionWindowDisabled() {
return null;
}

function LiveCaptionWindowSync({
settings,
}: {
settings: FloatingOverlaySettings;
}) {
const settingsRef = useLatestRef(settings);
const refreshSettingsRef = useRef<() => void>(() => {});

useMountEffect(() => {
let routeState = getLiveCaptionRouteState(
listenerStore.getState(),
settingsRef.current,
);
const windowSynchronizer = createLiveCaptionWindowSynchronizer();

const updateRouteState = (
nextRouteState: ReturnType<typeof getLiveCaptionRouteState>,
) => {
if (isSameLiveCaptionRouteState(nextRouteState, routeState)) {
return;
}

routeState = nextRouteState;
windowSynchronizer.update(routeState);
};
const refreshCurrentRouteState = () => {
updateRouteState(
getLiveCaptionRouteState(listenerStore.getState(), settingsRef.current),
);
};
refreshSettingsRef.current = refreshCurrentRouteState;

windowSynchronizer.update(routeState);

const unsubscribe = listenerStore.subscribe((state, previousState) => {
if (!haveLiveCaptionRouteInputsChanged(state, previousState)) {
return;
}

refreshCurrentRouteState();
});

return () => {
refreshSettingsRef.current = () => {};
unsubscribe();
void windowSynchronizer.dispose();
};
});

return (
<FloatingMeetingWindowSettingsSync
key={JSON.stringify(settings)}
onSettingsChange={() => refreshSettingsRef.current()}
/>
);
}

function FloatingMeetingWindowSync({
settings,
}: {
Expand Down Expand Up @@ -390,19 +326,6 @@ function getCurrentFloatingRouteState(
});
}

function haveLiveCaptionRouteInputsChanged(
state: ListenerState,
previousState: ListenerState,
) {
return (
state.live.status !== previousState.live.status ||
state.live.sessionId !== previousState.live.sessionId ||
state.live.liveTranscriptionActive !==
previousState.live.liveTranscriptionActive ||
state.liveCaptionText !== previousState.liveCaptionText
);
}

function haveFloatingRouteInputsChanged(
state: ListenerState,
previousState: ListenerState,
Expand Down
Loading
Loading