Skip to content

Commit f3992e4

Browse files
We don't need to keep memberStatusUpdate as a useRef
1 parent 22e5f66 commit f3992e4

4 files changed

Lines changed: 19 additions & 29 deletions

File tree

react-demo-app/src/components/Video/VideoElement.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export default function VideoElement({ videoRef, userId }: {
2727
.find(p => p.userId === session?.fromUserId);
2828
return localUser?.videoMuted && !localUser?.sharingScreen;
2929
} else {
30-
// const participantIdOnScreen = activeVideoConv?.activeParticipants?.[0];
31-
const participantIdOnScreen = activeVideoConv?.participantsUpdate?.activeParticipants?.[0]?.userId;
30+
const participantIdOnScreen = activeVideoConv?.activeParticipant;
3231
const participant = activeVideoConv?.participantsUpdate?.activeParticipants
3332
.find(p => p.userId === participantIdOnScreen);
3433
return participant?.videoMuted && !participant?.sharingScreen;

react-demo-app/src/components/Video/VideoElements.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ export default function VideoElements({
5454
}, [activeVideoConv?.inboundStream, activeVideoConv?.outboundStream, activeVideoConv?.screenOutboundStream,
5555
localParticipant?.sharingScreen, videoRef, vanityVideoRef]);
5656

57-
// const participantIdOnScreen = activeVideoConv?.activeParticipants?.[0];
58-
const participantIdOnScreen = activeVideoConv?.participantsUpdate?.activeParticipants?.[0]?.userId;
57+
const participantIdOnScreen = activeVideoConv?.activeParticipant
5958

6059
const userId = (id: string | undefined) => {
6160
if (!id) return;

react-demo-app/src/features/videoConversationsSlice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface IActiveVideoConversationsState { // rename this to remove the '
1010
inboundStream?: MediaStream;
1111
outboundStream?: MediaStream;
1212
screenOutboundStream?: MediaStream;
13-
activeParticipants?: string[];
14-
usersTalking?: { [userId: string]: boolean };
13+
activeParticipant?: string;
14+
usersTalking?: {[userId: string]: boolean};
1515
}
1616

1717
export interface IVideoConversationsState {
@@ -100,7 +100,7 @@ export const videoConversationsSlice = createSlice({
100100
setActiveParticipants: (state, action) => {
101101
const conv = findConvInState(state, action.payload.conversationId);
102102
if (conv) {
103-
// conv.activeParticipants = action.payload.activeParticipants;
103+
conv.activeParticipant = action.payload.activeParticipant;
104104
}
105105
},
106106
setUsersTalking: (state, action) => {

react-demo-app/src/hooks/useSdk.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
setActiveParticipants, setUsersTalking,
2424
updateConversationMediaStreams
2525
} from "../features/videoConversationsSlice.ts";
26-
import { useRef } from "react";
2726

2827
interface IAuthData {
2928
token: string;
@@ -39,8 +38,6 @@ export default function useSdk() {
3938
let webrtcSdk: GenesysCloudWebrtcSdk;
4039
const dispatch = useDispatch<AppDispatch>();
4140

42-
// const memberStatusUpdateRef = useRef<{ memberStatusMessage: MemberStatusMessage }>();
43-
4441
const sdk: GenesysCloudWebrtcSdk = useSelector((state: RootState) => state.sdk.sdk);
4542

4643
async function initWebrtcSDK(authData: IAuthData) {
@@ -137,21 +134,20 @@ export default function useSdk() {
137134
}
138135

139136
const updateMemberStatus = (memberStatusMessage: MemberStatusMessage, convId: string) => {
140-
// const lastUpdateParams = memberStatusUpdateRef.current?.memberStatusMessage?.params || {};
141-
// const mergedUpdateParams = { ...lastUpdateParams, ...memberStatusMessage.params }
142-
// const mergedUpdate = { ...memberStatusMessage, params: mergedUpdateParams }
143-
//
144-
// if (memberStatusMessage?.params?.incomingStreams) {
145-
// const userIds = memberStatusMessage.params.incomingStreams.map(stream => {
146-
// const appId = stream.appId || stream.appid;
147-
// return appId?.sourceUserId
148-
// });
149-
// dispatch(setActiveParticipants({
150-
// conversationId: convId,
151-
// activeParticipants: userIds
152-
// }));
153-
// }
154-
137+
// Detect which remote user is shown
138+
if (memberStatusMessage?.params?.incomingStreams) {
139+
const userIds = memberStatusMessage.params.incomingStreams.map(stream => {
140+
const appId = stream.appId || stream.appid;
141+
return appId?.sourceUserId
142+
});
143+
// We don't show more than one remote stream at a time
144+
const userId = userIds[0]
145+
dispatch(setActiveParticipants({
146+
conversationId: convId,
147+
activeParticipant: userId
148+
}));
149+
}
150+
// Detect if the user that is shown is 'speaking'
155151
if (memberStatusMessage?.params?.speakers) {
156152
const usersTalking = memberStatusMessage.params.speakers.reduce((acc, current) => {
157153
return { ...acc, [current.appId.sourceUserId]: current.activity === 'speaking' }
@@ -161,10 +157,6 @@ export default function useSdk() {
161157
usersTalking
162158
}));
163159
}
164-
165-
// memberStatusUpdateRef.current = {
166-
// memberStatusMessage: mergedUpdate
167-
// };
168160
}
169161

170162
const setupSessionListeners = (session: IExtendedMediaSession) => {

0 commit comments

Comments
 (0)