Git Product home page Git Product logo

topics's Introduction

Minimal WebPush Topic Demo

This is a suite of things to help show how sites can use WebPush topics.

Topics are a special class of WebPush messages that will automatically replace themselves if the user hasn't gotten them yet. Think of messages like "You have 4 pending notifications". Instead of getting a bunch of messages showing your increasing popularity, you'll just get the one "topic".

Getting Started

This demo was written on a Linux box. This means that macs may work too, but older installs of Windows might have a harder time of things.

In addition, you'll need to either serve the ./page directory from your local web server or run bin/topic_server with enough privileges to be able to start a web server at port 80 (default port is: 8200). This is because of a restriction enforced by ServiceWorkers. ServiceWorker scripts must either be served from a secure server (one that can run https:// or from localhost)

Prerequisites

  • build-essential or equivalent cc, make, etc. meta package
  • libssl-dev
  • $PYTHON development libraries (e.g. python3-dev)

Setup

PYTHON=python3
git clone https://github.com/jrconlin/topics.git
cd topics
virtualenv -p $PYTHON venv
source venv/bin/activate
python setup.py develop
venv/bin/topic_server

Now start your browser and go to the topic page being served. (Again, either this is under a server running on your local machine, or by running bin/topic_server -p 8200)

The page is fairly self explanatory, but basically, click on the Subscribe button, and say "Allow" when prompted.

Sending Messages

Once you've successfully sent the browser credentials to the server, you can use them to send WebPush notifications to yourself.

Feel free to run bin/topic_pusher --msg "Hello, I'm a message!" and you should see a notification pop up. That's a normal WebPush Message.

If you've successfully sent a message, things are working. To get the full topic experience, close the browser.

Once it's closed, send a few normal messages, and then send a few messages with a topic like

  bin/topic_pusher --msg "I'm message #1" --topic MyTopic
  bin/topic_pusher --msg "I'm message #2" --topic MyTopic

When you re-open your browser, you should see all of the pending messages, but you should only see the latest message for MyTopic. NOTE: Currently the topic name is not sent as part of the data. The msg can be any content, so it's trivial to turn it into a JSON object that includes the topic name if you wanted that info passed along.

Installation Errors

Could not find required distribution pyasn1

If you get the following error:

error: Could not find required distribution pyasn1

Then re-run:

python setup.py develop

OSX Users - SSL error

Apple has deprecated OpenSSL in favor of its own TLS and crypto libraries. If you get an SSL error on OSX (El Capitan), install OpenSSL with brew, then link brew libraries and install cryptography. NOTE: /usr/local/opt/openssl is symlinked to brew Cellar:

brew install openssl
ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" \
  CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography

Then re-run:

python setup.py develop

topics's People

Contributors

jrconlin avatar rpappalax avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

topics's Issues

Fix README

fix installation instructions and add notes on installation errors.

SyntaxError on install

Trying to python setup.py develop, but getting the following error on install (python 3.6.1)
Looks like it's choking on the exception handling in cyclone.

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 157, in save_modules
    yield saved
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 198, in setup_context
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 248, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 278, in run
    return func()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 246, in runner
    _execfile(setup_script, ns)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 46, in _execfile
    code = compile(script, filename, 'exec')
  File "/var/folders/1n/znmq6xc95wq38tm9qh93bz7r0000gn/T/easy_install-h_9kspix/cyclone-1.1/setup.py", line 100
    except Exception, e:
                    ^
SyntaxError: invalid syntax

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.