@@ -12,6 +12,7 @@ import {
12
12
booleanExposingStateControl ,
13
13
jsonObjectExposingStateControl ,
14
14
numberExposingStateControl ,
15
+ stringExposingStateControl ,
15
16
} from "comps/controls/codeStateControl" ;
16
17
import { PositionControl } from "comps/controls/dropdownControl" ;
17
18
import {
@@ -45,6 +46,8 @@ import AgoraRTC, {
45
46
IMicrophoneAudioTrack ,
46
47
IAgoraRTCClient ,
47
48
IAgoraRTCRemoteUser ,
49
+ UID ,
50
+ ILocalVideoTrack ,
48
51
} from "agora-rtc-sdk-ng" ;
49
52
import { JSONValue } from "@lowcoder-ee/index.sdk" ;
50
53
import { getData } from "../listViewComp/listViewUtils" ;
@@ -99,13 +102,14 @@ export const client: IAgoraRTCClient = AgoraRTC.createClient({
99
102
} ) ;
100
103
let audioTrack : IMicrophoneAudioTrack ;
101
104
let videoTrack : ICameraVideoTrack ;
102
-
105
+ let screenShareStream : ILocalVideoTrack ;
106
+ let userId : UID | null | undefined ;
103
107
const turnOnCamera = async ( flag ?: boolean ) => {
104
108
if ( videoTrack ) {
105
109
return videoTrack . setEnabled ( flag ! ) ;
106
110
}
107
111
videoTrack = await AgoraRTC . createCameraVideoTrack ( ) ;
108
- videoTrack . play ( "host-video ") ;
112
+ videoTrack . play ( userId + " ") ;
109
113
} ;
110
114
111
115
const turnOnMicrophone = async ( flag ?: boolean ) => {
@@ -115,24 +119,42 @@ const turnOnMicrophone = async (flag?: boolean) => {
115
119
audioTrack = await AgoraRTC . createMicrophoneAudioTrack ( ) ;
116
120
audioTrack . play ( ) ;
117
121
} ;
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
+ } ;
119
143
const leaveChannel = async ( ) => {
120
- console . log ( "user leaving 3" ) ;
121
144
if ( videoTrack ) {
122
145
await turnOnCamera ( false ) ;
123
146
await client . unpublish ( videoTrack ) ;
124
147
videoTrack . stop ( ) ;
125
148
}
126
149
127
- console . log ( "user leaving 2" ) ;
128
150
if ( audioTrack ) {
129
151
await turnOnMicrophone ( false ) ;
130
152
await client . unpublish ( audioTrack ) ;
131
153
audioTrack . stop ( ) ;
132
154
}
133
- console . log ( "user leaving" ) ;
134
155
135
156
await client . leave ( ) ;
157
+ window . location . reload ( ) ; //FixMe: this reloads the page when user leaves
136
158
isJoined = false ;
137
159
} ;
138
160
let isJoined = false ;
@@ -145,7 +167,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
145
167
if ( isJoined ) {
146
168
await leaveChannel ( ) ;
147
169
}
148
- let userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
149
170
console . log ( "me joining " , userId ) ;
150
171
await client . join ( appId , channel , token || null , userId ) ;
151
172
@@ -154,8 +175,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
154
175
155
176
const publishVideo = async ( appId : any , channel : any , height : any ) => {
156
177
await turnOnCamera ( true ) ;
157
- console . log ( appId , channel ) ;
158
-
159
178
if ( ! isJoined ) {
160
179
await joinChannel ( appId , channel , null ) ;
161
180
}
@@ -188,11 +207,13 @@ let MTComp = (function () {
188
207
audioControl : booleanExposingStateControl ( "false" ) ,
189
208
videoControl : booleanExposingStateControl ( "true" ) ,
190
209
endCall : booleanExposingStateControl ( "false" ) ,
210
+ sharingScreen : booleanExposingStateControl ( "false" ) ,
191
211
videoSettings : jsonObjectExposingStateControl ( "" ) ,
192
212
videoWidth : numberExposingStateControl ( "videoWidth" , 200 ) ,
193
213
videoHeight : numberExposingStateControl ( "videoHeight" , 200 ) ,
194
214
appId : withDefault ( StringControl , trans ( "prop.appid" ) ) ,
195
215
participants : stateComp < JSONValue > ( [ ] ) ,
216
+ host : stringExposingStateControl ( "host" ) ,
196
217
} ;
197
218
return new ContainerCompBuilder ( childrenMap , ( props , dispatch ) => {
198
219
const isTopBom = [ "top" , "bottom" ] . includes ( props . placement ) ;
@@ -349,6 +370,18 @@ MTComp = withMethodExposing(MTComp, [
349
370
comp . children . visible . getView ( ) . onChange ( true ) ;
350
371
} ,
351
372
} ,
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
+ } ,
352
385
{
353
386
method : {
354
387
name : "audioControl" ,
@@ -380,6 +413,8 @@ MTComp = withMethodExposing(MTComp, [
380
413
params : [ ] ,
381
414
} ,
382
415
execute : async ( comp , values ) => {
416
+ userId = Math . floor ( 100000 + Math . random ( ) * 900000 ) ;
417
+ comp . children . host . change ( userId + "" ) ;
383
418
await publishVideo (
384
419
comp . children . appId . getView ( ) ,
385
420
"testsdaadasdsa" ,
@@ -395,7 +430,6 @@ MTComp = withMethodExposing(MTComp, [
395
430
} ,
396
431
execute : async ( comp , values ) => {
397
432
let value = ! comp . children . endCall . getView ( ) . value ;
398
- console . log ( "" ) ;
399
433
400
434
await leaveChannel ( ) ;
401
435
comp . children . endCall . change ( value ) ;
@@ -416,6 +450,7 @@ MTComp = withMethodExposing(MTComp, [
416
450
export const VideoMeetingControllerComp = withExposingConfigs ( MTComp , [
417
451
new NameConfig ( "visible" , trans ( "export.visibleDesc" ) ) ,
418
452
new NameConfig ( "appId" , trans ( "prop.appid" ) ) ,
453
+ new NameConfig ( "host" , trans ( "prop.appid" ) ) ,
419
454
new NameConfig ( "participants" , trans ( "prop.participants" ) ) ,
420
455
] ) ;
421
456
0 commit comments