32 lines
903 B
C#
32 lines
903 B
C#
using WebPush;
|
|
using System;
|
|
|
|
namespace Aberwyn.Data
|
|
{
|
|
public class PushNotificationService
|
|
{
|
|
private readonly VapidDetails _vapidDetails;
|
|
private readonly WebPushClient _client;
|
|
|
|
public PushNotificationService(string subject, string publicKey, string privateKey)
|
|
{
|
|
_vapidDetails = new VapidDetails(subject, publicKey, privateKey);
|
|
_client = new WebPushClient();
|
|
}
|
|
|
|
public void SendNotification(string endpoint, string p256dh, string auth, string payload)
|
|
{
|
|
var subscription = new PushSubscription(endpoint, p256dh, auth);
|
|
|
|
try
|
|
{
|
|
_client.SendNotification(subscription, payload, _vapidDetails);
|
|
}
|
|
catch (WebPushException ex)
|
|
{
|
|
Console.WriteLine($"❌ Push-fel: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|