@@ -41,7 +41,7 @@ import { useUserViewMode } from "util/hooks";
4141import { isNumeric } from "util/stringUtils" ;
4242import { NameConfig , withExposingConfigs } from "../../generators/withExposing" ;
4343
44- import { v4 as uuidv4 } from ' uuid' ;
44+ import { v4 as uuidv4 } from " uuid" ;
4545
4646// import axios from "axios";
4747
@@ -147,6 +147,7 @@ const shareScreen = async (sharing: boolean) => {
147147 try {
148148 if ( sharing === false ) {
149149 await client . unpublish ( screenShareStream ) ;
150+ screenShareStream . close ( ) ;
150151 await client . publish ( videoTrack ) ;
151152 videoTrack . play ( userId + "" ) ;
152153 } else {
@@ -165,11 +166,16 @@ const shareScreen = async (sharing: boolean) => {
165166 }
166167} ;
167168const leaveChannel = async ( ) => {
169+ //stops local sharing video
170+ screenShareStream . close ( ) ;
171+
172+ //stops local video streaming and puts off the camera
168173 if ( videoTrack ) {
169174 await client . unpublish ( videoTrack ) ;
170175 await turnOnCamera ( false ) ;
171176 }
172177
178+ //mutes and stops locla audio stream
173179 if ( audioTrack ) {
174180 await turnOnMicrophone ( false ) ;
175181 }
@@ -183,12 +189,12 @@ const publishVideo = async (
183189 rtmToken : string ,
184190 rtcToken : string
185191) => {
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 ) ;
192198} ;
193199
194200const sendMessageRtm = ( message : any ) => {
@@ -231,8 +237,14 @@ export const meetingControllerChildren = {
231237 participants : stateComp < JSONValue > ( [ ] ) ,
232238 usersScreenShared : stateComp < JSONValue > ( [ ] ) ,
233239 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+ ) ,
236248 rtmToken : stringStateControl ( trans ( "meeting.rtmToken" ) ) ,
237249 rtcToken : stringStateControl ( trans ( "meeting.rtcToken" ) ) ,
238250 messages : stateComp < JSONValue > ( [ ] ) ,
@@ -265,7 +277,8 @@ let MTComp = (function () {
265277 } ) ;
266278 const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
267279 const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
268- const [ localUserVideo , setLocalUserVideo ] = useState < IAgoraRTCRemoteUser > ( ) ;
280+ const [ localUserVideo , setLocalUserVideo ] =
281+ useState < IAgoraRTCRemoteUser > ( ) ;
269282 const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
270283 const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
271284
@@ -323,6 +336,8 @@ let MTComp = (function () {
323336 }
324337 } , [ userLeft ] ) ;
325338
339+ console . log ( "sharing" , props . sharing ) ;
340+
326341 useEffect ( ( ) => {
327342 if ( updateVolume . userid ) {
328343 let prevUsers : [ ] = props . participants as [ ] ;
@@ -342,6 +357,28 @@ let MTComp = (function () {
342357 }
343358 } , [ updateVolume ] ) ;
344359
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+
345382 useEffect ( ( ) => {
346383 let prevUsers : [ ] = props . participants as [ ] ;
347384 const updatedItems = prevUsers . map ( ( userInfo : any ) => {
@@ -383,37 +420,52 @@ let MTComp = (function () {
383420 if ( prevMessages . length >= 500 ) {
384421 prevMessages . pop ( ) ; // Remove the oldest message
385422 }
386- return [ ...prevMessages , { "peermessage" : JSON . parse ( message . text + "" ) , "from" : peerId } ] ;
423+ return [
424+ ...prevMessages ,
425+ { peermessage : JSON . parse ( message . text + "" ) , from : peerId } ,
426+ ] ;
387427 } ) ;
388428 } ) ;
389-
429+
390430 rtmChannelResponse . on ( "ChannelMessage" , function ( message , memberId ) {
391431 setRtmMessages ( ( prevMessages : any [ ] ) => {
392432 // Check if the messages array exceeds the maximum limit
393433 if ( prevMessages . length >= 500 ) {
394434 prevMessages . pop ( ) ; // Remove the oldest message
395435 }
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+ ] ;
397443 } ) ;
398-
399- dispatch ( changeChildAction ( "messages" , getData ( rtmMessages ) . data , false ) ) ;
444+
445+ dispatch (
446+ changeChildAction ( "messages" , getData ( rtmMessages ) . data , false )
447+ ) ;
400448 } ) ;
401449 }
402450 } , [ rtmChannelResponse ] ) ;
403-
404451
405452 useEffect ( ( ) => {
406453 if ( client ) {
454+ //Enable Agora to send audio bytes
407455 client . enableAudioVolumeIndicator ( ) ;
456+ //user activity listeners
408457 client . on ( "user-joined" , ( user : IAgoraRTCRemoteUser ) => {
409458 setUserJoined ( user ) ;
410459 } ) ;
411460 client . on ( "user-left" , ( user : IAgoraRTCRemoteUser , reason : any ) => {
412461 setUserLeft ( user ) ;
413462 } ) ;
463+
464+ //listen to user speaking,
414465 client . on ( "volume-indicator" , ( volumeInfos : any ) => {
415466 if ( volumeInfos . length === 0 ) return ;
416467 volumeInfos . map ( ( volumeInfo : any ) => {
468+ //when the volume is above 30, user is probably speaking
417469 const speaking = volumeInfo . level >= 30 ;
418470 if (
419471 volumeInfo . uid === userId &&
@@ -534,8 +586,8 @@ let MTComp = (function () {
534586 } ) }
535587 </ Section >
536588 < Section name = { sectionNames . meetings } >
537- { children . appId . propertyView ( {
538- label : trans ( "meeting.appid" )
589+ { children . appId . propertyView ( {
590+ label : trans ( "meeting.appid" ) ,
539591 } ) }
540592 { children . meetingName . propertyView ( {
541593 label : trans ( "meeting.meetingName" ) ,
@@ -646,7 +698,10 @@ MTComp = withMethodExposing(MTComp, [
646698 } ,
647699 execute : async ( comp , values ) => {
648700 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 ;
650705 comp . children . localUser . change ( {
651706 user : userId + "" ,
652707 audiostatus : false ,
@@ -669,7 +724,9 @@ MTComp = withMethodExposing(MTComp, [
669724 comp . children . videoControl . change ( true ) ;
670725 await publishVideo (
671726 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 ,
673730 comp . children . rtmToken . getView ( ) . value ,
674731 comp . children . rtcToken . getView ( ) . value
675732 ) ;
@@ -790,7 +847,7 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
790847 new NameConfig ( "meetingActive" , trans ( "meeting.meetingActive" ) ) ,
791848 new NameConfig ( "meetingName" , trans ( "meeting.meetingName" ) ) ,
792849 new NameConfig ( "localUserID" , trans ( "meeting.localUserID" ) ) ,
793- new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
850+ new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
794851 new NameConfig ( "rtmToken" , trans ( "meeting.rtmToken" ) ) ,
795852 new NameConfig ( "rtcToken" , trans ( "meeting.rtcToken" ) ) ,
796853] ) ;
0 commit comments