tildeio / MessageChannel.js

27 stars 3 forks source link

MessageChannel.js

Build Status

MessageChannel.js proposes an implementation of the channel messaging described in the HTML5 specification.

Compatibility

It is important to note that the MessageChannel.js communication can only work with browser that supports window.postMessage.

Installation

MessageChannel.js depends on UUID.js and Kamino.js. The easiest way to get them is to install MessageChannel via bower. They will then wind up in bower_components.

bower install MessageChannel.js

Usage

The library works almost like a polyfill.

The only difference in the code is the way MessagePorts are sent between user agents.

 otherWindow.postMessage('hello', "http://example.com", [channel.port1]);
 worker.postMessage('hello', "http://example.com", [channel.port1]);

becomes:

 Window.postMessage(otherWindow, 'hello', "http://example.com", [channel.port1]);
 Worker.postMessage(worker, 'hello', "http://example.com", [channel.port1]);

Limitations

Build Tools

MessageChannel.js uses Grunt to automate building and testing.

Setup

Before you use any of the commands below, make sure you have installed node.js, which includes npm, the node package manager.

If you haven't before, install the grunt CLI tool:

$ npm install -g grunt-cli

This will put the grunt command in your system path, allowing it to be run from any directory.

Next, install MessageChannel's dependencies:

$ npm install

This will install all of the packages that MessageChannel's Gruntfile relies on into the local node_modules directory.

Tests

Run the MessageChannel tests by starting a test server:

grunt server

Once the server is running, visit http://localhost:8000/test/ in your browser.