Skip to content

Namespaces

Gerasimos (Makis) Maropoulos edited this page Jul 1, 2019 · 4 revisions

We've already seen how to declare and connect to namespaces but details were missing. In this section you will learn how to disallow a client from connecting to a namespace and what a namespace really is.

Here is a list of what we mean by the word Namespaces.

  1. Each connection can be connected to one or more namespaces.
  2. Namespaces should be static and should be declared in both server and client-side(clients can ignore some of the server's namespaces if not willing to connect to them).
  3. Client should connect to a namespace, even if its name is empty "".
  4. Client and server are notified of each namespace connection and disconnection through their OnNamespaceConnect, OnNamespaceConnected and OnNamespaceDisconnect built-in events.
  5. Client can ask server to connect to a namespace.
  6. Server can ask client to connect to a namespace.
  7. Server and client can accept or decline the client or server's connection to a namespace through their OnNamespaceConnect -> return err != nil.
  8. Client can ask server to disconnect from a namespace.
  9. Server can forcely disconnect a client from a namespace.
// blocks until connect in both sides.
nsConn, err := conn.Connect(ctx, "namespace") 
nsConn.Emit("event", body)
// nsConn.Conn.Write(neffos.Message{
//     Namespace: "namespace",
//     Event:     "event",
//     Body:      body,
// })
nsConn.Disconnect(ctx)

Continue by reading about Rooms.