From 6579b1a70a8fda7950792f40705c0069bae4eb54 Mon Sep 17 00:00:00 2001 From: Jim Gustafson Date: Thu, 4 Jan 2024 18:25:51 -0800 Subject: [PATCH] Update to RingRTC v2.35.0 Co-authored-by: ayumi yu Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com> --- package.json | 2 +- ts/background.ts | 6 + ts/calling/findBestMatchingDevice.ts | 12 +- ts/jobs/removeStorageKeyJobQueue.ts | 1 + ts/services/calling.ts | 33 ---- .../calling/findBestMatchingDevice_test.ts | 158 +++--------------- ts/types/Storage.d.ts | 2 +- ts/types/StorageUIKeys.ts | 1 - yarn.lock | 8 +- 9 files changed, 40 insertions(+), 183 deletions(-) diff --git a/package.json b/package.json index d8f954f71..0bb7c52cb 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "@react-spring/web": "9.5.5", "@signalapp/better-sqlite3": "8.6.0", "@signalapp/libsignal-client": "0.36.0", - "@signalapp/ringrtc": "2.34.5", + "@signalapp/ringrtc": "2.35.0", "@signalapp/windows-dummy-keystroke": "1.0.0", "@types/fabric": "4.5.3", "backbone": "1.4.0", diff --git a/ts/background.ts b/ts/background.ts index 704811bea..92682cd2e 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -875,6 +875,12 @@ export async function startApp(): Promise { await window.storage.remove('remoteBuildExpiration'); } + if (window.isBeforeVersion(lastVersion, '6.45.0-alpha')) { + await removeStorageKeyJobQueue.add({ + key: 'previousAudioDeviceModule', + }); + } + if (window.isBeforeVersion(lastVersion, '6.25.0-alpha')) { await removeStorageKeyJobQueue.add({ key: 'nextSignedKeyRotationTime', diff --git a/ts/calling/findBestMatchingDevice.ts b/ts/calling/findBestMatchingDevice.ts index 55821198f..57043a176 100644 --- a/ts/calling/findBestMatchingDevice.ts +++ b/ts/calling/findBestMatchingDevice.ts @@ -2,29 +2,21 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { AudioDevice } from '@signalapp/ringrtc'; -import { AudioDeviceModule } from './audioDeviceModule'; export function findBestMatchingAudioDeviceIndex({ available, preferred, - previousAudioDeviceModule, - currentAudioDeviceModule, }: Readonly<{ available: ReadonlyArray; preferred: undefined | AudioDevice; - previousAudioDeviceModule: AudioDeviceModule; - currentAudioDeviceModule: AudioDeviceModule; }>): undefined | number { if (!preferred) { return available.length > 0 ? 0 : undefined; } if ( - (currentAudioDeviceModule === AudioDeviceModule.WindowsAdm2 && - preferred.index === 0) || - (previousAudioDeviceModule === AudioDeviceModule.WindowsAdm2 && - preferred.index === 1 && - available.length >= 2) + preferred.index === 0 || + (preferred.index === 1 && available.length >= 2) ) { return preferred.index; } diff --git a/ts/jobs/removeStorageKeyJobQueue.ts b/ts/jobs/removeStorageKeyJobQueue.ts index c911ef6a3..c6c3e23a9 100644 --- a/ts/jobs/removeStorageKeyJobQueue.ts +++ b/ts/jobs/removeStorageKeyJobQueue.ts @@ -11,6 +11,7 @@ import { jobQueueDatabaseStore } from './JobQueueDatabaseStore'; const removeStorageKeyJobDataSchema = z.object({ key: z.enum([ 'challenge:retry-message-ids', + 'previousAudioDeviceModule', 'nextSignedKeyRotationTime', 'senderCertificateWithUuid', 'signedKeyRotationRejected', diff --git a/ts/services/calling.ts b/ts/services/calling.ts index 98c01475a..a9034ab0b 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -60,11 +60,6 @@ import { GroupCallConnectionState, GroupCallJoinState, } from '../types/Calling'; -import { - AudioDeviceModule, - getAudioDeviceModule, - parseAudioDeviceModule, -} from '../calling/audioDeviceModule'; import { findBestMatchingAudioDeviceIndex, findBestMatchingCameraId, @@ -316,10 +311,6 @@ export class CallingClass { private lastMediaDeviceSettings?: MediaDeviceSettings; - private previousAudioDeviceModule?: AudioDeviceModule; - - private currentAudioDeviceModule?: AudioDeviceModule; - private deviceReselectionTimer?: NodeJS.Timeout; private callsByConversation: { [conversationId: string]: Call | GroupCall }; @@ -345,20 +336,7 @@ export class CallingClass { this._sfuUrl = sfuUrl; - this.previousAudioDeviceModule = parseAudioDeviceModule( - window.storage.get('previousAudioDeviceModule') - ); - this.currentAudioDeviceModule = getAudioDeviceModule(); - drop( - window.storage.put( - 'previousAudioDeviceModule', - this.currentAudioDeviceModule - ) - ); - RingRTC.setConfig({ - use_new_audio_device_module: - this.currentAudioDeviceModule === AudioDeviceModule.WindowsAdm2, field_trials: undefined, }); @@ -1594,13 +1572,6 @@ export class CallingClass { } async getMediaDeviceSettings(): Promise { - const { previousAudioDeviceModule, currentAudioDeviceModule } = this; - if (!previousAudioDeviceModule || !currentAudioDeviceModule) { - throw new Error( - 'Calling#getMediaDeviceSettings cannot be called before audio device settings are set' - ); - } - const { availableCameras, availableMicrophones, availableSpeakers } = await this.getAvailableIODevices(); @@ -1608,8 +1579,6 @@ export class CallingClass { const selectedMicIndex = findBestMatchingAudioDeviceIndex({ available: availableMicrophones, preferred: preferredMicrophone, - previousAudioDeviceModule, - currentAudioDeviceModule, }); const selectedMicrophone = selectedMicIndex !== undefined @@ -1620,8 +1589,6 @@ export class CallingClass { const selectedSpeakerIndex = findBestMatchingAudioDeviceIndex({ available: availableSpeakers, preferred: preferredSpeaker, - previousAudioDeviceModule, - currentAudioDeviceModule, }); const selectedSpeaker = selectedSpeakerIndex !== undefined diff --git a/ts/test-both/calling/findBestMatchingDevice_test.ts b/ts/test-both/calling/findBestMatchingDevice_test.ts index ed0b5d96a..7ed4f845e 100644 --- a/ts/test-both/calling/findBestMatchingDevice_test.ts +++ b/ts/test-both/calling/findBestMatchingDevice_test.ts @@ -2,20 +2,12 @@ // SPDX-License-Identifier: AGPL-3.0-only import { assert } from 'chai'; -import { AudioDeviceModule } from '../../calling/audioDeviceModule'; import { findBestMatchingAudioDeviceIndex } from '../../calling/findBestMatchingDevice'; describe('"find best matching device" helpers', () => { describe('findBestMatchingAudioDeviceIndex', () => { - type AdmOptionsType = Readonly<{ - previousAudioDeviceModule: AudioDeviceModule; - currentAudioDeviceModule: AudioDeviceModule; - }>; - - const itReturnsUndefinedIfNoDevicesAreAvailable = ( - admOptions: AdmOptionsType - ) => { + const itReturnsUndefinedIfNoDevicesAreAvailable = () => { it('returns undefined if no devices are available', () => { [ undefined, @@ -25,16 +17,13 @@ describe('"find best matching device" helpers', () => { findBestMatchingAudioDeviceIndex({ available: [], preferred, - ...admOptions, }) ); }); }); }; - const itReturnsTheFirstAvailableDeviceIfNoneIsPreferred = ( - admOptions: AdmOptionsType - ) => { + const itReturnsTheFirstAvailableDeviceIfNoneIsPreferred = () => { it('returns the first available device if none is preferred', () => { assert.strictEqual( findBestMatchingAudioDeviceIndex({ @@ -44,14 +33,13 @@ describe('"find best matching device" helpers', () => { { name: 'C', index: 789, uniqueId: 'device-C' }, ], preferred: undefined, - ...admOptions, }), 0 ); }); }; - const testUniqueIdMatch = (admOptions: AdmOptionsType) => { + const testUniqueIdMatch = () => { assert.strictEqual( findBestMatchingAudioDeviceIndex({ available: [ @@ -60,13 +48,12 @@ describe('"find best matching device" helpers', () => { { name: 'C', index: 789, uniqueId: 'device-C' }, ], preferred: { name: 'Ignored', index: 99, uniqueId: 'device-C' }, - ...admOptions, }), 2 ); }; - const testNameMatch = (admOptions: AdmOptionsType) => { + const testNameMatch = () => { assert.strictEqual( findBestMatchingAudioDeviceIndex({ available: [ @@ -75,123 +62,32 @@ describe('"find best matching device" helpers', () => { { name: 'C', index: 789, uniqueId: 'device-C' }, ], preferred: { name: 'C', index: 99, uniqueId: 'ignored' }, - ...admOptions, }), 2 ); }; - const itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound = ( - admOptions: AdmOptionsType - ) => { - it('returns the first available device if the preferred device is not found', () => { - assert.strictEqual( - findBestMatchingAudioDeviceIndex({ - available: [ - { name: 'A', index: 123, uniqueId: 'device-A' }, - { name: 'B', index: 456, uniqueId: 'device-B' }, - { name: 'C', index: 789, uniqueId: 'device-C' }, - ], - preferred: { name: 'X', index: 123, uniqueId: 'Y' }, - ...admOptions, - }), - 0 - ); - }); - }; - - describe('with default audio device module', () => { - const admOptions = { - previousAudioDeviceModule: AudioDeviceModule.Default, - currentAudioDeviceModule: AudioDeviceModule.Default, + const itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound = + () => { + it('returns the first available device if the preferred device is not found', () => { + assert.strictEqual( + findBestMatchingAudioDeviceIndex({ + available: [ + { name: 'A', index: 123, uniqueId: 'device-A' }, + { name: 'B', index: 456, uniqueId: 'device-B' }, + { name: 'C', index: 789, uniqueId: 'device-C' }, + ], + preferred: { name: 'X', index: 123, uniqueId: 'Y' }, + }), + 0 + ); + }); }; - itReturnsUndefinedIfNoDevicesAreAvailable(admOptions); + describe('find best matching device', () => { + itReturnsUndefinedIfNoDevicesAreAvailable(); - itReturnsTheFirstAvailableDeviceIfNoneIsPreferred(admOptions); - - it('returns a unique ID match if it exists', () => { - testUniqueIdMatch(admOptions); - }); - - it('returns a name match if it exists', () => { - testNameMatch(admOptions); - }); - - itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound( - admOptions - ); - }); - - describe('when going from the default to Windows ADM2', () => { - const admOptions = { - previousAudioDeviceModule: AudioDeviceModule.Default, - currentAudioDeviceModule: AudioDeviceModule.WindowsAdm2, - }; - - itReturnsUndefinedIfNoDevicesAreAvailable(admOptions); - - itReturnsTheFirstAvailableDeviceIfNoneIsPreferred(admOptions); - - it('returns 0 if that was the previous preferred index (and a device is available)', () => { - assert.strictEqual( - findBestMatchingAudioDeviceIndex({ - available: [ - { name: 'A', index: 123, uniqueId: 'device-A' }, - { name: 'B', index: 456, uniqueId: 'device-B' }, - ], - preferred: { name: 'B', index: 0, uniqueId: 'device-B' }, - ...admOptions, - }), - 0 - ); - }); - - it('returns a unique ID match if it exists and the preferred index is not 0', () => { - testUniqueIdMatch(admOptions); - }); - - it('returns a name match if it exists and the preferred index is not 0', () => { - testNameMatch(admOptions); - }); - - itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound( - admOptions - ); - }); - - describe('when going "backwards" from Windows ADM2 to the default', () => { - const admOptions = { - previousAudioDeviceModule: AudioDeviceModule.WindowsAdm2, - currentAudioDeviceModule: AudioDeviceModule.Default, - }; - - itReturnsUndefinedIfNoDevicesAreAvailable(admOptions); - - itReturnsTheFirstAvailableDeviceIfNoneIsPreferred(admOptions); - - it('returns a unique ID match if it exists', () => { - testUniqueIdMatch(admOptions); - }); - - it('returns a name match if it exists', () => { - testNameMatch(admOptions); - }); - - itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound( - admOptions - ); - }); - - describe('with Windows ADM2', () => { - const admOptions = { - previousAudioDeviceModule: AudioDeviceModule.WindowsAdm2, - currentAudioDeviceModule: AudioDeviceModule.WindowsAdm2, - }; - - itReturnsUndefinedIfNoDevicesAreAvailable(admOptions); - - itReturnsTheFirstAvailableDeviceIfNoneIsPreferred(admOptions); + itReturnsTheFirstAvailableDeviceIfNoneIsPreferred(); [0, 1].forEach(index => { it(`returns ${index} if that was the previous preferred index (and a device is available)`, () => { @@ -203,7 +99,6 @@ describe('"find best matching device" helpers', () => { { name: 'C', index: 789, uniqueId: 'device-C' }, ], preferred: { name: 'C', index, uniqueId: 'device-C' }, - ...admOptions, }), index ); @@ -215,23 +110,20 @@ describe('"find best matching device" helpers', () => { findBestMatchingAudioDeviceIndex({ available: [{ name: 'A', index: 123, uniqueId: 'device-A' }], preferred: { name: 'C', index: 1, uniqueId: 'device-C' }, - ...admOptions, }), 0 ); }); it('returns a unique ID match if it exists and the preferred index is not 0 or 1', () => { - testUniqueIdMatch(admOptions); + testUniqueIdMatch(); }); it('returns a name match if it exists and the preferred index is not 0 or 1', () => { - testNameMatch(admOptions); + testNameMatch(); }); - itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound( - admOptions - ); + itReturnsTheFirstAvailableDeviceIfThePreferredDeviceIsNotFound(); }); }); }); diff --git a/ts/types/Storage.d.ts b/ts/types/Storage.d.ts index 966a191ad..2e9db33c1 100644 --- a/ts/types/Storage.d.ts +++ b/ts/types/Storage.d.ts @@ -140,7 +140,6 @@ export type StorageAccessType = { 'preferred-video-input-device': string; 'preferred-audio-input-device': AudioDevice; 'preferred-audio-output-device': AudioDevice; - previousAudioDeviceModule: AudioDeviceModule; remoteConfig: RemoteConfigType; serverTimeSkew: number; unidentifiedDeliveryIndicators: boolean; @@ -177,6 +176,7 @@ export type StorageAccessType = { // Deprecated 'challenge:retry-message-ids': never; nextSignedKeyRotationTime: number; + previousAudioDeviceModule: AudioDeviceModule; senderCertificateWithUuid: never; signaling_key: never; signedKeyRotationRejected: number; diff --git a/ts/types/StorageUIKeys.ts b/ts/types/StorageUIKeys.ts index fec72f38d..a4ab8e5e7 100644 --- a/ts/types/StorageUIKeys.ts +++ b/ts/types/StorageUIKeys.ts @@ -35,7 +35,6 @@ export const STORAGE_UI_KEYS: ReadonlyArray = [ 'preferred-video-input-device', 'preferredLeftPaneWidth', 'preferredReactionEmoji', - 'previousAudioDeviceModule', 'sendEditWarningShown', 'sent-media-quality', 'showStickerPickerHint', diff --git a/yarn.lock b/yarn.lock index 1cc4c1843..defa56b6b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3986,10 +3986,10 @@ ws "^8.4.2" zod "^3.20.2" -"@signalapp/ringrtc@2.34.5": - version "2.34.5" - resolved "https://registry.yarnpkg.com/@signalapp/ringrtc/-/ringrtc-2.34.5.tgz#33855d02845b0e8b476d7b611774127215966512" - integrity sha512-ORR3LI8Jn4MGosxa45cqjFyoggaOnJASa3rPx8FghfymWW+VClRYgh14jEouJpNwB6u9rviKOWyz7bF19uxn7w== +"@signalapp/ringrtc@2.35.0": + version "2.35.0" + resolved "https://registry.yarnpkg.com/@signalapp/ringrtc/-/ringrtc-2.35.0.tgz#ca9c5fd660fa370720b85f784fc287acbbc6e68f" + integrity sha512-PXy+Io24UhGJQYivayVwIwgAT4A1g88JDxvzz5PNddlpHmSSRoBnH57fcZ1ElHTkqrcNb+V4Tch6SAuYupucow== dependencies: https-proxy-agent "7.0.1" tar "^6.1.0"