diff --git a/src/client/channel/components/ChannelShareControl.tsx b/src/client/channel/components/ChannelShareControl.tsx index 0ea404bd2..d2a1fc15c 100644 --- a/src/client/channel/components/ChannelShareControl.tsx +++ b/src/client/channel/components/ChannelShareControl.tsx @@ -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"); diff --git a/tests/app-connection-button.test.ts b/tests/app-connection-button.test.ts index cdf99c1a3..98f650804 100644 --- a/tests/app-connection-button.test.ts +++ b/tests/app-connection-button.test.ts @@ -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(/ { 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(), streams: new Map(), state: { channel: { rooms: [{ id: "room", name: "Friday" }] }, publications: [] as { id: string; roomId: string }[], voice: [] }, + ownedScreens: new Set(), 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);