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

feat: add processed audio track only when plugin is added #3085

Merged
merged 2 commits into from
Jul 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class HMSAudioPluginsManager {
this.pluginsMap.set(name, plugin);
await this.processPlugin(plugin);
await this.connectToDestination();
await this.updateProcessedTrack();
} catch (err) {
HMSLogger.e(this.TAG, 'failed to add plugin', err);
throw err;
Expand Down Expand Up @@ -213,6 +214,7 @@ export class HMSAudioPluginsManager {
for (const plugin of plugins) {
await this.addPlugin(plugin);
}
this.updateProcessedTrack();
}

private async initAudioNodes() {
Expand All @@ -224,16 +226,19 @@ export class HMSAudioPluginsManager {
if (!this.destinationNode) {
this.destinationNode = this.audioContext.createMediaStreamDestination();
this.outputTrack = this.destinationNode.stream.getAudioTracks()[0];
try {
await this.hmsTrack.setProcessedTrack(this.outputTrack);
} catch (err) {
HMSLogger.e(this.TAG, 'error in setting processed track', err);
throw err;
}
}
}
}

private async updateProcessedTrack() {
try {
await this.hmsTrack.setProcessedTrack(this.outputTrack);
} catch (err) {
HMSLogger.e(this.TAG, 'error in setting processed track', err);
throw err;
}
}

private async processPlugin(plugin: HMSAudioPlugin) {
try {
const currentNode = await plugin.processAudioTrack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const useNoiseCancellationWithPlugin = () => {
if (inProgress) {
return;
}
if (!krispPlugin.checkSupport().isSupported) {
throw Error('Krisp plugin is not supported');
}
setInProgress(true);
if (enabled) {
await actions.addPluginToAudioTrack(krispPlugin);
Expand Down Expand Up @@ -281,13 +284,17 @@ export const AudioVideoToggle = ({ hideOptions = false }: { hideOptions?: boolea
useEffect(() => {
(async () => {
if (isNoiseCancellationEnabled && !isKrispPluginAdded && !inProgress && localPeer?.audioTrack) {
await setNoiseCancellationWithPlugin(true);
ToastManager.addToast({
title: `Noise Reduction Enabled`,
variant: 'standard',
duration: 2000,
icon: <AudioLevelIcon />,
});
try {
await setNoiseCancellationWithPlugin(true);
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
ToastManager.addToast({
title: `Noise Reduction Enabled`,
variant: 'standard',
duration: 2000,
icon: <AudioLevelIcon />,
});
} catch (error) {
console.error(error);
}
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Loading