|
|
@ -17,13 +17,16 @@ export class NotificationService { |
|
|
|
private subscriptionService: SubscriptionService = SubscriptionService.getInstance(); |
|
|
|
private vapidService: VapidService = VapidService.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private generateSalt(length = 16): Buffer { |
|
|
|
return crypto.randomBytes(length); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async broadcast(message: Message): Promise<void> { |
|
|
|
const subscriptions = await this.subscriptionService.fetchSubscriptions(); |
|
|
|
|
|
|
@ -32,10 +35,12 @@ export class NotificationService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async sendNotification(subscription: Subscription, message: Message) { |
|
|
|
await this.pushToEndpoint(subscription, message); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async pushToEndpoint(subscription: Subscription, message: Message): Promise<void> { |
|
|
|
const payload = JSON.stringify(message); |
|
|
|
|
|
|
@ -77,6 +82,7 @@ export class NotificationService { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private encrypt(publicKey: string, auth: string, payload: string): Buffer { |
|
|
|
http_ece.keys = { |
|
|
|
'p256dh': publicKey, |
|
|
|