How to use the web-push.sendNotification function in web-push

To help you get started, we’ve selected a few web-push examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timothyarmes / ta-meteor-apollo-starter-kit / app / api / users / server / resolvers / mutation / send-push-notification.js View on Github external
subscriptions.forEach((subscription) => {
    webPush.sendNotification(subscription, payload, options)
      .then(() => {})
      .catch((err) => {
        console.log(`Error when trying to deliver message for ${subscription.endpoint}`, err);
        // This is probably an old subscription, remove it
        deleteSubscription(null, { endpoint: subscription.endpoint }, { user });
      });
  });
};
github lunchclass / absolute / server / push / controller / send_push.js View on Github external
webpush.setVapidDetails(
      SERVER_SUBJECT,
      pushKeys.pushVapidKeys.publicKey,
      pushKeys.pushVapidKeys.privateKey,
    );

    // This is the same output of calling JSON.stringify on a PushSubscription
    const pushSubscription = {
      endpoint: endpoint,
      keys: {
        auth: keys.auth,
        p256dh: keys.p256dh,
      },
    };

    webpush.sendNotification(pushSubscription, payload)
    .then((webPushResult) => {
      return resolve(webPushResult);
    }).catch((webPushError) => {
      console.log(`push failed to ${endpoint}\n ${webPushError}`);
      return reject(webPushError);
    });
  });
}
github mozilla / serviceworker-cookbook / push-rich / server.js View on Github external
setTimeout(function() {
      webPush.sendNotification(subscription, payload, options)
      .then(function() {
        res.sendStatus(201);
      })
      .catch(function(error) {
        console.log(error);
        res.sendStatus(500);
      });
    }, req.body.delay * 1000);
  });
github codeuino / Social-Platform-Donut / server / controller / project.controller.js View on Github external
.then(sub => {
                    
                    const payload = JSON.stringify({
                        notification: {
                          'title': 'Push notifications with Service Workers'
                        }
                      })
                    const Sub ={ 
                        endpoint: sub.endpoint,
                       keys: sub.keys
                        }   
                    webPush.sendNotification(Sub,payload)
                    .then(result => console.log(result))
                    .catch(err => console.log(err))
                   })
github nebrius / contact-scheduler / archived / server / src / notifications.ts View on Github external
function processNextNotification(user: IUser, cb: CB): void {
  if (!user.state.weeklyContactList.length) {
    console.log(`No more contacts to process this week, go ${user.name}!`);
    cb(undefined);
    return;
  }
  for (const bucket of user.state.dailyBuckets) {
    if (bucket.timestamp <= Date.now() && Date.now() < bucket.timestamp + BUCKET_DURATION) {
      if (bucket.available) {
        const nextContact = user.state.weeklyContactList[0];
        if (nextContact && user.state.subscription) {
          console.log(`Time for ${user.name} to reach out to ${nextContact.name}`);
          sendNotification(user.state.subscription, JSON.stringify(nextContact))
            .then(() => cb(undefined))
            .catch(cb);
          return;
        }
      }
    }
  }
  cb(undefined);
}
github mutebg / pwa-weather / functions / index.js View on Github external
snapshot.forEach(doc => {
				webpush.sendNotification(doc.data().subscription);
			});
			res.status(200).send({ success: true, hour: currentHour });
github unwelch / unwel.ch / backend / src / push.js View on Github external
export const sendPush = (subscription, title, body, link) => {
  if (!subscription) return
  webpush.sendNotification(subscription, JSON.stringify({ title, body, link }))
}
github HermesMessenger / Hermes / server / web-push.js View on Github external
updateSubscriptionSettings(user, settings) {
        for (let uuid in subscriptions) {
            if (subscriptions[uuid].user === user) {
                subscriptions[uuid].settings = settings
                webPush.sendNotification(subscriptions[uuid], JSON.stringify({settings, type: 'updateSettings'}), { TTL: 60 * 60 })
            }
        }
    }
}

web-push

Web Push library for Node.js

MPL-2.0
Latest version published 10 months ago

Package Health Score

69 / 100
Full package analysis