Skip to content

Commit 03b21f0

Browse files
refactored/cleaned the code
1 parent 2dd01e5 commit 03b21f0

File tree

4 files changed

+120
-109
lines changed

4 files changed

+120
-109
lines changed

client/packages/lowcoder/src/comps/comps/meetingComp/videoMeetingControllerComp.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ export const meetingControllerChildren = {
190190
audioControl: booleanExposingStateControl("false"),
191191
videoControl: booleanExposingStateControl("true"),
192192
endCall: booleanExposingStateControl("false"),
193-
sharingScreen: booleanExposingStateControl("false"),
193+
sharing: booleanExposingStateControl("false"),
194194
videoSettings: jsonObjectExposingStateControl(""),
195195
videoWidth: numberExposingStateControl("videoWidth", 200),
196196
videoHeight: numberExposingStateControl("videoHeight", 200),
197197
appId: withDefault(StringControl, trans("meeting.appid")),
198198
participants: stateComp<JSONValue>([]),
199-
host: stringExposingStateControl("host"),
199+
usersScreenShared: stateComp<JSONValue>([]),
200+
localUser: jsonObjectExposingStateControl(""),
200201
meetingName: stringExposingStateControl("meetingName"),
201202
};
202203
let MTComp = (function () {
@@ -231,8 +232,6 @@ let MTComp = (function () {
231232
useEffect(() => {
232233
if (props.endCall.value) {
233234
let newUsers = userIds.filter((item: any) => item.user !== userId);
234-
console.log("newUsers", newUsers, userId);
235-
236235
dispatch(
237236
changeChildAction("participants", getData(newUsers).data, false)
238237
);
@@ -241,7 +240,11 @@ let MTComp = (function () {
241240

242241
useEffect(() => {
243242
client.on("user-joined", (user: IAgoraRTCRemoteUser) => {
244-
let userData = { user: user.uid, host: false };
243+
let userData = {
244+
user: user.uid,
245+
host: false,
246+
audiostatus: user.hasVideo,
247+
};
245248
if (userIds.length == 0) {
246249
userData.host = true;
247250
} else {
@@ -391,9 +394,9 @@ MTComp = withMethodExposing(MTComp, [
391394
params: [],
392395
},
393396
execute: async (comp, values) => {
394-
let sharing = !comp.children.sharingScreen.getView().value;
395-
comp.children.sharingScreen.change(sharing);
397+
let sharing = !comp.children.sharing.getView().value;
396398
await shareScreen(sharing);
399+
comp.children.sharing.change(sharing);
397400
},
398401
},
399402
{
@@ -404,6 +407,11 @@ MTComp = withMethodExposing(MTComp, [
404407
},
405408
execute: async (comp, values) => {
406409
let value = !comp.children.audioControl.getView().value;
410+
let localUserData = comp.children.localUser.change({
411+
user: userId + "",
412+
audiostatus: value,
413+
});
414+
console.log(localUserData);
407415
await turnOnMicrophone(value);
408416
comp.children.audioControl.change(value);
409417
},
@@ -421,7 +429,7 @@ MTComp = withMethodExposing(MTComp, [
421429
} else {
422430
await turnOnCamera(value);
423431
}
424-
432+
425433
comp.children.videoControl.change(value);
426434
},
427435
},
@@ -433,7 +441,10 @@ MTComp = withMethodExposing(MTComp, [
433441
},
434442
execute: async (comp, values) => {
435443
userId = Math.floor(100000 + Math.random() * 900000);
436-
comp.children.host.change(userId + "");
444+
comp.children.localUser.change({
445+
user: userId + "",
446+
audiostatus: false,
447+
});
437448
await publishVideo(
438449
comp.children.appId.getView(),
439450
comp.children.meetingName.getView().value == ""
@@ -470,7 +481,7 @@ MTComp = withMethodExposing(MTComp, [
470481
export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
471482
new NameConfig("visible", trans("export.visibleDesc")),
472483
new NameConfig("appId", trans("meeting.appid")),
473-
new NameConfig("host", trans("meeting.host")),
484+
new NameConfig("localUser", trans("meeting.host")),
474485
new NameConfig("participants", trans("meeting.participants")),
475486
new NameConfig("meetingName", trans("meeting.meetingName")),
476487
]);

client/packages/lowcoder/src/comps/comps/meetingComp/videoMeetingStreamComp.tsx

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ import { IForm } from "../formComp/formDataConstants";
2525
import { SimpleNameComp } from "../simpleNameComp";
2626
import { ButtonStyleControl } from "./videobuttonCompConstants";
2727
import { RefControl } from "comps/controls/refControl";
28-
import { useEffect, useRef } from "react";
28+
import { useEffect, useRef, useState } from "react";
2929

3030
import { AutoHeightControl } from "comps/controls/autoHeightControl";
3131
import {
3232
client,
33-
meetingControllerChildren,
3433
} from "./videoMeetingControllerComp";
3534

3635
import { IAgoraRTCRemoteUser } from "agora-rtc-sdk-ng";
@@ -61,8 +60,7 @@ const Container = styled.div<{ $style: any }>`
6160
display: flex;
6261
align-items: center;
6362
justify-content: center;
64-
`; // ${(props) => props.$style && getStyle(props.$style)} - they should be applyed to VideoContainer only
65-
63+
`;
6664
const VideoContainer = styled.video<{ $style: any }>`
6765
height: 100%;
6866
width: 100%;
@@ -154,13 +152,9 @@ const typeOptions = [
154152
},
155153
] as const;
156154

157-
export const videoShared = () => {
158-
console.log("data");
159-
};
160155
export const meetingStreamChildren = {
161156
autoHeight: withDefault(AutoHeightControl, "fixed"),
162157
type: dropdownControl(typeOptions, ""),
163-
// onEvent: ButtonEventHandlerControl,
164158
onEvent: MeetingEventHandlerControl,
165159
disabled: BoolCodeControl,
166160
loading: BoolCodeControl,
@@ -169,27 +163,28 @@ export const meetingStreamChildren = {
169163
suffixIcon: IconControl,
170164
style: ButtonStyleControl,
171165
viewRef: RefControl<HTMLElement>,
172-
// viewRef: RefControl<BaseStreamRef>,
173-
userId: stringExposingStateControl("user id", trans("meeting.userId")),
166+
userId: stringExposingStateControl(""),
174167
};
175168

176169
let VideoCompBuilder = (function (props) {
177-
return (
178-
new UICompBuilder(meetingStreamChildren, (props) => {
179-
const videoRef = useRef<HTMLVideoElement>(null);
180-
const conRef = useRef<HTMLDivElement>(null);
170+
return new UICompBuilder(meetingStreamChildren, (props) => {
171+
const videoRef = useRef<HTMLVideoElement>(null);
172+
const conRef = useRef<HTMLDivElement>(null);
173+
const [userId, setUserId] = useState();
181174

182-
useEffect(() => {
183-
onResize();
184-
}, []);
175+
useEffect(() => {
176+
onResize();
177+
}, []);
185178

186-
const onResize = async () => {
187-
const container = conRef.current;
188-
let videoCo = videoRef.current;
189-
videoCo!.style.height = container?.clientHeight + "px";
190-
videoCo!.style.width = container?.clientWidth + "px";
191-
};
192-
useEffect(() => {
179+
const onResize = async () => {
180+
const container = conRef.current;
181+
let videoCo = videoRef.current;
182+
videoCo!.style.height = container?.clientHeight + "px";
183+
videoCo!.style.width = container?.clientWidth + "px";
184+
};
185+
useEffect(() => {
186+
if (props.userId.value !== "") {
187+
let userData = JSON.parse(props.userId?.value);
193188
client.on(
194189
"user-published",
195190
async (user: IAgoraRTCRemoteUser, mediaType: "video" | "audio") => {
@@ -198,10 +193,10 @@ let VideoCompBuilder = (function (props) {
198193
let userId = user.uid + "";
199194
if (
200195
user.hasVideo &&
201-
user.uid + "" != props.userId.value &&
202-
props.userId.value != ""
196+
user.uid + "" != userData.user &&
197+
userData.user != ""
203198
) {
204-
props.onEvent("videoActiveInactive");
199+
props.onEvent("videoOn");
205200
}
206201
const element = document.getElementById(userId);
207202
if (element) {
@@ -212,10 +207,12 @@ let VideoCompBuilder = (function (props) {
212207
const remoteTrack = await client.subscribe(user, mediaType);
213208
if (
214209
user.hasAudio &&
215-
user.uid + "" != props.userId.value &&
216-
props.userId.value != ""
210+
user.uid + "" != userData.user &&
211+
userData.user != ""
217212
) {
218-
props.onEvent("audioMuteUnmute");
213+
userData.audiostatus = user.hasVideo;
214+
215+
props.onEvent("audioUnmuted");
219216
}
220217
remoteTrack.play();
221218
}
@@ -227,67 +224,67 @@ let VideoCompBuilder = (function (props) {
227224
if (mediaType === "audio") {
228225
if (
229226
!user.hasAudio &&
230-
user.uid + "" != props.userId.value &&
231-
props.userId.value != ""
227+
user.uid + "" != userData.user &&
228+
userData.user != ""
232229
) {
233-
props.onEvent("audioMuteUnmute");
230+
userData.audiostatus = user.hasVideo;
231+
props.onEvent("audioMuted");
234232
}
235233
}
236234
if (mediaType === "video") {
237235
if (
238236
!user.hasVideo &&
239-
user.uid + "" != props.userId.value &&
240-
props.userId.value != ""
237+
user.uid + "" != userData.user &&
238+
userData.user != ""
241239
) {
242-
props.onEvent("videoActiveInactive");
240+
props.onEvent("videoOff");
243241
}
244242
}
245243
}
246244
);
247-
}, [props.userId.value]);
245+
setUserId(userData.user);
246+
}
247+
}, [props.userId.value]);
248248

249-
return (
250-
<EditorContext.Consumer>
251-
{(editorState) => (
252-
<ReactResizeDetector onResize={onResize}>
253-
<Container ref={conRef} $style={props.style}>
254-
<VideoContainer
255-
onClick={() => props.onEvent("videoClicked")}
256-
ref={videoRef}
257-
$style={props.style}
258-
id={props.userId.value}
259-
></VideoContainer>
260-
</Container>
261-
</ReactResizeDetector>
262-
)}
263-
</EditorContext.Consumer>
264-
);
265-
})
266-
.setPropertyViewFn((children) => (
267-
<>
268-
<Section name={sectionNames.basic}>
269-
{children.userId.propertyView({ label: trans("meeting.videoId") })}
270-
{children.autoHeight.getPropertyView()}
271-
</Section>
272-
<Section name={sectionNames.interaction}>
273-
{children.onEvent.getPropertyView()}
274-
</Section>
275-
<Section name={sectionNames.layout}>
276-
{hiddenPropertyView(children)}
277-
</Section>
278-
<Section name={sectionNames.style}>
279-
{children.style.getPropertyView()}
280-
</Section>
281-
</>
282-
))
283-
// .setExposeMethodConfigs(refMethods<BaseStreamRef>([shareMethod]))
284-
.build()
285-
);
249+
250+
251+
return (
252+
<EditorContext.Consumer>
253+
{(editorState) => (
254+
<ReactResizeDetector onResize={onResize}>
255+
<Container ref={conRef} $style={props.style}>
256+
<VideoContainer
257+
onClick={() => props.onEvent("videoClicked")}
258+
ref={videoRef}
259+
$style={props.style}
260+
id={userId}
261+
></VideoContainer>
262+
</Container>
263+
</ReactResizeDetector>
264+
)}
265+
</EditorContext.Consumer>
266+
);
267+
})
268+
.setPropertyViewFn((children) => (
269+
<>
270+
<Section name={sectionNames.basic}>
271+
{children.userId.propertyView({ label: trans("meeting.videoId") })}
272+
{children.autoHeight.getPropertyView()}
273+
</Section>
274+
<Section name={sectionNames.interaction}>
275+
{children.onEvent.getPropertyView()}
276+
</Section>
277+
<Section name={sectionNames.layout}>
278+
{hiddenPropertyView(children)}
279+
</Section>
280+
<Section name={sectionNames.style}>
281+
{children.style.getPropertyView()}
282+
</Section>
283+
</>
284+
))
285+
.build();
286286
})();
287287

288-
// interface BaseStreamRef {
289-
// shared: () => void;
290-
// }
291288
VideoCompBuilder = class extends VideoCompBuilder {
292289
override autoHeight(): boolean {
293290
return this.children.autoHeight.getView();

client/packages/lowcoder/src/comps/controls/eventHandlerControl.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,25 @@ export const mentionEvent: EventConfigType = {
348348
value: "mention",
349349
description: trans("event.mentionDesc"),
350350
};
351-
export const screenShared: EventConfigType = {
352-
label: trans("meeting.screenShared"),
353-
value: "screenShared",
354-
description: trans("meeting.screenSharedDesc"),
351+
export const audioUnmuted: EventConfigType = {
352+
label: trans("meeting.audioUnmuted"),
353+
value: "audioUnmuted",
354+
description: trans("meeting.audioUnmuted"),
355355
};
356-
export const cameraView: EventConfigType = {
357-
label: trans("meeting.cameraView"),
358-
value: "cameraView",
359-
description: trans("meeting.cameraViewDesc"),
356+
export const audioMuted: EventConfigType = {
357+
label: trans("meeting.audioMuted"),
358+
value: "audioMuted",
359+
description: trans("meeting.audioMuted"),
360360
};
361-
export const audioMuteUnmute: EventConfigType = {
362-
label: trans("meeting.audioMuteUnmute"),
363-
value: "audioMuteUnmute",
364-
description: trans("meeting.audioMuteUnmute"),
361+
export const videoOff: EventConfigType = {
362+
label: trans("meeting.videoOff"),
363+
value: "videoOff",
364+
description: trans("meeting.videoOff"),
365365
};
366-
export const videoActiveInactive: EventConfigType = {
367-
label: trans("meeting.videoActiveInactive"),
368-
value: "videoActiveInactive",
369-
description: trans("meeting.videoActiveInactive"),
366+
export const videoOn: EventConfigType = {
367+
label: trans("meeting.videoOn"),
368+
value: "videoOn",
369+
description: trans("meeting.videoOn"),
370370
};
371371
export const videoClicked: EventConfigType = {
372372
label: trans("meeting.videoClicked"),
@@ -401,9 +401,9 @@ export const ScannerEventHandlerControl = eventHandlerControl([
401401
] as const);
402402

403403
export const MeetingEventHandlerControl = eventHandlerControl([
404-
screenShared,
405-
cameraView,
406-
audioMuteUnmute,
407-
videoActiveInactive,
404+
audioMuted,
405+
audioUnmuted,
406+
videoOff,
407+
videoOn,
408408
videoClicked,
409409
] as const);

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,11 @@ export const en = {
14391439
cameraViewDesc: "Camera View",
14401440
screenShared: "Screen Shared",
14411441
screenSharedDesc: "Screen Shared",
1442-
audioMuteUnmute: "Audio Mute",
1442+
audioUnmuted: "Audio Unmuted",
1443+
audioMuted: "Audio Muted",
14431444
videoClicked: "Video Clicked",
1444-
videoActiveInactive: "Video Active Inactive",
1445+
videoOff: "Video Off",
1446+
videoOn: "Video On",
14451447
size: "Size",
14461448
top: "Top",
14471449
host: "Host",
@@ -1451,6 +1453,7 @@ export const en = {
14511453
right: "Right",
14521454
bottom: "Bottom",
14531455
videoId: "Video Id",
1456+
audioStatus: "audio status",
14541457
left: "Left",
14551458
widthTooltip: "Number or percentage, e.g. 520, 60%",
14561459
heightTooltip: "Number, e.g. 378",

0 commit comments

Comments
 (0)