This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(worker): switch push notifications to use VAPID
- Loading branch information
Showing
8 changed files
with
46 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 13 additions & 17 deletions
30
service-worker/worker/src/test/e2e/harness/server/push.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
declare interface WebPushParams { | ||
TTL?: number; | ||
userPublicKey?: Buffer; | ||
userAuth?: Buffer; | ||
payload?: any; | ||
vapid?: any; | ||
vapidDetails: { | ||
subject: string; | ||
publicKey: string; | ||
privateKey: string; | ||
}; | ||
} | ||
|
||
declare interface WebPush { | ||
sendNotification(endpoint: string, params: WebPushParams): Promise<any>; | ||
setGCMAPIKey(key: string); | ||
sendNotification(subscription: any, message: any, options: WebPushParams): Promise<any>; | ||
} | ||
|
||
let push: WebPush = require('web-push'); | ||
|
||
export function sendPush(reg: any, payload?: Object): Promise<any> { | ||
let endpoint = reg.url; | ||
|
||
return push.sendNotification(endpoint, { | ||
userPublicKey: reg.key, | ||
userAuth: reg.auth, | ||
payload: new Buffer(JSON.stringify(payload)) | ||
export function sendPush(subscription: any, payload?: Object): Promise<any> { | ||
return push.sendNotification(subscription, JSON.stringify(payload), { | ||
vapidDetails: { | ||
subject: 'mailto:test@angular.io', | ||
publicKey: 'BLRl_fG1TCTc1D2JwzOpdZjaRcJucXtG8TAd5g9vuYjl6KUUDxgoRjQPCgjZfY-_Rusd_qtjNvanHXeFvOFlxH4', | ||
privateKey: 't3JtFOflouvPUxFKeSSmZdjuVidnD_0dNGFM1v-N4PI', | ||
}, | ||
}); | ||
} | ||
|
||
export function setGCMAPIKey(key: string): void { | ||
push.setGCMAPIKey(key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters