Skip to content

Commit 9130234

Browse files
committed
add media key debugging option
1 parent 2a5dc60 commit 9130234

File tree

5 files changed

+86
-23
lines changed

5 files changed

+86
-23
lines changed

public/locales/en-GB/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
"preferences_tab_h4": "Preferences",
153153
"preferences_tab_show_hand_raised_timer_description": "Show a timer when a participant raises their hand",
154154
"preferences_tab_show_hand_raised_timer_label": "Show hand raise duration",
155+
"show_media_keys": "Show media encryption keys",
155156
"speaker_device_selection_label": "Speaker"
156157
},
157158
"star_rating_input_label_one": "{{count}} stars",

src/settings/SettingsModal.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
developerSettingsTab as developerSettingsTabSetting,
2929
duplicateTiles as duplicateTilesSetting,
3030
nonMemberTiles as nonMemberTilesSetting,
31+
showMediaKeys as showMediaKeysSetting,
3132
useOptInAnalytics,
3233
} from "./settings";
3334
import { isFirefox } from "../Platform";
@@ -71,6 +72,8 @@ export const SettingsModal: FC<Props> = ({
7172

7273
const [nonMemberTiles, setNonMemberTiles] = useSetting(nonMemberTilesSetting);
7374

75+
const [showMediaKeys, setShowMediaKeys] = useSetting(showMediaKeysSetting);
76+
7477
// Generate a `SelectInput` with a list of devices for a given device kind.
7578
const generateDeviceSelection = (
7679
devices: MediaDevice,
@@ -253,6 +256,20 @@ export const SettingsModal: FC<Props> = ({
253256
)}
254257
/>
255258
</FieldRow>
259+
<FieldRow>
260+
<InputField
261+
id="showMediaKeys"
262+
type="checkbox"
263+
label={t("settings.show_media_keys")}
264+
checked={showMediaKeys}
265+
onChange={useCallback(
266+
(event: ChangeEvent<HTMLInputElement>): void => {
267+
setShowMediaKeys(event.target.checked);
268+
},
269+
[setShowMediaKeys],
270+
)}
271+
/>
272+
</FieldRow>
256273
</>
257274
),
258275
};

src/settings/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export const developerSettingsTab = new Setting(
7272

7373
export const duplicateTiles = new Setting("duplicate-tiles", 0);
7474

75-
export const nonMemberTiles = new Setting("non-member-tiles", true);
75+
export const nonMemberTiles = new Setting("non-member-tiles", false);
76+
77+
export const showMediaKeys = new Setting("non-member-tiles", false);
7678

7779
export const audioInput = new Setting<string | undefined>(
7880
"audio-input",

src/state/MediaViewModel.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
MatrixRTCSession,
4242
MatrixRTCSessionEvent,
4343
} from "matrix-js-sdk/src/matrixrtc";
44-
import { logger } from "matrix-js-sdk/src/logger";
4544

4645
import { ViewModel } from "./ViewModel";
4746
import { useReactiveState } from "../useReactiveState";
@@ -221,18 +220,22 @@ abstract class BaseUserMediaViewModel extends BaseMediaViewModel {
221220
Track.Source.Camera,
222221
);
223222

224-
// rtcSession.on(
225-
// MatrixRTCSessionEvent.EncryptionKeyChanged,
226-
// (key, index, participantId) => {
227-
// if (id.startsWith(participantId))
228-
// logger.info("got new keys: ", participant, { index, key });
229-
// logger.info("All keys for participant ", participant, " - ", [
230-
// ...this.keys.value,
231-
// { index, key },
232-
// ]);
233-
// this.keys.next([...this.keys.value, { index, key }]);
234-
// },
235-
// );
223+
combineLatest([
224+
participant,
225+
fromEvent(rtcSession, MatrixRTCSessionEvent.EncryptionKeyChanged).pipe(
226+
startWith(null),
227+
),
228+
]).subscribe(([par, ev]) => {
229+
for (const participantKeys of rtcSession.getEncryptionKeys()) {
230+
if (participantKeys[0] === par?.identity) {
231+
this.keys.next(
232+
Array.from(participantKeys[1].entries()).map(([i, k]) => {
233+
return { index: i, key: k };
234+
}),
235+
);
236+
}
237+
}
238+
});
236239

237240
const media = participant.pipe(
238241
switchMap((p) => (p && observeParticipantMedia(p)) ?? of(undefined)),

src/tile/MediaView.tsx

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Please see LICENSE in the repository root for full details.
77

88
import { TrackReferenceOrPlaceholder } from "@livekit/components-core";
99
import { animated } from "@react-spring/web";
10-
import { RoomMember } from "matrix-js-sdk/src/matrix";
11-
import { ComponentProps, ReactNode, forwardRef } from "react";
10+
import { encodeUnpaddedBase64, RoomMember } from "matrix-js-sdk/src/matrix";
11+
import { ComponentProps, FC, ReactNode, forwardRef } from "react";
1212
import { useTranslation } from "react-i18next";
1313
import classNames from "classnames";
1414
import { VideoTrack } from "@livekit/components-react";
@@ -18,7 +18,11 @@ import { ErrorIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
1818
import styles from "./MediaView.module.css";
1919
import { Avatar } from "../Avatar";
2020
import { RaisedHandIndicator } from "../reactions/RaisedHandIndicator";
21-
import { showHandRaisedTimer, useSetting } from "../settings/settings";
21+
import {
22+
showHandRaisedTimer,
23+
showMediaKeys as showMediaKeysSettings,
24+
useSetting,
25+
} from "../settings/settings";
2226

2327
interface Props extends ComponentProps<typeof animated.div> {
2428
className?: string;
@@ -62,6 +66,7 @@ export const MediaView = forwardRef<HTMLDivElement, Props>(
6266
) => {
6367
const { t } = useTranslation();
6468
const [handRaiseTimerVisible] = useSetting(showHandRaisedTimer);
69+
const [showMediaKeys] = useSetting(showMediaKeysSettings);
6570

6671
const avatarSize = Math.round(Math.min(targetWidth, targetHeight) / 2);
6772

@@ -100,12 +105,7 @@ export const MediaView = forwardRef<HTMLDivElement, Props>(
100105
minature={avatarSize < 96}
101106
showTimer={handRaiseTimerVisible}
102107
/>
103-
{/* {keys &&
104-
keys.map(({ index, key }) => (
105-
<Text as="span" size="sm">
106-
index:{index}, key:{key}
107-
</Text>
108-
))} */}
108+
{keys && showMediaKeys && <MediaKeyList keys={keys} />}
109109
<div className={styles.nameTag}>
110110
{nameTagLeadingIcon}
111111
<Text as="span" size="sm" weight="medium" className={styles.name}>
@@ -132,5 +132,45 @@ export const MediaView = forwardRef<HTMLDivElement, Props>(
132132
);
133133
},
134134
);
135+
interface MediaKeyListProps {
136+
keys: {
137+
index: number;
138+
key: Uint8Array;
139+
}[];
140+
}
135141

142+
export const MediaKeyList: FC<MediaKeyListProps> = ({ keys }) => {
143+
return (
144+
<div
145+
style={{
146+
display: "flex",
147+
flexDirection: "column",
148+
height: "70%",
149+
overflow: "scroll",
150+
color: "white",
151+
}}
152+
>
153+
{keys.map(({ index, key }) => (
154+
<div
155+
style={{
156+
display: "flex",
157+
flexDirection: "column",
158+
backgroundColor: "#000000c0",
159+
margin: "3px",
160+
padding: "5px",
161+
borderRadius: "5px",
162+
}}
163+
key={index}
164+
>
165+
<Text as="span" size="sm">
166+
index:{index}
167+
</Text>
168+
<Text as="span" size="xs">
169+
key:{key ? encodeUnpaddedBase64(key) : "unavailable"}
170+
</Text>
171+
</div>
172+
))}
173+
</div>
174+
);
175+
};
136176
MediaView.displayName = "MediaView";

0 commit comments

Comments
 (0)