Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5680d13

Browse files
Handle missing Element Call brand (#9376)
1 parent 26a74a1 commit 5680d13

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

src/IConfigOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export interface IConfigOptions {
117117
obey_asserted_identity?: boolean; // MSC3086
118118
};
119119
element_call: {
120-
url: string;
121-
use_exclusively: boolean;
122-
brand: string;
120+
url?: string;
121+
use_exclusively?: boolean;
122+
brand?: string;
123123
};
124124

125125
logout_redirect_url?: string;

src/components/views/rooms/RoomHeader.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore";
5252
import { isVideoRoom as calcIsVideoRoom } from "../../../utils/video-rooms";
5353
import LegacyCallHandler, { LegacyCallHandlerEvent } from "../../../LegacyCallHandler";
5454
import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings";
55-
import SdkConfig from "../../../SdkConfig";
55+
import SdkConfig, { DEFAULTS } from "../../../SdkConfig";
5656
import { useEventEmitterState, useTypedEventEmitterState } from "../../../hooks/useEventEmitter";
5757
import { useWidgets } from "../right_panel/RoomSummaryCard";
5858
import { WidgetType } from "../../../widgets/WidgetType";
@@ -195,7 +195,7 @@ const VideoCallButton: FC<VideoCallButtonProps> = ({ room, busy, setBusy, behavi
195195
let menu: JSX.Element | null = null;
196196
if (menuOpen) {
197197
const buttonRect = buttonRef.current!.getBoundingClientRect();
198-
const brand = SdkConfig.get("element_call").brand;
198+
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
199199
menu = <IconizedContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu}>
200200
<IconizedContextMenuOptionList>
201201
<IconizedContextMenuOption label={_t("Video call (Jitsi)")} onClick={onJitsiClick} />
@@ -230,7 +230,9 @@ const CallButtons: FC<CallButtonsProps> = ({ room }) => {
230230
const groupCallsEnabled = useFeatureEnabled("feature_group_calls");
231231
const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms");
232232
const isVideoRoom = useMemo(() => videoRoomsEnabled && calcIsVideoRoom(room), [videoRoomsEnabled, room]);
233-
const useElementCallExclusively = useMemo(() => SdkConfig.get("element_call").use_exclusively, []);
233+
const useElementCallExclusively = useMemo(() => {
234+
return SdkConfig.get("element_call").use_exclusively ?? DEFAULTS.element_call.use_exclusively;
235+
}, []);
234236

235237
const hasLegacyCall = useEventEmitterState(
236238
LegacyCallHandler.instance,

src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import SettingsFieldset from '../../SettingsFieldset';
3232
import SettingsStore from "../../../../../settings/SettingsStore";
3333
import { VoiceBroadcastInfoEventType } from '../../../../../voice-broadcast';
3434
import { ElementCall } from "../../../../../models/Call";
35-
import SdkConfig from "../../../../../SdkConfig";
35+
import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";
3636

3737
interface IEventShowOpts {
3838
isState?: boolean;
@@ -446,7 +446,7 @@ export default class RolesRoomSettingsTab extends React.Component<IProps> {
446446

447447
let label = plEventsToLabels[eventType];
448448
if (label) {
449-
const brand = SdkConfig.get("element_call").brand;
449+
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
450450
label = _t(label, { brand });
451451
} else {
452452
label = _t("Send %(eventType)s events", { eventType });

src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import SettingsSubsection from "../../shared/SettingsSubsection";
2525
import SettingsTab from "../SettingsTab";
2626
import { ElementCall } from "../../../../../models/Call";
2727
import { useRoomState } from "../../../../../hooks/useRoomState";
28-
import SdkConfig from "../../../../../SdkConfig";
28+
import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";
2929

3030
interface ElementCallSwitchProps {
3131
roomId: string;
@@ -69,7 +69,7 @@ const ElementCallSwitch: React.FC<ElementCallSwitchProps> = ({ roomId }) => {
6969
});
7070
}, [roomId, content, events, isPublic]);
7171

72-
const brand = SdkConfig.get("element_call").brand;
72+
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
7373

7474
return <LabelledToggleSwitch
7575
data-testid="element-call-switch"

src/models/Call.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import type { Room } from "matrix-js-sdk/src/models/room";
3131
import type { RoomMember } from "matrix-js-sdk/src/models/room-member";
3232
import type { ClientWidgetApi } from "matrix-widget-api";
3333
import type { IApp } from "../stores/WidgetStore";
34-
import SdkConfig from "../SdkConfig";
34+
import SdkConfig, { DEFAULTS } from "../SdkConfig";
3535
import SettingsStore from "../settings/SettingsStore";
3636
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../MediaDeviceHandler";
3737
import { timeout } from "../utils/promise";
@@ -622,7 +622,7 @@ export class ElementCall extends Call {
622622

623623
private constructor(public readonly groupCall: MatrixEvent, client: MatrixClient) {
624624
// Splice together the Element Call URL for this call
625-
const url = new URL(SdkConfig.get("element_call").url);
625+
const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url);
626626
url.pathname = "/room";
627627
const params = new URLSearchParams({
628628
embed: "",

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
4040
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
4141
import { Direction } from "matrix-js-sdk/src/matrix";
4242

43-
import SdkConfig from "../../SdkConfig";
43+
import SdkConfig, { DEFAULTS } from "../../SdkConfig";
4444
import { iterableDiff, iterableIntersection } from "../../utils/iterables";
4545
import { MatrixClientPeg } from "../../MatrixClientPeg";
4646
import Modal from "../../Modal";
@@ -104,7 +104,10 @@ export class StopGapWidgetDriver extends WidgetDriver {
104104
// Auto-approve the legacy visibility capability. We send it regardless of capability.
105105
// Widgets don't technically need to request this capability, but Scalar still does.
106106
this.allowedCapabilities.add("visibility");
107-
} else if (virtual && new URL(SdkConfig.get("element_call").url).origin === this.forWidget.origin) {
107+
} else if (
108+
virtual
109+
&& new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url).origin === this.forWidget.origin
110+
) {
108111
// This is a trusted Element Call widget that we control
109112
this.allowedCapabilities.add(MatrixCapabilities.AlwaysOnScreen);
110113
this.allowedCapabilities.add(MatrixCapabilities.MSC3846TurnServers);

0 commit comments

Comments
 (0)