var util=require("util"),driver=require("websocket-driver"),API=require("./websocket/api"),WebSocket=function(e,t,r,i,o){o=o||{},this._stream=t,this._driver=driver.http(e,{maxLength:o.maxLength,protocols:i});var s=this;if(this._stream&&this._stream.writable){if(!this._stream.readable)return this._stream.end();var c=function(){s._stream.removeListener("data",c)};this._stream.on("data",c),API.call(this,o),process.nextTick(function(){s._driver.start(),s._driver.io.write(r)})}};util.inherits(WebSocket,API),WebSocket.isWebSocket=function(e){return driver.isWebSocket(e)},WebSocket.validateOptions=function(e,t){driver.validateOptions(e,t)},WebSocket.WebSocket=WebSocket,WebSocket.Client=require("./websocket/client"),WebSocket.EventSource=require("./eventsource"),module.exports=WebSocket;