gitmyhub

webpush

Ruby ★ 2 updated 1y ago ⑂ fork

webpush, Encryption Utilities for Web Push protocol

A Ruby gem that sends push notifications from a Ruby backend straight to a user's web browser, handling the encryption and delivery so your app can reach users even when they are not on your site.

RubyJavaScriptService Workerssetup: moderatecomplexity 2/5

The webpush gem lets a Ruby backend send push notifications straight to a user's web browser, even when that person isn't actively looking at your website. It handles the heavy lifting of the Web Push Protocol, including the encryption required to securely deliver messages to browsers like Chrome, Firefox, and Edge.

At a high level, making web push notifications work requires coordination between the server and the browser. On the browser side, the user's device runs a small background script called a service worker, which listens for incoming push events. When the user agrees to receive notifications, the browser generates a unique subscription containing encryption details. The backend then uses this gem to package a message, encrypt it using those details, and send it to the browser's push service, which delivers the notification to the user's screen.

This tool is designed for Ruby developers building web applications who want to re-engage their users with timely updates. For example, a project management app could use it to alert a user that a new task has been assigned to them, or an e-commerce site could notify a shopper that an item they saved is back in stock. It provides the server-side glue needed to bridge the gap between a Ruby application and the browser's built-in notification system.

A notable aspect of this project is its support for VAPID, a standard that lets servers identify themselves to browser push services without relying on third-party API keys. The gem can generate these VAPID keys for you, though it also supports older methods like using Google's GCM API keys. The README provides extensive JavaScript examples for the browser-side setup, acknowledging that getting a service worker properly registered and subscribed is a multi-step process that happens entirely outside of the Ruby code.

Where it fits