Overview

Vocantly provides real-time features through WebSocket connections. The realtime service handles instant message delivery, presence tracking, typing indicators, and more.

WebSocket Connection

Connection Endpoint

Authentication

Use the token from your backend (never keys). Browsers use Sec-WebSocket-Protocol:
Or using the SDK:

Connection Lifecycle

Connection States

Automatic Reconnection

The SDK automatically handles reconnection with exponential backoff:
  • Initial reconnect: 1 second
  • Max delay: 30 seconds
  • Max retries: Unlimited

Joining Conversations

To receive messages for a conversation, you must join it:
Response:

Sending Messages

Message Format

Using SDK

Receiving Messages

Messages are broadcast to all connected clients in the conversation:

Presence

Track user online/offline status:

Update Presence

Presence has two states: online and offline. It’s tracked automatically — a user is online while connected and offline when they disconnect.

Listen for Presence Updates

WebSocket Protocol

Typing Indicators

Show when users are typing:

Start Typing

Stop Typing

Receive Typing Indicators

Typing indicators automatically expire after 5 seconds if not explicitly stopped.

Read Receipts

Track when messages are read:

Send Read Receipt

Receive Read Receipts

Message Types

Client → Server

  • join - Join a conversation room
  • leave - Leave a conversation room
  • message - Send a message
  • read - Mark message as read
  • typing_start - Start typing indicator
  • typing_stop - Stop typing indicator

Server → Client

  • joined - Successfully joined room
  • left - Successfully left room
  • message - New message received
  • receipt - Receipt update
  • typing - Typing indicator update
  • presence - Presence update
  • error - Error message

Error Handling

Connection Errors

Message Errors

Multi-Node Architecture

The realtime service is horizontally scalable:
  • Multiple nodes can run simultaneously
  • Redis Pub/Sub for inter-node communication
  • Messages broadcast across all nodes
  • Load balancer distributes connections

Performance Considerations

Connection Pooling

Reuse WebSocket connections when possible

Room Management

Leave rooms when not needed to reduce overhead

Message Batching

Batch operations when possible

Error Recovery

Implement robust error handling and reconnection

Next Steps

WebSocket Protocol

Complete WebSocket protocol reference

Presence & Typing

Presence and typing indicators

SDK Realtime

SDK real-time features

Troubleshooting

Common issues and solutions