@@ -41,7 +41,10 @@ import { useUserViewMode } from "util/hooks";
41
41
import { isNumeric } from "util/stringUtils" ;
42
42
import { NameConfig , withExposingConfigs } from "../../generators/withExposing" ;
43
43
44
- import axios from "axios" ;
44
+ import { v4 as uuidv4 } from 'uuid' ;
45
+
46
+ // import axios from "axios";
47
+
45
48
import AgoraRTC , {
46
49
ICameraVideoTrack ,
47
50
IMicrophoneAudioTrack ,
@@ -51,7 +54,7 @@ import AgoraRTC, {
51
54
ILocalVideoTrack ,
52
55
} from "agora-rtc-sdk-ng" ;
53
56
54
- import { JSONValue } from "@lowcoder-ee/index.sdk" ;
57
+ import { JSONValue , NumberControl } from "@lowcoder-ee/index.sdk" ;
55
58
import { getData } from "../listViewComp/listViewUtils" ;
56
59
import AgoraRTM , { RtmChannel , RtmClient } from "agora-rtm-sdk" ;
57
60
@@ -103,28 +106,23 @@ export const client: IAgoraRTCClient = AgoraRTC.createClient({
103
106
mode : "rtc" ,
104
107
codec : "vp8" ,
105
108
} ) ;
106
- AgoraRTC . setLogLevel ( 3 ) ;
109
+
110
+ AgoraRTC . setLogLevel ( 4 ) ;
111
+
112
+ /*
113
+ 0: DEBUG. Output all API logs.
114
+ 1: INFO. Output logs of the INFO, WARNING and ERROR level.
115
+ 2: WARNING. Output logs of the WARNING and ERROR level.
116
+ 3: ERROR. Output logs of the ERROR level.
117
+ 4: NONE. Do not output any log.
118
+ */
107
119
108
120
let audioTrack : IMicrophoneAudioTrack ;
109
121
let videoTrack : ICameraVideoTrack ;
110
122
let screenShareStream : ILocalVideoTrack ;
111
123
let userId : UID | null | undefined ;
112
124
let rtmChannelResponse : RtmChannel ;
113
125
let rtmClient : RtmClient ;
114
- const agoraTokenUrl = `https://sandbox.wiggolive.com/token/rtc` ;
115
-
116
- const generateToken = async (
117
- appId : any ,
118
- certificate : any ,
119
- channelName : any
120
- ) => {
121
- let response = await axios . post ( agoraTokenUrl , {
122
- appId,
123
- certificate,
124
- channelName,
125
- } ) ;
126
- return response . data ;
127
- } ;
128
126
129
127
const turnOnCamera = async ( flag ?: boolean ) => {
130
128
if ( videoTrack ) {
@@ -147,7 +145,7 @@ const turnOnMicrophone = async (flag?: boolean) => {
147
145
} ;
148
146
const shareScreen = async ( sharing : boolean ) => {
149
147
try {
150
- if ( sharing == false ) {
148
+ if ( sharing === false ) {
151
149
await client . unpublish ( screenShareStream ) ;
152
150
await client . publish ( videoTrack ) ;
153
151
videoTrack . play ( userId + "" ) ;
@@ -179,23 +177,18 @@ const leaveChannel = async () => {
179
177
await rtmChannelResponse . leave ( ) ;
180
178
} ;
181
179
182
- const hostChanged = ( users : any ) => { } ;
183
-
184
180
const publishVideo = async (
185
181
appId : string ,
186
- channel : any ,
187
- height : any ,
188
- certifiCateKey : string
182
+ channel : string ,
183
+ rtmToken : string ,
184
+ rtcToken : string
189
185
) => {
190
- let token = null ;
191
- if ( certifiCateKey ) {
192
- token = await generateToken ( appId , certifiCateKey , channel ) ;
193
- }
194
- await turnOnCamera ( true ) ;
195
- await client . join ( appId , channel , token , userId ) ;
196
- await client . publish ( videoTrack ) ;
197
-
198
- await rtmInit ( appId , userId , channel ) ;
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 ) ;
199
192
} ;
200
193
201
194
const sendMessageRtm = ( message : any ) => {
@@ -206,10 +199,11 @@ const sendPeerMessageRtm = (message: any, toId: string) => {
206
199
rtmClient . sendMessageToPeer ( { text : JSON . stringify ( message ) } , toId ) ;
207
200
} ;
208
201
209
- const rtmInit = async ( appId : any , uid : any , channel : any ) => {
202
+ const rtmInit = async ( appId : any , uid : any , token : any , channel : any ) => {
210
203
rtmClient = AgoraRTM . createInstance ( appId ) ;
211
204
let options = {
212
205
uid : String ( uid ) ,
206
+ token : token ? token : null ,
213
207
} ;
214
208
await rtmClient . login ( options ) ;
215
209
@@ -237,8 +231,10 @@ export const meetingControllerChildren = {
237
231
participants : stateComp < JSONValue > ( [ ] ) ,
238
232
usersScreenShared : stateComp < JSONValue > ( [ ] ) ,
239
233
localUser : jsonObjectExposingStateControl ( "" ) ,
240
- meetingName : stringStateControl ( "meetingName" ) ,
241
- certifiCateKey : stringStateControl ( "" ) ,
234
+ localUserID : withDefault ( stringStateControl ( trans ( "meeting.localUserID" ) ) , uuidv4 ( ) + "" ) ,
235
+ meetingName : withDefault ( stringStateControl ( trans ( "meeting.meetingName" ) ) , uuidv4 ( ) + "" ) ,
236
+ rtmToken : stringStateControl ( trans ( "meeting.rtmToken" ) ) ,
237
+ rtcToken : stringStateControl ( trans ( "meeting.rtcToken" ) ) ,
242
238
messages : stateComp < JSONValue > ( [ ] ) ,
243
239
} ;
244
240
let MTComp = ( function ( ) {
@@ -269,34 +265,29 @@ let MTComp = (function () {
269
265
} ) ;
270
266
const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
271
267
const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
272
- const [ localUserVideo , setLocalUserVideo ] =
273
- useState < IAgoraRTCRemoteUser > ( ) ;
268
+ const [ localUserVideo , setLocalUserVideo ] = useState < IAgoraRTCRemoteUser > ( ) ;
274
269
const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
275
270
const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
276
271
277
272
useEffect ( ( ) => {
278
273
if ( userJoined ) {
274
+ let prevUsers : any [ ] = props . participants as [ ] ;
279
275
let userData = {
280
276
user : userJoined . uid ,
281
- host : false ,
282
277
audiostatus : userJoined . hasAudio ,
283
278
streamingVideo : true ,
284
279
} ;
285
280
setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
286
- if ( userIds . length == 0 ) {
287
- userData . host = true ;
288
- } else {
289
- userData . host = false ;
290
- }
291
281
dispatch (
292
282
changeChildAction (
293
283
"participants" ,
294
- removeDuplicates ( getData ( [ ...userIds , userData ] ) . data , "user" ) ,
284
+ removeDuplicates ( getData ( [ ...prevUsers , userData ] ) . data , "user" ) ,
295
285
false
296
286
)
297
287
) ;
298
288
}
299
289
} , [ userJoined ] ) ;
290
+
300
291
function removeDuplicates ( arr : any , prop : any ) {
301
292
const uniqueObjects = [ ] ;
302
293
const seenValues = new Set ( ) ;
@@ -320,7 +311,6 @@ let MTComp = (function () {
320
311
let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
321
312
if ( hostExists . length == 0 && newUsers . length > 0 ) {
322
313
newUsers [ 0 ] . host = true ;
323
- hostChanged ( newUsers ) ;
324
314
}
325
315
setUserIds ( newUsers ) ;
326
316
dispatch (
@@ -432,8 +422,6 @@ let MTComp = (function () {
432
422
client . on (
433
423
"user-unpublished" ,
434
424
( user : IAgoraRTCRemoteUser , mediaType : "video" | "audio" ) => {
435
- console . log ( "user-unpublished" ) ;
436
-
437
425
setLocalUserVideo ( user ) ;
438
426
}
439
427
) ;
@@ -507,15 +495,6 @@ let MTComp = (function () {
507
495
. setPropertyViewFn ( ( children ) => (
508
496
< >
509
497
< Section name = { sectionNames . basic } >
510
- { children . appId . propertyView ( { label : trans ( "meeting.appid" ) } ) }
511
- { children . certifiCateKey . propertyView ( {
512
- label : trans ( "meeting.certifiCateKey" ) ,
513
- } ) }
514
-
515
- { children . meetingName . propertyView ( {
516
- label : trans ( "meeting.meetingName" ) ,
517
- } ) }
518
-
519
498
{ children . placement . propertyView ( {
520
499
label : trans ( "drawer.placement" ) ,
521
500
radioButton : true ,
@@ -541,6 +520,23 @@ let MTComp = (function () {
541
520
label : trans ( "prop.showMask" ) ,
542
521
} ) }
543
522
</ Section >
523
+ < Section name = { sectionNames . meetings } >
524
+ { children . appId . propertyView ( {
525
+ label : trans ( "meeting.appid" )
526
+ } ) }
527
+ { children . meetingName . propertyView ( {
528
+ label : trans ( "meeting.meetingName" ) ,
529
+ } ) }
530
+ { children . localUserID . propertyView ( {
531
+ label : trans ( "meeting.localUserID" ) ,
532
+ } ) }
533
+ { children . rtmToken . propertyView ( {
534
+ label : trans ( "meeting.rtmToken" ) ,
535
+ } ) }
536
+ { children . rtcToken . propertyView ( {
537
+ label : trans ( "meeting.rtcToken" ) ,
538
+ } ) }
539
+ </ Section >
544
540
< Section name = { sectionNames . interaction } >
545
541
{ children . onEvent . getPropertyView ( ) }
546
542
</ Section >
@@ -636,7 +632,8 @@ MTComp = withMethodExposing(MTComp, [
636
632
params : [ ] ,
637
633
} ,
638
634
execute : async ( comp , values ) => {
639
- userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
635
+ if ( comp . children . meetingActive . getView ( ) . value ) return ;
636
+ userId = comp . children . localUserID . getView ( ) . value === "" ? uuidv4 ( ) : comp . children . localUserID . getView ( ) . value ;
640
637
comp . children . localUser . change ( {
641
638
user : userId + "" ,
642
639
audiostatus : false ,
@@ -659,11 +656,9 @@ MTComp = withMethodExposing(MTComp, [
659
656
comp . children . videoControl . change ( true ) ;
660
657
await publishVideo (
661
658
comp . children . appId . getView ( ) ,
662
- comp . children . meetingName . getView ( ) . value == ""
663
- ? "_meetingId"
664
- : comp . children . meetingName . getView ( ) . value ,
665
- comp . children ,
666
- comp . children . certifiCateKey . getView ( ) . value
659
+ comp . children . meetingName . getView ( ) . value === "" ? uuidv4 ( ) : comp . children . meetingName . getView ( ) . value ,
660
+ comp . children . rtmToken . getView ( ) . value ,
661
+ comp . children . rtcToken . getView ( ) . value
667
662
) ;
668
663
comp . children . meetingActive . change ( true ) ;
669
664
} ,
@@ -677,9 +672,9 @@ MTComp = withMethodExposing(MTComp, [
677
672
execute : async ( comp , values ) => {
678
673
if ( ! comp . children . meetingActive . getView ( ) . value ) return ;
679
674
let otherData =
680
- values != undefined && values [ 1 ] !== undefined ? values [ 1 ] : "" ;
675
+ values !== undefined && values [ 1 ] !== undefined ? values [ 1 ] : "" ;
681
676
let toUsers : any =
682
- values != undefined && values [ 0 ] !== undefined ? values [ 0 ] : "" ;
677
+ values !== undefined && values [ 0 ] !== undefined ? values [ 0 ] : "" ;
683
678
684
679
let message : any = {
685
680
time : Date . now ( ) ,
@@ -711,7 +706,7 @@ MTComp = withMethodExposing(MTComp, [
711
706
{
712
707
method : {
713
708
name : "setUserName" ,
714
- description : trans ( "meeting.meetingName " ) ,
709
+ description : trans ( "meeting.userName " ) ,
715
710
params : [ ] ,
716
711
} ,
717
712
execute : async ( comp , values ) => {
@@ -720,6 +715,28 @@ MTComp = withMethodExposing(MTComp, [
720
715
comp . children . localUser . change ( { ...userLocal , userName : userName } ) ;
721
716
} ,
722
717
} ,
718
+ {
719
+ method : {
720
+ name : "setRTCToken" ,
721
+ description : trans ( "meeting.rtcToken" ) ,
722
+ params : [ ] ,
723
+ } ,
724
+ execute : async ( comp , values ) => {
725
+ let rtcToken : any = values [ 0 ] ;
726
+ comp . children . rtcToken . change ( rtcToken ) ;
727
+ } ,
728
+ } ,
729
+ {
730
+ method : {
731
+ name : "setRTMToken" ,
732
+ description : trans ( "meeting.rtmToken" ) ,
733
+ params : [ ] ,
734
+ } ,
735
+ execute : async ( comp , values ) => {
736
+ let rtmToken : any = values [ 0 ] ;
737
+ comp . children . rtmToken . change ( rtmToken ) ;
738
+ } ,
739
+ } ,
723
740
{
724
741
method : {
725
742
name : "endMeeting" ,
@@ -758,7 +775,10 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
758
775
new NameConfig ( "appId" , trans ( "meeting.appid" ) ) ,
759
776
new NameConfig ( "localUser" , trans ( "meeting.host" ) ) ,
760
777
new NameConfig ( "participants" , trans ( "meeting.participants" ) ) ,
761
- new NameConfig ( "meetingActive" , trans ( "meeting.meetingName " ) ) ,
778
+ new NameConfig ( "meetingActive" , trans ( "meeting.meetingActive " ) ) ,
762
779
new NameConfig ( "meetingName" , trans ( "meeting.meetingName" ) ) ,
763
- new NameConfig ( "messages" , trans ( "meeting.meetingName" ) ) ,
780
+ new NameConfig ( "localUserID" , trans ( "meeting.localUserID" ) ) ,
781
+ new NameConfig ( "messages" , trans ( "meeting.messages" ) ) ,
782
+ new NameConfig ( "rtmToken" , trans ( "meeting.rtmToken" ) ) ,
783
+ new NameConfig ( "rtcToken" , trans ( "meeting.rtcToken" ) ) ,
764
784
] ) ;
0 commit comments