Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix battery drain from Web Audio #29203

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/audio/BackgroundAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
private audioContext = createAudioContext();
private sounds: Record<string, AudioBuffer> = {};

public constructor() {
this.audioContext.suspend();

Check failure on line 23 in src/audio/BackgroundAudio.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

RoomNotificationStateStore › Emits no event when a room has no unreads

TypeError: this.audioContext.suspend is not a function at new suspend (src/audio/BackgroundAudio.ts:23:27) at new LegacyCallHandler (src/LegacyCallHandler.tsx:171:31) at Function.get instance [as instance] (src/LegacyCallHandler.tsx:176:42) at VisibilityProvider.instance [as isRoomVisible] (src/stores/room-list/filters/VisibilityProvider.ts:38:31) at RoomNotificationStateStore.isRoomVisible [as emitUpdateIfStateChanged] (src/stores/notifications/RoomNotificationStateStore.ts:119:45) at EventEmitter.emitUpdateIfStateChanged (src/stores/notifications/RoomNotificationStateStore.ts:100:14) at Object.emit (test/unit-tests/stores/RoomNotificationStateStore-test.ts:40:16)

Check failure on line 23 in src/audio/BackgroundAudio.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

RoomNotificationStateStore › Emits an event when a room has unreads

TypeError: this.audioContext.suspend is not a function at new suspend (src/audio/BackgroundAudio.ts:23:27) at new LegacyCallHandler (src/LegacyCallHandler.tsx:171:31) at Function.get instance [as instance] (src/LegacyCallHandler.tsx:176:42) at VisibilityProvider.instance [as isRoomVisible] (src/stores/room-list/filters/VisibilityProvider.ts:38:31) at RoomNotificationStateStore.isRoomVisible [as emitUpdateIfStateChanged] (src/stores/notifications/RoomNotificationStateStore.ts:119:45) at EventEmitter.emitUpdateIfStateChanged (src/stores/notifications/RoomNotificationStateStore.ts:100:14) at Object.emit (test/unit-tests/stores/RoomNotificationStateStore-test.ts:52:16)

Check failure on line 23 in src/audio/BackgroundAudio.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

RoomNotificationStateStore › Emits an event when a feature flag changes notification state

TypeError: this.audioContext.suspend is not a function at new suspend (src/audio/BackgroundAudio.ts:23:27) at new LegacyCallHandler (src/LegacyCallHandler.tsx:171:31) at Function.get instance [as instance] (src/LegacyCallHandler.tsx:176:42) at VisibilityProvider.instance [as isRoomVisible] (src/stores/room-list/filters/VisibilityProvider.ts:38:31) at RoomNotificationStateStore.isRoomVisible [as emitUpdateIfStateChanged] (src/stores/notifications/RoomNotificationStateStore.ts:119:45) at EventEmitter.emitUpdateIfStateChanged (src/stores/notifications/RoomNotificationStateStore.ts:100:14) at Object.emit (test/unit-tests/stores/RoomNotificationStateStore-test.ts:63:16)
}

public async pickFormatAndPlay<F extends Array<keyof typeof formatMap>>(
urlPrefix: string,
formats: F,
Expand Down Expand Up @@ -48,6 +52,12 @@
source.buffer = this.sounds[url];
source.loop = loop;
source.connect(this.audioContext.destination);

this.audioContext.resume();
source.onended = () => {
this.audioContext.suspend();
};

source.start();
return source;
}
Expand Down
Loading