2023-10-07 00:09:47 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
|
|
|
import {user_settings} from "./user_settings";
|
|
|
|
|
2023-10-11 00:44:18 +02:00
|
|
|
export function initialize(): void {
|
|
|
|
update_notification_sound_source($("audio#user-notification-sound-audio"), user_settings);
|
2023-10-07 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
2023-10-11 00:44:18 +02:00
|
|
|
export function update_notification_sound_source(
|
|
|
|
$container_elem: JQuery<HTMLAudioElement>,
|
|
|
|
settings_object: {notification_sound: string},
|
|
|
|
): void {
|
2023-10-07 00:09:47 +02:00
|
|
|
const notification_sound = settings_object.notification_sound;
|
|
|
|
const audio_file_without_extension = "/static/audio/notification_sounds/" + notification_sound;
|
2023-10-11 00:41:17 +02:00
|
|
|
$container_elem
|
2023-10-07 00:09:47 +02:00
|
|
|
.find(".notification-sound-source-ogg")
|
|
|
|
.attr("src", `${audio_file_without_extension}.ogg`);
|
2023-10-11 00:41:17 +02:00
|
|
|
$container_elem
|
2023-10-07 00:09:47 +02:00
|
|
|
.find(".notification-sound-source-mp3")
|
|
|
|
.attr("src", `${audio_file_without_extension}.mp3`);
|
|
|
|
|
|
|
|
if (notification_sound !== "none") {
|
|
|
|
// Load it so that it is ready to be played; without this the old sound
|
|
|
|
// is played.
|
2023-10-11 00:41:17 +02:00
|
|
|
$container_elem[0].load();
|
2023-10-07 00:09:47 +02:00
|
|
|
}
|
|
|
|
}
|