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

Initial support for Raise Hand feature #2542

Open
wants to merge 10 commits into
base: livekit
Choose a base branch
from
1 change: 1 addition & 0 deletions public/locales/en-GB/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"options": "Options",
"password": "Password",
"profile": "Profile",
"raise_hand": "Raise hand",
"settings": "Settings",
"unencrypted": "Not encrypted",
"username": "Username",
Expand Down
45 changes: 24 additions & 21 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import { MediaDevicesProvider } from "./livekit/MediaDevicesContext";
import { widget } from "./widget";
import { useTheme } from "./useTheme";
import { ReactionsProvider } from "./useReactions";

Check warning on line 31 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L31

Added line #L31 was not covered by tests

const SentryRoute = Sentry.withSentryRouting(Route);

Expand Down Expand Up @@ -82,27 +83,29 @@
<TooltipProvider>
{loaded ? (
<Suspense fallback={null}>
<ClientProvider>
<MediaDevicesProvider>
<Sentry.ErrorBoundary fallback={errorPage}>
<DisconnectedBanner />
<Switch>
<SentryRoute exact path="/">
<HomePage />
</SentryRoute>
<SentryRoute exact path="/login">
<LoginPage />
</SentryRoute>
<SentryRoute exact path="/register">
<RegisterPage />
</SentryRoute>
<SentryRoute path="*">
<RoomPage />
</SentryRoute>
</Switch>
</Sentry.ErrorBoundary>
</MediaDevicesProvider>
</ClientProvider>
<ReactionsProvider>
<ClientProvider>
<MediaDevicesProvider>
<Sentry.ErrorBoundary fallback={errorPage}>
<DisconnectedBanner />
<Switch>
<SentryRoute exact path="/">
<HomePage />
</SentryRoute>
<SentryRoute exact path="/login">
<LoginPage />
</SentryRoute>
<SentryRoute exact path="/register">
<RegisterPage />
</SentryRoute>
<SentryRoute path="*">
<RoomPage />
</SentryRoute>
</Switch>
</Sentry.ErrorBoundary>
</MediaDevicesProvider>
</ClientProvider>
</ReactionsProvider>

Check warning on line 108 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L86-L108

Added lines #L86 - L108 were not covered by tests
</Suspense>
) : (
<LoadingView />
Expand Down
41 changes: 38 additions & 3 deletions src/ClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import { useTranslation } from "react-i18next";
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
import { MatrixError } from "matrix-js-sdk/src/matrix";
import { WidgetApi } from "matrix-widget-api";

import { ErrorView } from "./FullScreenView";
import { fallbackICEServerAllowed, initClient } from "./utils/matrix";
Expand All @@ -36,6 +37,7 @@
import { translatedError } from "./TranslatedError";
import { useEventTarget } from "./useEvents";
import { Config } from "./config/Config";
import { useReactions } from "./useReactions";

declare global {
interface Window {
Expand Down Expand Up @@ -144,6 +146,7 @@
}

export const ClientProvider: FC<Props> = ({ children }) => {
const { setSupportsReactions } = useReactions();

Check warning on line 149 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L149

Added line #L149 was not covered by tests
const history = useHistory();

// null = signed out, undefined = loading
Expand Down Expand Up @@ -188,11 +191,11 @@
saveSession({ ...session, passwordlessUser: false });

setInitClientState({
client: initClientState.client,
...initClientState,

Check warning on line 194 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L194

Added line #L194 was not covered by tests
passwordlessUser: false,
});
},
[initClientState?.client],
[initClientState],

Check warning on line 198 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L198

Added line #L198 was not covered by tests
);

const setClient = useCallback(
Expand All @@ -206,6 +209,7 @@
if (clientParams) {
saveSession(clientParams.session);
setInitClientState({
widgetApi: null,

Check warning on line 212 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L212

Added line #L212 was not covered by tests
client: clientParams.client,
passwordlessUser: clientParams.session.passwordlessUser,
});
Expand Down Expand Up @@ -309,12 +313,40 @@
initClientState.client.on(ClientEvent.Sync, onSync);
}

if (initClientState.widgetApi) {
let supportsReactions = true;

Check warning on line 317 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L316-L317

Added lines #L316 - L317 were not covered by tests

const reactSend = initClientState.widgetApi.hasCapability(
"org.matrix.msc2762.send.event:m.reaction",
);
const redactSend = initClientState.widgetApi.hasCapability(
"org.matrix.msc2762.send.event:m.room.redaction",
);
const reactRcv = initClientState.widgetApi.hasCapability(
"org.matrix.msc2762.receive.event:m.reaction",
);
const redactRcv = initClientState.widgetApi.hasCapability(
"org.matrix.msc2762.receive.event:m.room.redaction",
);

Check warning on line 330 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L319-L330

Added lines #L319 - L330 were not covered by tests

if (!reactSend || !reactRcv || !redactSend || !redactRcv) {
supportsReactions = false;
}

Check warning on line 334 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L332-L334

Added lines #L332 - L334 were not covered by tests

setSupportsReactions(supportsReactions);
if (!supportsReactions) {
logger.warn("Widget does not support reactions");
} else {
logger.warn("Widget does support reactions");
}
}

Check warning on line 342 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L336-L342

Added lines #L336 - L342 were not covered by tests

return (): void => {
if (initClientState.client) {
initClientState.client.removeListener(ClientEvent.Sync, onSync);
}
};
}, [initClientState, onSync]);
}, [initClientState, onSync, setSupportsReactions]);

Check warning on line 349 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L349

Added line #L349 was not covered by tests

if (alreadyOpenedErr) {
return <ErrorView error={alreadyOpenedErr} />;
Expand All @@ -326,6 +358,7 @@
};

type InitResult = {
widgetApi: WidgetApi | null;
client: MatrixClient;
passwordlessUser: boolean;
};
Expand All @@ -336,6 +369,7 @@
logger.log("Using a matryoshka client");
const client = await widget.client;
return {
widgetApi: widget.api,

Check warning on line 372 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L372

Added line #L372 was not covered by tests
client,
passwordlessUser: false,
};
Expand Down Expand Up @@ -364,6 +398,7 @@
try {
const client = await initClient(initClientParams, true);
return {
widgetApi: null,

Check warning on line 401 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L401

Added line #L401 was not covered by tests
client,
passwordlessUser,
};
Expand Down
33 changes: 33 additions & 0 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,39 @@
);
};

interface RaiseHandButtonProps extends ComponentPropsWithoutRef<"button"> {
raised: boolean;
}
export const RaiseHandButton: FC<RaiseHandButtonProps> = ({
raised,
...props
}) => {
const { t } = useTranslation();

Check warning on line 101 in src/button/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/button/Button.tsx#L98-L101

Added lines #L98 - L101 were not covered by tests

return (
<Tooltip label={t("common.raise_hand")}>
<CpdButton
kind={raised ? "primary" : "secondary"}
{...props}
style={{ paddingLeft: 8, paddingRight: 8 }}

Check warning on line 108 in src/button/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/button/Button.tsx#L103-L108

Added lines #L103 - L108 were not covered by tests
>
<p
role="img"
aria-label="raised hand"
style={{
width: "30px",
height: "0px",
display: "inline-block",
fontSize: "22px",
}}
>

Check warning on line 119 in src/button/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/button/Button.tsx#L110-L119

Added lines #L110 - L119 were not covered by tests
</p>
</CpdButton>
</Tooltip>

Check warning on line 123 in src/button/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/button/Button.tsx#L121-L123

Added lines #L121 - L123 were not covered by tests
);
};

Check warning on line 125 in src/button/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/button/Button.tsx#L125

Added line #L125 was not covered by tests

export const EndCallButton: FC<ComponentPropsWithoutRef<"button">> = ({
className,
...props
Expand Down
Loading