The Web Socket API is modeled after Node.js' 'ws' module. This module only supports the Web Socket server portion of the API.
This IDL provides an overview of the interface; see below for documentation of specific API functions.
// require returns a WebSocket object
// var ws = require('ws');
interface WebSocket {
WebSocketServer Server(Object options);
};
interface WebSocketServer: EventEmitter;
interface WebSocketConnection: EventEmitter {
// WebSocketConnection methods
void send(Buffer data, Boolean mask);
void ping(Buffer data, Boolean mask);
void pong(Buffer data, Boolean mask);
};
WebSocketServer Server(Object options)
Create a Web Socket server object. Options object may contain:
WebSocketServer is EventEmitter with the following events:
WebSocketConnection
conn
Emitted when a client has connected to the server. The argument to any
registered listener will be a WebSocketConnection
object which can be used to
communicate with the client.
{
port : Port to bind to
backlog : Max number of concurrent connections
clientTracking : enable client tracking
maxPayload : set the max payload bytes per message
acceptHandler : handler to call to accept/deny connections
}
The acceptHandler
property sets a function handler to be called when there is
a new connection. The argument will be an array of sub-protocols (Strings) that
the client is requesting to use. To accept the connection, return one of these
strings from the handler.
Returns a WebSocketServer
object.
WebSocketServer is EventEmitter with the following events:
Emitted when the web socket has closed.
Error
err
Emitted when the web socket has an error. They type of error can be found in
the err
object argument.
Buffer
data
Emitted when the web socket has received data. The data will be contained in
the data
Buffer argument.
Buffer
data
Emitted when the socket has received a ping. The ping's payload is contained in
the data
argument.
Buffer
data
Emitted when the socket has received a pong. The pong's payload is contained in
the data
argument.
void send(Buffer data, Boolean mask)
Send data to the other end of the web socket connection. The data
parameter
should contain the data payload to send. The mask
parameter says whether the
data payload should be masked.
void ping(Buffer data, Boolean mask)
Send a ping to the other end of the web socket connection. The data
parameter
should contain the data payload to send. The mask
parameter says whether the
data payload should be masked.
void pong(Buffer data, Boolean mask)
Send a pong to the other end of the web socket connection. The data
parameter
should contain the data payload to send. The mask
parameter says whether the
data payload should be masked.