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> {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const callingTones = new CallingTones();
|