Browse Source

add notification sound logic

pull/185/head
Marc Hyeler 2 years ago
parent
commit
e9e6239498
  1. BIN
      public/notification.mp3
  2. 2
      src/core/subscriptions.ts
  3. 17
      src/core/utils/notify.ts

BIN
public/notification.mp3

Binary file not shown.

2
src/core/subscriptions.ts

@ -1,5 +1,6 @@
import type { Device } from "@core/stores/deviceStore.js"; import type { Device } from "@core/stores/deviceStore.js";
import { Protobuf, Types } from "@meshtastic/js"; import { Protobuf, Types } from "@meshtastic/js";
import { playNotificationSound } from "./utils/notify";
export const subscribeAll = ( export const subscribeAll = (
device: Device, device: Device,
@ -84,6 +85,7 @@ export const subscribeAll = (
...messagePacket, ...messagePacket,
state: messagePacket.from !== myNodeNum ? "ack" : "waiting", state: messagePacket.from !== myNodeNum ? "ack" : "waiting",
}); });
playNotificationSound();
}); });
connection.events.onPendingSettingsChange.subscribe((state) => { connection.events.onPendingSettingsChange.subscribe((state) => {

17
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;
};
}
};
Loading…
Cancel
Save