Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow join unmuted in widget mode #2848

Open
wants to merge 13 commits into
base: livekit
Choose a base branch
from
35 changes: 34 additions & 1 deletion src/room/MuteStates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@
expect(screen.getByTestId("video-enabled").textContent).toBe("false");
});

it("skipLobby mutes inputs", () => {
it("skipLobby mutes inputs on SPA", () => {
mockConfig();
vi.mock("../widget", () => {
return {
widget: null,
ElementWidgetActions: {},
};
});

render(
<MemoryRouter initialEntries={["/room/?skipLobby=true"]}>
Expand All @@ -166,7 +172,34 @@
</MediaDevicesContext.Provider>
</MemoryRouter>,
);
expect(screen.getByTestId("audio-enabled").textContent).toBe("false");

Check failure on line 175 in src/room/MuteStates.test.tsx

View workflow job for this annotation

GitHub Actions / Run vitest tests

src/room/MuteStates.test.tsx > useMuteStates > skipLobby mutes inputs on SPA

AssertionError: expected 'true' to be 'false' // Object.is equality Expected: "false" Received: "true" ❯ src/room/MuteStates.test.tsx:175:61
expect(screen.getByTestId("video-enabled").textContent).toBe("false");
});

it("skipLobby does not mute inputs in widget mode", () => {
mockConfig();
vi.mock("../widget", () => {
return {
widget: {
api: {
transport: {
send: async (): Promise<void> => new Promise((r) => r()),
},
},
lazyActions: { on: vi.fn(), off: vi.fn() },
},
ElementWidgetActions: {},
};
});

render(
<MemoryRouter initialEntries={["/room/?skipLobby=true"]}>
<MediaDevicesContext.Provider value={mockMediaDevices()}>
<TestComponent />
</MediaDevicesContext.Provider>
</MemoryRouter>,
);
expect(screen.getByTestId("audio-enabled").textContent).toBe("true");
expect(screen.getByTestId("video-enabled").textContent).toBe("true");
});
});
7 changes: 4 additions & 3 deletions src/room/MuteStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ export function useMuteStates(): MuteStates {
const devices = useMediaDevices();

const { skipLobby } = useUrlParams();

// In SPA without lobby we need to protect from unmuted joins (Privacy).
const allowStartUnmuted = !skipLobby || widget !== null;
hughns marked this conversation as resolved.
Show resolved Hide resolved
const audio = useMuteState(devices.audioInput, () => {
return Config.get().media_devices.enable_audio && !skipLobby;
return Config.get().media_devices.enable_audio && allowStartUnmuted;
});
const video = useMuteState(
devices.videoInput,
() => Config.get().media_devices.enable_video && !skipLobby,
() => Config.get().media_devices.enable_video && allowStartUnmuted,
);

useEffect(() => {
Expand Down
Loading