@@ -41,7 +41,7 @@ import { useUserViewMode } from "util/hooks";
41
41
import { isNumeric } from "util/stringUtils" ;
42
42
import { NameConfig , withExposingConfigs } from "../../generators/withExposing" ;
43
43
44
- import { v4 as uuidv4 } from ' uuid' ;
44
+ import { v4 as uuidv4 } from " uuid" ;
45
45
46
46
// import axios from "axios";
47
47
@@ -147,6 +147,7 @@ const shareScreen = async (sharing: boolean) => {
147
147
try {
148
148
if ( sharing === false ) {
149
149
await client . unpublish ( screenShareStream ) ;
150
+ screenShareStream . close ( ) ;
150
151
await client . publish ( videoTrack ) ;
151
152
videoTrack . play ( userId + "" ) ;
152
153
} else {
@@ -165,11 +166,16 @@ const shareScreen = async (sharing: boolean) => {
165
166
}
166
167
} ;
167
168
const leaveChannel = async ( ) => {
169
+ //stops local sharing video
170
+ screenShareStream . close ( ) ;
171
+
172
+ //stops local video streaming and puts off the camera
168
173
if ( videoTrack ) {
169
174
await client . unpublish ( videoTrack ) ;
170
175
await turnOnCamera ( false ) ;
171
176
}
172
177
178
+ //mutes and stops locla audio stream
173
179
if ( audioTrack ) {
174
180
await turnOnMicrophone ( false ) ;
175
181
}
@@ -183,12 +189,12 @@ const publishVideo = async (
183
189
rtmToken : string ,
184
190
rtcToken : string
185
191
) => {
186
- // initializing the Agora Meeting Client
187
- await turnOnCamera ( true ) ;
188
- await client . join ( appId , channel , rtcToken , userId ) ;
189
- await client . publish ( videoTrack ) ;
190
- // initializing the Agora RTM Client
191
- await rtmInit ( appId , userId , rtmToken , channel ) ;
192
+ // initializing the Agora Meeting Client
193
+ await turnOnCamera ( true ) ;
194
+ await client . join ( appId , channel , rtcToken , userId ) ;
195
+ await client . publish ( videoTrack ) ;
196
+ // initializing the Agora RTM Client
197
+ await rtmInit ( appId , userId , rtmToken , channel ) ;
192
198
} ;
193
199
194
200
const sendMessageRtm = ( message : any ) => {
@@ -231,8 +237,14 @@ export const meetingControllerChildren = {
231
237
participants : stateComp < JSONValue > ( [ ] ) ,
232
238
usersScreenShared : stateComp < JSONValue > ( [ ] ) ,
233
239
localUser : jsonObjectExposingStateControl ( "" ) ,
234
- localUserID : withDefault ( stringStateControl ( trans ( "meeting.localUserID" ) ) , uuidv4 ( ) + "" ) ,
235
- meetingName : withDefault ( stringStateControl ( trans ( "meeting.meetingName" ) ) , uuidv4 ( ) + "" ) ,
240
+ localUserID : withDefault (
241
+ stringStateControl ( trans ( "meeting.localUserID" ) ) ,
242
+ uuidv4 ( ) + ""
243
+ ) ,
244
+ meetingName : withDefault (
245
+ stringStateControl ( trans ( "meeting.meetingName" ) ) ,
246
+ uuidv4 ( ) + ""
247
+ ) ,
236
248
rtmToken : stringStateControl ( trans ( "meeting.rtmToken" ) ) ,
237
249
rtcToken : stringStateControl ( trans ( "meeting.rtcToken" ) ) ,
238
250
messages : stateComp < JSONValue > ( [ ] ) ,
@@ -265,7 +277,8 @@ let MTComp = (function () {
265
277
} ) ;
266
278
const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
267
279
const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
268
- const [ localUserVideo , setLocalUserVideo ] = useState < IAgoraRTCRemoteUser > ( ) ;
280
+ const [ localUserVideo , setLocalUserVideo ] =
281
+ useState < IAgoraRTCRemoteUser > ( ) ;
269
282
const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
270
283
const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
271
284
@@ -323,6 +336,8 @@ let MTComp = (function () {
323
336
}
324
337
} , [ userLeft ] ) ;
325
338
339
+ console . log ( "sharing" , props . sharing ) ;
340
+
326
341
useEffect ( ( ) => {
327
342
if ( updateVolume . userid ) {
328
343
let prevUsers : [ ] = props . participants as [ ] ;
@@ -342,6 +357,28 @@ let MTComp = (function () {
342
357
}
343
358
} , [ updateVolume ] ) ;
344
359
360
+ useEffect ( ( ) => {
361
+ let prevUsers : [ ] = props . participants as [ ] ;
362
+ const updatedItems = prevUsers . map ( ( userInfo : any ) => {
363
+ if ( userInfo . user === localUserVideo ?. uid ) {
364
+ return { ...userInfo , streamingSharing : props . sharing . value } ;
365
+ }
366
+ return userInfo ;
367
+ } ) ;
368
+ dispatch (
369
+ changeChildAction ( "participants" , getData ( updatedItems ) . data , false )
370
+ ) ;
371
+
372
+ let localObject = {
373
+ user : userId + "" ,
374
+ audiostatus : props . audioControl . value ,
375
+ streamingVideo : props . videoControl . value ,
376
+ streamingSharing : props . sharing . value ,
377
+ speaking : localUserSpeaking ,
378
+ } ;
379
+ props . localUser . onChange ( localObject ) ;
380
+ } , [ props . sharing . value ] ) ;
381
+
345
382
useEffect ( ( ) => {
346
383
let prevUsers : [ ] = props . participants as [ ] ;
347
384
const updatedItems = prevUsers . map ( ( userInfo : any ) => {
@@ -383,37 +420,52 @@ let MTComp = (function () {
383
420
if ( prevMessages . length >= 500 ) {
384
421
prevMessages . pop ( ) ; // Remove the oldest message
385
422
}
386
- return [ ...prevMessages , { "peermessage" : JSON . parse ( message . text + "" ) , "from" : peerId } ] ;
423
+ return [
424
+ ...prevMessages ,
425
+ { peermessage : JSON . parse ( message . text + "" ) , from : peerId } ,
426
+ ] ;
387
427
} ) ;
388
428
} ) ;
389
-
429
+
390
430
rtmChannelResponse . on ( "ChannelMessage" , function ( message , memberId ) {
391
431
setRtmMessages ( ( prevMessages : any [ ] ) => {
392
432
// Check if the messages array exceeds the maximum limit
393
433
if ( prevMessages . length >= 500 ) {
394
434
prevMessages . pop ( ) ; // Remove the oldest message
395
435
}
396
- return [ ...prevMessages , { "channelmessage" : JSON . parse ( message . text + "" ) , "from" : memberId } ] ;
436
+ return [
437
+ ...prevMessages ,
438
+ {
439
+ channelmessage : JSON . parse ( message . text + "" ) ,
440
+ from : memberId ,
441
+ } ,
442
+ ] ;
397
443
} ) ;
398
-
399
- dispatch ( changeChildAction ( "messages" , getData ( rtmMessages ) . data , false ) ) ;
444
+
445
+ dispatch (
446
+ changeChildAction ( "messages" , getData ( rtmMessages ) . data , false )
447
+ ) ;
400
448
} ) ;
401
449
}
402
450
} , [ rtmChannelResponse ] ) ;
403
-
404
451
405
452
useEffect ( ( ) => {
406
453
if ( client ) {
454
+ //Enable Agora to send audio bytes
407
455
client . enableAudioVolumeIndicator ( ) ;
456
+ //user activity listeners
408
457
client . on ( "user-joined" , ( user : IAgoraRTCRemoteUser ) => {
409
458
setUserJoined ( user ) ;
410
459
} ) ;
411
460
client . on ( "user-left" , ( user : IAgoraRTCRemoteUser , reason : any ) => {
412
461
setUserLeft ( user ) ;
413
462
} ) ;
463
+
464
+ //listen to user speaking,
414
465
client . on ( "volume-indicator" , ( volumeInfos : any ) => {
415
466
if ( volumeInfos . length === 0 ) return ;
416
467
volumeInfos . map ( ( volumeInfo : any ) => {
468
+ //when the volume is above 30, user is probably speaking
417
469
const speaking = volumeInfo . level >= 30 ;
418
470
if (
419
471
volumeInfo . uid === userId &&
@@ -534,8 +586,8 @@ let MTComp = (function () {
534
586
} ) }
535
587
</ Section >
536
588
< Section name = { sectionNames . meetings } >
537
- { children . appId . propertyView ( {
538
- label : trans ( "meeting.appid" )
589
+ { children . appId . propertyView ( {
590
+ label : trans ( "meeting.appid" ) ,
539
591
} ) }
540
592
{ children . meetingName . propertyView ( {
541
593
label : trans ( "meeting.meetingName" ) ,
@@ -646,7 +698,10 @@ MTComp = withMethodExposing(MTComp, [
646
698
} ,
647
699
execute : async ( comp , values ) => {
648
700
if ( comp . children . meetingActive . getView ( ) . value ) return ;
649
- userId = comp . children . localUserID . getView ( ) . value === "" ? uuidv4 ( ) : comp . children . localUserID . getView ( ) . value ;
701
+ userId =
702
+ comp . children . localUserID . getView ( ) . value === ""
703
+ ? uuidv4 ( )
704
+ : comp . children . localUserID . getView ( ) . value ;
650
705
comp . children . localUser . change ( {
651
706
user : userId + "" ,
652
707
audiostatus : false ,
@@ -669,7 +724,9 @@ MTComp = withMethodExposing(MTComp, [
669
724
comp . children . videoControl . change ( true ) ;
670
725
await publishVideo (
671
726
comp . children . appId . getView ( ) ,
672
- comp . children . meetingName . getView ( ) . value === "" ? uuidv4 ( ) : comp . children . meetingName . getView ( ) . value ,
727
+ comp . children . meetingName . getView ( ) . value === ""
728
+ ? uuidv4 ( )
729
+ : comp . children . meetingName . getView ( ) . value ,
673
730
comp . children . rtmToken . getView ( ) . value ,
674
731
comp . children . rtcToken . getView ( ) . value
675
732
) ;
@@ -790,7 +847,7 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
790
847
new NameConfig ( "meetingActive" , trans ( "meeting.meetingActive" ) ) ,
791
848
new NameConfig ( "meetingName" , trans ( "meeting.meetingName" ) ) ,
792
849
new NameConfig ( "localUserID" , trans ( "meeting.localUserID" ) ) ,
793
- new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
850
+ new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
794
851
new NameConfig ( "rtmToken" , trans ( "meeting.rtmToken" ) ) ,
795
852
new NameConfig ( "rtcToken" , trans ( "meeting.rtcToken" ) ) ,
796
853
] ) ;
0 commit comments