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