This class is a WebSocket server. It is an EventEmitter
.
options
Object
host
Stringport
Numberserver
http.SerververifyClient
Functionpath
StringnoServer
BooleandisableHixie
BooleanclientTracking
Booleancallback
FunctionConstruct a new server object.
Either port
or server
must be provided, otherwise you might enable
noServer
if you want to pass the requests directly. Please note that the
callback
is only used when you supply the a port
number in the options.
Close the server and terminate all clients
Handles a HTTP Upgrade request. request
is an instance of http.ServerRequest
, socket
is an instance of net.Socket
.
When the Upgrade was successfully, the callback
will be called with a ws.WebSocket
object as parameter.
function (error) { }
If the underlying server emits an error, it will be forwarded here.
function (headers) { }
Emitted with the object of HTTP headers that are going to be written to the Stream
as part of the handshake.
function (socket) { }
When a new WebSocket connection is established. socket
is an object of type ws.WebSocket
.
This class represents a WebSocket connection. It is an EventEmitter
.
address
String|Arrayoptions
Object
protocol
Stringagent
Agentheaders
ObjectprotocolVersion
Number|Stringaddress
is a Stringhost
Stringorigin
Stringpfx
String|Bufferkey
String|Bufferpassphrase
Stringcert
String|Bufferca
Arrayciphers
StringrejectUnauthorized
BooleanInstantiating with an address
creates a new WebSocket client object. If address
is an Array (request, socket, rest), it is instantiated as a Server client (e.g. called from the ws.Server
).
Received bytes count.
Possible states are WebSocket.CONNECTING
, WebSocket.OPEN
, WebSocket.CLOSING
, WebSocket.CLOSED
.
The WebSocket protocol version used for this connection, 8
, 13
or hixie-76
(the latter only for server clients).
The URL of the WebSocket server (only for clients)
Describes the feature of the used protocol version. E.g. supports.binary
is a boolean that describes if the connection supports binary messages.
Gracefully closes the connection, after sending a description message
Pause the client stream
Sends a ping. data
is sent, options
is an object with members mask
and binary
. dontFailWhenClosed
indicates whether or not to throw if the connection isnt open.
Sends a pong. data
is sent, options
is an object with members mask
and binary
. dontFailWhenClosed
indicates whether or not to throw if the connection isnt open.
Resume the client stream
Sends data
through the connection. options
can be an object with members mask
and binary
. The optional callback
is executed after the send completes.
Streams data through calls to a user supplied function. options
can be an object with members mask
and binary
. callback
is executed on successive ticks of which send is function (data, final)
.
Immediately shuts down the connection
Emulates the W3C Browser based WebSocket interface using function members.
Emulates the W3C Browser based WebSocket interface using addEventListener.
function (error) { }
If the client emits an error, this event is emitted (errors from the underlying net.Socket
are forwarded here).
function (code, message) { }
Is emitted when the connection is closed. code
is defined in the WebSocket specification.
The close
event is also emitted when then underlying net.Socket
closes the connection (end
or close
).
function (data, flags) { }
Is emitted when data is received. flags
is an object with member binary
.
function (data, flags) { }
Is emitted when a ping is received. flags
is an object with member binary
.
function (data, flags) { }
Is emitted when a pong is received. flags
is an object with member binary
.
function () { }
Emitted when the connection is established.