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
Item Index
Methods
Properties
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
StringThe message to send to clients
-
data
MixedThe 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.
use
Syntax
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
FunctionFunction to call when receiving the message
Returns:
The socket namespace