Add notification config

This commit is contained in:
Nicolas Mowen 2024-07-19 14:32:20 -06:00
parent 41a0518cfb
commit b4633dbaae
6 changed files with 35 additions and 27 deletions

View File

@ -402,7 +402,7 @@ class FrigateApp:
if self.config.mqtt.enabled: if self.config.mqtt.enabled:
comms.append(MqttClient(self.config)) comms.append(MqttClient(self.config))
# TODO check if notifications are enabled if self.config.notifications.enabled:
comms.append(FirebaseClient(self.config, self.stop_event)) comms.append(FirebaseClient(self.config, self.stop_event))
comms.append(WebSocketClient(self.config)) comms.append(WebSocketClient(self.config))

View File

@ -75,10 +75,10 @@ class FirebaseMessenger(threading.Thread):
), ),
webpush=messaging.WebpushConfig( webpush=messaging.WebpushConfig(
fcm_options=messaging.WebpushFCMOptions( fcm_options=messaging.WebpushFCMOptions(
link=f"https://localhost:5173/review?id={reviewId}" link=f"{self.config.notifications.base_url}/review?id={reviewId}"
) )
), ),
data={"id": reviewId, "imageUrl": f'https://localhost:5173{payload["after"]["thumb_path"].replace("/media/frigate", "")}'}, data={"id": reviewId, "imageUrl": f'{self.config.notifications.base_url}{payload["after"]["thumb_path"].replace("/media/frigate", "")}'},
tokens=[ tokens=[
"cNNicZp6S92qn4kAVJnzd7:APA91bGv-MvDmNoZ2xqJTkPyCTmyv2WG0tfwIqWUuNtq3SXlpQJpdPCCjTEehOLDa0Yphv__KdxOQYEfaFvYfTW2qQevX-tSnRCVa_sJazQ_rfTervpo_zBVJD1T5GfYaY6kr41Wr_fP" "cNNicZp6S92qn4kAVJnzd7:APA91bGv-MvDmNoZ2xqJTkPyCTmyv2WG0tfwIqWUuNtq3SXlpQJpdPCCjTEehOLDa0Yphv__KdxOQYEfaFvYfTW2qQevX-tSnRCVa_sJazQ_rfTervpo_zBVJD1T5GfYaY6kr41Wr_fP"
], ],

View File

@ -169,6 +169,11 @@ class AuthConfig(FrigateBaseModel):
hash_iterations: int = Field(default=600000, title="Password hash iterations") hash_iterations: int = Field(default=600000, title="Password hash iterations")
class NotificationConfig(FrigateBaseModel):
enabled: bool = Field(default=False, title="Enable notifications")
base_url: Optional[str] = Field(default=None, title="Base url for notification link and image.")
class StatsConfig(FrigateBaseModel): class StatsConfig(FrigateBaseModel):
amd_gpu_stats: bool = Field(default=True, title="Enable AMD GPU stats.") amd_gpu_stats: bool = Field(default=True, title="Enable AMD GPU stats.")
intel_gpu_stats: bool = Field(default=True, title="Enable Intel GPU stats.") intel_gpu_stats: bool = Field(default=True, title="Enable Intel GPU stats.")
@ -1361,6 +1366,7 @@ class FrigateConfig(FrigateBaseModel):
default_factory=dict, title="Frigate environment variables." default_factory=dict, title="Frigate environment variables."
) )
ui: UIConfig = Field(default_factory=UIConfig, title="UI configuration.") ui: UIConfig = Field(default_factory=UIConfig, title="UI configuration.")
notifications: NotificationConfig = Field(default_factory=NotificationConfig, title="Notification Config")
telemetry: TelemetryConfig = Field( telemetry: TelemetryConfig = Field(
default_factory=TelemetryConfig, title="Telemetry configuration." default_factory=TelemetryConfig, title="Telemetry configuration."
) )

View File

@ -7,15 +7,11 @@ importScripts("https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js")
// Initialize the Firebase app in the service worker by passing in // Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object. // your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object // https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({ const fbConfig = await (
apiKey: "AIzaSyCoweRLtvai8iNwhsoT-GH_CH_0pckqMmA", await fetch(`${window.location.href}/firebase-config.json`)
authDomain: "frigate-ed674.firebaseapp.com", ).json();
projectId: "frigate-ed674",
storageBucket: "frigate-ed674.appspot.com", firebase.initializeApp(fbConfig);
messagingSenderId: "76314288339",
appId: "1:76314288339:web:090e170610d3bf0966f426",
measurementId: "G-GZ1JKNDJZK",
});
// Retrieve an instance of Firebase Messaging so that it can handle background // Retrieve an instance of Firebase Messaging so that it can handle background
// messages. // messages.
@ -29,7 +25,7 @@ messaging.onBackgroundMessage((payload) => {
// Customize notification here // Customize notification here
const notificationOptions = { const notificationOptions = {
body: payload.notification.body, body: payload.notification.body,
icon: , icon: payload.data.imageUrl,
tag: payload.data.id, // ensure that the notifications for same items are written over tag: payload.data.id, // ensure that the notifications for same items are written over
}; };

View File

@ -1,14 +1,29 @@
import { firebaseConfig } from "@/types/notifications"; import { getMessaging } from "firebase/messaging";
import { getMessaging, getToken } from "firebase/messaging";
import { initializeApp } from "firebase/app"; import { initializeApp } from "firebase/app";
import { useMemo } from "react"; import { useEffect, useMemo, useState } from "react";
export function useFirebaseApp() { export function useFirebaseApp() {
const [firebaseConfig, setFirebaseConfig] = useState();
useEffect(() => {
if (!firebaseConfig) {
fetch(`${window.location.href}/firebase-config.json`).then(
async (resp) => {
setFirebaseConfig(await resp.json());
},
);
}
}, [firebaseConfig]);
return useMemo(() => { return useMemo(() => {
if (!firebaseConfig) {
return;
}
const app = initializeApp(firebaseConfig); const app = initializeApp(firebaseConfig);
app.automaticDataCollectionEnabled = false; app.automaticDataCollectionEnabled = false;
return app; return app;
}, []); }, [firebaseConfig]);
} }
export function useFirebaseMessaging() { export function useFirebaseMessaging() {

View File

@ -1,9 +0,0 @@
export const firebaseConfig = {
apiKey: "AIzaSyCoweRLtvai8iNwhsoT-GH_CH_0pckqMmA",
authDomain: "frigate-ed674.firebaseapp.com",
projectId: "frigate-ed674",
storageBucket: "frigate-ed674.appspot.com",
messagingSenderId: "76314288339",
appId: "1:76314288339:web:090e170610d3bf0966f426",
measurementId: "G-GZ1JKNDJZK",
};