<commit_before># Websocket multiplexer

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

Its different to the [SockJS multiplexer](https://github.com/sockjs/websocket-multiplex) 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

```bash
component install manuelstofer/websocket-multiplexer
```

```bash
npm install websocket-multiplexer
```

```Javascript
var Multiplexer = require('websocket-multiplexer');
```


### API

With named channels:

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

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

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

});
```

Anonymous channels:

```Javascript
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](https://github.com/einaros/ws) in examples/ws


### Multiplexer

```webidl
interface Multiplexer {
  attribute Function onchannel;

  // create a channel
  void channel(optional String channel_id);
};
WebSocket implements EventTarget;
```

### Channel

```webidl
interface Channel {
  // networking
  attribute String name;
  attribute Function onmessage;
  attribute Function onclose;
  void send(in DOMString data);
  void close();
};
WebSocket implements EventTarget;
```<commit_msg>Fix webidl in readme<commit_after># Websocket multiplexer

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

Its different to the [SockJS multiplexer](https://github.com/sockjs/websocket-multiplex) 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

```bash
component install manuelstofer/websocket-multiplexer
```

```bash
npm install websocket-multiplexer
```

```Javascript
var Multiplexer = require('websocket-multiplexer');
```


### API

With named channels:

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

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

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

});
```

Anonymous channels:

```Javascript
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](https://github.com/einaros/ws) in examples/ws


### Multiplexer

```webidl
interface Multiplexer {
  attribute Function onchannel;

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

### Channel

```webidl
interface Channel {
  // networking
  attribute String name;
  attribute Function onmessage;
  attribute Function onclose;
  void send(in DOMString data);
  void close();
};
Channel implements EventTarget;
```
{'fraction_non_alphanumeric': 0.12264969626844084, 'fraction_numerical': 0.0, 'mean_word_length': 4.668852459016393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2031056', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1000, 'n_words': 305}