@@ -11,7 +11,6 @@ import { StringControl } from "comps/controls/codeControl";
1111import {
1212 booleanExposingStateControl ,
1313 jsonObjectExposingStateControl ,
14- jsonValueExposingStateControl ,
1514 numberExposingStateControl ,
1615} from "comps/controls/codeStateControl" ;
1716import { PositionControl } from "comps/controls/dropdownControl" ;
@@ -21,7 +20,7 @@ import {
2120} from "comps/controls/eventHandlerControl" ;
2221import { styleControl } from "comps/controls/styleControl" ;
2322import { DrawerStyle } from "comps/controls/styleControlConstants" ;
24- import { withDefault } from "comps/generators" ;
23+ import { stateComp , withDefault } from "comps/generators" ;
2524import { withMethodExposing } from "comps/generators/withMethodExposing" ;
2625import { BackgroundColorContext } from "comps/utils/backgroundColorContext" ;
2726import { CanvasContainerID } from "constants/domLocators" ;
@@ -34,7 +33,7 @@ import {
3433 Section ,
3534 sectionNames ,
3635} from "lowcoder-design" ;
37- import { useCallback , useEffect } from "react" ;
36+ import { useCallback , useEffect , useState } from "react" ;
3837import { ResizeHandle } from "react-resizable" ;
3938import styled from "styled-components" ;
4039import { useUserViewMode } from "util/hooks" ;
@@ -47,6 +46,8 @@ import AgoraRTC, {
4746 IAgoraRTCClient ,
4847 IAgoraRTCRemoteUser ,
4948} from "agora-rtc-sdk-ng" ;
49+ import { JSONValue } from "@lowcoder-ee/index.sdk" ;
50+ import { getData } from "../listViewComp/listViewUtils" ;
5051
5152const EventOptions = [ closeEvent ] as const ;
5253
@@ -92,11 +93,10 @@ function transToPxSize(size: string | number) {
9293 return isNumeric ( size ) ? size + "px" : ( size as string ) ;
9394}
9495
95- let client : IAgoraRTCClient = AgoraRTC . createClient ( {
96+ export const client : IAgoraRTCClient = AgoraRTC . createClient ( {
9697 mode : "rtc" ,
9798 codec : "vp8" ,
9899} ) ;
99-
100100let audioTrack : IMicrophoneAudioTrack ;
101101let videoTrack : ICameraVideoTrack ;
102102
@@ -105,7 +105,7 @@ const turnOnCamera = async (flag?: boolean) => {
105105 return videoTrack . setEnabled ( flag ! ) ;
106106 }
107107 videoTrack = await AgoraRTC . createCameraVideoTrack ( ) ;
108- videoTrack . play ( "camera -video" ) ;
108+ videoTrack . play ( "host -video" ) ;
109109} ;
110110
111111const turnOnMicrophone = async ( flag ?: boolean ) => {
@@ -151,13 +151,9 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
151151 if ( isJoined ) {
152152 await leaveChannel ( ) ;
153153 }
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 ) ;
161157
162158 isJoined = true ;
163159} ;
@@ -177,30 +173,13 @@ const publishVideo = async (appId: any, channel: any, height: any) => {
177173 const videoSettings = mediaStreamTrack . getSettings ( ) ;
178174 const videoWidth = videoSettings . width ;
179175 const videoHeight = videoSettings . height ;
180- console . log ( "videoHeight " , videoHeight ) ;
181-
182176 height . videoWidth . change ( videoWidth ) ;
183177 height . videoHeight . change ( videoHeight ) ;
184- console . log ( `Video width: ${ videoWidth } px, height: ${ videoHeight } px` ) ;
185178 } else {
186179 console . error ( "Media stream track not found" ) ;
187180 }
188181} ;
189182
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-
204183let MTComp = ( function ( ) {
205184 const childrenMap = {
206185 visible : booleanExposingStateControl ( "visible" ) ,
@@ -219,7 +198,7 @@ let MTComp = (function () {
219198 videoWidth : numberExposingStateControl ( "videoWidth" , 200 ) ,
220199 videoHeight : numberExposingStateControl ( "videoHeight" , 200 ) ,
221200 appId : withDefault ( StringControl , trans ( "prop.appid" ) ) ,
222- participants : jsonValueExposingStateControl ( "participants" ) ,
201+ participants : stateComp < JSONValue > ( [ ] ) ,
223202 } ;
224203 return new ContainerCompBuilder ( childrenMap , ( props , dispatch ) => {
225204 const isTopBom = [ "top" , "bottom" ] . includes ( props . placement ) ;
@@ -239,34 +218,20 @@ let MTComp = (function () {
239218 } ,
240219 [ dispatch , isTopBom ]
241220 ) ;
221+ const [ userIds , setUserIds ] = useState < any > ( [ ] ) ;
242222
243223 useEffect ( ( ) => {
244- console . log ( "nnnn ", props . participants ) ;
245- } , [ props . participants . value ] ) ;
224+ dispatch ( changeChildAction ( "participants ", getData ( userIds ) . data , false ) ) ;
225+ } , [ userIds ] ) ;
246226
247227 useEffect ( ( ) => {
248228 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+ } ) ;
264232 client . on ( "user-offline" , ( uid : any , reason : any ) => {
265233 console . log ( `User ${ uid } left the channel.` ) ;
266234 } ) ;
267- client . on ( "user-published" , ( user , mediaType ) => {
268- console . log ( `User ${ user . uid } published ${ user . videoTrack } stream.` ) ;
269- } ) ;
270235 client . on ( "stream-removed" , ( user : IAgoraRTCRemoteUser ) => {
271236 console . log ( `Stream from user ${ user . uid } removed.` ) ;
272237 } ) ;
@@ -463,3 +428,7 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
463428 new NameConfig ( "appId" , trans ( "prop.appid" ) ) ,
464429 new NameConfig ( "participants" , trans ( "prop.participants" ) ) ,
465430] ) ;
431+
432+ export function agoraClient ( ) {
433+ return client ;
434+ }
0 commit comments