@@ -12,6 +12,7 @@ import {
1212 booleanExposingStateControl ,
1313 jsonObjectExposingStateControl ,
1414 numberExposingStateControl ,
15+ stringExposingStateControl ,
1516} from "comps/controls/codeStateControl" ;
1617import { PositionControl } from "comps/controls/dropdownControl" ;
1718import {
@@ -45,6 +46,8 @@ import AgoraRTC, {
4546 IMicrophoneAudioTrack ,
4647 IAgoraRTCClient ,
4748 IAgoraRTCRemoteUser ,
49+ UID ,
50+ ILocalVideoTrack ,
4851} from "agora-rtc-sdk-ng" ;
4952import { JSONValue } from "@lowcoder-ee/index.sdk" ;
5053import { getData } from "../listViewComp/listViewUtils" ;
@@ -99,13 +102,14 @@ export const client: IAgoraRTCClient = AgoraRTC.createClient({
99102} ) ;
100103let audioTrack : IMicrophoneAudioTrack ;
101104let videoTrack : ICameraVideoTrack ;
102-
105+ let screenShareStream : ILocalVideoTrack ;
106+ let userId : UID | null | undefined ;
103107const turnOnCamera = async ( flag ?: boolean ) => {
104108 if ( videoTrack ) {
105109 return videoTrack . setEnabled ( flag ! ) ;
106110 }
107111 videoTrack = await AgoraRTC . createCameraVideoTrack ( ) ;
108- videoTrack . play ( "host-video ") ;
112+ videoTrack . play ( userId + " ") ;
109113} ;
110114
111115const turnOnMicrophone = async ( flag ?: boolean ) => {
@@ -115,24 +119,42 @@ const turnOnMicrophone = async (flag?: boolean) => {
115119 audioTrack = await AgoraRTC . createMicrophoneAudioTrack ( ) ;
116120 audioTrack . play ( ) ;
117121} ;
118-
122+ const shareScreen = async ( sharing : boolean ) => {
123+ try {
124+ if ( sharing == false ) {
125+ await client . unpublish ( screenShareStream ) ;
126+ await client . publish ( videoTrack ) ;
127+ videoTrack . play ( userId + "" ) ;
128+ } else {
129+ screenShareStream = await AgoraRTC . createScreenVideoTrack (
130+ {
131+ screenSourceType : "screen" ,
132+ } ,
133+ "disable"
134+ ) ;
135+ await client . unpublish ( videoTrack ) ;
136+ screenShareStream . play ( userId + "" ) ;
137+ await client . publish ( screenShareStream ) ;
138+ }
139+ } catch ( error ) {
140+ console . error ( "Failed to create screen share stream:" , error ) ;
141+ }
142+ } ;
119143const leaveChannel = async ( ) => {
120- console . log ( "user leaving 3" ) ;
121144 if ( videoTrack ) {
122145 await turnOnCamera ( false ) ;
123146 await client . unpublish ( videoTrack ) ;
124147 videoTrack . stop ( ) ;
125148 }
126149
127- console . log ( "user leaving 2" ) ;
128150 if ( audioTrack ) {
129151 await turnOnMicrophone ( false ) ;
130152 await client . unpublish ( audioTrack ) ;
131153 audioTrack . stop ( ) ;
132154 }
133- console . log ( "user leaving" ) ;
134155
135156 await client . leave ( ) ;
157+ window . location . reload ( ) ; //FixMe: this reloads the page when user leaves
136158 isJoined = false ;
137159} ;
138160let isJoined = false ;
@@ -145,7 +167,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
145167 if ( isJoined ) {
146168 await leaveChannel ( ) ;
147169 }
148- let userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
149170 console . log ( "me joining " , userId ) ;
150171 await client . join ( appId , channel , token || null , userId ) ;
151172
@@ -154,8 +175,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
154175
155176const publishVideo = async ( appId : any , channel : any , height : any ) => {
156177 await turnOnCamera ( true ) ;
157- console . log ( appId , channel ) ;
158-
159178 if ( ! isJoined ) {
160179 await joinChannel ( appId , channel , null ) ;
161180 }
@@ -188,11 +207,13 @@ let MTComp = (function () {
188207 audioControl : booleanExposingStateControl ( "false" ) ,
189208 videoControl : booleanExposingStateControl ( "true" ) ,
190209 endCall : booleanExposingStateControl ( "false" ) ,
210+ sharingScreen : booleanExposingStateControl ( "false" ) ,
191211 videoSettings : jsonObjectExposingStateControl ( "" ) ,
192212 videoWidth : numberExposingStateControl ( "videoWidth" , 200 ) ,
193213 videoHeight : numberExposingStateControl ( "videoHeight" , 200 ) ,
194214 appId : withDefault ( StringControl , trans ( "prop.appid" ) ) ,
195215 participants : stateComp < JSONValue > ( [ ] ) ,
216+ host : stringExposingStateControl ( "host" ) ,
196217 } ;
197218 return new ContainerCompBuilder ( childrenMap , ( props , dispatch ) => {
198219 const isTopBom = [ "top" , "bottom" ] . includes ( props . placement ) ;
@@ -349,6 +370,18 @@ MTComp = withMethodExposing(MTComp, [
349370 comp . children . visible . getView ( ) . onChange ( true ) ;
350371 } ,
351372 } ,
373+ {
374+ method : {
375+ name : "startSharing" ,
376+ description : trans ( "drawer.openDrawerDesc" ) ,
377+ params : [ ] ,
378+ } ,
379+ execute : async ( comp , values ) => {
380+ let sharing = ! comp . children . sharingScreen . getView ( ) . value ;
381+ comp . children . sharingScreen . change ( sharing ) ;
382+ await shareScreen ( sharing ) ;
383+ } ,
384+ } ,
352385 {
353386 method : {
354387 name : "audioControl" ,
@@ -380,6 +413,8 @@ MTComp = withMethodExposing(MTComp, [
380413 params : [ ] ,
381414 } ,
382415 execute : async ( comp , values ) => {
416+ userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
417+ comp . children . host . change ( userId + "" ) ;
383418 await publishVideo (
384419 comp . children . appId . getView ( ) ,
385420 "testsdaadasdsa" ,
@@ -395,7 +430,6 @@ MTComp = withMethodExposing(MTComp, [
395430 } ,
396431 execute : async ( comp , values ) => {
397432 let value = ! comp . children . endCall . getView ( ) . value ;
398- console . log ( "" ) ;
399433
400434 await leaveChannel ( ) ;
401435 comp . children . endCall . change ( value ) ;
@@ -416,6 +450,7 @@ MTComp = withMethodExposing(MTComp, [
416450export const VideoMeetingControllerComp = withExposingConfigs ( MTComp , [
417451 new NameConfig ( "visible" , trans ( "export.visibleDesc" ) ) ,
418452 new NameConfig ( "appId" , trans ( "prop.appid" ) ) ,
453+ new NameConfig ( "host" , trans ( "prop.appid" ) ) ,
419454 new NameConfig ( "participants" , trans ( "prop.participants" ) ) ,
420455] ) ;
421456
0 commit comments