Skip to content

Commit

Permalink
fix: audio track constraints when krisp is enabled (#3374)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored Nov 22, 2024
1 parent 3566b40 commit 0abdada
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { standardMediaConstraints } from './constants';
import { IAnalyticsPropertiesProvider } from '../../analytics/IAnalyticsPropertiesProvider';
import { HMSAudioCodec, HMSAudioMode, HMSAudioTrackSettings as IHMSAudioTrackSettings } from '../../interfaces';

Expand All @@ -8,20 +9,11 @@ export class HMSAudioTrackSettingsBuilder {
private _deviceId = 'default';
private _audioMode: HMSAudioMode = HMSAudioMode.VOICE;
private _advanced: Array<MediaTrackConstraintSet> = [
// @ts-ignore
{ googEchoCancellation: { exact: true } },
// @ts-ignore
{ googExperimentalEchoCancellation: { exact: true } },
// @ts-ignore
...standardMediaConstraints,
{ autoGainControl: { exact: true } },
// @ts-ignore
{ noiseSuppression: { exact: true } },
// @ts-ignore
{ googHighpassFilter: { exact: true } },
// @ts-ignore
{ googAudioMirroring: { exact: true } },
];

volume(volume: number) {
if (!(0.0 <= volume && volume <= 1.0)) {
throw Error('volume can only be in range [0.0, 1.0]');
Expand Down
8 changes: 8 additions & 0 deletions packages/hms-video-store/src/media/settings/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const standardMediaConstraints = [
{ echoCancellation: { exact: true } },
{ highpassFilter: { exact: true } },
{ audioMirroring: { exact: true } },
// These options can vary depending on the audio plugin
// { autoGainControl: { exact: true } },
// { noiseSuppression: { exact: true } },
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import AnalyticsEventFactory from '../../analytics/AnalyticsEventFactory';
import { ErrorFactory } from '../../error/ErrorFactory';
import { HMSAction } from '../../error/HMSAction';
import { EventBus } from '../../events/EventBus';
import { HMSAudioTrackSettingsBuilder } from '../../media/settings';
import { standardMediaConstraints } from '../../media/settings/constants';
import { HMSLocalAudioTrack } from '../../media/tracks';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';
Expand Down Expand Up @@ -74,7 +76,7 @@ export class HMSAudioPluginsManager {
}

switch (plugin.getName()) {
case 'HMSKrispPlugin':
case 'HMSKrispPlugin': {
if (!this.room?.isNoiseCancellationEnabled) {
const errorMessage = 'Krisp Noise Cancellation is not enabled for this room';
if (this.pluginsMap.size === 0) {
Expand All @@ -85,7 +87,23 @@ export class HMSAudioPluginsManager {
}
}
this.eventBus.analytics.publish(AnalyticsEventFactory.krispStart());
const { settings } = this.hmsTrack;
const newAudioTrackSettings = new HMSAudioTrackSettingsBuilder()
.codec(settings.codec)
.maxBitrate(settings.maxBitrate)
.deviceId(settings.deviceId!)
.advanced([
...standardMediaConstraints,
// @ts-ignore
{ autoGainControl: { exact: false } },
// @ts-ignore
{ noiseSuppression: { exact: false } },
])
.audioMode(settings.audioMode)
.build();
await this.hmsTrack.setSettings(newAudioTrackSettings);
break;
}

default:
}
Expand Down Expand Up @@ -162,9 +180,25 @@ export class HMSAudioPluginsManager {

async removePlugin(plugin: HMSAudioPlugin) {
switch (plugin.getName()) {
case 'HMSKrispPlugin':
case 'HMSKrispPlugin': {
this.eventBus.analytics.publish(AnalyticsEventFactory.krispStop());
const { settings } = this.hmsTrack;
const newAudioTrackSettings = new HMSAudioTrackSettingsBuilder()
.codec(settings.codec)
.maxBitrate(settings.maxBitrate)
.deviceId(settings.deviceId!)
.advanced([
...standardMediaConstraints,
// @ts-ignore
{ autoGainControl: { exact: true } },
// @ts-ignore
{ noiseSuppression: { exact: true } },
])
.audioMode(settings.audioMode)
.build();
await this.hmsTrack.setSettings(newAudioTrackSettings);
break;
}
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/roomkit-react/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 7 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@100mslive/[email protected].1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@100mslive/hms-noise-cancellation/-/hms-noise-cancellation-0.0.1.tgz#037c8bdfb6b2d7bf12f9d257422150fe6ca43acb"
integrity sha512-DGnzcXRDJREWypIjGX70er+f2k/XLLRF41lrXPs1+PtB1imdEkECPPS0Fg4BA0BCWKDNAGTZBHZPrBDgUmr9Lw==
"@100mslive/[email protected].2-alpha.7":
version "0.0.2-alpha.7"
resolved "https://registry.yarnpkg.com/@100mslive/hms-noise-cancellation/-/hms-noise-cancellation-0.0.2-alpha.7.tgz#049221bf8cac991c2e29594cf92e4022d1a8190b"
integrity sha512-XRhhbGWDWnSnKK6cfSiVaBpRyTleG/ysZr36Vec3WJab26rLBP7B9JTn0kT8MYpbBW+1mmyuPjR7vwI20Qo/vQ==

"@100mslive/[email protected]":
version "0.12.12"
Expand Down Expand Up @@ -16541,16 +16541,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -16655,14 +16646,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -18015,7 +17999,7 @@ worker-timers@^7.0.40:
worker-timers-broker "^6.0.95"
worker-timers-worker "^7.0.59"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -18033,15 +18017,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 0abdada

Please sign in to comment.