Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Spyna committed Aug 27, 2019
1 parent 3dd1d16 commit d2943e7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<meta property="og:url" content="https://github.com/Spyna/push-notification-demo" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Web push notification demo" />
<meta property="og:description" content="How to implement Web Push Notification" />
<meta property="og:image" content="https://github.com/Spyna/push-notification-demo/raw/master/push-notification.jpg" />
<meta property="og:image:width" content="466" />
<meta property="og:image:height" content="643" />

![A push notificatin][pushNotificaiton]

[pushNotificaiton]: https://github.com/Spyna/push-notification-demo/raw/master/push-notification.jpg "Push notification"

# push-notification-demo

## Front end
Expand Down
14 changes: 7 additions & 7 deletions front-end/src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ let subscritionId;
const pushNotificationSuported = isPushNotificationSupported();

const pushNotificationConsentSpan = document.getElementById("push-notification-consent");
const sendPushNotificationButton = document.getElementById("send-push-notification-button");
sendPushNotificationButton.addEventListener("click", sendNotification);
const pushNotificationSupportedSpan = document.getElementById("push-notification-supported");
pushNotificationSupportedSpan.innerHTML = pushNotificationSuported;

const askUserPemissionButton = document.getElementById("ask-user-permission-button");
askUserPemissionButton.addEventListener("click", askUserPermission);

const susbribeToPushNotificationButton = document.getElementById("create-notification-subscription-button");
susbribeToPushNotificationButton.addEventListener("click", susbribeToPushNotification);

const sendSubscriptionButton = document.getElementById("send-subscription-button");
sendSubscriptionButton.addEventListener("click", sendSubscriptionToPushServer);

const askUserPemissionButton = document.getElementById("ask-user-permission-button");
askUserPemissionButton.addEventListener("click", askUserPermission);

const pushNotificationSupportedSpan = document.getElementById("push-notification-supported");
pushNotificationSupportedSpan.innerHTML = pushNotificationSuported;
const sendPushNotificationButton = document.getElementById("send-push-notification-button");
sendPushNotificationButton.addEventListener("click", sendNotification);

if (pushNotificationSuported) {
updateUserConsent(Notification.permission);
Expand Down
9 changes: 1 addition & 8 deletions front-end/src/scripts/push-notifications.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { urlB64ToUint8Array } from "./utils/base64";

const pushServerPublicKey = "BIN2Jc5Vmkmy-S3AUrcMlpKxJpLeVRAfu9WBqUbJ70SJOCWGCGXKY-Xzyh7HDr6KbRDGYHjqZ06OcS3BjD7uAm8";

/**
* the public key needs to be encoded in a Uint8Array
*/
const convertedPushServerPublicKey = urlB64ToUint8Array(pushServerPublicKey);

/**
* checks if Push notification and service workers are supported by your browser
*/
Expand Down Expand Up @@ -65,7 +58,7 @@ function createNotificationSubscription() {
return serviceWorker.pushManager
.subscribe({
userVisibleOnly: true,
applicationServerKey: convertedPushServerPublicKey
applicationServerKey: pushServerPublicKey
})
.then(function(subscription) {
console.log("User is subscribed.", subscription);
Expand Down
18 changes: 0 additions & 18 deletions front-end/src/scripts/utils/base64.js

This file was deleted.

Binary file added push-notification.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2943e7

Please sign in to comment.