@@ -15,7 +15,7 @@ limitations under the License.
1515*/
1616
1717import 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" ;
1919import { Button , Tooltip } from "@vector-im/compound-web" ;
2020import { 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";
3535import AccessibleButton , { ButtonEvent } from "../components/views/elements/AccessibleButton" ;
3636import { useDispatcher } from "../hooks/useDispatcher" ;
3737import { ActionPayload } from "../dispatcher/payloads" ;
38- import { Call } from "../models/Call" ;
38+ import { Call , CallEvent } from "../models/Call" ;
3939import LegacyCallHandler , { AudioID } from "../LegacyCallHandler" ;
4040import { useEventEmitter } from "../hooks/useEventEmitter" ;
4141import { 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