Skip to content

Commit 7edc8af

Browse files
authored
Merge pull request #2687 from robintown/media-devices-config
Add config options for starting with audio and video enabled
2 parents 5907bf7 + 551c3f4 commit 7edc8af

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/config/Config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
77

8+
import { merge } from "lodash";
9+
810
import { getUrlParams } from "../UrlParams";
911
import {
1012
DEFAULT_CONFIG,
@@ -15,7 +17,7 @@ import {
1517
export class Config {
1618
private static internalInstance: Config | undefined;
1719

18-
public static get(): ConfigOptions {
20+
public static get(): ResolvedConfigOptions {
1921
if (!this.internalInstance?.config)
2022
throw new Error("Config instance read before config got initialized");
2123
return this.internalInstance.config;
@@ -29,7 +31,7 @@ export class Config {
2931
Config.internalInstance.initPromise = downloadConfig(
3032
"../config.json",
3133
).then((config) => {
32-
internalInstance.config = { ...DEFAULT_CONFIG, ...config };
34+
internalInstance.config = merge({}, DEFAULT_CONFIG, config);
3335
});
3436
}
3537
return Config.internalInstance.initPromise;

src/config/ConfigOptions.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ export interface ConfigOptions {
7777
* A link to the end-user license agreement (EULA)
7878
*/
7979
eula: string;
80+
81+
media_devices?: {
82+
/**
83+
* Defines whether participants should start with audio enabled by default.
84+
*/
85+
enable_audio?: boolean;
86+
/**
87+
* Defines whether participants should start with video enabled by default.
88+
*/
89+
enable_video?: boolean;
90+
};
8091
}
8192

8293
// Overrides members from ConfigOptions that are always provided by the
@@ -88,6 +99,10 @@ export interface ResolvedConfigOptions extends ConfigOptions {
8899
server_name: string;
89100
};
90101
};
102+
media_devices: {
103+
enable_audio: boolean;
104+
enable_video: boolean;
105+
};
91106
}
92107

93108
export const DEFAULT_CONFIG: ResolvedConfigOptions = {
@@ -98,4 +113,8 @@ export const DEFAULT_CONFIG: ResolvedConfigOptions = {
98113
},
99114
},
100115
eula: "https://static.element.io/legal/online-EULA.pdf",
116+
media_devices: {
117+
enable_audio: true,
118+
enable_video: true,
119+
},
101120
};

src/room/MuteStates.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { logger } from "matrix-js-sdk/src/logger";
1818
import { MediaDevice, useMediaDevices } from "../livekit/MediaDevicesContext";
1919
import { useReactiveState } from "../useReactiveState";
2020
import { ElementWidgetActions, widget } from "../widget";
21+
import { Config } from "../config/Config";
2122

2223
/**
2324
* If there already are this many participants in the call, we automatically mute
@@ -71,8 +72,14 @@ function useMuteState(
7172
export function useMuteStates(): MuteStates {
7273
const devices = useMediaDevices();
7374

74-
const audio = useMuteState(devices.audioInput, () => true);
75-
const video = useMuteState(devices.videoInput, () => true);
75+
const audio = useMuteState(
76+
devices.audioInput,
77+
() => Config.get().media_devices.enable_audio,
78+
);
79+
const video = useMuteState(
80+
devices.videoInput,
81+
() => Config.get().media_devices.enable_video,
82+
);
7683

7784
useEffect(() => {
7885
widget?.api.transport

src/rtcSessionHelper.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { expect, test, vi } from "vitest";
1010

1111
import { enterRTCSession } from "../src/rtcSessionHelpers";
1212
import { Config } from "../src/config/Config";
13+
import { DEFAULT_CONFIG } from "./config/ConfigOptions";
1314

1415
test("It joins the correct Session", async () => {
1516
const focusFromOlderMembership = {
@@ -34,8 +35,8 @@ test("It joins the correct Session", async () => {
3435
};
3536

3637
vi.spyOn(Config, "get").mockReturnValue({
38+
...DEFAULT_CONFIG,
3739
livekit: { livekit_service_url: "http://my-default-service-url.com" },
38-
eula: "",
3940
});
4041
const mockedSession = vi.mocked({
4142
room: {

0 commit comments

Comments
 (0)