@@ -148,7 +148,8 @@ const turnOnMicrophone = async (flag?: boolean) => {
148
148
} ;
149
149
const shareScreen = async ( sharing : boolean ) => {
150
150
try {
151
- if ( sharing === false ) {
151
+ console . log ( "sharing " , sharing ) ;
152
+ if ( sharing === false && screenShareStream ) {
152
153
await client . unpublish ( screenShareStream ) ;
153
154
screenShareStream . close ( ) ;
154
155
await client . publish ( videoTrack ) ;
@@ -237,7 +238,8 @@ const meetingControllerChildren = {
237
238
audioControl : withDefault ( BooleanStateControl , "false" ) ,
238
239
videoControl : withDefault ( BooleanStateControl , "true" ) ,
239
240
endCall : withDefault ( BooleanStateControl , "false" ) ,
240
- sharing : withDefault ( BooleanStateControl , "false" ) ,
241
+ sharingData : stateComp < JSONValue > ( [ ] ) , //withDefault(BooleanStateControl, "false"),
242
+ isSharing : withDefault ( BooleanStateControl , "false" ) ,
241
243
appId : withDefault ( StringControl , trans ( "meeting.appid" ) ) ,
242
244
participants : stateComp < JSONValue > ( [ ] ) ,
243
245
usersScreenShared : stateComp < JSONValue > ( [ ] ) ,
@@ -286,20 +288,32 @@ let MTComp = (function () {
286
288
useState < IAgoraRTCRemoteUser > ( ) ;
287
289
const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
288
290
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
+ } ;
290
302
useEffect ( ( ) => {
291
303
if ( userJoined ) {
292
304
const remoteUsers = client . remoteUsers ;
293
305
let users : {
294
306
user : UID ;
295
307
audiostatus : boolean ;
296
308
streamingVideo : boolean ;
309
+ sharingScreen : boolean ;
297
310
} [ ] = [ ] ;
298
311
remoteUsers . forEach ( ( user ) => {
299
312
let userData = {
300
313
user : user . uid ,
301
314
audiostatus : user . hasAudio ,
302
315
streamingVideo : user . hasVideo ,
316
+ sharingScreen : userSharigScreen ( user . uid ) ,
303
317
} ;
304
318
users . push ( userData ) ;
305
319
setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
@@ -369,27 +383,17 @@ let MTComp = (function () {
369
383
} , [ updateVolume ] ) ;
370
384
371
385
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 ) } ) ;
380
393
dispatch (
381
- changeChildAction ( "participants " , getData ( updatedItems ) . data , false )
394
+ changeChildAction ( "sharingData " , props . isSharing . value ? data : { } , false )
382
395
) ;
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 ] ) ;
393
397
394
398
useEffect ( ( ) => {
395
399
let prevUsers : any = props . participants as [ ] ;
@@ -441,23 +445,56 @@ let MTComp = (function () {
441
445
} ) ;
442
446
443
447
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
+ }
461
498
} ) ;
462
499
}
463
500
} , [ rtmChannelResponse ] ) ;
@@ -668,9 +705,14 @@ MTComp = withMethodExposing(MTComp, [
668
705
} ,
669
706
execute : async ( comp , values ) => {
670
707
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 ) ;
672
715
await shareScreen ( sharing ) ;
673
- comp . children . sharing . change ( sharing ) ;
674
716
} ,
675
717
} ,
676
718
{
@@ -872,4 +914,5 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
872
914
new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
873
915
new NameConfig ( "rtmToken" , trans ( "meeting.rtmToken" ) ) ,
874
916
new NameConfig ( "rtcToken" , trans ( "meeting.rtcToken" ) ) ,
917
+ new NameConfig ( "sharingData" , trans ( "meeting.screenSharing" ) ) ,
875
918
] ) ;
0 commit comments