Skip to content

WIP: Agora integrationn #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1aa9f11
agora integration initial setaup
freddysundowner Oct 7, 2023
cf0fac6
Small fixes to make it running locally
Oct 7, 2023
6ca3d4d
v
freddysundowner Oct 9, 2023
82c198b
Merge branch 'agora-integrationn' of https://github.com/lowcoder-org/…
freddysundowner Oct 9, 2023
5017338
renaming refactoring of the components
freddysundowner Oct 9, 2023
d1050eb
more meeting components name refactoring fixes
freddysundowner Oct 9, 2023
db0753f
initial-participants listview with videos
freddysundowner Oct 10, 2023
26a980a
implemented user leaving the call and removing the user from the list…
freddysundowner Oct 12, 2023
36de39c
added sharing of screen
freddysundowner Oct 12, 2023
834c825
refactored control buttons
freddysundowner Oct 12, 2023
5472d95
fixed button data fields
freddysundowner Oct 13, 2023
b808ac9
added styling of the video component
freddysundowner Oct 13, 2023
e62d64c
added meeting name to the meeting controller data field
freddysundowner Oct 13, 2023
34a001e
fixed video component styling
freddysundowner Oct 13, 2023
c78a54c
added video stream controller events
freddysundowner Oct 14, 2023
84c9749
fixed styling for VideoStream Component
Oct 15, 2023
c278c6d
finished audio/mute event on video stream component
freddysundowner Oct 16, 2023
a02fd07
Merge branch 'agora-integrationn' of https://github.com/lowcoder-org/…
freddysundowner Oct 16, 2023
d131b71
Feat: video toggle event
freddysundowner Oct 16, 2023
2dd01e5
Feat: video click event
freddysundowner Oct 16, 2023
03b21f0
refactored/cleaned the code
freddysundowner Oct 17, 2023
7420095
Fix: audio echo on the local user
freddysundowner Oct 18, 2023
447dd8e
Merge branch 'dev' into agora-integrationn
FalkWolsky Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added sharing of screen
  • Loading branch information
freddysundowner committed Oct 12, 2023
commit 36de39ca6f9bb494b11e76819a546b9cbba7ed91
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
booleanExposingStateControl,
jsonObjectExposingStateControl,
numberExposingStateControl,
stringExposingStateControl,
} from "comps/controls/codeStateControl";
import { PositionControl } from "comps/controls/dropdownControl";
import {
Expand Down Expand Up @@ -45,6 +46,8 @@ import AgoraRTC, {
IMicrophoneAudioTrack,
IAgoraRTCClient,
IAgoraRTCRemoteUser,
UID,
ILocalVideoTrack,
} from "agora-rtc-sdk-ng";
import { JSONValue } from "@lowcoder-ee/index.sdk";
import { getData } from "../listViewComp/listViewUtils";
Expand Down Expand Up @@ -99,13 +102,14 @@ export const client: IAgoraRTCClient = AgoraRTC.createClient({
});
let audioTrack: IMicrophoneAudioTrack;
let videoTrack: ICameraVideoTrack;

let screenShareStream: ILocalVideoTrack;
let userId: UID | null | undefined;
const turnOnCamera = async (flag?: boolean) => {
if (videoTrack) {
return videoTrack.setEnabled(flag!);
}
videoTrack = await AgoraRTC.createCameraVideoTrack();
videoTrack.play("host-video");
videoTrack.play(userId + "");
};

const turnOnMicrophone = async (flag?: boolean) => {
Expand All @@ -115,24 +119,42 @@ const turnOnMicrophone = async (flag?: boolean) => {
audioTrack = await AgoraRTC.createMicrophoneAudioTrack();
audioTrack.play();
};

const shareScreen = async (sharing: boolean) => {
try {
if (sharing == false) {
await client.unpublish(screenShareStream);
await client.publish(videoTrack);
videoTrack.play(userId + "");
} else {
screenShareStream = await AgoraRTC.createScreenVideoTrack(
{
screenSourceType: "screen",
},
"disable"
);
await client.unpublish(videoTrack);
screenShareStream.play(userId + "");
await client.publish(screenShareStream);
}
} catch (error) {
console.error("Failed to create screen share stream:", error);
}
};
const leaveChannel = async () => {
console.log("user leaving 3");
if (videoTrack) {
await turnOnCamera(false);
await client.unpublish(videoTrack);
videoTrack.stop();
}

console.log("user leaving 2");
if (audioTrack) {
await turnOnMicrophone(false);
await client.unpublish(audioTrack);
audioTrack.stop();
}
console.log("user leaving");

await client.leave();
window.location.reload(); //FixMe: this reloads the page when user leaves
isJoined = false;
};
let isJoined = false;
Expand All @@ -145,7 +167,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {
if (isJoined) {
await leaveChannel();
}
let userId = Math.floor(100000 + Math.random() * 900000);
console.log("me joining ", userId);
await client.join(appId, channel, token || null, userId);

Expand All @@ -154,8 +175,6 @@ const joinChannel = async (appId: any, channel: any, token: any) => {

const publishVideo = async (appId: any, channel: any, height: any) => {
await turnOnCamera(true);
console.log(appId, channel);

if (!isJoined) {
await joinChannel(appId, channel, null);
}
Expand Down Expand Up @@ -188,11 +207,13 @@ let MTComp = (function () {
audioControl: booleanExposingStateControl("false"),
videoControl: booleanExposingStateControl("true"),
endCall: booleanExposingStateControl("false"),
sharingScreen: booleanExposingStateControl("false"),
videoSettings: jsonObjectExposingStateControl(""),
videoWidth: numberExposingStateControl("videoWidth", 200),
videoHeight: numberExposingStateControl("videoHeight", 200),
appId: withDefault(StringControl, trans("prop.appid")),
participants: stateComp<JSONValue>([]),
host: stringExposingStateControl("host"),
};
return new ContainerCompBuilder(childrenMap, (props, dispatch) => {
const isTopBom = ["top", "bottom"].includes(props.placement);
Expand Down Expand Up @@ -349,6 +370,18 @@ MTComp = withMethodExposing(MTComp, [
comp.children.visible.getView().onChange(true);
},
},
{
method: {
name: "startSharing",
description: trans("drawer.openDrawerDesc"),
params: [],
},
execute: async (comp, values) => {
let sharing = !comp.children.sharingScreen.getView().value;
comp.children.sharingScreen.change(sharing);
await shareScreen(sharing);
},
},
{
method: {
name: "audioControl",
Expand Down Expand Up @@ -380,6 +413,8 @@ MTComp = withMethodExposing(MTComp, [
params: [],
},
execute: async (comp, values) => {
userId = Math.floor(100000 + Math.random() * 900000);
comp.children.host.change(userId + "");
await publishVideo(
comp.children.appId.getView(),
"testsdaadasdsa",
Expand All @@ -395,7 +430,6 @@ MTComp = withMethodExposing(MTComp, [
},
execute: async (comp, values) => {
let value = !comp.children.endCall.getView().value;
console.log("");

await leaveChannel();
comp.children.endCall.change(value);
Expand All @@ -416,6 +450,7 @@ MTComp = withMethodExposing(MTComp, [
export const VideoMeetingControllerComp = withExposingConfigs(MTComp, [
new NameConfig("visible", trans("export.visibleDesc")),
new NameConfig("appId", trans("prop.appid")),
new NameConfig("host", trans("prop.appid")),
new NameConfig("participants", trans("prop.participants")),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { useEffect, useRef, useState } from "react";
import { AutoHeightControl } from "comps/controls/autoHeightControl";
import { client } from "./videoMeetingControllerComp";

import { IAgoraRTCRemoteUser, UID } from "agora-rtc-sdk-ng";
import AgoraRTC, { IAgoraRTCRemoteUser, UID } from "agora-rtc-sdk-ng";

import { stringExposingStateControl } from "@lowcoder-ee/index.sdk";

Expand Down Expand Up @@ -168,12 +168,18 @@ let VideoCompBuilder = (function (props) {
videoCo!.style.width = container?.clientWidth + "px";
};
useEffect(() => {

client.on(
"user-published",
async (user: IAgoraRTCRemoteUser, mediaType: "video" | "audio") => {
if (mediaType === "video") {
const remoteTrack = await client.subscribe(user, mediaType);
remoteTrack.play(user.uid + "");
let userId = user.uid + "";
const element = document.getElementById(userId);
if (element) {
console.log("userId", element);
remoteTrack.play(userId);
}
}
if (mediaType === "audio") {
const remoteTrack = await client.subscribe(user, mediaType);
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ export const en = {
title: "Meeting title",
meetingCompName: "Meeting Controller",
videoCompName: "Video Stream",
videoSharingCompName: "Video Sharing",
meetingControlCompName: "Controls Buttons",
meetingCompDesc: "Meeting component",
meetingCompControls: "Meeting control",
Expand Down