Compare commits

..
Author SHA1 Message Date
Lotus CIandClaude Opus 5.5 73bf2133dc fix(lotus): restart the shared mic sampler only when the LiveKit rooms change (#45)
CI / Publish to Gitea npm registry (pull_request) Skipped
CI / Build embedded bundle (pull_request) Successful in 3m16s
observeLocalMicSample$ switchMapped on every allConnections$ emission,
which re-emits far more often than the set of rooms changes. Each one
stopped the clone, closed the AudioContext and emitted null, and the
null reset the muted-speech gate, so the "You're muted" nudge could
never stay true long enough to fire. Map to the room list and only
restart when it actually changes.

Fixes #45

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-18 01:17:06 -04:00
5 changed files with 23 additions and 40 deletions
-2
View File
@@ -34,7 +34,6 @@ describe("LotusWidgetActions", () => {
LotusWidgetActions.SetHotkeys,
LotusWidgetActions.SetFrameScreenshare,
LotusWidgetActions.PromptScreenshare,
LotusWidgetActions.Reconnect,
];
expect(new Set(LOTUS_TO_WIDGET_ACTIONS)).toEqual(new Set(expectedToWidget));
@@ -57,6 +56,5 @@ describe("LotusWidgetActions", () => {
);
expect(LOTUS_TO_WIDGET_ACTIONS).not.toContain(LotusWidgetActions.MicLevel);
expect(LOTUS_TO_WIDGET_ACTIONS).not.toContain(LotusWidgetActions.Hotkey);
expect(LOTUS_TO_WIDGET_ACTIONS).not.toContain(LotusWidgetActions.CallError);
});
});
-9
View File
@@ -116,14 +116,6 @@ export enum LotusWidgetActions {
* only when it changes (≤ 10 Hz); 0 while muted or with no mic.
*/
MicLevel = "io.lotus.mic_level",
/**
* fromWidget: the call's error page is up (`{ code, recoverable }`) or
* cleared (`{ code: null }`) (cinny #318), so the host stops showing the call
* as joined after "Connection lost".
*/
CallError = "io.lotus.call_error",
/** toWidget: press the error page's Reconnect / Try again (cinny #318). */
Reconnect = "io.lotus.reconnect",
}
/** toWidget Lotus actions that must be allow-listed in `initializeWidget`. */
@@ -141,5 +133,4 @@ export const LOTUS_TO_WIDGET_ACTIONS: LotusWidgetActions[] = [
LotusWidgetActions.SetHotkeys,
LotusWidgetActions.SetFrameScreenshare,
LotusWidgetActions.PromptScreenshare,
LotusWidgetActions.Reconnect,
];
+12 -1
View File
@@ -7,7 +7,7 @@ Please see LICENSE in the repository root for full details.
import { describe, expect, it } from "vitest";
import { MicLevelQuantizer } from "./lotusMicLevel";
import { MicLevelQuantizer, sameRooms } from "./lotusMicLevel";
describe("MicLevelQuantizer", () => {
it("maps RMS to 0–3 bars", () => {
@@ -35,3 +35,14 @@ describe("MicLevelQuantizer", () => {
expect(q.push(0)).toBe(0);
});
});
describe("sameRooms (EC #45)", () => {
it("compares rooms by identity and order", () => {
const a = {};
const b = {};
expect(sameRooms([a, b], [a, b])).toBe(true);
expect(sameRooms([a], [a, b])).toBe(false);
expect(sameRooms([a, b], [b, a])).toBe(false);
expect(sameRooms([{}], [{}])).toBe(false);
});
});
+11 -2
View File
@@ -46,6 +46,10 @@ const micPublication = (
: null;
};
/** Pure: the same LiveKit rooms, in the same order (by identity). */
export const sameRooms = <T>(a: readonly T[], b: readonly T[]): boolean =>
a.length === b.length && a.every((r, i) => r === b[i]);
const samplers = new WeakMap<
CallViewModel,
Observable<LocalMicSample | null>
@@ -62,10 +66,15 @@ export function observeLocalMicSample$(
const cached = samplers.get(vm);
if (cached) return cached;
const sampler$ = vm.allConnections$.pipe(
map((data) => data.getConnections().map((c) => c.livekitRoom)),
// [EC #45] allConnections$ re-emits far more often than the set of
// LiveKit rooms changes; restarting the tap each time closed the
// AudioContext ~1×/s and emitted null, which reset the muted-speech
// gate so the "You're muted" nudge could never fire.
distinctUntilChanged(sameRooms),
switchMap(
(data) =>
(rooms) =>
new Observable<LocalMicSample | null>((subscriber) => {
const rooms = data.getConnections().map((c) => c.livekitRoom);
let ctx: AudioContext | null = null;
let clone: MediaStreamTrack | null = null;
let timer: ReturnType<typeof setInterval> | undefined;
-26
View File
@@ -13,7 +13,6 @@ import {
type ReactNode,
type SVGAttributes,
useCallback,
useEffect,
} from "react";
import { Trans, useTranslation } from "react-i18next";
import {
@@ -25,7 +24,6 @@ import {
import { Button } from "@vector-im/compound-web";
import { logger } from "matrix-js-sdk/lib/logger";
import { MatrixError } from "matrix-js-sdk";
import { type IWidgetApiRequest } from "matrix-widget-api";
import {
ConnectionLostError,
@@ -40,7 +38,6 @@ import { FullScreenView } from "../FullScreenView.tsx";
import { ErrorView } from "../ErrorView.tsx";
import { type WidgetHelpers } from "../widget.ts";
import styles from "../ErrorView.module.css";
import { LotusWidgetActions, lotusSendToHost } from "../lotus/lotusWidget";
export type CallErrorRecoveryAction = "reconnect"; // | "retry" ;
@@ -77,29 +74,6 @@ const ErrorPage: FC<ErrorPageProps> = ({
icon = ErrorSolidIcon;
}
// [cinny #318] Tell the host the call dropped (it kept showing the call as
// joined), and let its call bar press Reconnect for us.
const recoverable =
error instanceof ConnectionLostError ||
error instanceof LivekitConnectionError ||
error instanceof PeerConnectionTimeoutError;
useEffect(() => {
lotusSendToHost(LotusWidgetActions.CallError, {
code: error.code,
recoverable,
});
const w = widget;
const onReconnect = (ev: CustomEvent<IWidgetApiRequest>): void => {
w?.api.transport.reply(ev.detail, {});
if (recoverable) void recoveryActionHandler("reconnect");
};
w?.lazyActions?.on(LotusWidgetActions.Reconnect, onReconnect);
return (): void => {
w?.lazyActions?.off(LotusWidgetActions.Reconnect, onReconnect);
lotusSendToHost(LotusWidgetActions.CallError, { code: null });
};
}, [error.code, recoverable, recoveryActionHandler, widget]);
const actions: { label: string; onClick: () => void }[] = [];
if (error instanceof ConnectionLostError) {
actions.push({