Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
W3CWebSocket
2
============
3
 
4
* [Constructor](#constructor)
5
* [Limitations](#limitations)
6
 
7
`var W3CWebSocket = require('websocket').w3cwebsocket`
8
 
9
Implementation of the [W3C WebSocket API](http://www.w3.org/TR/websockets/) for browsers.
10
 
11
The exposed class lets the developer use the browser *W3C WebSocket API* in Node:
12
 
13
```javascript
14
var WS = require('websocket').w3cwebsocket;
15
 
16
WS === window.WebSocket
17
// => true when in the browser
18
 
19
var ws = new WS('ws://example.com/resource', 'foo', 'http://example.com');
20
// - In Node it creates an instance of websocket.W3CWebSocket.
21
// - In the browser it creates an instance of window.WebSocket (third parameter
22
//   is ignored by the native WebSocket constructor).
23
 
24
ws.onopen = function() { console.log('ws open'); };
25
// etc.
26
```
27
 
28
 
29
Constructor
30
-----------
31
 
32
```javascript
33
new W3CWebSocket(requestUrl, requestedProtocols, [[[[origin], headers], requestOptions], clientConfig])
34
```
35
 
36
**clientConfig** is the parameter of the [WebSocketClient](./WebSocketClient.md) constructor.
37
 
38
**requestUrl**, **requestedProtocols**, **origin**, **headers** and **requestOptions** are parameters to be used in the `connect()` method of [WebSocketClient](./WebSocketClient.md).
39
 
40
This constructor API makes it possible to use the W3C API and "browserify" the Node application into a valid browser library.
41
 
42
When running in a browser (for example by using [browserify](http://browserify.org/)) the browser's native `WebSocket` implementation is used, and thus just the first and second arguments (`requestUrl` and `requestedProtocols`) are used (those allowed by the *W3C WebSocket API*).
43
 
44
 
45
Limitations
46
-----------
47
 
48
* `bufferedAmount` attribute is always 0.
49
* `binaryType` is "arraybuffer" by default given that "blob" is not supported (Node does not implement the `Blob` class).
50
* `send()` method allows arguments of type `DOMString`, `ArrayBuffer`, `ArrayBufferView` (`Int8Array`, etc) or Node `Buffer`, but does not allow `Blob`.