Put "is speaking?" threshold in remote config; lower default

This commit is contained in:
Evan Hahn 2022-03-01 17:39:09 -06:00 committed by GitHub
parent 2b0c98f943
commit cfa0711909
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import * as log from './logging/log';
export type ConfigKeyType = export type ConfigKeyType =
| 'desktop.announcementGroup' | 'desktop.announcementGroup'
| 'desktop.calling.audioLevelForSpeaking'
| 'desktop.clientExpiration' | 'desktop.clientExpiration'
| 'desktop.groupCallOutboundRing' | 'desktop.groupCallOutboundRing'
| 'desktop.internalUser' | 'desktop.internalUser'

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
export const AUDIO_LEVEL_INTERVAL_MS = 250; export const AUDIO_LEVEL_INTERVAL_MS = 250;
export const AUDIO_LEVEL_FOR_SPEAKING = 0.25; export const DEFAULT_AUDIO_LEVEL_FOR_SPEAKING = 0.15;
export const REQUESTED_VIDEO_WIDTH = 640; export const REQUESTED_VIDEO_WIDTH = 640;
export const REQUESTED_VIDEO_HEIGHT = 480; export const REQUESTED_VIDEO_HEIGHT = 480;

View file

@ -0,0 +1,20 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type * as RemoteConfig from '../RemoteConfig';
import { DEFAULT_AUDIO_LEVEL_FOR_SPEAKING } from './constants';
export function getAudioLevelForSpeaking(
getValueFromRemoteConfig: typeof RemoteConfig.getValue
): number {
const configValue = getValueFromRemoteConfig(
'desktop.calling.audioLevelForSpeaking'
);
if (typeof configValue !== 'string') {
return DEFAULT_AUDIO_LEVEL_FOR_SPEAKING;
}
const result = parseFloat(configValue);
const isResultValid = result > 0 && result <= 1;
return isResultValid ? result : DEFAULT_AUDIO_LEVEL_FOR_SPEAKING;
}

View file

@ -37,6 +37,7 @@ import {
} from 'ringrtc'; } from 'ringrtc';
import { uniqBy, noop } from 'lodash'; import { uniqBy, noop } from 'lodash';
import * as RemoteConfig from '../RemoteConfig';
import type { import type {
ActionsType as UxActionsType, ActionsType as UxActionsType,
GroupCallParticipantInfoType, GroupCallParticipantInfoType,
@ -62,6 +63,7 @@ import {
getAudioDeviceModule, getAudioDeviceModule,
parseAudioDeviceModule, parseAudioDeviceModule,
} from '../calling/audioDeviceModule'; } from '../calling/audioDeviceModule';
import { getAudioLevelForSpeaking } from '../calling/getAudioLevelForSpeaking';
import { import {
findBestMatchingAudioDeviceIndex, findBestMatchingAudioDeviceIndex,
findBestMatchingCameraId, findBestMatchingCameraId,
@ -682,6 +684,9 @@ export class CallingClass {
const localAudioLevel = groupCall.getLocalDeviceState().audioLevel; const localAudioLevel = groupCall.getLocalDeviceState().audioLevel;
this.uxActions?.groupCallAudioLevelsChange({ this.uxActions?.groupCallAudioLevelsChange({
audioLevelForSpeaking: getAudioLevelForSpeaking(
RemoteConfig.getValue
),
conversationId, conversationId,
localAudioLevel, localAudioLevel,
remoteDeviceStates, remoteDeviceStates,

View file

@ -15,7 +15,6 @@ import { getPlatform } from '../selectors/user';
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing'; import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
import { missingCaseError } from '../../util/missingCaseError'; import { missingCaseError } from '../../util/missingCaseError';
import { calling } from '../../services/calling'; import { calling } from '../../services/calling';
import { AUDIO_LEVEL_FOR_SPEAKING } from '../../calling/constants';
import type { StateType as RootStateType } from '../reducer'; import type { StateType as RootStateType } from '../reducer';
import type { import type {
ChangeIODevicePayloadType, ChangeIODevicePayloadType,
@ -464,6 +463,7 @@ type DeclineCallActionType = {
}; };
type GroupCallAudioLevelsChangeActionPayloadType = Readonly<{ type GroupCallAudioLevelsChangeActionPayloadType = Readonly<{
audioLevelForSpeaking: number;
conversationId: string; conversationId: string;
localAudioLevel: number; localAudioLevel: number;
remoteDeviceStates: ReadonlyArray<{ audioLevel: number; demuxId: number }>; remoteDeviceStates: ReadonlyArray<{ audioLevel: number; demuxId: number }>;
@ -1697,8 +1697,12 @@ export function reducer(
} }
if (action.type === GROUP_CALL_AUDIO_LEVELS_CHANGE) { if (action.type === GROUP_CALL_AUDIO_LEVELS_CHANGE) {
const { conversationId, localAudioLevel, remoteDeviceStates } = const {
action.payload; audioLevelForSpeaking,
conversationId,
localAudioLevel,
remoteDeviceStates,
} = action.payload;
const { activeCallState } = state; const { activeCallState } = state;
const existingCall = getGroupCall(conversationId, state); const existingCall = getGroupCall(conversationId, state);
@ -1709,14 +1713,14 @@ export function reducer(
return state; return state;
} }
const amISpeaking = localAudioLevel > AUDIO_LEVEL_FOR_SPEAKING; const amISpeaking = localAudioLevel > audioLevelForSpeaking;
const speakingDemuxIds = new Set<number>(); const speakingDemuxIds = new Set<number>();
remoteDeviceStates.forEach(({ audioLevel, demuxId }) => { remoteDeviceStates.forEach(({ audioLevel, demuxId }) => {
// We expect `audioLevel` to be a number but have this check just in case. // We expect `audioLevel` to be a number but have this check just in case.
if ( if (
typeof audioLevel === 'number' && typeof audioLevel === 'number' &&
audioLevel > AUDIO_LEVEL_FOR_SPEAKING audioLevel > audioLevelForSpeaking
) { ) {
speakingDemuxIds.add(demuxId); speakingDemuxIds.add(demuxId);
} }

View file

@ -765,6 +765,7 @@ describe('calling duck', () => {
it("does nothing if there's no relevant call", () => { it("does nothing if there's no relevant call", () => {
const action = groupCallAudioLevelsChange({ const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'garbage', conversationId: 'garbage',
localAudioLevel: 1, localAudioLevel: 1,
remoteDeviceStates, remoteDeviceStates,
@ -788,6 +789,7 @@ describe('calling duck', () => {
}, },
}; };
const action = groupCallAudioLevelsChange({ const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'fake-group-call-conversation-id', conversationId: 'fake-group-call-conversation-id',
localAudioLevel: 0.1, localAudioLevel: 0.1,
remoteDeviceStates, remoteDeviceStates,
@ -800,6 +802,7 @@ describe('calling duck', () => {
it('updates the set of speaking participants, including yourself', () => { it('updates the set of speaking participants, including yourself', () => {
const action = groupCallAudioLevelsChange({ const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'fake-group-call-conversation-id', conversationId: 'fake-group-call-conversation-id',
localAudioLevel: 0.8, localAudioLevel: 0.8,
remoteDeviceStates, remoteDeviceStates,