einaros/ws — Issue #18: W3C API compatibility
Author: aslakhellesoy
Created: 2012-02-06 10:28:58+00:00
State: open

I'm writing a library on top of your excellent library that I'd like to use both on Node.js and in browsers. I have ran into 2 issues with API incompatibility:

## Adding event listeners

The W3C API allows these two variants:

```javascript
ws.onmessage = function(e) {
var payload = e.data;
};

ws.addEventListener('message', function(e) {
var payload = e.data;
});
```

Your implementation allows:

```javascript
ws.on('message', function(payload){
});
```

I'm proposing 3 changes:

* Deliver messages in an `Event` object with a `data` attribute
* Allow `ws.addEventListener(eventName, Function)`
* Allow `ws.onmessage = Function`

This would break the current API, but it would also make it follow the official API more closely. Would you be interested in a patch for this?

Aslak