bazaar

A publish-subscribe (broadcast-listen) layer for same-origin inter-window communication

npm install bazaar
28 downloads in the last month

Bazaar

Description: A publish-subscribe (broadcast-listen) layer for same-origin inter-window communication. Let's you broadcast messages to all opened windows, which are listening.

Home page: jakut.is/git/BAZAAR/about

npm package: bazaar

jam package: bazaar

License: MIT

Author: Vytautas Jakutis

Example usage

demo code

// '/bazaar-worker.js' specifies the url of worker script
// 'hub1' specifies the namespace, this argument is optional, default is '__bazaar__'
var hub = window.bazaar('/bazaar-worker.js', 'hub1');

if(hub === null) {
    alert('your web browser is not supported');
} else {
    document.onmousedown = function() {
        hub.broadcast(new Date().getTime());
    };
    hub.listen(function(err, ts) {
        if(err) {
            return alert("An error occurred when receiving a message.");
        }
        alert(ts);
    });
}

Supported browsers

  • Mozilla Firefox 2.0+
  • Opera 10.50+
  • Google Chrome 5+
  • Microsoft Internet Explorer 6+
  • Apple Safari 4.0+
npm loves you