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

Commit

Permalink
Handle missing Element Call brand (#9376)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBrandner authored Oct 7, 2022
1 parent 26a74a1 commit 5680d13
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/IConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export interface IConfigOptions {
obey_asserted_identity?: boolean; // MSC3086
};
element_call: {
url: string;
use_exclusively: boolean;
brand: string;
url?: string;
use_exclusively?: boolean;
brand?: string;
};

logout_redirect_url?: string;
Expand Down
8 changes: 5 additions & 3 deletions src/components/views/rooms/RoomHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore";
import { isVideoRoom as calcIsVideoRoom } from "../../../utils/video-rooms";
import LegacyCallHandler, { LegacyCallHandlerEvent } from "../../../LegacyCallHandler";
import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings";
import SdkConfig from "../../../SdkConfig";
import SdkConfig, { DEFAULTS } from "../../../SdkConfig";
import { useEventEmitterState, useTypedEventEmitterState } from "../../../hooks/useEventEmitter";
import { useWidgets } from "../right_panel/RoomSummaryCard";
import { WidgetType } from "../../../widgets/WidgetType";
Expand Down Expand Up @@ -195,7 +195,7 @@ const VideoCallButton: FC<VideoCallButtonProps> = ({ room, busy, setBusy, behavi
let menu: JSX.Element | null = null;
if (menuOpen) {
const buttonRect = buttonRef.current!.getBoundingClientRect();
const brand = SdkConfig.get("element_call").brand;
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
menu = <IconizedContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu}>
<IconizedContextMenuOptionList>
<IconizedContextMenuOption label={_t("Video call (Jitsi)")} onClick={onJitsiClick} />
Expand Down Expand Up @@ -230,7 +230,9 @@ const CallButtons: FC<CallButtonsProps> = ({ room }) => {
const groupCallsEnabled = useFeatureEnabled("feature_group_calls");
const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms");
const isVideoRoom = useMemo(() => videoRoomsEnabled && calcIsVideoRoom(room), [videoRoomsEnabled, room]);
const useElementCallExclusively = useMemo(() => SdkConfig.get("element_call").use_exclusively, []);
const useElementCallExclusively = useMemo(() => {
return SdkConfig.get("element_call").use_exclusively ?? DEFAULTS.element_call.use_exclusively;
}, []);

const hasLegacyCall = useEventEmitterState(
LegacyCallHandler.instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import SettingsFieldset from '../../SettingsFieldset';
import SettingsStore from "../../../../../settings/SettingsStore";
import { VoiceBroadcastInfoEventType } from '../../../../../voice-broadcast';
import { ElementCall } from "../../../../../models/Call";
import SdkConfig from "../../../../../SdkConfig";
import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";

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

let label = plEventsToLabels[eventType];
if (label) {
const brand = SdkConfig.get("element_call").brand;
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
label = _t(label, { brand });
} else {
label = _t("Send %(eventType)s events", { eventType });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SettingsSubsection from "../../shared/SettingsSubsection";
import SettingsTab from "../SettingsTab";
import { ElementCall } from "../../../../../models/Call";
import { useRoomState } from "../../../../../hooks/useRoomState";
import SdkConfig from "../../../../../SdkConfig";
import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";

interface ElementCallSwitchProps {
roomId: string;
Expand Down Expand Up @@ -69,7 +69,7 @@ const ElementCallSwitch: React.FC<ElementCallSwitchProps> = ({ roomId }) => {
});
}, [roomId, content, events, isPublic]);

const brand = SdkConfig.get("element_call").brand;
const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;

return <LabelledToggleSwitch
data-testid="element-call-switch"
Expand Down
4 changes: 2 additions & 2 deletions src/models/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { Room } from "matrix-js-sdk/src/models/room";
import type { RoomMember } from "matrix-js-sdk/src/models/room-member";
import type { ClientWidgetApi } from "matrix-widget-api";
import type { IApp } from "../stores/WidgetStore";
import SdkConfig from "../SdkConfig";
import SdkConfig, { DEFAULTS } from "../SdkConfig";
import SettingsStore from "../settings/SettingsStore";
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../MediaDeviceHandler";
import { timeout } from "../utils/promise";
Expand Down Expand Up @@ -622,7 +622,7 @@ export class ElementCall extends Call {

private constructor(public readonly groupCall: MatrixEvent, client: MatrixClient) {
// Splice together the Element Call URL for this call
const url = new URL(SdkConfig.get("element_call").url);
const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url);
url.pathname = "/room";
const params = new URLSearchParams({
embed: "",
Expand Down
7 changes: 5 additions & 2 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
import { Direction } from "matrix-js-sdk/src/matrix";

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

0 comments on commit 5680d13

Please sign in to comment.