Skip to content

Commit 871e856

Browse files
feat: speaking status to participant and local object
1 parent 21aa2bb commit 871e856

File tree

1 file changed

+49
-28
lines changed

1 file changed

+49
-28
lines changed

client/packages/lowcoder/src/comps/comps/meetingComp/videoMeetingControllerComp.tsx

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,7 @@ let MTComp = (function () {
312312
const [rtmMessages, setRtmMessages] = useState<any>([]);
313313

314314
useEffect(() => {
315-
dispatch(
316-
changeChildAction("participants", getData(userIds).data, false)
317-
);
318-
}, [userIds]);
319-
320-
useEffect(() => {
315+
console.log(userIds);
321316
dispatch(
322317
changeChildAction("participants", getData(userIds).data, false)
323318
);
@@ -372,28 +367,51 @@ let MTComp = (function () {
372367
}, [rtmChannelResponse]);
373368

374369
useEffect(() => {
375-
client.on("user-joined", (user: IAgoraRTCRemoteUser) => {
376-
let userData = {
377-
user: user.uid,
378-
host: false,
379-
audiostatus: user.hasVideo,
380-
};
381-
if (userIds.length == 0) {
382-
userData.host = true;
383-
} else {
384-
userData.host = false;
385-
}
386-
setUserIds((userIds: any) => [...userIds, userData]);
387-
});
388-
client.on("user-left", (user: IAgoraRTCRemoteUser, reason: any) => {
389-
let newUsers = userIds.filter((item: any) => item.user !== user.uid);
390-
let hostExists = newUsers.filter((f: any) => f.host === true);
391-
if (hostExists.length == 0 && newUsers.length > 0) {
392-
newUsers[0].host = true;
393-
hostChanged(newUsers);
394-
}
395-
setUserIds(newUsers);
396-
});
370+
if (client) {
371+
client.enableAudioVolumeIndicator();
372+
client.on("user-joined", (user: IAgoraRTCRemoteUser) => {
373+
let userData = {
374+
user: user.uid,
375+
host: false,
376+
audiostatus: user.hasVideo,
377+
};
378+
379+
if (userIds.length == 0) {
380+
userData.host = true;
381+
} else {
382+
userData.host = false;
383+
}
384+
setUserIds((userIds: any) => [...userIds, userData]);
385+
});
386+
client.on("user-left", (user: IAgoraRTCRemoteUser, reason: any) => {
387+
let newUsers = userIds.filter(
388+
(item: any) => item.user !== user.uid
389+
);
390+
let hostExists = newUsers.filter((f: any) => f.host === true);
391+
if (hostExists.length == 0 && newUsers.length > 0) {
392+
newUsers[0].host = true;
393+
hostChanged(newUsers);
394+
}
395+
setUserIds(newUsers);
396+
});
397+
client.on("volume-indicator", (volumeInfos: any) => {
398+
if (volumeInfos.length == 0) return;
399+
volumeInfos.map((volumeInfo: any) => {
400+
const speaking = volumeInfo.level >= 30;
401+
if (volumeInfo.uid == userId) {
402+
props.localUser.onChange({
403+
...props.localUser.value,
404+
speaking,
405+
});
406+
} else {
407+
const userInfo = userIds.find(
408+
(info: any) => info.user === volumeInfo.uid
409+
);
410+
setUserIds([...userIds, { ...userInfo, speaking }]);
411+
}
412+
});
413+
});
414+
}
397415
}, [client]);
398416

399417
return (
@@ -579,7 +597,10 @@ MTComp = withMethodExposing(MTComp, [
579597
comp.children.localUser.change({
580598
user: userId + "",
581599
audiostatus: false,
600+
speaking: false,
582601
});
602+
console.log(userId);
603+
583604
await publishVideo(
584605
comp.children.appId.getView(),
585606
comp.children.meetingName.getView().value == ""

0 commit comments

Comments
 (0)