Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning if incompatible versions are being used #391

Merged
merged 4 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"classnames": "^2.3.1",
"color-hash": "^2.0.1",
"events": "^3.3.0",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#5e766978b8cf80d943f796df1067722a6a5918a7",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#b97b862fb66bafee542e3c0baac35d6576b3a75d",
"mermaid": "^8.13.8",
"normalize.css": "^8.0.1",
"pako": "^2.0.4",
Expand Down
27 changes: 26 additions & 1 deletion src/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from "classnames";
import React, { useRef } from "react";
import React, { useCallback, useRef } from "react";
import { Link } from "react-router-dom";
import styles from "./Header.module.css";
import { ReactComponent as Logo } from "./icons/Logo.svg";
Expand All @@ -8,6 +8,9 @@ import { ReactComponent as ArrowLeftIcon } from "./icons/ArrowLeft.svg";
import { useButton } from "@react-aria/button";
import { Subtitle } from "./typography/Typography";
import { Avatar } from "./Avatar";
import { IncompatibleVersionModal } from "./IncompatibleVersionModal";
import { useModalTriggerState } from "./Modal";
import { Button } from "./button";

export function Header({ children, className, ...rest }) {
return (
Expand Down Expand Up @@ -84,3 +87,25 @@ export function RoomSetupHeaderInfo({ roomName, avatarUrl, ...rest }) {
</button>
);
}

export function VersionMismatchWarning({ users, room }) {
const { modalState, modalProps } = useModalTriggerState();

const onDetailsClick = useCallback(() => {
modalState.open();
}, [modalState]);

if (users.size === 0) return null;

return (
<span className={styles.versionMismatchWarning}>
Incomaptible versions!
dbkr marked this conversation as resolved.
Show resolved Hide resolved
<Button variant="link" onClick={onDetailsClick}>
Details
</Button>
{modalState.isOpen && (
<IncompatibleVersionModal userIds={users} room={room} {...modalProps} />
)}
</span>
);
}
18 changes: 18 additions & 0 deletions src/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@
flex-shrink: 0;
}

.versionMismatchWarning {
padding-left: 15px;
}

.versionMismatchWarning::before {
content: "";
display: inline-block;
position: relative;
top: 1px;
width: 16px;
height: 16px;
mask-image: url("./icons/AlertTriangleFilled.svg");
mask-repeat: no-repeat;
mask-size: contain;
background-color: var(--alert);
padding-right: 5px;
}

@media (min-width: 800px) {
.headerLogo,
.roomAvatar,
Expand Down
48 changes: 48 additions & 0 deletions src/IncompatibleVersionModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2022 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { Room } from "matrix-js-sdk";
import React from "react";

import { Modal, ModalContent } from "./Modal";
import { Body } from "./typography/Typography";

interface Props {
userIds: Set<string>;
room: Room;
}

export const IncompatibleVersionModal: React.FC<Props> = ({
userIds,
room,
...rest
}) => {
const userLis = Array.from(userIds).map((u) => (
<li>{room.getMember(u).name}</li>
));

return (
<Modal title="Incompatible Versions" isDismissable {...rest}>
<ModalContent>
<Body>
Other users are trying to join this call from incompatible versions.
These users should ensure that they have refreshed their browsers:
<ul>{userLis}</ul>
</Body>
</ModalContent>
</Modal>
);
};
1 change: 1 addition & 0 deletions src/button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const variantToClassName = {
iconCopy: [styles.iconCopyButton],
secondaryHangup: [styles.secondaryHangup],
dropdown: [styles.dropdownButton],
link: [styles.linkButton],
};

export const sizeToClassName = {
Expand Down
7 changes: 7 additions & 0 deletions src/button/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,10 @@ limitations under the License.
.lg {
height: 40px;
}

.linkButton {
background-color: transparent;
border: none;
color: var(--accent);
cursor: pointer;
}
3 changes: 3 additions & 0 deletions src/icons/AlertTriangleFilled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/room/GroupCallView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function GroupCallView({
screenshareFeeds,
hasLocalParticipant,
participants,
unencryptedEventsFromUsers,
} = useGroupCall(groupCall);

const avatarUrl = useRoomAvatar(groupCall.room);
Expand Down Expand Up @@ -112,6 +113,7 @@ export function GroupCallView({
localScreenshareFeed={localScreenshareFeed}
screenshareFeeds={screenshareFeeds}
roomId={roomId}
unencryptedEventsFromUsers={unencryptedEventsFromUsers}
/>
);
}
Expand Down
13 changes: 12 additions & 1 deletion src/room/InCallView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import {
VideoButton,
ScreenshareButton,
} from "../button";
import { Header, LeftNav, RightNav, RoomHeaderInfo } from "../Header";
import {
Header,
LeftNav,
RightNav,
RoomHeaderInfo,
VersionMismatchWarning,
} from "../Header";
import { VideoGrid, useVideoGridLayout } from "../video-grid/VideoGrid";
import { VideoTileContainer } from "../video-grid/VideoTileContainer";
import { GroupCallInspector } from "./GroupCallInspector";
Expand Down Expand Up @@ -59,6 +65,7 @@ export function InCallView({
isScreensharing,
screenshareFeeds,
roomId,
unencryptedEventsFromUsers,
}) {
usePreventScroll();
const [layout, setLayout] = useVideoGridLayout(screenshareFeeds.length > 0);
Expand Down Expand Up @@ -135,6 +142,10 @@ export function InCallView({
<Header>
<LeftNav>
<RoomHeaderInfo roomName={roomName} avatarUrl={avatarUrl} />
<VersionMismatchWarning
users={unencryptedEventsFromUsers}
room={groupCall.room}
/>
</LeftNav>
<RightNav>
<GridLayoutMenu layout={layout} setLayout={setLayout} />
Expand Down
23 changes: 22 additions & 1 deletion src/room/useGroupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useReducer, useState } from "react";
import {
GroupCallEvent,
GroupCallState,
GroupCall,
GroupCallErrorCode,
GroupCallUnknownDeviceError,
GroupCallError,
} from "matrix-js-sdk/src/webrtc/groupCall";
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
Expand Down Expand Up @@ -48,6 +51,7 @@ export interface UseGroupCallType {
localDesktopCapturerSourceId: string;
participants: RoomMember[];
hasLocalParticipant: boolean;
unencryptedEventsFromUsers: Set<string>;
}

interface State {
Expand Down Expand Up @@ -106,6 +110,13 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
hasLocalParticipant: false,
});

const [unencryptedEventsFromUsers, addUnencryptedEventUser] = useReducer(
(state: Set<string>, newVal: string) => {
return new Set(state).add(newVal);
},
new Set<string>()
);

const updateState = (state: Partial<State>) =>
setState((prevState) => ({ ...prevState, ...state }));

Expand Down Expand Up @@ -180,6 +191,13 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
});
}

function onError(e: GroupCallError): void {
if (e.code === GroupCallErrorCode.UnknownDevice) {
const unknownDeviceError = e as GroupCallUnknownDeviceError;
addUnencryptedEventUser(unknownDeviceError.userId);
}
}

groupCall.on(GroupCallEvent.GroupCallStateChanged, onGroupCallStateChanged);
groupCall.on(GroupCallEvent.UserMediaFeedsChanged, onUserMediaFeedsChanged);
groupCall.on(
Expand All @@ -194,6 +212,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
);
groupCall.on(GroupCallEvent.CallsChanged, onCallsChanged);
groupCall.on(GroupCallEvent.ParticipantsChanged, onParticipantsChanged);
groupCall.on(GroupCallEvent.Error, onError);

updateState({
error: null,
Expand Down Expand Up @@ -242,6 +261,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
GroupCallEvent.ParticipantsChanged,
onParticipantsChanged
);
groupCall.removeListener(GroupCallEvent.Error, onError);
groupCall.leave();
};
}, [groupCall]);
Expand Down Expand Up @@ -319,5 +339,6 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
localDesktopCapturerSourceId,
participants,
hasLocalParticipant,
unencryptedEventsFromUsers,
};
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8597,9 +8597,9 @@ matrix-events-sdk@^0.0.1-beta.7:
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.7.tgz#5ffe45eba1f67cc8d7c2377736c728b322524934"
integrity sha512-9jl4wtWanUFSy2sr2lCjErN/oC8KTAtaeaozJtrgot1JiQcEI4Rda9OLgQ7nLKaqb4Z/QUx/fR3XpDzm5Jy1JA==

"matrix-js-sdk@github:matrix-org/matrix-js-sdk#5e766978b8cf80d943f796df1067722a6a5918a7":
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#b97b862fb66bafee542e3c0baac35d6576b3a75d":
version "17.2.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/5e766978b8cf80d943f796df1067722a6a5918a7"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/b97b862fb66bafee542e3c0baac35d6576b3a75d"
dependencies:
"@babel/runtime" "^7.12.5"
another-json "^0.2.0"
Expand Down