Git Product home page Git Product logo

tellbrowser's Introduction

TellBrowser

A stupidly simple nodejs + socket.io pub/sub for sending asynchronous notifications from your server to the user.

It's not production-grade, but may be useful for prototypes, demos etc. I've used it as a mock e-mail and text message backend.

How it works

  1. The client makes a random cookie named TellBrowserKey and subs to a channel with that name.
  2. The cookie gets sent with subsequent requests.
  3. The server can store the cookie and POST to it to notify the user after a background operation completes.

The primary limitation is that if the user happens to be in the middle of a page load while the notification is fired then the notification is lost. Fortunately single-page apps don't suffer from this problem as much. A better implementation might store the messages for a few minutes or until the user has explicitly acknowledged them.

How to use

  1. Copy config.example.json to config.json and edit if necessary.
  2. Run npm install and bower install to download dependencies.
  3. Run grunt to build.
  4. Start with node app.js.

Currently the app can only be run as a single instance.

Client

Include the following scripts.

<script src="http://localhost:4000/socket.io/socket.io.js"></script>
<script src="http://localhost:4000/lib/tellbrowser-client.min.js"></script>

Here's a usage example using notifyjs:

<!-- The following libs are indeed served by the app for maximal convenience. -->
<link href="http://localhost:4000/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="http://localhost:4000/lib/jquery/jquery.min.js"></script>
<script src="http://localhost:4000/lib/notifyjs/notify-combined.min.js"></script>

<script>
    window.addEventListener('load', function () {
        var client = new TellBrowser('http://localhost:4000/');

        client.listen(function (msg) {
            // We're assuming the server sends simple strings.
            $.notify(msg, { autoHide: false, className: 'info' });
        });
</script>

Server

Just send a POST request to http://localhost:4000/tellbrowser/<key> where <key> is the value of the TellBrowserKey cookie. The body of the request can be any JSON object.

tellbrowser's People

Contributors

mpartel avatar

Watchers

 avatar  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.