Channels overview
Channels overview
Section titled “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.
What are channels?
Section titled “What are channels?”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.
Channel types
Section titled “Channel types”Jetsocket.io supports several types of channels, each designed for different use cases:
Public channels
Section titled “Public channels”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
Section titled “Private channels”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
Section titled “Presence channels”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
Section titled “Encrypted channels”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
Channel naming conventions
Section titled “Channel naming conventions”- 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
Channel lifecycle
Section titled “Channel lifecycle”- Subscription: Client subscribes to a channel
- Authentication (for private/presence channels): Server authorizes the subscription
- Connection: Client is connected and can receive events
- Event handling: Client receives and processes events
- Unsubscription: Client unsubscribes from the channel
Best practices
Section titled “Best practices”- 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
Next steps
Section titled “Next steps”Learn more about specific channel types: