OpenVeo server API for plugins

API Docs for: 7.0.0
Show:

SocketServer

Summary

Defines a SocketServer around a socket.io server.

Creating a server using socket.io can't be done without launching the server and start listening to messages. SocketServer helps creating a socket server and add namespaces to it without starting the server.

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

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

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

// Add namespace1 to the server
server.addNamespace('/namespace1', namespace1);

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

  // Adding a namespace after the server is started will also work
  server.addNamespace('/namespace2', namespace2);
  namespace2.emit('namespace2.message');
});

Constructor

SocketServer

Syntax

SocketServer

()

Summary

Item Index

Properties

Methods

addNamespace

Syntax

addNamespace

(
  • name
  • namespace
)

Summary

Adds a namespace to the server.

Parameters:

close

Syntax

close

()

Summary

Closes the server.

getNamespace

Syntax

getNamespace

(
  • name
)
SocketNamespace

Summary

Gets a namespace.

Parameters:

  • name String

    The namespace name

Returns:

SocketNamespace:

The namespace

listen

Syntax

listen

(
  • port
)
Function async

Summary

Starts the Socket server and mount namespaces.

Parameters:

  • port Number

    The port to use for the server

Returns:

Function:

callback Function to call when its done

Properties

io

Syntax

io

Server

Summary

The Socket.io server.

namespaces

Syntax

namespaces

Object

Summary

The list of namespaces added to the server indexed by names.