Skip to content

Commit db0753f

Browse files
initial-participants listview with videos
1 parent d1050eb commit db0753f

File tree

2 files changed

+65
-76
lines changed

2 files changed

+65
-76
lines changed

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

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { StringControl } from "comps/controls/codeControl";
1111
import {
1212
booleanExposingStateControl,
1313
jsonObjectExposingStateControl,
14-
jsonValueExposingStateControl,
1514
numberExposingStateControl,
1615
} from "comps/controls/codeStateControl";
1716
import { PositionControl } from "comps/controls/dropdownControl";
@@ -21,7 +20,7 @@ import {
2120
} from "comps/controls/eventHandlerControl";
2221
import { styleControl } from "comps/controls/styleControl";
2322
import { DrawerStyle } from "comps/controls/styleControlConstants";
24-
import { withDefault } from "comps/generators";
23+
import { stateComp, withDefault } from "comps/generators";
2524
import { withMethodExposing } from "comps/generators/withMethodExposing";
2625
import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
2726
import { 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";
3837
import { ResizeHandle } from "react-resizable";
3938
import styled from "styled-components";
4039
import { 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

5152
const 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-
100100
let audioTrack: IMicrophoneAudioTrack;
101101
let 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

111111
const 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-
204183
let 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+
}

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

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
ArrayControl,
3-
ArrayOrJSONObjectControl,
4-
BoolCodeControl,
5-
JSONObjectArrayControl,
6-
NumberControl,
7-
StringControl,
8-
} from "comps/controls/codeControl";
1+
import { BoolCodeControl } from "comps/controls/codeControl";
92
import { dropdownControl } from "comps/controls/dropdownControl";
103
import { ButtonEventHandlerControl } from "comps/controls/eventHandlerControl";
114
import { IconControl } from "comps/controls/iconControl";
@@ -36,24 +29,18 @@ import { RefControl } from "comps/controls/refControl";
3629
import { useEffect, useRef, useState } from "react";
3730

3831
import { AutoHeightControl } from "comps/controls/autoHeightControl";
39-
import {
40-
arrayStringExposingStateControl,
41-
booleanExposingStateControl,
42-
jsonObjectExposingStateControl,
43-
stringExposingStateControl,
44-
withMethodExposing,
45-
} from "@lowcoder-ee/index.sdk";
32+
import { client } from "./videoMeetingControllerComp";
33+
34+
import { IAgoraRTCRemoteUser, UID } from "agora-rtc-sdk-ng";
35+
36+
import { stringExposingStateControl } from "@lowcoder-ee/index.sdk";
4637
// import useAgora from "@lowcoder-ee/comps/hooks/agoraFunctions";
4738

4839
const FormLabel = styled(CommonBlueLabel)`
4940
font-size: 13px;
5041
margin-right: 4px;
5142
`;
5243

53-
const IconWrapper = styled.div`
54-
display: flex;
55-
`;
56-
5744
function getFormOptions(editorState: EditorState) {
5845
return editorState
5946
.uiCompInfoList()
@@ -165,10 +152,7 @@ let VideoCompBuilder = (function (props) {
165152
suffixIcon: IconControl,
166153
style: ButtonStyleControl,
167154
viewRef: RefControl<HTMLElement>,
168-
userId: stringExposingStateControl(
169-
"text",
170-
trans("meeting.userId", { name: "{{currentUser.name}}" })
171-
),
155+
userId: stringExposingStateControl("user id", trans("meeting.userId")),
172156
};
173157
return new UICompBuilder(childrenMap, (props) => {
174158
const videoRef = useRef<HTMLVideoElement>(null);
@@ -178,21 +162,54 @@ let VideoCompBuilder = (function (props) {
178162
onResize();
179163
}, []);
180164

181-
182165
const onResize = async () => {
183166
const container = conRef.current;
184167
let videoCo = videoRef.current;
185168
videoCo!.style.height = container?.clientHeight + "px";
186169
videoCo!.style.width = container?.clientWidth + "px";
187170
};
188171

172+
useEffect(() => {
173+
client.on(
174+
"user-published",
175+
async (user: IAgoraRTCRemoteUser, mediaType: "video" | "audio") => {
176+
if (mediaType === "video") {
177+
178+
// const videoElement = document.createElement("video");
179+
// videoElement.id = user.uid + "";
180+
// videoElement.width = 640;
181+
// videoElement.height = 360;
182+
183+
// if (conRef.current) {
184+
// conRef.current.appendChild(videoElement);
185+
// }
186+
187+
// console.log("elementHtml", document.getElementById(user.uid + ""));
188+
189+
const remoteTrack = await client.subscribe(user, mediaType);
190+
remoteTrack.play(user.uid + "_v");
191+
console.log("user-published ", user.uid);
192+
}
193+
if (mediaType === "audio") {
194+
const remoteTrack = await client.subscribe(user, mediaType);
195+
remoteTrack.play();
196+
}
197+
}
198+
);
199+
200+
client.on("user-joined", (user: IAgoraRTCRemoteUser) => {
201+
console.log("drawer joined", user.uid);
202+
});
203+
}, [props.userId]);
204+
189205
return (
190206
<EditorContext.Consumer>
191207
{(editorState) => (
192208
<ReactResizeDetector onResize={onResize}>
193209
<Container ref={conRef} $style={props.style}>
194210
<video
195211
ref={videoRef}
212+
id={props.userId.value + "_v"}
196213
style={{ width: 300, height: 300 }}
197214
></video>
198215
</Container>
@@ -203,6 +220,10 @@ let VideoCompBuilder = (function (props) {
203220
})
204221
.setPropertyViewFn((children) => (
205222
<>
223+
<Section name={sectionNames.basic}>
224+
{children.userId.propertyView({ label: trans("text") })}
225+
{children.autoHeight.getPropertyView()}
226+
</Section>
206227
</>
207228
))
208229
.build();
@@ -214,7 +235,6 @@ VideoCompBuilder = class extends VideoCompBuilder {
214235
}
215236
};
216237

217-
218238
export const VideoMeetingStreamComp = withExposingConfigs(VideoCompBuilder, [
219239
new NameConfig("loading", trans("button.loadingDesc")),
220240
...CommonNameConfig,

0 commit comments

Comments
 (0)