Skip to content

Commit c278c6d

Browse files
finished audio/mute event on video stream component
1 parent c78a54c commit c278c6d

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ const turnOnMicrophone = async (flag?: boolean) => {
121121
}
122122
audioTrack = await AgoraRTC.createMicrophoneAudioTrack();
123123
audioTrack.play();
124+
125+
if (!flag) {
126+
await client.unpublish(audioTrack);
127+
} else {
128+
await client.publish(audioTrack);
129+
}
124130
};
125131
const shareScreen = async (sharing: boolean) => {
126132
try {
@@ -162,40 +168,20 @@ const leaveChannel = async () => {
162168
};
163169
let isJoined = false;
164170

165-
const joinChannel = async (appId: any, channel: any, token: any) => {
166-
if (!channel) {
167-
channel = "react-room";
168-
}
169-
170-
if (isJoined) {
171-
await leaveChannel();
172-
}
173-
console.log("me joining ", userId);
174-
await client.join(appId, channel, token || null, userId);
175-
176-
isJoined = true;
177-
};
178171
const hostChanged = (users: any) => {};
179172

180-
181-
182173
const publishVideo = async (appId: any, channel: any, height: any) => {
183174
await turnOnCamera(true);
184-
if (!isJoined) {
185-
await joinChannel(appId, channel, null);
186-
}
187-
175+
await client.join(appId, channel, null, userId);
188176
await client.publish(videoTrack);
189-
const mediaStreamTrack = videoTrack.getMediaStreamTrack();
190177

178+
const mediaStreamTrack = videoTrack.getMediaStreamTrack();
191179
if (mediaStreamTrack) {
192180
const videoSettings = mediaStreamTrack.getSettings();
193181
const videoWidth = videoSettings.width;
194182
const videoHeight = videoSettings.height;
195183
height.videoWidth.change(videoWidth);
196184
height.videoHeight.change(videoHeight);
197-
} else {
198-
console.error("Media stream track not found");
199185
}
200186
};
201187

@@ -252,15 +238,12 @@ let MTComp = (function () {
252238

253239
useEffect(() => {
254240
client.on("user-joined", (user: IAgoraRTCRemoteUser) => {
255-
console.log("userData", user);
256241
let userData = { user: user.uid, host: false };
257242
if (userIds.length == 0) {
258243
userData.host = true;
259244
} else {
260245
userData.host = false;
261246
}
262-
console.log("userData", userData);
263-
264247
setUserIds((userIds: any) => [...userIds, userData]);
265248
});
266249
client.on("user-left", (user: IAgoraRTCRemoteUser, reason: any) => {
@@ -416,9 +399,11 @@ MTComp = withMethodExposing(MTComp, [
416399
description: trans("meeting.actionBtnDesc"),
417400
params: [],
418401
},
419-
execute: (comp, values) => {
402+
execute: async (comp, values) => {
420403
let value = !comp.children.audioControl.getView().value;
421-
turnOnMicrophone(value);
404+
console.log("turnOnMicrophone", value);
405+
// await audioTrack.setEnabled(value);
406+
await turnOnMicrophone(value);
422407
comp.children.audioControl.change(value);
423408
},
424409
},

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@ import { RefControl } from "comps/controls/refControl";
2828
import { useEffect, useRef } from "react";
2929

3030
import { AutoHeightControl } from "comps/controls/autoHeightControl";
31-
import {
32-
client,
33-
meetingControllerChildren,
34-
} from "./videoMeetingControllerComp";
31+
import { client } from "./videoMeetingControllerComp";
3532

3633
import { IAgoraRTCRemoteUser } from "agora-rtc-sdk-ng";
3734

3835
import {
39-
ButtonEventHandlerControl,
4036
MeetingEventHandlerControl,
4137
hiddenPropertyView,
42-
refMethods,
4338
stringExposingStateControl,
4439
} from "@lowcoder-ee/index.sdk";
4540

@@ -156,13 +151,10 @@ const typeOptions = [
156151
value: "submit",
157152
},
158153
] as const;
159-
function isDefault(type?: string) {
160-
return !type;
161-
}
154+
162155
export const videoShared = () => {
163156
console.log("data");
164-
165-
}
157+
};
166158
export const meetingStreamChildren = {
167159
autoHeight: withDefault(AutoHeightControl, "fixed"),
168160
type: dropdownControl(typeOptions, ""),
@@ -201,8 +193,6 @@ let VideoCompBuilder = (function (props) {
201193
async (user: IAgoraRTCRemoteUser, mediaType: "video" | "audio") => {
202194
if (mediaType === "video") {
203195
const remoteTrack = await client.subscribe(user, mediaType);
204-
console.log("remoteTrack", remoteTrack);
205-
206196
let userId = user.uid + "";
207197
const element = document.getElementById(userId);
208198
if (element) {
@@ -211,10 +201,31 @@ let VideoCompBuilder = (function (props) {
211201
}
212202
if (mediaType === "audio") {
213203
const remoteTrack = await client.subscribe(user, mediaType);
204+
if (
205+
user.hasAudio &&
206+
user.uid + "" != props.userId.value &&
207+
props.userId.value != ""
208+
) {
209+
props.onEvent("audioMuteUnmute");
210+
}
214211
remoteTrack.play();
215212
}
216213
}
217214
);
215+
client.on(
216+
"user-unpublished",
217+
(user: IAgoraRTCRemoteUser, mediaType: "video" | "audio") => {
218+
if (mediaType === "audio") {
219+
if (
220+
!user.hasAudio &&
221+
user.uid + "" != props.userId.value &&
222+
props.userId.value != ""
223+
) {
224+
props.onEvent("audioMuteUnmute");
225+
}
226+
}
227+
}
228+
);
218229
}, [props.userId.value]);
219230

220231
return (

0 commit comments

Comments
 (0)