diff --git a/packages/hms-video-store/src/media/settings/HMSAudioTrackSettings.ts b/packages/hms-video-store/src/media/settings/HMSAudioTrackSettings.ts index f49020741e..20aa877ac0 100644 --- a/packages/hms-video-store/src/media/settings/HMSAudioTrackSettings.ts +++ b/packages/hms-video-store/src/media/settings/HMSAudioTrackSettings.ts @@ -1,3 +1,4 @@ +import { standardMediaConstraints } from './constants'; import { IAnalyticsPropertiesProvider } from '../../analytics/IAnalyticsPropertiesProvider'; import { HMSAudioCodec, HMSAudioMode, HMSAudioTrackSettings as IHMSAudioTrackSettings } from '../../interfaces'; @@ -8,20 +9,11 @@ export class HMSAudioTrackSettingsBuilder { private _deviceId = 'default'; private _audioMode: HMSAudioMode = HMSAudioMode.VOICE; private _advanced: Array = [ - // @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]'); diff --git a/packages/hms-video-store/src/media/settings/constants.ts b/packages/hms-video-store/src/media/settings/constants.ts new file mode 100644 index 0000000000..e1f0e8f4d2 --- /dev/null +++ b/packages/hms-video-store/src/media/settings/constants.ts @@ -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 } }, +]; diff --git a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts index 75100bb9a5..fa84d76ed4 100644 --- a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts @@ -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'; @@ -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) { @@ -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: } @@ -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; } diff --git a/packages/roomkit-react/package.json b/packages/roomkit-react/package.json index c6e888665f..7f858bf231 100644 --- a/packages/roomkit-react/package.json +++ b/packages/roomkit-react/package.json @@ -76,7 +76,7 @@ }, "dependencies": { "@100mslive/hls-player": "0.3.25-alpha.3", - "@100mslive/hms-noise-cancellation": "0.0.1", + "@100mslive/hms-noise-cancellation": "0.0.2-alpha.7", "@100mslive/hms-virtual-background": "1.13.25-alpha.3", "@100mslive/hms-whiteboard": "0.0.15-alpha.3", "@100mslive/react-icons": "0.10.25-alpha.3", diff --git a/yarn.lock b/yarn.lock index e5e417a61a..0f8d119744 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@100mslive/hms-noise-cancellation@0.0.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/hms-noise-cancellation@0.0.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/types-prebuilt@0.12.12": version "0.12.12" @@ -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== @@ -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== @@ -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== @@ -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"