diff --git a/public/notification.mp3 b/public/notification.mp3 new file mode 100644 index 00000000..4e8f14a0 Binary files /dev/null and b/public/notification.mp3 differ diff --git a/src/core/subscriptions.ts b/src/core/subscriptions.ts index cdbaa892..16590afd 100644 --- a/src/core/subscriptions.ts +++ b/src/core/subscriptions.ts @@ -1,5 +1,6 @@ import type { Device } from "@core/stores/deviceStore.js"; import { Protobuf, Types } from "@meshtastic/js"; +import { playNotificationSound } from "./utils/notify"; export const subscribeAll = ( device: Device, @@ -84,6 +85,7 @@ export const subscribeAll = ( ...messagePacket, state: messagePacket.from !== myNodeNum ? "ack" : "waiting", }); + playNotificationSound(); }); connection.events.onPendingSettingsChange.subscribe((state) => { diff --git a/src/core/utils/notify.ts b/src/core/utils/notify.ts new file mode 100644 index 00000000..3ffec809 --- /dev/null +++ b/src/core/utils/notify.ts @@ -0,0 +1,17 @@ +import { useAppStore } from '@core/stores/appStore.js'; + +const notificationSound = new Audio("/notification.mp3"); + +let isPlaying = false; + +export const playNotificationSound = () => { + const { notifications } = useAppStore.getState(); + if (notifications && !isPlaying) { + isPlaying = true; + notificationSound.play(); + + notificationSound.onended = () => { + isPlaying = false; + }; + } +};