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';
|
2020-09-14 21:56:35 +00:00
|
|
|
import { Sound } from './Sound';
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2020-09-18 20:40:41 +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;
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
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
|
|
|
}
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
async someonePresenting() {
|
2021-08-18 20:08:14 +00:00
|
|
|
const canPlayTone = window.Events.getCallRingtoneNotification();
|
2021-05-20 21:54:03 +00:00
|
|
|
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();
|