Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88c648ba8b | ||
|
|
0aa543cc7d | ||
|
|
cc57292bf4 | ||
|
|
22f9083768 | ||
|
|
d7d75cbba5 | ||
|
|
4be3e92eb6 | ||
|
|
a1dd0e254c | ||
|
|
888ed1a66c | ||
|
|
73bf2133dc | ||
|
|
07e1506dd8 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lotusguild/element-call-embedded",
|
||||
"version": "0.25.0-lotus.24",
|
||||
"version": "0.25.0-lotus.25",
|
||||
"files": [
|
||||
"README.md",
|
||||
"LICENSE-AGPL-3.0",
|
||||
|
||||
@@ -34,6 +34,7 @@ describe("LotusWidgetActions", () => {
|
||||
LotusWidgetActions.SetHotkeys,
|
||||
LotusWidgetActions.SetFrameScreenshare,
|
||||
LotusWidgetActions.PromptScreenshare,
|
||||
LotusWidgetActions.Reconnect,
|
||||
];
|
||||
|
||||
expect(new Set(LOTUS_TO_WIDGET_ACTIONS)).toEqual(new Set(expectedToWidget));
|
||||
@@ -56,5 +57,6 @@ 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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -116,6 +116,14 @@ 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`. */
|
||||
@@ -133,4 +141,5 @@ export const LOTUS_TO_WIDGET_ACTIONS: LotusWidgetActions[] = [
|
||||
LotusWidgetActions.SetHotkeys,
|
||||
LotusWidgetActions.SetFrameScreenshare,
|
||||
LotusWidgetActions.PromptScreenshare,
|
||||
LotusWidgetActions.Reconnect,
|
||||
];
|
||||
|
||||
@@ -11,6 +11,7 @@ import { of } from "rxjs";
|
||||
|
||||
import { type CallViewModel } from "../state/CallViewModel/CallViewModel";
|
||||
import {
|
||||
canPublishSoundboard,
|
||||
MAX_INJECT_BYTES,
|
||||
parseInjectSource,
|
||||
startLotusAudioInject,
|
||||
@@ -258,3 +259,17 @@ test("parseInjectSource rejects oversized or non-buffer audio", () => {
|
||||
expect(parseInjectSource({ audio: "not bytes" })).toBeNull();
|
||||
expect(parseInjectSource({ audio: new Uint8Array(4) })).toBeNull();
|
||||
});
|
||||
|
||||
test("canPublishSoundboard: refused by a microphone-only grant (EC #47)", () => {
|
||||
expect(canPublishSoundboard(undefined)).toBe(true);
|
||||
expect(
|
||||
canPublishSoundboard({ canPublish: true, canPublishSources: [] }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
canPublishSoundboard({ canPublish: true, canPublishSources: [2] }),
|
||||
).toBe(false);
|
||||
expect(
|
||||
canPublishSoundboard({ canPublish: true, canPublishSources: [2, 0] }),
|
||||
).toBe(true);
|
||||
expect(canPublishSoundboard({ canPublish: false })).toBe(false);
|
||||
});
|
||||
|
||||
@@ -60,6 +60,22 @@ function acquireSharedAudio(): {
|
||||
* No effect unless the host sends the action. Returns a teardown function that
|
||||
* also aborts any clip still playing.
|
||||
*/
|
||||
/**
|
||||
* Pure: whether these LiveKit permissions allow publishing the soundboard's
|
||||
* Unknown-source track (EC #47). No permissions or an empty source list
|
||||
* means unrestricted; otherwise UNKNOWN (TrackSource 0) must be allowed.
|
||||
*/
|
||||
export function canPublishSoundboard(
|
||||
perm:
|
||||
| { canPublish?: boolean; canPublishSources?: readonly number[] }
|
||||
| undefined,
|
||||
): boolean {
|
||||
if (!perm) return true;
|
||||
if (perm.canPublish === false) return false;
|
||||
const sources = perm.canPublishSources ?? [];
|
||||
return sources.length === 0 || sources.includes(0);
|
||||
}
|
||||
|
||||
export function startLotusAudioInject(vm: CallViewModel): () => void {
|
||||
const w = widget;
|
||||
if (!w) return () => undefined;
|
||||
@@ -116,6 +132,19 @@ export function startLotusAudioInject(vm: CallViewModel): () => void {
|
||||
return;
|
||||
}
|
||||
|
||||
// [EC #47] Clips publish as an Unknown-source track. Audio-only rooms get
|
||||
// a token limited to the microphone source, where LiveKit refuses that
|
||||
// publish *after* we replied; say so up front instead of failing silently.
|
||||
if (
|
||||
rooms.some((r) => !canPublishSoundboard(r.localParticipant.permissions))
|
||||
) {
|
||||
w.api.transport.reply(ev.detail, {
|
||||
played: false,
|
||||
reason: "not_permitted",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
w.api.transport.reply(ev.detail, {});
|
||||
void playInjectedClip(clip, volume, rooms, activeClips).catch((e) =>
|
||||
logger.warn("[lotus] inject_audio failed", e),
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
type ReactNode,
|
||||
type SVGAttributes,
|
||||
useCallback,
|
||||
useEffect,
|
||||
} from "react";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import {
|
||||
@@ -24,6 +25,7 @@ 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,
|
||||
@@ -38,6 +40,7 @@ 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" ;
|
||||
|
||||
@@ -74,6 +77,29 @@ 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({
|
||||
|
||||
@@ -868,16 +868,19 @@ export function enterRTCSession(
|
||||
};
|
||||
}
|
||||
|
||||
// Calculates `maximumNetworkErrorRetryCount`. The connection is failed if EITHER:
|
||||
// - The /sync loop is unresponsive for > `gracePeriod` ms, or
|
||||
// - A delayed leave event is emitted (after `leaveDelay` ms period).
|
||||
// Note: Use leaveDelay >> gracePeriod for delegated leave events.
|
||||
// Calculates `maximumNetworkErrorRetryCount`: enough retries to outlast the
|
||||
// server's delayed-leave window (see [lotus #46] below).
|
||||
const gracePeriod = Config.get().sync_disconnect_grace_period_ms;
|
||||
const leaveDelay = matrixRtcSessionConfig?.delayed_leave_event_delay_ms;
|
||||
const retryInterval = matrixRtcSessionConfig?.network_error_retry_ms;
|
||||
|
||||
// Math.min is used to account for the respective worst case: /sync not available or leave event emitted.
|
||||
const maxWaitTime = Math.min(gracePeriod, leaveDelay);
|
||||
// [lotus #46] Keep retrying for as long as the homeserver itself would keep
|
||||
// our membership: until its delayed leave fires (`leaveDelay`). Capping at
|
||||
// the 10 s sync grace period made a ~20–35 s homeserver stall end everyone's
|
||||
// call ("Connection lost") even with a 60 s server-side leave delay. The
|
||||
// embedded call has no /sync loop of its own, so the grace period doesn't
|
||||
// describe anything it can observe.
|
||||
const maxWaitTime = Math.max(gracePeriod, leaveDelay);
|
||||
const maximumNetworkErrorRetryCount =
|
||||
Math.ceil(maxWaitTime / retryInterval) + 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user