OpenVeo server API for plugins

API Docs for: 7.0.0
Show:

SocketNamespace

Summary

Defines socket.io namespace wrapper.

SocketNamespace wraps a socket.io namespace to be able to connect the namespace to the server after adding handlers to it. Creating a Namespace using socket.io can't be done without creating the server and attaching the namespace to it.

var openVeoApi = require('@openveo/api');
var namespace = new openVeoApi.socket.SocketNamespace();
var server = new openVeoApi.socket.SocketServer();

// Add a middleware
namespace.use(function(socket, next) {
  console.log('Called for every message');
});

// Listen to a message
namespace.on('test.message', function(data) {
  console.log('test.message received');
  console.log(data);
});

// Add namespace to server
server.addNamespace('/myName', namespace);

// Start server
server.listen(80, function() {
  console.log('Socket server started');
  namespace.emit('test.message', 'some data');
});

Constructor

SocketNamespace

Syntax

SocketNamespace

()

Summary

Methods

emit

Syntax

emit

(
  • message
  • data
)

Summary

Emits a message to all clients connected to the namespace.

It will work only if the socket server is started.

Parameters:

  • message String

    The message to send to clients

  • data Mixed

    The data to send to clients

mountHandlers

Syntax

mountHandlers

() private

Summary

Mounts the namespace's handlers on socket.io namespace.

mountMiddlewares

Syntax

mountMiddlewares

() private

Summary

Mounts the namespace's middlewares on socket.io namespace.

on

Syntax

on

(
  • id
  • handler
)

Summary

Listens to a socket's message.

Parameters:

  • id String

    The message id to listen to

  • handler Function

    Function to call when receiving the message

use

Syntax

use

(
  • middleware
)
SocketNamespace chainable

Summary

Registers a middleware.

Middleware gets executed for every incoming socket and receives as parameters the socket and a function to optionally defer execution to the next registered middleware.

Parameters:

  • middleware Function

    Function to call when receiving the message

Returns:

SocketNamespace:

The socket namespace

Properties

handlers

Syntax

handlers

Object

Summary

The list of messages' handlers.

middlewares

Syntax

middlewares

Array

Summary

The list of middlewares.

namespace

Syntax

namespace

Namespace

Summary

The socket namespace.