WebsocketChannel Class
A signaling channel using WebSockets. Wraps around ws
WebSockets. Reference implementation of a channel.
Constructor
WebsocketChannel
(
-
ws
Parameters:
-
ws
WebSocketThe websocket connection with the client
Example:
// using only one Room
var es = require('easy-signaling');
var ws = require('ws')
var wss = new ws.WebSocketServer({port: 8080, host: '0.0.0.0'})
var room = new es.Room();
wss.on('connection', function(ws) {
channel = new es.WebsocketChannel(ws);
room.create_guest(channel);
});
// using Hotel to support multiple rooms based on the URL
var es = require('easy-signaling');
var ws = require('ws')
var wss = new ws.WebSocketServer({port: 8080, host: '0.0.0.0'})
var hotel = new es.Hotel();
wss.on('connection', function(ws) {
channel = new es.WebsocketChannel(ws);
hotel.create_guest(channel, ws.upgradeReq.url);
});
Methods
close
()
Close the connection to the client
send
(
-
data
Send data to the client
Parameters:
-
data
ObjectThe message to be sent
Events
closed
()
The WebSocket was closed
error
(
-
error
An error occured with the WebSocket
Parameters:
-
error
ErrorThe error which occured
message
(
-
data
A message was received
Parameters:
-
data
ObjectThe decoded message