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

Commit a35bf68

Browse files
authored
Stop the ongoing ring if another device joins the call session. (#12866)
1 parent 2978b86 commit a35bf68

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/toasts/IncomingCallToast.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React, { useCallback, useEffect, useState } from "react";
18-
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
18+
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
1919
import { Button, Tooltip } from "@vector-im/compound-web";
2020
import { Icon as VideoCallIcon } from "@vector-im/compound-design-tokens/icons/video-call-solid.svg";
2121

@@ -35,7 +35,7 @@ import { useCall, useJoinCallButtonDisabledTooltip } from "../hooks/useCall";
3535
import AccessibleButton, { ButtonEvent } from "../components/views/elements/AccessibleButton";
3636
import { useDispatcher } from "../hooks/useDispatcher";
3737
import { ActionPayload } from "../dispatcher/payloads";
38-
import { Call } from "../models/Call";
38+
import { Call, CallEvent } from "../models/Call";
3939
import LegacyCallHandler, { AudioID } from "../LegacyCallHandler";
4040
import { useEventEmitter } from "../hooks/useEventEmitter";
4141
import { CallStore, CallStoreEvent } from "../stores/CallStore";
@@ -111,6 +111,16 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
111111
[dismissToast, notifyEvent],
112112
);
113113

114+
// Dismiss if antother device from this user joins.
115+
const onParticipantChange = useCallback(
116+
(participants: Map<RoomMember, Set<string>>, prevParticipants: Map<RoomMember, Set<string>>) => {
117+
if (Array.from(participants.keys()).some((p) => p.userId == room?.client.getUserId())) {
118+
dismissToast();
119+
}
120+
},
121+
[dismissToast, room?.client],
122+
);
123+
114124
// Dismiss on timeout.
115125
useEffect(() => {
116126
const timeout = setTimeout(dismissToast, MAX_RING_TIME_MS);
@@ -158,6 +168,7 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
158168
);
159169

160170
useEventEmitter(CallStore.instance, CallStoreEvent.Call, onCall);
171+
useEventEmitter(call ?? undefined, CallEvent.Participants, onParticipantChange);
161172

162173
return (
163174
<>

0 commit comments

Comments
 (0)