Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09bc461

Browse files
added global and participant screen share flag
1 parent 7371179 commit 09bc461

File tree

3 files changed

+2978
-2730
lines changed

3 files changed

+2978
-2730
lines changed

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

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ const turnOnMicrophone = async (flag?: boolean) => {
148148
};
149149
const shareScreen = async (sharing: boolean) => {
150150
try {
151-
if (sharing === false) {
151+
console.log("sharing ", sharing);
152+
if (sharing === false && screenShareStream) {
152153
await client.unpublish(screenShareStream);
153154
screenShareStream.close();
154155
await client.publish(videoTrack);
@@ -237,7 +238,8 @@ const meetingControllerChildren = {
237238
audioControl: withDefault(BooleanStateControl, "false"),
238239
videoControl: withDefault(BooleanStateControl, "true"),
239240
endCall: withDefault(BooleanStateControl, "false"),
240-
sharing: withDefault(BooleanStateControl, "false"),
241+
sharingData: stateComp<JSONValue>([]), //withDefault(BooleanStateControl, "false"),
242+
isSharing: withDefault(BooleanStateControl, "false"),
241243
appId: withDefault(StringControl, trans("meeting.appid")),
242244
participants: stateComp<JSONValue>([]),
243245
usersScreenShared: stateComp<JSONValue>([]),
@@ -286,20 +288,32 @@ let MTComp = (function () {
286288
useState<IAgoraRTCRemoteUser>();
287289
const [userJoined, setUserJoined] = useState<IAgoraRTCRemoteUser>();
288290
const [userLeft, setUserLeft] = useState<IAgoraRTCRemoteUser>();
289-
291+
const userSharigScreen = (userid: any) => {
292+
//check if passed userid exists in the props.participants array and check if participants is null
293+
let prevUsers: [] = props.participants as [];
294+
let foundUsers: any = [];
295+
prevUsers.forEach((user: any) => {
296+
if (user.user === userid) {
297+
foundUsers.push(user.user as any);
298+
}
299+
});
300+
return foundUsers.length > 0;
301+
};
290302
useEffect(() => {
291303
if (userJoined) {
292304
const remoteUsers = client.remoteUsers;
293305
let users: {
294306
user: UID;
295307
audiostatus: boolean;
296308
streamingVideo: boolean;
309+
sharingScreen: boolean;
297310
}[] = [];
298311
remoteUsers.forEach((user) => {
299312
let userData = {
300313
user: user.uid,
301314
audiostatus: user.hasAudio,
302315
streamingVideo: user.hasVideo,
316+
sharingScreen: userSharigScreen(user.uid),
303317
};
304318
users.push(userData);
305319
setUserIds((userIds: any) => [...userIds, userData]);
@@ -369,27 +383,17 @@ let MTComp = (function () {
369383
}, [updateVolume]);
370384

371385
useEffect(() => {
372-
let prevUsers: any = props.participants as [];
373-
if (prevUsers == "") return;
374-
const updatedItems = prevUsers.map((userInfo: any) => {
375-
if (userInfo.user === localUserVideo?.uid) {
376-
return { ...userInfo, streamingSharing: props.sharing.value };
377-
}
378-
return userInfo;
379-
});
386+
if (rtmChannelResponse == null) return;
387+
let data = {
388+
uid: props.localUserID.value,
389+
sharingScreen: props.isSharing.value,
390+
};
391+
392+
rtmChannelResponse.sendMessage({ text: JSON.stringify(data) });
380393
dispatch(
381-
changeChildAction("participants", getData(updatedItems).data, false)
394+
changeChildAction("sharingData", props.isSharing.value ? data : {}, false)
382395
);
383-
384-
let localObject = {
385-
user: userId + "",
386-
audiostatus: props.audioControl.value,
387-
streamingVideo: props.videoControl.value,
388-
streamingSharing: props.sharing.value,
389-
speaking: localUserSpeaking,
390-
};
391-
props.localUser.onChange(localObject);
392-
}, [props.sharing.value]);
396+
}, [props.isSharing.value]);
393397

394398
useEffect(() => {
395399
let prevUsers: any = props.participants as [];
@@ -441,23 +445,56 @@ let MTComp = (function () {
441445
});
442446

443447
rtmChannelResponse.on("ChannelMessage", function (message, memberId) {
444-
setRtmMessages((prevMessages: any[]) => {
445-
// Check if the messages array exceeds the maximum limit
446-
if (prevMessages.length >= 500) {
447-
prevMessages.pop(); // Remove the oldest message
448-
}
449-
return [
450-
...prevMessages,
451-
{
452-
channelmessage: JSON.parse(message.text + ""),
453-
from: memberId,
454-
},
455-
];
456-
});
457-
458-
dispatch(
459-
changeChildAction("messages", getData(rtmMessages).data, false)
460-
);
448+
let messageData = JSON.parse(message.text + "");
449+
if (messageData.sharingScreen != null) {
450+
dispatch(
451+
changeChildAction(
452+
"sharingData",
453+
messageData.sharingScreen
454+
? {
455+
uid: messageData.uid,
456+
sharingScreen: messageData.sharingScreen,
457+
}
458+
: {},
459+
false
460+
)
461+
);
462+
let prevUsers: [] = props.participants as [];
463+
464+
const updatedItems = prevUsers.map((userInfo: any) => {
465+
if (userInfo.user === messageData.uid) {
466+
return {
467+
...userInfo,
468+
sharingScreen: messageData.sharingScreen,
469+
};
470+
}
471+
return userInfo;
472+
});
473+
dispatch(
474+
changeChildAction(
475+
"participants",
476+
getData(updatedItems).data,
477+
false
478+
)
479+
);
480+
} else {
481+
setRtmMessages((prevMessages: any[]) => {
482+
// Check if the messages array exceeds the maximum limit
483+
if (prevMessages.length >= 500) {
484+
prevMessages.pop(); // Remove the oldest message
485+
}
486+
return [
487+
...prevMessages,
488+
{
489+
channelmessage: JSON.parse(message.text + ""),
490+
from: memberId,
491+
},
492+
];
493+
});
494+
dispatch(
495+
changeChildAction("messages", getData(rtmMessages).data, false)
496+
);
497+
}
461498
});
462499
}
463500
}, [rtmChannelResponse]);
@@ -668,9 +705,14 @@ MTComp = withMethodExposing(MTComp, [
668705
},
669706
execute: async (comp, values) => {
670707
if (!comp.children.meetingActive.getView().value) return;
671-
let sharing = !comp.children.sharing.getView().value;
708+
let sharing = !comp.children.isSharing.getView().value;
709+
710+
comp.children.localUser.change({
711+
sharingScreen: sharing,
712+
...comp.children.localUser.getView().value,
713+
});
714+
comp.children.isSharing.change(sharing);
672715
await shareScreen(sharing);
673-
comp.children.sharing.change(sharing);
674716
},
675717
},
676718
{
@@ -872,4 +914,5 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
872914
new NameConfig("messages", trans("meeting.messages")),
873915
new NameConfig("rtmToken", trans("meeting.rtmToken")),
874916
new NameConfig("rtcToken", trans("meeting.rtcToken")),
917+
new NameConfig("sharingData", trans("meeting.screenSharing")),
875918
]);

0 commit comments

Comments
 (0)