Skip to content

Commit 66d35f7

Browse files
fix: DM showing voip calls that are happening on different session - #41282
1 parent 43b8964 commit 66d35f7

6 files changed

Lines changed: 46 additions & 2 deletions

File tree

apps/meteor/client/views/room/body/MediaCallRoom.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type { IRoom } from '@rocket.chat/core-typings';
22
import { isDirectMessageRoom } from '@rocket.chat/core-typings';
33
import { useUserId } from '@rocket.chat/ui-contexts';
44
import type { PeerInfo } from '@rocket.chat/ui-voip';
5-
import { MediaCallRoomActivity, usePeekMediaSessionState, usePeekMediaSessionPeerInfo } from '@rocket.chat/ui-voip';
5+
import {
6+
MediaCallRoomActivity,
7+
usePeekMediaSessionState,
8+
usePeekMediaSessionPeerInfo,
9+
usePeekMediaSessionHidden,
10+
} from '@rocket.chat/ui-voip';
611
import type { ReactNode } from 'react';
712
import { memo } from 'react';
813

@@ -42,11 +47,12 @@ export type MediaCallRoomProps = {
4247

4348
const MediaCallRoom = ({ children }: MediaCallRoomProps) => {
4449
const state = usePeekMediaSessionState();
50+
const hidden = usePeekMediaSessionHidden();
4551
const peerInfo = usePeekMediaSessionPeerInfo();
4652
const userId = useUserId();
4753
const room = useRoom();
4854

49-
if (state !== 'ongoing' || !isMediaCallRoom(room, peerInfo, userId)) {
55+
if (hidden || state !== 'ongoing' || !isMediaCallRoom(room, peerInfo, userId)) {
5056
return children;
5157
}
5258

packages/media-signaling/src/definition/call/callStates/ITempMediaCallData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { IClientMediaCallLocalParticipant } from '../IClientMediaCallPartic
33

44
export interface ITempMediaCallData {
55
readonly confirmed: false;
6+
readonly hidden: boolean;
67
readonly tempCallId: string;
78

89
readonly state: CallState;

packages/media-signaling/src/lib/Call.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export class ClientMediaCall implements IClientMediaCall {
280280

281281
return {
282282
confirmed: false,
283+
hidden: this.hidden,
283284
tempCallId: this.tempCallId,
284285
state: this.state,
285286
title: this.contact.displayName || number || 'unknown',

packages/ui-voip/src/context/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { usePeerAutocomplete, isFirstPeerAutocompleteOption } from './usePeerAut
55
export { useWidgetExternalControls } from './useWidgetExternalControls';
66
export { usePeekMediaSessionState } from './usePeekMediaSessionState';
77
export { usePeekMediaSessionCallId } from './usePeekMediaSessionCallId';
8+
export { usePeekMediaSessionHidden } from './usePeekMediaSessionHidden';
89
export { usePeekMediaSessionPeerInfo } from './usePeekMediaSessionPeerInfo';
910
export { usePeekMediaSessionFeatures } from './usePeekMediaSessionFeatures';
1011
export type { PeekMediaSessionStateReturn } from './usePeekMediaSessionState';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useCallback, useSyncExternalStore } from 'react';
2+
3+
import { useMediaCallInstance } from './MediaCallInstanceContext';
4+
5+
export const usePeekMediaSessionHidden = (): boolean => {
6+
const { instance } = useMediaCallInstance();
7+
8+
const subscribe = useCallback(
9+
(onStoreChange: () => void): (() => void) => {
10+
if (!instance) {
11+
return () => undefined;
12+
}
13+
14+
const offCbs = [instance.on('sessionStateChange', onStoreChange), instance.on('hiddenCall', onStoreChange)];
15+
16+
return () => {
17+
offCbs.forEach((offCb) => offCb());
18+
};
19+
},
20+
[instance],
21+
);
22+
23+
const getSnapshot = useCallback(() => {
24+
if (!instance) {
25+
return false;
26+
}
27+
28+
const instanceState = instance.getState();
29+
30+
return instanceState?.hidden ?? false;
31+
}, [instance]);
32+
33+
return useSyncExternalStore(subscribe, getSnapshot);
34+
};

packages/ui-voip/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
usePeekMediaSessionState,
88
usePeekMediaSessionPeerInfo,
99
usePeekMediaSessionFeatures,
10+
usePeekMediaSessionHidden,
1011
} from './context';
1112
export type { PeekMediaSessionStateReturn } from './context';
1213
export type { PeerInfo } from './context';

0 commit comments

Comments
 (0)