Skip to content

Commit e12e0e5

Browse files
authored
Merge pull request #506 from lowcoder-org/agora-integrationn
Agora Token Handling and small Fixes
2 parents 3788c5e + 054f028 commit e12e0e5

File tree

6 files changed

+115
-79
lines changed

6 files changed

+115
-79
lines changed

client/packages/lowcoder-design/src/components/Section.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,5 @@ export const sectionNames = {
142142
validation: trans("prop.validation"),
143143
layout: trans("prop.layout"),
144144
style: trans("prop.style"),
145+
meetings : trans("prop.meetings"),
145146
};

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

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const en = {
2323
validation: "Validation",
2424
layout: "Layout",
2525
style: "Style",
26+
meetings : "Meeting Settings",
2627
},
2728
passwordInput: {
2829
label: "Password:",

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ let ButtonTmpComp = (function () {
179179
iconSize: withDefault(StringControl, "20px"),
180180
type: dropdownControl(typeOptions, ""),
181181
autoHeight: withDefault(AutoHeightControl, "fixed"),
182+
aspectRatio: withDefault(StringControl, "1 / 1"),
182183
onEvent: ButtonEventHandlerControl,
183184
disabled: BoolCodeControl,
184185
loading: BoolCodeControl,
@@ -244,8 +245,16 @@ let ButtonTmpComp = (function () {
244245
loading={props.loading}
245246
style={
246247
props.autoHeight
247-
? { width: "100%", height: "100%" }
248-
: undefined
248+
? {
249+
width: "100%",
250+
height: "100%",
251+
aspectRatio: props.aspectRatio,
252+
borderRadius: props.style.radius,
253+
}
254+
: {
255+
aspectRatio: props.aspectRatio,
256+
borderRadius: props.style.radius,
257+
}
249258
}
250259
disabled={
251260
props.disabled ||
@@ -304,6 +313,9 @@ let ButtonTmpComp = (function () {
304313
</Section>
305314
<Section name={sectionNames.style}>
306315
{children.style.getPropertyView()}
316+
{children.aspectRatio.propertyView({
317+
label: "Video Aspect Ratio",
318+
})}
307319
</Section>
308320
</>
309321
))

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

+83-63
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import { useUserViewMode } from "util/hooks";
4141
import { isNumeric } from "util/stringUtils";
4242
import { NameConfig, withExposingConfigs } from "../../generators/withExposing";
4343

44-
import axios from "axios";
44+
import { v4 as uuidv4 } from 'uuid';
45+
46+
// import axios from "axios";
47+
4548
import AgoraRTC, {
4649
ICameraVideoTrack,
4750
IMicrophoneAudioTrack,
@@ -51,7 +54,7 @@ import AgoraRTC, {
5154
ILocalVideoTrack,
5255
} from "agora-rtc-sdk-ng";
5356

54-
import { JSONValue } from "@lowcoder-ee/index.sdk";
57+
import { JSONValue, NumberControl } from "@lowcoder-ee/index.sdk";
5558
import { getData } from "../listViewComp/listViewUtils";
5659
import AgoraRTM, { RtmChannel, RtmClient } from "agora-rtm-sdk";
5760

@@ -103,7 +106,16 @@ export const client: IAgoraRTCClient = AgoraRTC.createClient({
103106
mode: "rtc",
104107
codec: "vp8",
105108
});
106-
AgoraRTC.setLogLevel(3);
109+
110+
AgoraRTC.setLogLevel(4);
111+
112+
/*
113+
0: DEBUG. Output all API logs.
114+
1: INFO. Output logs of the INFO, WARNING and ERROR level.
115+
2: WARNING. Output logs of the WARNING and ERROR level.
116+
3: ERROR. Output logs of the ERROR level.
117+
4: NONE. Do not output any log.
118+
*/
107119

108120
let audioTrack: IMicrophoneAudioTrack;
109121
let videoTrack: ICameraVideoTrack;
@@ -112,23 +124,6 @@ let userId: UID | null | undefined;
112124
let rtmChannelResponse: RtmChannel;
113125
let rtmClient: RtmClient;
114126

115-
const generateToken = async (
116-
appId: any,
117-
certificate: any,
118-
channelName: any,
119-
serverurl: any
120-
) => {
121-
let response = await axios.post(
122-
serverurl ?? "https://sandbox.wiggolive.com/token/rtc",
123-
{
124-
appId,
125-
certificate,
126-
channelName,
127-
}
128-
);
129-
return response.data;
130-
};
131-
132127
const turnOnCamera = async (flag?: boolean) => {
133128
if (videoTrack) {
134129
return videoTrack.setEnabled(flag!);
@@ -150,7 +145,7 @@ const turnOnMicrophone = async (flag?: boolean) => {
150145
};
151146
const shareScreen = async (sharing: boolean) => {
152147
try {
153-
if (sharing == false) {
148+
if (sharing === false) {
154149
await client.unpublish(screenShareStream);
155150
await client.publish(videoTrack);
156151
videoTrack.play(userId + "");
@@ -184,20 +179,16 @@ const leaveChannel = async () => {
184179

185180
const publishVideo = async (
186181
appId: string,
187-
channel: any,
188-
height: any,
189-
certifiCateKey: string,
190-
serverurl: string
182+
channel: string,
183+
rtmToken: string,
184+
rtcToken: string
191185
) => {
192-
let token = null;
193-
if (certifiCateKey) {
194-
token = await generateToken(appId, certifiCateKey, channel, serverurl);
195-
}
196-
await turnOnCamera(true);
197-
await client.join(appId, channel, token, userId);
198-
await client.publish(videoTrack);
199-
200-
await rtmInit(appId, userId, channel);
186+
// initializing the Agora Meeting Client
187+
await turnOnCamera(true);
188+
await client.join(appId, channel, rtcToken, userId);
189+
await client.publish(videoTrack);
190+
// initializing the Agora RTM Client
191+
await rtmInit(appId, userId, rtmToken, channel);
201192
};
202193

203194
const sendMessageRtm = (message: any) => {
@@ -208,10 +199,11 @@ const sendPeerMessageRtm = (message: any, toId: string) => {
208199
rtmClient.sendMessageToPeer({ text: JSON.stringify(message) }, toId);
209200
};
210201

211-
const rtmInit = async (appId: any, uid: any, channel: any) => {
202+
const rtmInit = async (appId: any, uid: any, token: any, channel: any) => {
212203
rtmClient = AgoraRTM.createInstance(appId);
213204
let options = {
214205
uid: String(uid),
206+
token: token ? token : null,
215207
};
216208
await rtmClient.login(options);
217209

@@ -236,12 +228,13 @@ export const meetingControllerChildren = {
236228
endCall: withDefault(BooleanStateControl, "false"),
237229
sharing: withDefault(BooleanStateControl, "false"),
238230
appId: withDefault(StringControl, trans("meeting.appid")),
239-
tokenServerUrl: withDefault(StringControl, trans("meeting.serverurl")),
240231
participants: stateComp<JSONValue>([]),
241232
usersScreenShared: stateComp<JSONValue>([]),
242233
localUser: jsonObjectExposingStateControl(""),
243-
meetingName: stringStateControl("meetingName"),
244-
certifiCateKey: stringStateControl(""),
234+
localUserID : withDefault(stringStateControl(trans("meeting.localUserID")), uuidv4() + ""),
235+
meetingName: withDefault(stringStateControl(trans("meeting.meetingName")), uuidv4() + ""),
236+
rtmToken: stringStateControl(trans("meeting.rtmToken")),
237+
rtcToken: stringStateControl(trans("meeting.rtcToken")),
245238
messages: stateComp<JSONValue>([]),
246239
};
247240
let MTComp = (function () {
@@ -272,8 +265,7 @@ let MTComp = (function () {
272265
});
273266
const [rtmMessages, setRtmMessages] = useState<any>([]);
274267
const [localUserSpeaking, setLocalUserSpeaking] = useState<any>(false);
275-
const [localUserVideo, setLocalUserVideo] =
276-
useState<IAgoraRTCRemoteUser>();
268+
const [localUserVideo, setLocalUserVideo] = useState<IAgoraRTCRemoteUser>();
277269
const [userJoined, setUserJoined] = useState<IAgoraRTCRemoteUser>();
278270
const [userLeft, setUserLeft] = useState<IAgoraRTCRemoteUser>();
279271

@@ -503,17 +495,6 @@ let MTComp = (function () {
503495
.setPropertyViewFn((children) => (
504496
<>
505497
<Section name={sectionNames.basic}>
506-
{children.appId.propertyView({ label: trans("meeting.appid") })}
507-
{children.certifiCateKey.propertyView({
508-
label: trans("meeting.certifiCateKey"),
509-
})}
510-
{children.meetingName.propertyView({
511-
label: trans("meeting.meetingName"),
512-
})}
513-
{children.tokenServerUrl.propertyView({
514-
label: trans("meeting.serverurl"),
515-
})}
516-
517498
{children.placement.propertyView({
518499
label: trans("drawer.placement"),
519500
radioButton: true,
@@ -539,6 +520,23 @@ let MTComp = (function () {
539520
label: trans("prop.showMask"),
540521
})}
541522
</Section>
523+
<Section name={sectionNames.meetings}>
524+
{children.appId.propertyView({
525+
label: trans("meeting.appid")
526+
})}
527+
{children.meetingName.propertyView({
528+
label: trans("meeting.meetingName"),
529+
})}
530+
{children.localUserID.propertyView({
531+
label: trans("meeting.localUserID"),
532+
})}
533+
{children.rtmToken.propertyView({
534+
label: trans("meeting.rtmToken"),
535+
})}
536+
{children.rtcToken.propertyView({
537+
label: trans("meeting.rtcToken"),
538+
})}
539+
</Section>
542540
<Section name={sectionNames.interaction}>
543541
{children.onEvent.getPropertyView()}
544542
</Section>
@@ -635,7 +633,7 @@ MTComp = withMethodExposing(MTComp, [
635633
},
636634
execute: async (comp, values) => {
637635
if (comp.children.meetingActive.getView().value) return;
638-
userId = Math.floor(100000 + Math.random() * 900000);
636+
userId = comp.children.localUserID.getView().value === "" ? uuidv4() : comp.children.localUserID.getView().value;
639637
comp.children.localUser.change({
640638
user: userId + "",
641639
audiostatus: false,
@@ -658,12 +656,9 @@ MTComp = withMethodExposing(MTComp, [
658656
comp.children.videoControl.change(true);
659657
await publishVideo(
660658
comp.children.appId.getView(),
661-
comp.children.meetingName.getView().value == ""
662-
? "_meetingId"
663-
: comp.children.meetingName.getView().value,
664-
comp.children,
665-
comp.children.certifiCateKey.getView().value,
666-
comp.children.tokenServerUrl.getView()
659+
comp.children.meetingName.getView().value === "" ? uuidv4() : comp.children.meetingName.getView().value,
660+
comp.children.rtmToken.getView().value,
661+
comp.children.rtcToken.getView().value
667662
);
668663
comp.children.meetingActive.change(true);
669664
},
@@ -677,9 +672,9 @@ MTComp = withMethodExposing(MTComp, [
677672
execute: async (comp, values) => {
678673
if (!comp.children.meetingActive.getView().value) return;
679674
let otherData =
680-
values != undefined && values[1] !== undefined ? values[1] : "";
675+
values !== undefined && values[1] !== undefined ? values[1] : "";
681676
let toUsers: any =
682-
values != undefined && values[0] !== undefined ? values[0] : "";
677+
values !== undefined && values[0] !== undefined ? values[0] : "";
683678

684679
let message: any = {
685680
time: Date.now(),
@@ -711,7 +706,7 @@ MTComp = withMethodExposing(MTComp, [
711706
{
712707
method: {
713708
name: "setUserName",
714-
description: trans("meeting.meetingName"),
709+
description: trans("meeting.userName"),
715710
params: [],
716711
},
717712
execute: async (comp, values) => {
@@ -720,6 +715,28 @@ MTComp = withMethodExposing(MTComp, [
720715
comp.children.localUser.change({ ...userLocal, userName: userName });
721716
},
722717
},
718+
{
719+
method: {
720+
name: "setRTCToken",
721+
description: trans("meeting.rtcToken"),
722+
params: [],
723+
},
724+
execute: async (comp, values) => {
725+
let rtcToken: any = values[0];
726+
comp.children.rtcToken.change(rtcToken);
727+
},
728+
},
729+
{
730+
method: {
731+
name: "setRTMToken",
732+
description: trans("meeting.rtmToken"),
733+
params: [],
734+
},
735+
execute: async (comp, values) => {
736+
let rtmToken: any = values[0];
737+
comp.children.rtmToken.change(rtmToken);
738+
},
739+
},
723740
{
724741
method: {
725742
name: "endMeeting",
@@ -758,7 +775,10 @@ export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
758775
new NameConfig("appId", trans("meeting.appid")),
759776
new NameConfig("localUser", trans("meeting.host")),
760777
new NameConfig("participants", trans("meeting.participants")),
761-
new NameConfig("meetingActive", trans("meeting.meetingName")),
778+
new NameConfig("meetingActive", trans("meeting.meetingActive")),
762779
new NameConfig("meetingName", trans("meeting.meetingName")),
763-
new NameConfig("messages", trans("meeting.meetingName")),
780+
new NameConfig("localUserID", trans("meeting.localUserID")),
781+
new NameConfig("messages", trans("meeting.messages")),
782+
new NameConfig("rtmToken", trans("meeting.rtmToken")),
783+
new NameConfig("rtcToken", trans("meeting.rtcToken")),
764784
]);

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ export const meetingStreamChildren = {
151151
style: ButtonStyleControl,
152152
viewRef: RefControl<HTMLElement>,
153153
userId: stringExposingStateControl(""),
154-
profileImageUrl: withDefault(
155-
StringStateControl,
156-
"https://via.placeholder.com/120"
157-
),
154+
profileImageUrl: withDefault(StringStateControl, "https://api.dicebear.com/7.x/fun-emoji/svg?seed=Peanut&radius=50&backgroundColor=transparent&randomizeIds=true&eyes=wink,sleepClose"),
158155
noVideoText: stringExposingStateControl("No Video"),
159156
};
160157

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

+15-10
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ export const en = {
14421442
height: "Drawer height",
14431443
},
14441444
meeting: {
1445+
logLevel: "Agora SDK Log Level",
14451446
placement: "Meeting placement",
14461447
meeting: "Meeting Settings",
14471448
cameraView: "Camera View",
@@ -1455,18 +1456,21 @@ export const en = {
14551456
videoOn: "Video On",
14561457
size: "Size",
14571458
top: "Top",
1458-
host: "Host",
1459-
participants: "Participants",
1460-
shareScreen: "Share Screen",
1461-
appid: "Application Id",
1462-
serverurl: "Token Server url",
1459+
host: "Host of the Meetingroom",
1460+
participants: "Participants of the Meetingroom",
1461+
shareScreen: "Local Screenshare",
1462+
appid: "Agora Application Id",
14631463
meetingName: "Meeting Name",
1464+
localUserID: "Host User Id",
1465+
userName: "Host User Name",
1466+
rtmToken : "Agora RTM Token",
1467+
rtcToken : "Agora RTC Token",
14641468
videoCompText: "No video Text",
14651469
profileImageUrl: "Profile Image Url",
14661470
right: "Right",
14671471
bottom: "Bottom",
1468-
videoId: "Video Id",
1469-
audioStatus: "audio status",
1472+
videoId: "Video Stream Id",
1473+
audioStatus: "Audio status",
14701474
left: "Left",
14711475
widthTooltip: "Number or percentage, e.g. 520, 60%",
14721476
heightTooltip: "Number, e.g. 378",
@@ -1476,18 +1480,19 @@ export const en = {
14761480
height: "Drawer height",
14771481
actionBtnDesc: "Action Button",
14781482
broadCast: "BroadCast Messages",
1479-
certifiCateKey: "certifiCate Key",
1480-
title: "Meeting title",
1483+
title: "Meeting Title",
14811484
meetingCompName: "Meeting Controller",
14821485
videoCompName: "Video Stream",
1483-
videoSharingCompName: "Video Sharing",
1486+
videoSharingCompName: "Screen Sharing",
14841487
meetingControlCompName: "Controls Buttons",
14851488
meetingCompDesc: "Meeting component",
14861489
meetingCompControls: "Meeting control",
14871490
meetingCompKeywords: "",
14881491
iconSize: "Icon Size",
14891492
userId: "userId",
14901493
roomId: "roomId",
1494+
meetingActive : "Ongoing Meeting",
1495+
messages : "Broadcasted Messages",
14911496
},
14921497
settings: {
14931498
title: "Settings",

0 commit comments

Comments
 (0)