Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73bf2133dc | ||
|
|
58625c86b0 | ||
|
|
e3ac9a96d6 | ||
|
|
34d541b707 | ||
|
|
eb59fd5b3f | ||
|
|
fea233f5e1 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lotusguild/element-call-embedded",
|
||||
"version": "0.25.0-lotus.22",
|
||||
"version": "0.25.0-lotus.24",
|
||||
"files": [
|
||||
"README.md",
|
||||
"LICENSE-AGPL-3.0",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright 2026 Lotus Guild
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import { audioOutputList } from "./lotusAudioOutput";
|
||||
import { type AudioOutputDeviceLabel } from "../state/MediaDevices";
|
||||
|
||||
test("audioOutputList labels every kind of output (cinny #310)", () => {
|
||||
const m = new Map<string, AudioOutputDeviceLabel>([
|
||||
["", { type: "default", name: "Speakers" }],
|
||||
["a1", { type: "name", name: "Headset" }],
|
||||
["a2", { type: "number", number: 3 }],
|
||||
]);
|
||||
expect(audioOutputList(m)).toEqual([
|
||||
{ id: "", label: "Default (Speakers)" },
|
||||
{ id: "a1", label: "Headset" },
|
||||
{ id: "a2", label: "Output 3" },
|
||||
]);
|
||||
});
|
||||
@@ -8,7 +8,12 @@ Please see LICENSE in the repository root for full details.
|
||||
import { type IWidgetApiRequest } from "matrix-widget-api";
|
||||
import { logger } from "matrix-js-sdk/lib/logger";
|
||||
|
||||
import { type MediaDevices } from "../state/MediaDevices";
|
||||
import { combineLatest } from "rxjs";
|
||||
|
||||
import {
|
||||
type AudioOutputDeviceLabel,
|
||||
type MediaDevices,
|
||||
} from "../state/MediaDevices";
|
||||
import { widget } from "../widget";
|
||||
import { LotusWidgetActions } from "./lotusActions";
|
||||
import { lotusSendToHost } from "./lotusWidget";
|
||||
@@ -19,6 +24,10 @@ import { lotusSendToHost } from "./lotusWidget";
|
||||
* selects the output; the fork answers each change (and the initial state)
|
||||
* with `io.lotus.audio_output_state { deviceId, available: [{id,label}] }`.
|
||||
* No effect unless the host sends the action. Returns a teardown function.
|
||||
*
|
||||
* [cinny #310] Browsers hash deviceIds per frame/origin, so the host can't
|
||||
* use ids from its own enumerateDevices(); it builds its menu from
|
||||
* `available` here, whose ids are valid in this frame.
|
||||
*/
|
||||
export function startLotusAudioOutput(mediaDevices: MediaDevices): () => void {
|
||||
const w = widget;
|
||||
@@ -33,9 +42,13 @@ export function startLotusAudioOutput(mediaDevices: MediaDevices): () => void {
|
||||
};
|
||||
w.lazyActions.on(LotusWidgetActions.SetAudioOutput, handler);
|
||||
|
||||
const sub = mediaDevices.audioOutput.selected$.subscribe((selected) => {
|
||||
const sub = combineLatest([
|
||||
mediaDevices.audioOutput.available$,
|
||||
mediaDevices.audioOutput.selected$,
|
||||
]).subscribe(([available, selected]) => {
|
||||
lotusSendToHost(LotusWidgetActions.AudioOutputState, {
|
||||
deviceId: selected?.id ?? null,
|
||||
available: audioOutputList(available),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,3 +57,29 @@ export function startLotusAudioOutput(mediaDevices: MediaDevices): () => void {
|
||||
w.lazyActions.off(LotusWidgetActions.SetAudioOutput, handler);
|
||||
};
|
||||
}
|
||||
|
||||
/** The output list as `{id, label}` for the host's menu (#310). */
|
||||
export function audioOutputList(
|
||||
available: Map<string, AudioOutputDeviceLabel>,
|
||||
): { id: string; label: string }[] {
|
||||
return [...available].map(([id, l]) => {
|
||||
let label: string;
|
||||
switch (l.type) {
|
||||
case "name":
|
||||
label = l.name;
|
||||
break;
|
||||
case "number":
|
||||
label = `Output ${l.number}`;
|
||||
break;
|
||||
case "default":
|
||||
label = l.name ? `Default (${l.name})` : "Default";
|
||||
break;
|
||||
case "speaker":
|
||||
label = "Speaker";
|
||||
break;
|
||||
default:
|
||||
label = "Earpiece";
|
||||
}
|
||||
return { id, label };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user