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
{ | |
"course": { | |
"title": "Tabs", | |
"ids": [ "my-tab-id-1", "my-tab-id-3", "my-tab-id-4", "my-tab-id-6" ] | |
}, | |
"tabs": [ | |
{ | |
"_id": "my-tab-id-1", | |
"header": "Pink Dahlia", | |
"content": "<p>Pink Dahlia symbolizes kindness and grace. Color pink in general symbolizes everything that is good and kind in this world.</p>", |
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
{ | |
"course": { | |
"title": "Quiz", | |
"ids": [ 0, 2 ] | |
}, | |
"blocks": [ | |
{ | |
"type": "KnowledgeCheck", | |
"data": { | |
"prompt": "What is this a picture of?", |
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
export function unsubscribePush() { | |
navigator.serviceWorker.ready.then(registration => { | |
//Find the registered push subscription in the service worker | |
registration.pushManager | |
.getSubscription() | |
.then(subscription => { | |
if (!subscription) { | |
return | |
//If there isn't a subscription, then there's nothing to do | |
} |
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
import axios from "axios" | |
export default function subscribePush() { | |
navigator.serviceWorker.ready.then(registration => { | |
if (!registration.pushManager) { | |
alert("Push Unsupported") | |
return | |
} | |
registration.pushManager | |
.subscribe({ |
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
const vapidPublicKey = | |
"< Your Public VAPID Key Here >" | |
const convertedVapidKey = urlBase64ToUint8Array(vapidPublicKey) | |
function urlBase64ToUint8Array(base64String) { | |
const padding = "=".repeat((4 - base64String.length % 4) % 4) | |
const base64 = (base64String + padding).replace(/\-/g, "+").replace(/_/g, "/") | |
const rawData = window.atob(base64) | |
const outputArray = new Uint8Array(rawData.length) |
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
self.addEventListener("push", event => { | |
const data = event.data.json() | |
const { title } = data | |
const body = { | |
body: data.body, | |
icon: data.icon | |
} | |
event.waitUntil(self.registration.showNotification(title, body)) |
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
const router = require("express").Router() | |
module.exports = router | |
const webpush = require("web-push") | |
webpush.setGCMAPIKey(process.env.GOOGLE_API_KEY) | |
webpush.setVapidDetails( | |
"mailto:[email protected]", | |
process.env.PUBLIC_VAPID_KEY, | |
process.env.PRIVATE_VAPID_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
const testData = { | |
title: "Testing", | |
body: "It's a success!", | |
icon: "/path/to/an/icon.png" | |
} | |
let subscription | |
let pushIntervalID | |
router.post("/register", (req, res, next) => { |
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
const aSyncLog = (...args) => setTimeout(() => args.forEach(arg => console.log(arg)), 5000) |