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

Commit f152310

Browse files
authored
Use random widget IDs for video rooms (#8739)
1 parent abfc66a commit f152310

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

src/CallHandler.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,7 @@ export default class CallHandler extends EventEmitter {
10351035
}
10361036

10371037
try {
1038-
const userId = client.credentials.userId;
1039-
await WidgetUtils.addJitsiWidget(roomId, type, 'Jitsi', `jitsi_${userId}_${Date.now()}`);
1038+
await WidgetUtils.addJitsiWidget(roomId, type, 'Jitsi', false);
10401039
logger.log('Jitsi widget added');
10411040
} catch (e) {
10421041
if (e.errcode === 'M_FORBIDDEN') {

src/utils/VideoChannelUtils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ interface IVideoChannelMemberContent {
3535
devices: string[];
3636
}
3737

38-
export const VIDEO_CHANNEL = "io.element.video";
3938
export const VIDEO_CHANNEL_MEMBER = "io.element.video.member";
4039

4140
export const getVideoChannel = (roomId: string): IApp => {
4241
const apps = WidgetStore.instance.getApps(roomId);
43-
return apps.find(app => WidgetType.JITSI.matches(app.type) && app.id === VIDEO_CHANNEL);
42+
return apps.find(app => WidgetType.JITSI.matches(app.type) && app.data.isVideoChannel);
4443
};
4544

4645
export const addVideoChannel = async (roomId: string, roomName: string) => {
47-
await WidgetUtils.addJitsiWidget(roomId, CallType.Video, "Video channel", VIDEO_CHANNEL, roomName);
46+
await WidgetUtils.addJitsiWidget(roomId, CallType.Video, "Video channel", true, roomName);
4847
};
4948

5049
export const getConnectedMembers = (room: Room, connectedLocalEcho: boolean): Set<RoomMember> => {

src/utils/WidgetUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2323
import { logger } from "matrix-js-sdk/src/logger";
2424
import { ClientEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix";
2525
import { CallType } from "matrix-js-sdk/src/webrtc/call";
26-
import { randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
26+
import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
2727

2828
import { MatrixClientPeg } from '../MatrixClientPeg';
2929
import SdkConfig from "../SdkConfig";
@@ -35,7 +35,6 @@ import { Jitsi } from "../widgets/Jitsi";
3535
import { objectClone } from "./objects";
3636
import { _t } from "../languageHandler";
3737
import { IApp } from "../stores/WidgetStore";
38-
import { VIDEO_CHANNEL } from "./VideoChannelUtils";
3938

4039
// How long we wait for the state event echo to come back from the server
4140
// before waitFor[Room/User]Widget rejects its promise
@@ -444,11 +443,12 @@ export default class WidgetUtils {
444443
roomId: string,
445444
type: CallType,
446445
name: string,
447-
widgetId: string,
446+
isVideoChannel: boolean,
448447
oobRoomName?: string,
449448
): Promise<void> {
450449
const domain = Jitsi.getInstance().preferredDomain;
451450
const auth = await Jitsi.getInstance().getJitsiAuth();
451+
const widgetId = randomString(24); // Must be globally unique
452452

453453
let confId;
454454
if (auth === 'openidtoken-jwt') {
@@ -471,7 +471,7 @@ export default class WidgetUtils {
471471
conferenceId: confId,
472472
roomName: oobRoomName ?? MatrixClientPeg.get().getRoom(roomId)?.name,
473473
isAudioOnly: type === CallType.Voice,
474-
isVideoChannel: widgetId === VIDEO_CHANNEL,
474+
isVideoChannel,
475475
domain,
476476
auth,
477477
});

test/components/structures/VideoRoomView-test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
mkVideoChannelMember,
3333
} from "../../test-utils";
3434
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
35-
import { VIDEO_CHANNEL, VIDEO_CHANNEL_MEMBER } from "../../../src/utils/VideoChannelUtils";
35+
import { VIDEO_CHANNEL_MEMBER } from "../../../src/utils/VideoChannelUtils";
3636
import WidgetStore from "../../../src/stores/WidgetStore";
3737
import _VideoRoomView from "../../../src/components/structures/VideoRoomView";
3838
import VideoLobby from "../../../src/components/views/voip/VideoLobby";
@@ -42,14 +42,15 @@ const VideoRoomView = wrapInMatrixClientContext(_VideoRoomView);
4242

4343
describe("VideoRoomView", () => {
4444
jest.spyOn(WidgetStore.instance, "getApps").mockReturnValue([{
45-
id: VIDEO_CHANNEL,
45+
id: "1",
4646
eventId: "$1:example.org",
4747
roomId: "!1:example.org",
4848
type: MatrixWidgetType.JitsiMeet,
4949
url: "https://example.org",
5050
name: "Video channel",
5151
creatorUserId: "@alice:example.org",
5252
avatar_url: null,
53+
data: { isVideoChannel: true },
5354
}]);
5455
Object.defineProperty(navigator, "mediaDevices", {
5556
value: { enumerateDevices: () => [] },

test/createRoom-test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { stubClient, setupAsyncStoreWithClient } from "./test-utils";
2323
import { MatrixClientPeg } from "../src/MatrixClientPeg";
2424
import WidgetStore from "../src/stores/WidgetStore";
2525
import WidgetUtils from "../src/utils/WidgetUtils";
26-
import { VIDEO_CHANNEL, VIDEO_CHANNEL_MEMBER } from "../src/utils/VideoChannelUtils";
26+
import { VIDEO_CHANNEL_MEMBER } from "../src/utils/VideoChannelUtils";
2727
import createRoom, { canEncryptToAllUsers } from '../src/createRoom';
2828

2929
describe("createRoom", () => {
@@ -43,12 +43,11 @@ describe("createRoom", () => {
4343
events: { [VIDEO_CHANNEL_MEMBER]: videoMemberPower },
4444
},
4545
}]] = mocked(client.createRoom).mock.calls as any; // no good type
46-
const [[widgetRoomId, widgetStateKey, , widgetId]] = mocked(client.sendStateEvent).mock.calls;
46+
const [[widgetRoomId, widgetStateKey]] = mocked(client.sendStateEvent).mock.calls;
4747

4848
// We should have set up the Jitsi widget
4949
expect(widgetRoomId).toEqual(roomId);
5050
expect(widgetStateKey).toEqual("im.vector.modular.widgets");
51-
expect(widgetId).toEqual(VIDEO_CHANNEL);
5251

5352
// All members should be able to update their connected devices
5453
expect(videoMemberPower).toEqual(0);

test/stores/VideoChannelStore-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ import WidgetStore, { IApp } from "../../src/stores/WidgetStore";
2323
import { WidgetMessagingStore } from "../../src/stores/widgets/WidgetMessagingStore";
2424
import { ElementWidgetActions } from "../../src/stores/widgets/ElementWidgetActions";
2525
import VideoChannelStore, { VideoChannelEvent } from "../../src/stores/VideoChannelStore";
26-
import { VIDEO_CHANNEL } from "../../src/utils/VideoChannelUtils";
2726

2827
describe("VideoChannelStore", () => {
2928
const store = VideoChannelStore.instance;
3029

31-
const widget = { id: VIDEO_CHANNEL } as unknown as Widget;
30+
const widget = { id: "1" } as unknown as Widget;
3231
const app = {
33-
id: VIDEO_CHANNEL,
32+
id: "1",
3433
eventId: "$1:example.org",
3534
roomId: "!1:example.org",
3635
type: MatrixWidgetType.JitsiMeet,
3736
url: "",
3837
name: "Video channel",
3938
creatorUserId: "@alice:example.org",
4039
avatar_url: null,
40+
data: { isVideoChannel: true },
4141
} as IApp;
4242

4343
// Set up mocks to simulate the remote end of the widget API

0 commit comments

Comments
 (0)