Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
888ed1a66c |
@@ -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, sameRooms } from "./lotusMicLevel";
|
||||
import { MicLevelQuantizer } from "./lotusMicLevel";
|
||||
|
||||
describe("MicLevelQuantizer", () => {
|
||||
it("maps RMS to 0–3 bars", () => {
|
||||
@@ -35,14 +35,3 @@ 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,10 +46,6 @@ 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>
|
||||
@@ -66,15 +62,10 @@ 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(
|
||||
(rooms) =>
|
||||
(data) =>
|
||||
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