Overview
The SnackBase SDK automatically falls back to SSE when WebSocket is not available:SSE vs WebSocket
The SDK prefers WebSocket but falls back to SSE automatically.
SSE URL
The SDK constructs the SSE URL from your base URL:Subscriptions with SSE
SSE subscriptions are specified at connection time:Connection Lifecycle
1. Connection
2. State Changes
3. Disconnection
SSE Message Format
Messages are received as text/event-stream:Automatic Reconnection
SSE has built-in reconnection:Authentication
SSE connections include the authentication token in the URL:SSE Limitations
1. One-Way Communication
SSE is server-to-client only:2. Limited Subscriptions After Connection
With SSE, subscriptions are set at connection time:3. No Heartbeat
SSE uses connection keep-alive instead of heartbeat:When to Use SSE
Use SSE when:- WebSocket is unavailable - Older browsers or restrictive networks
- Simple updates needed - One-way server updates are sufficient
- Lower server load - SSE uses fewer resources than WebSocket
React Example
Cross-Browser Considerations
SSE is supported in most browsers:
For IE 11, use an SSE polyfill:
Debugging SSE
Enable logging to debug SSE issues:- Open DevTools (F12)
- Go to Network tab
- Filter by EventStream
- Select the SSE connection
- View messages in Response tab
Common Issues
1. Connection Closes Immediately
Problem: SSE connection closes after opening Solutions:- Check authentication token is valid
- Verify server allows SSE connections
- Check for proxy/load balancer issues
2. No Events Received
Problem: Connection stays open but no events received Solutions:- Verify subscriptions are set before connection
- Check collection names are correct
- Ensure server has events to send
3. Frequent Reconnections
Problem: SSE keeps reconnecting Solutions:- Check network stability
- Verify server timeout settings
- Increase reconnection delay
Performance Tips
1. Minimize Subscriptions
Only subscribe to what you need:2. Debounce Updates
Debounce rapid updates:3. Use Connection Pooling
For multiple tabs, use BroadcastChannel:Next Steps
- WebSocket - WebSocket for bidirectional communication
- Events - Event reference
- Realtime Overview - Getting started