upd: web push
Deskripsi: - pengaplikasian web push pada pengumuman - pengaplikasian web push pada diskusi divisi No Issues
This commit is contained in:
26
src/module/_global/fun/send_web_push.ts
Normal file
26
src/module/_global/fun/send_web_push.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { WibuServerPush } from "wibu-pkg";
|
||||
|
||||
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
||||
try {
|
||||
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
||||
|
||||
const kirim = await WibuServerPush.sendMany({
|
||||
subscriptions: subs as any,
|
||||
data: {
|
||||
body: message.body,
|
||||
title: message.title,
|
||||
link: "/home?cat=notification",
|
||||
variant: "notification"
|
||||
}
|
||||
})
|
||||
|
||||
if (kirim) {
|
||||
return { success: true, message: "Berhasil mengirim notifikasi" }
|
||||
}
|
||||
|
||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||
} catch (error) {
|
||||
console.error("Send web push notification error", error);
|
||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import { ScrollProvider } from "./components/scroll_provider";
|
||||
import SkeletonUser from "./components/skeleton_user";
|
||||
import SkeletonList from "./components/skeleton_list";
|
||||
import { funViewDir } from "./fun/view_dir";
|
||||
import { funSendWebPush } from "./fun/send_web_push";
|
||||
|
||||
export { WARNA };
|
||||
export { LayoutLogin };
|
||||
@@ -61,3 +62,4 @@ export { SkeletonUser }
|
||||
export { SkeletonList }
|
||||
export { keyWibu }
|
||||
export { funViewDir }
|
||||
export { funSendWebPush }
|
||||
|
||||
Reference in New Issue
Block a user