Skip to content

Commit

Permalink
Put "is speaking?" threshold in remote config; lower default
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Mar 1, 2022
1 parent 2b0c98f commit cfa0711
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions ts/RemoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as log from './logging/log';

export type ConfigKeyType =
| 'desktop.announcementGroup'
| 'desktop.calling.audioLevelForSpeaking'
| 'desktop.clientExpiration'
| 'desktop.groupCallOutboundRing'
| 'desktop.internalUser'
Expand Down
2 changes: 1 addition & 1 deletion ts/calling/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only

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_HEIGHT = 480;
Expand Down
20 changes: 20 additions & 0 deletions ts/calling/getAudioLevelForSpeaking.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 5 additions & 0 deletions ts/services/calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from 'ringrtc';
import { uniqBy, noop } from 'lodash';

import * as RemoteConfig from '../RemoteConfig';
import type {
ActionsType as UxActionsType,
GroupCallParticipantInfoType,
Expand All @@ -62,6 +63,7 @@ import {
getAudioDeviceModule,
parseAudioDeviceModule,
} from '../calling/audioDeviceModule';
import { getAudioLevelForSpeaking } from '../calling/getAudioLevelForSpeaking';
import {
findBestMatchingAudioDeviceIndex,
findBestMatchingCameraId,
Expand Down Expand Up @@ -682,6 +684,9 @@ export class CallingClass {
const localAudioLevel = groupCall.getLocalDeviceState().audioLevel;

this.uxActions?.groupCallAudioLevelsChange({
audioLevelForSpeaking: getAudioLevelForSpeaking(
RemoteConfig.getValue
),
conversationId,
localAudioLevel,
remoteDeviceStates,
Expand Down
14 changes: 9 additions & 5 deletions ts/state/ducks/calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getPlatform } from '../selectors/user';
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
import { missingCaseError } from '../../util/missingCaseError';
import { calling } from '../../services/calling';
import { AUDIO_LEVEL_FOR_SPEAKING } from '../../calling/constants';
import type { StateType as RootStateType } from '../reducer';
import type {
ChangeIODevicePayloadType,
Expand Down Expand Up @@ -464,6 +463,7 @@ type DeclineCallActionType = {
};

type GroupCallAudioLevelsChangeActionPayloadType = Readonly<{
audioLevelForSpeaking: number;
conversationId: string;
localAudioLevel: number;
remoteDeviceStates: ReadonlyArray<{ audioLevel: number; demuxId: number }>;
Expand Down Expand Up @@ -1697,8 +1697,12 @@ export function reducer(
}

if (action.type === GROUP_CALL_AUDIO_LEVELS_CHANGE) {
const { conversationId, localAudioLevel, remoteDeviceStates } =
action.payload;
const {
audioLevelForSpeaking,
conversationId,
localAudioLevel,
remoteDeviceStates,
} = action.payload;

const { activeCallState } = state;
const existingCall = getGroupCall(conversationId, state);
Expand All @@ -1709,14 +1713,14 @@ export function reducer(
return state;
}

const amISpeaking = localAudioLevel > AUDIO_LEVEL_FOR_SPEAKING;
const amISpeaking = localAudioLevel > audioLevelForSpeaking;

const speakingDemuxIds = new Set<number>();
remoteDeviceStates.forEach(({ audioLevel, demuxId }) => {
// We expect `audioLevel` to be a number but have this check just in case.
if (
typeof audioLevel === 'number' &&
audioLevel > AUDIO_LEVEL_FOR_SPEAKING
audioLevel > audioLevelForSpeaking
) {
speakingDemuxIds.add(demuxId);
}
Expand Down
3 changes: 3 additions & 0 deletions ts/test-electron/state/ducks/calling_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ describe('calling duck', () => {

it("does nothing if there's no relevant call", () => {
const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'garbage',
localAudioLevel: 1,
remoteDeviceStates,
Expand All @@ -788,6 +789,7 @@ describe('calling duck', () => {
},
};
const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'fake-group-call-conversation-id',
localAudioLevel: 0.1,
remoteDeviceStates,
Expand All @@ -800,6 +802,7 @@ describe('calling duck', () => {

it('updates the set of speaking participants, including yourself', () => {
const action = groupCallAudioLevelsChange({
audioLevelForSpeaking: 0.25,
conversationId: 'fake-group-call-conversation-id',
localAudioLevel: 0.8,
remoteDeviceStates,
Expand Down

0 comments on commit cfa0711

Please sign in to comment.