Skip to content

add more logs for learning #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/config/webpush.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import webpush from 'web-push';

const publicVapidKey = 'BMrfFtMtL9IWl9vchDbbbYzJlbQwplyZ_fbv8Pei8gPNna_Dr1O-Ng7U7fy0LLqz5RKIxEytTIzyk6TLrcKbN30';
const privateVapidKey = 'E5gpbs9Y6r5TscHC64Ce9-hXojA9I1qQL0kuvX8Jz5Y';
const publicVapidKey = 'BBrX9faJjI6fnzLWb102Kmjn9w7q8xogB864Urp84NbljEz-FWD7lwe3gqwQgWBg2Zn9CIu2Tjm51O31MmalSXw';
const privateVapidKey = '_CprP8t4DFikcowAKEDDjXY8Nmm1Pbc1I2nygD9-PPs';

export default (): void => {
webpush.setVapidDetails(
Expand Down
18 changes: 15 additions & 3 deletions app/controllers/subscriptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const remove = async (
return;
}

const successful = await subscriptionRepository.deleteByEndpoint(endpoint);
const successful = await subscriptionRepository.deleteByEndpoint(endpoint);
if (successful) {
res.sendStatus(200);
} else {
Expand All @@ -49,13 +49,25 @@ export const broadcast = async (
const subscriptions = await subscriptionRepository.getAll();

const notifications: Promise<SendResult>[] = [];




subscriptions.forEach((subscription) => {
notifications.push(webpush.sendNotification(subscription, JSON.stringify(notification)));
console.log(`sub:${subscription}`);
const options = {
proxy: 'http://localhost:7890',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this? Will this work for others as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a example for people need a proxy :)

};

var ret = webpush.sendNotification(subscription, JSON.stringify(notification), options);
notifications.push(ret);
});

await Promise.all(notifications);
let rets = await Promise.all(notifications);
console.log(rets);
res.sendStatus(200);
} catch (e) {
console.log(e);
next(e);
}
};
2 changes: 1 addition & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if ('serviceWorker' in navigator) {
});
}

const publicVapidKey = 'BMrfFtMtL9IWl9vchDbbbYzJlbQwplyZ_fbv8Pei8gPNna_Dr1O-Ng7U7fy0LLqz5RKIxEytTIzyk6TLrcKbN30';
const publicVapidKey = 'BBrX9faJjI6fnzLWb102Kmjn9w7q8xogB864Urp84NbljEz-FWD7lwe3gqwQgWBg2Zn9CIu2Tjm51O31MmalSXw';

const urlBase64ToUint8Array = (base64String) => {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
Expand Down
7 changes: 3 additions & 4 deletions client/sw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
self.addEventListener('push', (e) => {
const data = e.data.json();
self.registration.showNotification(data.title, {
body: data.body,
icon: data.icon,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove these options?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debug: data.boy add data.icon is null

});
console.log(data);

self.registration.showNotification(data.title);
});