2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 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';
|
2022-06-27 16:46:43 +00:00
|
|
|
import { MINUTE } from './durations';
|
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,
|
2022-06-27 16:46:43 +00:00
|
|
|
timeout: MINUTE * 30,
|
2021-11-23 22:01:03 +00:00
|
|
|
throwOnTimeout: true,
|
2020-09-18 20:40:41 +00:00
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
|
|
|
|
class CallingTones {
|
|
|
|
private ringtone?: Sound;
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
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
|
|
|
|
|
|
|
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();
|