Coder Social home page Coder Social logo

push-api-demo's Introduction

push-api-demo

This is an attempt to create a simple chatroom example to demonstrate the Push API. It also illustrates some uses of Service Workers, and how to use Channel Messaging to communicate data between a Service Worker and the main window context.

Current status

At the moment this demo only works on Firefox Nightly. The working parts are:

  • Requesting permission to send notifications/push messages.
  • Registering and activating a service worker to handle the Push/Channel Messages.
  • Subscribing/unsubscribing (to/from) the push sevice.
  • Sending a push message from the server.
  • Receiving a push message in the SW via the onpush handler and firing a notification as a result.
  • Sending messages to and from the SW via a message channel.

Still to do:

  • Setting up the Google Cloud Messaging service properly so the example will work in Chrome as well.
  • Setting up functionality to allow subscribed users to send messages to the chatroom that will be seen by all subscribed users.
  • Hosting the server somewhere on t'internet so it can be accessed by multiple users (a chatroom is pretty useless with only one user!)
  • Fixing the service worker so that the data sent in the push messages is read and used (Firefox currently doesn't support the PushMessageData methods, see Bug 1149195 โ€” this is the most serious blocker for now.)

Running the demo

To get it running:

  1. Clone this repo locally (you'll need to install git, then use the command git clone https://github.com/chrisdavidmills/push-api-demo.git)
  2. Install NodeJS on your computer.
  3. Load the sample app in Firefox Nightly. Note that it needs to run under HTTPS, as Service workers will only run in a secure context.
  4. in your terminal/command line, navigate to the directory that you cloned this repo into, and run the command node server to start the same server running. This server is HTTPS, and runs at 127.0.0.1:7000.
  5. Go back to the sample app and play with the subscribe/unsubscribe functionality. Monitor the browser console and terminal window (that the server is running in) to see what is happening. You will also see user information being written into, and removed from, the endpoint.txt file as subscribe/unsubscribe commands are issued.

Note: Some of the client-side code in this demo is heavily influenced by Matt Gaunt's excellent examples in Push Notifications on the Open Web. Thanks for the awesome work Matt!

push-api-demo's People

Contributors

chrisdavidmills avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.