Rooms

Rooms provide logical namespaces for organizing topics within your application.

What are Rooms?

Rooms are containers that group related topics together. They help organize your messaging structure and provide isolation between different contexts (e.g., different game lobbies, chat channels, or user spaces).

import { NoLag } from '@nolag/js-sdk'

const client = NoLag('your_access_token')
await client.connect()

// Set up app and room
const room = client.setApp('my-app').setRoom('game-lobby')

// Subscribe to topics within this room
room.subscribe('chat')
room.subscribe('player-updates')

// Messages are scoped to this room
room.emit('chat', { text: 'Hello lobby!' })

Room Types

Static Rooms

Defined in your app configuration via the dashboard. These rooms exist permanently and are ideal for fixed channels like general, announcements, or support.

Dynamic Rooms

Created programmatically via the REST API for user-specific or session-specific namespaces. Dynamic rooms must be created server-side before clients can connect to them.

Important: Rooms cannot be created via WebSocket connections. You must first create the room and grant actor access using the REST API, then clients can connect via WebSocket.

Step 1: Create Room via API

import { NoLagApi } from '@nolag/js-sdk'

const api = new NoLagApi('your_api_key')

// Create a dynamic room - inherits topics from app config
const room = await api.rooms.create(appId, {
  name: `game-${gameId}`
})

// Grant actor access to the room
await api.rooms.grantAccess(room.roomId, {
  actorTokenId: 'act_xxx',
  permission: 'pubSub'
})

Step 2: Connect via WebSocket

// After room is created via API, connect to it via WebSocket
const gameRoom = client.setApp('my-app').setRoom(`game-${gameId}`)
gameRoom.subscribe('moves')
gameRoom.subscribe('chat')

Topic Resolution

Topics within a room are namespaced automatically. When you subscribe to chat in room game-lobby, the full topic path is my-app/game-lobby/chat.

Use Cases

  • Game lobbies - Each game session gets its own room
  • Chat channels - Separate rooms for different conversations
  • User spaces - Private rooms for user-specific notifications
  • Multi-tenant apps - Isolate data between organizations

Next Steps