3 // * http://dev.w3.org/html5/websockets/
4 // * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget
5 // * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event
7 var util = require('util'),
8 driver = require('websocket-driver'),
9 API = require('./websocket/api');
11 var WebSocket = function(request, socket, body, protocols, options) {
12 options = options || {};
14 this._stream = socket;
15 this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols});
18 if (!this._stream || !this._stream.writable) return;
19 if (!this._stream.readable) return this._stream.end();
21 var catchup = function() { self._stream.removeListener('data', catchup) };
22 this._stream.on('data', catchup);
24 API.call(this, options);
26 process.nextTick(function() {
28 self._driver.io.write(body);
31 util.inherits(WebSocket, API);
33 WebSocket.isWebSocket = function(request) {
34 return driver.isWebSocket(request);
37 WebSocket.validateOptions = function(options, validKeys) {
38 driver.validateOptions(options, validKeys);
41 WebSocket.WebSocket = WebSocket;
42 WebSocket.Client = require('./websocket/client');
43 WebSocket.EventSource = require('./eventsource');
45 module.exports = WebSocket;