CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 23s
CI / Build & Quality Checks (pull_request) Successful in 5m9s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Playwright smoke (e2e) (pull_request) Successful in 23m21s
Settings → Calls → "In-game overlay (beta)", desktop only, off by default, device-local. While a call is joined it sends the call snapshot to the desktop's new `set_overlay_state` command, which shows a small always-on-top, click-through list while Lotus isn't focused. - utils/callOverlay: pure snapshot builder. Everyone in the call, you first, one row per person across devices (speaking if any device is, muted only if all are), your own mute/deafen/PTT. In PTT mode you're not shown as Muted while the key is up. - useTauriOverlay: live io.lotus.call_state participants plus control state, coalesced to at most one send per 100 ms (latest always lands), unchanged snapshots skipped, cleared on unmount. - Overlay position setting (four corners). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
122 lines
3.5 KiB
TypeScript
122 lines
3.5 KiB
TypeScript
/**
|
|
* [cinny-desktop #25] In-game voice overlay: the call snapshot the desktop app
|
|
* draws in its always-on-top overlay window. Pure, so it can be tested without
|
|
* a call; `useTauriOverlay` feeds it live state and sends the result to the
|
|
* native `set_overlay_state` command.
|
|
*/
|
|
|
|
export type OverlayCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
|
|
export const OVERLAY_CORNERS: readonly OverlayCorner[] = [
|
|
'top-left',
|
|
'top-right',
|
|
'bottom-left',
|
|
'bottom-right',
|
|
];
|
|
|
|
export type OverlayPerson = {
|
|
userId: string;
|
|
name: string;
|
|
speaking: boolean;
|
|
muted: boolean;
|
|
isSelf: boolean;
|
|
};
|
|
|
|
/** Mirrors `OverlayState` in cinny-desktop `src-tauri/src/native/overlay.rs`. */
|
|
export type OverlaySnapshot = {
|
|
active: boolean;
|
|
corner: OverlayCorner;
|
|
muted: boolean;
|
|
deafened: boolean;
|
|
ptt: boolean;
|
|
people: OverlayPerson[];
|
|
};
|
|
|
|
/** The subset of an `io.lotus.call_state` participant the overlay needs. */
|
|
export type OverlayParticipant = {
|
|
userId: string;
|
|
speaking: boolean;
|
|
audioEnabled: boolean;
|
|
};
|
|
|
|
export type OverlayInput = {
|
|
/** Settings → Calls → In-game overlay. */
|
|
enabled: boolean;
|
|
/** In a joined call. */
|
|
joined: boolean;
|
|
corner: OverlayCorner;
|
|
myUserId: string | null;
|
|
/** Per device, in the fork's order (stable while people stay). */
|
|
participants: readonly OverlayParticipant[];
|
|
nameOf: (userId: string) => string;
|
|
/** Own mic is off (`microphone === false`). */
|
|
muted: boolean;
|
|
/** Own call audio is off (`sound === false`). */
|
|
deafened: boolean;
|
|
pttMode: boolean;
|
|
};
|
|
|
|
export const inactiveOverlay = (corner: OverlayCorner): OverlaySnapshot => ({
|
|
active: false,
|
|
corner,
|
|
muted: false,
|
|
deafened: false,
|
|
ptt: false,
|
|
people: [],
|
|
});
|
|
|
|
/**
|
|
* Build the snapshot: everyone in the call (you first, then everyone else in
|
|
* call order), one row per person even with several devices (speaking if any
|
|
* device is, muted only if every device is), and your own mute / deafen / PTT
|
|
* state for the header.
|
|
*
|
|
* In push-to-talk mode the mic is "off" whenever the key isn't held, so you
|
|
* are not shown as Muted then: the header says PTT, and your row lights up
|
|
* while you transmit.
|
|
*/
|
|
export function buildOverlaySnapshot(input: OverlayInput): OverlaySnapshot {
|
|
const { corner } = input;
|
|
if (!input.enabled || !input.joined) return inactiveOverlay(corner);
|
|
|
|
const byUser = new Map<string, { speaking: boolean; muted: boolean }>();
|
|
input.participants.forEach((p) => {
|
|
if (!p.userId.startsWith('@')) return;
|
|
const prev = byUser.get(p.userId);
|
|
byUser.set(p.userId, {
|
|
speaking: (prev?.speaking ?? false) || p.speaking,
|
|
muted: (prev?.muted ?? true) && !p.audioEnabled,
|
|
});
|
|
});
|
|
|
|
const selfMuted = input.pttMode ? false : input.muted;
|
|
const people: OverlayPerson[] = [];
|
|
const me = input.myUserId;
|
|
if (me) {
|
|
const mine = byUser.get(me);
|
|
people.push({
|
|
userId: me,
|
|
name: input.nameOf(me),
|
|
speaking: (mine?.speaking ?? false) && !selfMuted && !input.deafened,
|
|
muted: selfMuted || input.deafened,
|
|
isSelf: true,
|
|
});
|
|
}
|
|
byUser.forEach((state, userId) => {
|
|
if (userId === me) return;
|
|
people.push({ userId, name: input.nameOf(userId), ...state, isSelf: false });
|
|
});
|
|
|
|
return {
|
|
active: true,
|
|
corner,
|
|
muted: selfMuted,
|
|
deafened: input.deafened,
|
|
ptt: input.pttMode,
|
|
people,
|
|
};
|
|
}
|
|
|
|
/** Key for skipping sends when nothing visible changed. */
|
|
export const overlaySnapshotKey = (s: OverlaySnapshot): string => JSON.stringify(s);
|