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,8 +402,8 @@ class FrigateApp:
if self.config.mqtt.enabled:
comms.append(MqttClient(self.config))
# TODO check if notifications are enabled
comms.append(FirebaseClient(self.config, self.stop_event))
if self.config.notifications.enabled:
comms.append(FirebaseClient(self.config, self.stop_event))
comms.append(WebSocketClient(self.config))
comms.append(self.inter_process_communicator)

View File

@ -75,10 +75,10 @@ class FirebaseMessenger(threading.Thread):
),
webpush=messaging.WebpushConfig(
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=[
"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")
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):
amd_gpu_stats: bool = Field(default=True, title="Enable AMD 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."
)
ui: UIConfig = Field(default_factory=UIConfig, title="UI configuration.")
notifications: NotificationConfig = Field(default_factory=NotificationConfig, title="Notification Config")
telemetry: TelemetryConfig = Field(
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
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
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",
});
const fbConfig = await (
await fetch(`${window.location.href}/firebase-config.json`)
).json();
firebase.initializeApp(fbConfig);
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
@ -29,7 +25,7 @@ messaging.onBackgroundMessage((payload) => {
// Customize notification here
const notificationOptions = {
body: payload.notification.body,
icon: ,
icon: payload.data.imageUrl,
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, getToken } from "firebase/messaging";
import { getMessaging } from "firebase/messaging";
import { initializeApp } from "firebase/app";
import { useMemo } from "react";
import { useEffect, useMemo, useState } from "react";
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(() => {
if (!firebaseConfig) {
return;
}
const app = initializeApp(firebaseConfig);
app.automaticDataCollectionEnabled = false;
return app;
}, []);
}, [firebaseConfig]);
}
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",
};