Signal-Desktop/ts/util/callingTones.ts

74 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// 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,
});
2020-06-04 18:16:19 +00:00
class CallingTones {
private ringtone?: Sound;
// eslint-disable-next-line class-methods-use-this
async playEndCall(): Promise<void> {
2020-08-27 00:03:42 +00:00
const canPlayTone = await window.getCallRingtoneNotification();
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;
}
const canPlayTone = await window.getCallRingtoneNotification();
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
}
// eslint-disable-next-line class-methods-use-this
async someonePresenting() {
const canPlayTone = await window.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();