API Docs for:
Show:

WebsocketChannel Class

Extends events.EventEmitter
Module: easy-signaling

A signaling channel using WebSockets. Wraps around ws WebSockets. Reference implementation of a channel.

Constructor

WebsocketChannel

(
  • ws
)

Parameters:

  • ws WebSocket

    The 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);
});

Item Index

Methods

Methods

close

()

Close the connection to the client

send

(
  • data
)

Send data to the client

Parameters:

  • data Object

    The message to be sent

Events

closed

()

The WebSocket was closed

error

(
  • error
)

An error occured with the WebSocket

Parameters:

  • error Error

    The error which occured

message

(
  • data
)

A message was received

Parameters:

  • data Object

    The decoded message