Skip to content

Implement Namespaces #6

@gil0mendes

Description

@gil0mendes

Connexa should allow you to "namespace" their sockets, which essentially means assigning endpoints or paths.

This is a useful feature to minimize the number of resources (TCP connections) and at the same time separate concerns within your application by introducing separated between communication channels.

Default namespace

We call the default namespace / and it's the one Connexa clients connect to by default and the one the server listens to by default.

This namespace is identified by server:

server.emit('hi', 'everyone');

Each namespace emits a connection event that receives each Socket instance as a parameter

server.on('connection', (socket) {
  socket.on('disconnect', (_) { });
});

Custom namespaces

To set up a custom namespace, you can call the of function on the server-side:

var nsp = server.of('/my-namespace');
nsp.on('connection', function(socket) {
  print('client connected > ' + socket.id);
});
nsp.emit('hi', 'I live!');

On the client side, you tell Connexa client to connect to that namespace:

var socket = Connexa.connect('/my-namespace');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions