0.0.7 • Published 9 years ago

websocket-multiplexer v0.0.7

Weekly downloads
1
License
MIT
Repository
-
Last release
9 years ago

Websocket multiplexer

Websocket multiplexer, emulates virtual channels over web socket or SockJS.

Its different to the SockJS multiplexer in some ways:

  • Client / Server agnostic.
  • Anonymous channels.
  • Open new channels at any time. No need to specify them ahead.
  • CommonJS, use it with component, browserify or as node.js module.

Installation

component install manuelstofer/websocket-multiplexer
npm install websocket-multiplexer
var Multiplexer = require('websocket-multiplexer');

API

With named channels:

var multiplexer = new Multiplexer({ socket: websocket }),
    example = multiplexer.channel('example');

example.addEventListener('message', function (evt) {
    console.log(evt.data);
});

example.addEventListener('close', function (evt) {

});

Create anonymous channels:

var multiplexer = new Multiplexer({ socket: websocket }),
    channel = multiplexer.channel();

channel.send('hello');

Listen for anonymous channels:

var multiplexer = new Multiplexer({ socket: websocket });

multiplexer.addEventListener('channel', function (evt) {
    var channel = evt.channel;

    channel.addEventListener('message', function (evt) {
        console.log(evt.data);
    });
});

There are also some examples for node.js + ws in examples/ws

Multiplexer

interface Multiplexer {
  attribute Function onchannel;

  // create a channel
  void channel(optional String channel_id);
  void close();
};
Multiplexer implements EventTarget;

Channel

interface Channel {
  attribute String name;
  attribute Function onmessage;
  attribute Function onclose;
  void send(in DOMString data);
  void close();
};
Channel implements EventTarget;
0.0.7

9 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago