fix(sharing): bind room header settings to the active source
This commit is contained in:
1 parent
fbebd86faf
commit
4d2f22bd2b
2 files changed
+21
-8
No files matched your search
@@ -78,8 +78,8 @@ export function ChannelShareControl({ channel, roomId, publicationId, compact =
|
||||
const externalInput = channel.externalInput(roomId);
|
||||
const available = browserSupported || cameraSupported || appConnected;
|
||||
const pickerAvailable = appConnected || cameraSupported;
|
||||
const sharing = publicationId ? channel.state?.publications.find(publication =>
|
||||
publication.id === publicationId && publication.roomId === roomId && channel.ownedScreens.has(publication.id)) : undefined;
|
||||
const sharing = channel.state?.publications.find(publication => publication.kind === "screen" &&
|
||||
(!publicationId || publication.id === publicationId) && publication.roomId === roomId && channel.ownedScreens.has(publication.id));
|
||||
const roomName = sharing ? channel.state?.channel.rooms.find(room => room.id === roomId)?.name : undefined;
|
||||
const settingsTitle = roomName
|
||||
? lang === "zh" ? `${roomName}的分享设置` : `Share settings in ${roomName}`
|
||||
@@ -105,7 +105,8 @@ export function ChannelShareControl({ channel, roomId, publicationId, compact =
|
||||
const microphonePending = !!sharing && channel.pending.has(`source-microphone:${sharing.id}`);
|
||||
const { sourceMicrophones } = channel;
|
||||
const loadAudioApplications = useCallback(async () => (await nativeSources()).sources, [nativeSources]);
|
||||
const loadMicrophones = useCallback(() => publicationId ? sourceMicrophones(publicationId) : Promise.resolve([]), [publicationId, sourceMicrophones]);
|
||||
const sharingId = sharing?.id;
|
||||
const loadMicrophones = useCallback(() => sharingId ? sourceMicrophones(sharingId) : Promise.resolve([]), [sharingId, sourceMicrophones]);
|
||||
const roomMicrophone = channel.state?.voice.some(voice => voice.sessionId === channel.sessionId && !voice.muted);
|
||||
const busy = channel.pending.has(`screen:${roomId}`) || !!sharing && channel.pending.has(`source-audio:${sharing.id}`);
|
||||
const label = t(sharing ? "host.switchSource" : "host.start");
|
||||
|
||||
@@ -95,22 +95,34 @@ describe("shared App connection entry", () => {
|
||||
expect(html).toMatch(/aria-label="(?:Share settings|分享设置)"/);
|
||||
});
|
||||
it("binds live controls to their owned publication without retargeting a retired source", () => {
|
||||
setCopy({ lang: "en", vis: false });
|
||||
vi.stubGlobal("navigator", { mediaDevices: { getDisplayMedia: vi.fn() } });
|
||||
const ownedScreens = new Set(["mine"]);
|
||||
const ownedScreens = new Set(["mine", "voice"]);
|
||||
const screenQuality = vi.fn(() => ({ applied: DEFAULT_QUALITY_SETTINGS, requested: DEFAULT_QUALITY_SETTINGS }));
|
||||
const channel = { quality: DEFAULT_QUALITY_SETTINGS, setQuality: vi.fn(), appConnected: false, pending: new Set(), nativeCaptureRequest: () => undefined, nativeCaptureSelection: () => undefined, externalInput: () => undefined,
|
||||
screenQuality: () => undefined, screenCodecMode: () => undefined,
|
||||
screenQuality, screenCodecMode: () => undefined,
|
||||
sourceAudio: () => undefined, sourceMicrophone: () => undefined,
|
||||
ownedScreens, streams: new Map(), state: { channel: { rooms: [{ id: "room", name: "Friday" }] }, publications: [{ id: "mine", roomId: "room" }], voice: [] },
|
||||
ownedScreens, streams: new Map(), state: { channel: { rooms: [{ id: "room", name: "Friday" }] }, publications: [
|
||||
{ id: "other-endpoint", roomId: "room", kind: "screen", userId: "self" },
|
||||
{ id: "voice", roomId: "room", kind: "voice", userId: "self" },
|
||||
{ id: "mine", roomId: "room", kind: "screen", userId: "self" },
|
||||
], voice: [] },
|
||||
} as unknown as ChannelController;
|
||||
const html = renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "room", publicationId: "mine", compact: true, disabled: false }));
|
||||
expect(html).toMatch(/aria-label="(?:Switch source in Friday|切换Friday的分享源)"/);
|
||||
expect(html.match(/<button\b/g)).toHaveLength(2);
|
||||
expect(html).toMatch(/aria-label="(?:Share settings in Friday|Friday的分享设置)"/);
|
||||
const header = renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "room", disabled: false }));
|
||||
expect(header).toContain('aria-label="Switch source in Friday"');
|
||||
expect(header).toContain('aria-label="Share settings in Friday"');
|
||||
expect(screenQuality.mock.calls).toEqual([["mine"], ["mine"]]);
|
||||
expect(renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "room", publicationId: "retired", disabled: false }))).toBe("");
|
||||
const elsewhere = renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "other", disabled: false }));
|
||||
expect(elsewhere).not.toMatch(/aria-label="(?:Switch source|切换来源)"/);
|
||||
expect(renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "other", publicationId: "mine", disabled: false }))).toBe("");
|
||||
ownedScreens.clear();
|
||||
expect(renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "room", publicationId: "mine", disabled: false }))).toBe("");
|
||||
expect(renderToStaticMarkup(createElement(ChannelShareControl, { channel, roomId: "room", disabled: false }))).toContain(`aria-label="${t("en", "host.start")}"`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,7 +137,7 @@ describe("Native sharing capabilities", () => {
|
||||
const channel = { quality: DEFAULT_QUALITY_SETTINGS, setQuality: vi.fn(), appConnected: true, pending: new Set(),
|
||||
videoCodecMode: "vp8", nativeCaptureRequest: () => undefined, nativeCaptureSelection: () => undefined, externalInput: () => undefined,
|
||||
screenQuality: () => undefined, screenCodecMode: () => "h264", sourceAudio: () => undefined, sourceMicrophone: () => undefined,
|
||||
ownedScreens: new Set<string>(), streams: new Map(), state: { channel: { rooms: [{ id: "room", name: "Friday" }] }, publications: [] as { id: string; roomId: string }[], voice: [] },
|
||||
ownedScreens: new Set<string>(), streams: new Map(), state: { channel: { rooms: [{ id: "room", name: "Friday" }] }, publications: [] as { id: string; roomId: string; kind: "screen"; source: { kind: "screen" } }[], voice: [] },
|
||||
};
|
||||
const render = (settings = false) => {
|
||||
// Open the real picker with the same completed targets response on each render.
|
||||
@@ -149,7 +161,7 @@ describe("Native sharing capabilities", () => {
|
||||
expect(render().replaceAll("'", "'")).toContain(t("en", "host.sourcePicker.unsupported"));
|
||||
|
||||
sources.codecs = ["h264"];
|
||||
channel.state.publications.push({ id: "mine", roomId: "room" });
|
||||
channel.state.publications.push({ id: "mine", roomId: "room", kind: "screen", source: { kind: "screen" } });
|
||||
channel.ownedScreens.add("mine");
|
||||
channel.videoCodecMode = "vp8";
|
||||
const sharing = render(true);
|
||||
|
||||
Reference in new issue
Block a user