@@ -11,7 +11,6 @@ import { StringControl } from "comps/controls/codeControl";
11
11
import {
12
12
booleanExposingStateControl ,
13
13
jsonObjectExposingStateControl ,
14
- jsonValueExposingStateControl ,
15
14
numberExposingStateControl ,
16
15
} from "comps/controls/codeStateControl" ;
17
16
import { PositionControl } from "comps/controls/dropdownControl" ;
@@ -21,7 +20,7 @@ import {
21
20
} from "comps/controls/eventHandlerControl" ;
22
21
import { styleControl } from "comps/controls/styleControl" ;
23
22
import { DrawerStyle } from "comps/controls/styleControlConstants" ;
24
- import { withDefault } from "comps/generators" ;
23
+ import { stateComp , withDefault } from "comps/generators" ;
25
24
import { withMethodExposing } from "comps/generators/withMethodExposing" ;
26
25
import { BackgroundColorContext } from "comps/utils/backgroundColorContext" ;
27
26
import { CanvasContainerID } from "constants/domLocators" ;
@@ -34,7 +33,7 @@ import {
34
33
Section ,
35
34
sectionNames ,
36
35
} from "lowcoder-design" ;
37
- import { useCallback , useEffect } from "react" ;
36
+ import { useCallback , useEffect , useState } from "react" ;
38
37
import { ResizeHandle } from "react-resizable" ;
39
38
import styled from "styled-components" ;
40
39
import { useUserViewMode } from "util/hooks" ;
@@ -47,6 +46,8 @@ import AgoraRTC, {
47
46
IAgoraRTCClient ,
48
47
IAgoraRTCRemoteUser ,
49
48
} from "agora-rtc-sdk-ng" ;
49
+ import { JSONValue } from "@lowcoder-ee/index.sdk" ;
50
+ import { getData } from "../listViewComp/listViewUtils" ;
50
51
51
52
const EventOptions = [ closeEvent ] as const ;
52
53
@@ -92,11 +93,10 @@ function transToPxSize(size: string | number) {
92
93
return isNumeric ( size ) ? size + "px" : ( size as string ) ;
93
94
}
94
95
95
- let client : IAgoraRTCClient = AgoraRTC . createClient ( {
96
+ export const client : IAgoraRTCClient = AgoraRTC . createClient ( {
96
97
mode : "rtc" ,
97
98
codec : "vp8" ,
98
99
} ) ;
99
-
100
100
let audioTrack : IMicrophoneAudioTrack ;
101
101
let videoTrack : ICameraVideoTrack ;
102
102
@@ -105,7 +105,7 @@ const turnOnCamera = async (flag?: boolean) => {
105
105
return videoTrack . setEnabled ( flag ! ) ;
106
106
}
107
107
videoTrack = await AgoraRTC . createCameraVideoTrack ( ) ;
108
- videoTrack . play ( "camera -video" ) ;
108
+ videoTrack . play ( "host -video" ) ;
109
109
} ;
110
110
111
111
const turnOnMicrophone = async ( flag ?: boolean ) => {
@@ -151,13 +151,9 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
151
151
if ( isJoined ) {
152
152
await leaveChannel ( ) ;
153
153
}
154
-
155
- await client . join (
156
- appId ,
157
- channel ,
158
- token || null ,
159
- Math . floor ( 100000 + Math . random ( ) * 900000 )
160
- ) ;
154
+ let userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
155
+ console . log ( "me joining " , userId ) ;
156
+ await client . join ( appId , channel , token || null , userId ) ;
161
157
162
158
isJoined = true ;
163
159
} ;
@@ -177,30 +173,13 @@ const publishVideo = async (appId: any, channel: any, height: any) => {
177
173
const videoSettings = mediaStreamTrack . getSettings ( ) ;
178
174
const videoWidth = videoSettings . width ;
179
175
const videoHeight = videoSettings . height ;
180
- console . log ( "videoHeight " , videoHeight ) ;
181
-
182
176
height . videoWidth . change ( videoWidth ) ;
183
177
height . videoHeight . change ( videoHeight ) ;
184
- console . log ( `Video width: ${ videoWidth } px, height: ${ videoHeight } px` ) ;
185
178
} else {
186
179
console . error ( "Media stream track not found" ) ;
187
180
}
188
181
} ;
189
182
190
- const onUserPublish = async (
191
- user : IAgoraRTCRemoteUser ,
192
- mediaType : "video" | "audio"
193
- ) => {
194
- if ( mediaType === "video" ) {
195
- const remoteTrack = await client . subscribe ( user , mediaType ) ;
196
- remoteTrack . play ( "remote-video" ) ;
197
- }
198
- if ( mediaType === "audio" ) {
199
- const remoteTrack = await client . subscribe ( user , mediaType ) ;
200
- remoteTrack . play ( ) ;
201
- }
202
- } ;
203
-
204
183
let MTComp = ( function ( ) {
205
184
const childrenMap = {
206
185
visible : booleanExposingStateControl ( "visible" ) ,
@@ -219,7 +198,7 @@ let MTComp = (function () {
219
198
videoWidth : numberExposingStateControl ( "videoWidth" , 200 ) ,
220
199
videoHeight : numberExposingStateControl ( "videoHeight" , 200 ) ,
221
200
appId : withDefault ( StringControl , trans ( "prop.appid" ) ) ,
222
- participants : jsonValueExposingStateControl ( "participants" ) ,
201
+ participants : stateComp < JSONValue > ( [ ] ) ,
223
202
} ;
224
203
return new ContainerCompBuilder ( childrenMap , ( props , dispatch ) => {
225
204
const isTopBom = [ "top" , "bottom" ] . includes ( props . placement ) ;
@@ -239,34 +218,20 @@ let MTComp = (function () {
239
218
} ,
240
219
[ dispatch , isTopBom ]
241
220
) ;
221
+ const [ userIds , setUserIds ] = useState < any > ( [ ] ) ;
242
222
243
223
useEffect ( ( ) => {
244
- console . log ( "nnnn ", props . participants ) ;
245
- } , [ props . participants . value ] ) ;
224
+ dispatch ( changeChildAction ( "participants ", getData ( userIds ) . data , false ) ) ;
225
+ } , [ userIds ] ) ;
246
226
247
227
useEffect ( ( ) => {
248
228
if ( client ) {
249
- client . on (
250
- "user-published" ,
251
- async ( user : IAgoraRTCRemoteUser , mediaType : "video" | "audio" ) => {
252
- if ( mediaType === "video" ) {
253
- const remoteTrack = await client . subscribe ( user , mediaType ) ;
254
- remoteTrack . play ( "remote-video" ) ;
255
- }
256
- if ( mediaType === "audio" ) {
257
- const remoteTrack = await client . subscribe ( user , mediaType ) ;
258
- remoteTrack . play ( ) ;
259
- }
260
- }
261
- ) ;
262
-
263
- client . on ( "user-joined" , ( user : IAgoraRTCRemoteUser ) => { } ) ;
229
+ client . on ( "user-joined" , ( user : IAgoraRTCRemoteUser ) => {
230
+ setUserIds ( ( userIds : any ) => [ ...userIds , { user : user . uid } ] ) ;
231
+ } ) ;
264
232
client . on ( "user-offline" , ( uid : any , reason : any ) => {
265
233
console . log ( `User ${ uid } left the channel.` ) ;
266
234
} ) ;
267
- client . on ( "user-published" , ( user , mediaType ) => {
268
- console . log ( `User ${ user . uid } published ${ user . videoTrack } stream.` ) ;
269
- } ) ;
270
235
client . on ( "stream-removed" , ( user : IAgoraRTCRemoteUser ) => {
271
236
console . log ( `Stream from user ${ user . uid } removed.` ) ;
272
237
} ) ;
@@ -463,3 +428,7 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
463
428
new NameConfig ( "appId" , trans ( "prop.appid" ) ) ,
464
429
new NameConfig ( "participants" , trans ( "prop.participants" ) ) ,
465
430
] ) ;
431
+
432
+ export function agoraClient ( ) {
433
+ return client ;
434
+ }
0 commit comments