2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-26 20:03:42 -04:00
|
|
|
import PQueue from 'p-queue';
|
2022-06-27 09:46:43 -07:00
|
|
|
import { MINUTE } from './durations';
|
2023-05-08 15:59:36 -04:00
|
|
|
import { Sound, SoundType } from './Sound';
|
2020-06-04 11:16:19 -07:00
|
|
|
|
2020-09-18 13:40:41 -07:00
|
|
|
const ringtoneEventQueue = new PQueue({
|
|
|
|
concurrency: 1,
|
2022-06-27 09:46:43 -07:00
|
|
|
timeout: MINUTE * 30,
|
2021-11-23 23:01:03 +01:00
|
|
|
throwOnTimeout: true,
|
2020-09-18 13:40:41 -07:00
|
|
|
});
|
2020-06-04 11:16:19 -07:00
|
|
|
|
|
|
|
class CallingTones {
|
|
|
|
private ringtone?: Sound;
|
|
|
|
|
2024-01-10 21:57:36 -08:00
|
|
|
async handRaised() {
|
|
|
|
const canPlayTone = window.Events.getCallRingtoneNotification();
|
|
|
|
if (!canPlayTone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tone = new Sound({
|
|
|
|
soundType: SoundType.CallingHandRaised,
|
|
|
|
});
|
|
|
|
|
|
|
|
await tone.play();
|
|
|
|
}
|
|
|
|
|
2020-09-14 14:56:35 -07:00
|
|
|
async playEndCall(): Promise<void> {
|
2021-08-18 16:08:14 -04:00
|
|
|
const canPlayTone = window.Events.getCallRingtoneNotification();
|
2020-08-26 20:03:42 -04:00
|
|
|
if (!canPlayTone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tone = new Sound({
|
2023-05-08 15:59:36 -04:00
|
|
|
soundType: SoundType.CallingHangUp,
|
2020-06-04 11:16:19 -07:00
|
|
|
});
|
2020-08-26 20:03:42 -04:00
|
|
|
await tone.play();
|
2020-06-04 11:16:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async playRingtone() {
|
2020-08-26 20:03:42 -04:00
|
|
|
await ringtoneEventQueue.add(async () => {
|
|
|
|
if (this.ringtone) {
|
|
|
|
this.ringtone.stop();
|
|
|
|
this.ringtone = undefined;
|
|
|
|
}
|
|
|
|
|
2021-08-18 16:08:14 -04:00
|
|
|
const canPlayTone = window.Events.getCallRingtoneNotification();
|
2020-08-26 20:03:42 -04:00
|
|
|
if (!canPlayTone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ringtone = new Sound({
|
|
|
|
loop: true,
|
2023-05-08 15:59:36 -04:00
|
|
|
soundType: SoundType.Ringtone,
|
2020-08-26 20:03:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
await this.ringtone.play();
|
2020-06-04 11:16:19 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-26 20:03:42 -04:00
|
|
|
async stopRingtone() {
|
|
|
|
await ringtoneEventQueue.add(async () => {
|
|
|
|
if (this.ringtone) {
|
|
|
|
this.ringtone.stop();
|
|
|
|
this.ringtone = undefined;
|
|
|
|
}
|
|
|
|
});
|
2020-06-04 11:16:19 -07:00
|
|
|
}
|
2021-05-20 17:54:03 -04:00
|
|
|
|
|
|
|
async someonePresenting() {
|
2021-08-18 16:08:14 -04:00
|
|
|
const canPlayTone = window.Events.getCallRingtoneNotification();
|
2021-05-20 17:54:03 -04:00
|
|
|
if (!canPlayTone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tone = new Sound({
|
2023-05-08 15:59:36 -04:00
|
|
|
soundType: SoundType.CallingPresenting,
|
2021-05-20 17:54:03 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
await tone.play();
|
|
|
|
}
|
2020-06-04 11:16:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export const callingTones = new CallingTones();
|