Skip to content
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

refactor(service-providers): enable audio with share screen in electron #1881

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
"onleave",
"leavechannel",
"videosource",
"soundflower",

// css / less
"minlength",
Expand Down
2 changes: 2 additions & 0 deletions desktop/renderer-app/src/tasks/init-flat-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import { combine } from "value-enhancer";

import { runtime } from "../utils/runtime";
import { portalWindowManager } from "../utils/portal-window-manager";
import { ipcAsyncByPreviewFileWindow } from "../utils/ipc";

Expand Down Expand Up @@ -97,6 +98,7 @@ export function initFlatServices(): void {
instance = new AgoraRTCElectron({
APP_ID: process.env.AGORA_APP_ID,
rtcEngine,
isMac: runtime.isMac,
});
resolve(instance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export interface FlatRTCAgoraElectronDevice {
export interface AgoraRTCElectronConfig {
APP_ID: string;
rtcEngine: AgoraSdk;
isMac: boolean;
}

export class AgoraRTCElectron extends IServiceVideoChat {
private static LOW_VOLUME_LEVEL_THRESHOLD = 0.00001;

public readonly isMac: boolean;
public readonly shareScreen = new AgoraRTCElectronShareScreen({ rtc: this });

public readonly APP_ID: string;
Expand Down Expand Up @@ -71,6 +73,7 @@ export class AgoraRTCElectron extends IServiceVideoChat {
super();
this.APP_ID = config.APP_ID;
this.rtcEngine = config.rtcEngine;
this.isMac = config.isMac;
this._init(this.rtcEngine);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ export class AgoraRTCElectronShareScreen extends IServiceShareScreen {
this._pTogglingShareScreen = new Promise<void>(resolve => {
this.client.once("videoSourceJoinedSuccess", () => {
this.client.videoSourceSetVideoProfile(43, false);
// Install the virtual sound card "soundflower" on macOS.
// https://api-ref.agora.io/en/voice-sdk/electron/3.x/classes/agorartcengine.html#videosourceenableloopbackrecording
// https://docs.agora.io/cn/video-legacy/API%20Reference/electron/classes/agorartcengine.html#videosourceenableloopbackrecording
const deviceName = this._rtc.isMac ? "soundflower" : undefined;
this.client.videoSourceEnableLoopbackRecording(true, deviceName);
if (screenInfo.type === "display") {
this.client.videoSourceStartScreenCaptureByScreen(
screenInfo.screenId as ScreenSymbol,
Expand Down