You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
743 B
TypeScript
36 lines
743 B
TypeScript
const sound = './sound/ringing.mp3';
|
|
|
|
let currentlyRinging = false;
|
|
|
|
let ringingAudio: HTMLAudioElement | undefined;
|
|
|
|
function stopRinging() {
|
|
if (ringingAudio) {
|
|
ringingAudio.pause();
|
|
ringingAudio.srcObject = null;
|
|
}
|
|
}
|
|
|
|
function startRinging() {
|
|
if (!ringingAudio) {
|
|
ringingAudio = new Audio(sound);
|
|
ringingAudio.loop = true;
|
|
ringingAudio.volume = 0.6;
|
|
}
|
|
void ringingAudio.play().catch(window.log.info);
|
|
}
|
|
|
|
export function getIsRinging() {
|
|
return currentlyRinging;
|
|
}
|
|
|
|
export function setIsRinging(isRinging: boolean) {
|
|
if (!currentlyRinging && isRinging) {
|
|
startRinging();
|
|
currentlyRinging = true;
|
|
} else if (currentlyRinging && !isRinging) {
|
|
stopRinging();
|
|
currentlyRinging = false;
|
|
}
|
|
}
|