Skip to content

Channels overview

Channels are the core concept in Jetsocket.io. They provide a way to organize and route real-time messages to specific groups of clients.

A channel is a named conduit through which events flow. Clients can subscribe to channels to receive events, and servers can trigger events on channels to send messages to all subscribed clients.

Jetsocket.io supports several types of channels, each designed for different use cases:

Public channels are the simplest type. Any client can subscribe to them without authentication.

const channel = jetsocket.subscribe("my-channel");

Use cases:

  • Public notifications
  • Live feeds
  • Broadcast messages

Private channels require authentication. Clients must be authorized by your server before they can subscribe.

const channel = jetsocket.subscribe("private-my-channel");

Use cases:

  • User-specific data
  • Sensitive information
  • Personal notifications

Presence channels are private channels that also track who is currently subscribed. They provide information about the members of the channel.

const channel = jetsocket.subscribe("presence-my-channel");

Use cases:

  • Chat rooms
  • Online user lists
  • Collaborative features

Encrypted channels provide end-to-end encryption for sensitive data. Only authorized clients can decrypt the messages.

const channel = jetsocket.subscribe("private-encrypted-my-channel");

Use cases:

  • Financial data
  • Medical information
  • Legal documents
  • Public channels: my-channel, notifications, live-feed
  • Private channels: private-my-channel, private-user-123
  • Presence channels: presence-my-channel, presence-room-456
  • Encrypted channels: private-encrypted-my-channel
  1. Subscription: Client subscribes to a channel
  2. Authentication (for private/presence channels): Server authorizes the subscription
  3. Connection: Client is connected and can receive events
  4. Event handling: Client receives and processes events
  5. Unsubscription: Client unsubscribes from the channel
  • Use descriptive names: Choose channel names that clearly indicate their purpose
  • Namespace your channels: Use prefixes to organize channels by feature or user
  • Limit channel scope: Create specific channels rather than broadcasting to everyone
  • Handle errors: Always handle subscription errors and connection issues
  • Clean up: Unsubscribe from channels when they’re no longer needed

Learn more about specific channel types: