Rooms

Neffos supports any number of rooms under a connected namespace.

  1. Each connection connected to a namespace can join to one or more rooms.

  2. Rooms are dynamic.

  3. Server#Broadcast(Message {Namespace: ..., Room: ...}) sends data to all clients connected to a specific Namespace:Room.

  4. Client and server can ask remote side to join to a room, get notified by OnRoomJoin and OnRoomJoined.

  5. Client and server can ask remote side to leave from a room, get notified by OnRoomLeave and OnRoomLeft.

  6. Client and server can disallow remote request for room join through their OnRoomJoin -> return err != nil.

  7. Client and server can disallow remote request for room leave through their OnRoomLeave -> return err != nil.

// blocks until join in both sides.
room, err := nsConn.JoinRoom(ctx, "room")
room.Emit("event", body)
// room.NSConn.Conn.Write(neffos.Message{
//     Namespace: "namespace",
//     Room:      "room",
//     Event:     "event",
//     Body:      body,
// })
room.Leave(ctx)

Last updated