signal-desktop/ts/util/callingTones.ts

73 lines
1.5 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-27 00:03:42 +00:00
import PQueue from 'p-queue';
import { Sound } from './Sound';
2020-06-04 18:16:19 +00:00
const ringtoneEventQueue = new PQueue({
concurrency: 1,
timeout: 1000 * 60 * 2,
2021-11-23 22:01:03 +00:00
throwOnTimeout: true,
});
2020-06-04 18:16:19 +00:00
class CallingTones {
private ringtone?: Sound;
async playEndCall(): Promise<void> {
2021-08-18 20:08:14 +00:00
const canPlayTone = window.Events.getCallRingtoneNotification();
2020-08-27 00:03:42 +00:00
if (!canPlayTone) {
return;
}
const tone = new Sound({
2020-06-04 18:16:19 +00:00
src: 'sounds/navigation-cancel.ogg',
});
2020-08-27 00:03:42 +00:00
await tone.play();
2020-06-04 18:16:19 +00:00
}
async playRingtone() {
2020-08-27 00:03:42 +00:00
await ringtoneEventQueue.add(async () => {
if (this.ringtone) {
this.ringtone.stop();
this.ringtone = undefined;
}
2021-08-18 20:08:14 +00:00
const canPlayTone = window.Events.getCallRingtoneNotification();
2020-08-27 00:03:42 +00:00
if (!canPlayTone) {
return;
}
this.ringtone = new Sound({
loop: true,
src: 'sounds/ringtone_minimal.ogg',
});
await this.ringtone.play();
2020-06-04 18:16:19 +00:00
});
}
2020-08-27 00:03:42 +00:00
async stopRingtone() {
await ringtoneEventQueue.add(async () => {
if (this.ringtone) {
this.ringtone.stop();
this.ringtone = undefined;
}
});
2020-06-04 18:16:19 +00:00
}
async someonePresenting() {
2021-08-18 20:08:14 +00:00
const canPlayTone = window.Events.getCallRingtoneNotification();
if (!canPlayTone) {
return;
}
const tone = new Sound({
src: 'sounds/navigation_selection-complete-celebration.ogg',
});
await tone.play();
}
2020-06-04 18:16:19 +00:00
}
export const callingTones = new CallingTones();