Overview
Tzafon provides real-time streaming capabilities for monitoring browser sessions, receiving live updates, and managing session lifecycle. These features use Server-Sent Events (SSE) for efficient one-way streaming.Event Streaming
streamEvents()
Stream real-time events from a computer session. Receive updates about actions, page changes, and session state.- Session state changes
- Action completion notifications
- Error events
- Page navigation events
- Real-time monitoring dashboards
- Progress tracking for long-running tasks
- Debugging and logging
- Building reactive UIs
Screencast Streaming
streamScreencast()
Stream live screencast frames from a browser session. Frames are delivered as base64-encoded JPEG images via SSE.- Base64-encoded JPEG images
- Delivered via SSE
data:events - Typical frame rate depends on activity
- Live browser viewing
- Session monitoring
- Recording automation runs
- Building browser preview UIs
Session Management
keepAlive()
Extend the timeout for an active session. Call periodically to prevent automatic termination due to inactivity.- Resets the inactivity timer
- Returns current session status
- Fails if session already terminated
- Long-running automation tasks
- Interactive sessions with pauses
- Preventing timeout during user input
WebSocket Connection
connectWebsocket()
Establish a WebSocket connection for bidirectional real-time communication.- Two-way communication with sessions
- Real-time control interfaces
- Low-latency interactions
Best Practices
Handle connection drops
Handle connection drops
SSE and WebSocket connections can drop. Implement reconnection logic with exponential backoff.
Buffer screencast frames
Buffer screencast frames
Screencast frames arrive rapidly. Buffer or throttle display updates to avoid overwhelming the UI.
Clean up connections
Clean up connections
Always close SSE/WebSocket connections when done to free resources on both client and server.
Use keepAlive for long tasks
Use keepAlive for long tasks
For automation that includes waiting for external events, call keepAlive periodically to prevent session timeout.
API Reference
| Endpoint | Method | Description |
|---|---|---|
/computers/{id}/events | GET | SSE stream of session events |
/computers/{id}/screencast | GET | SSE stream of screencast frames |
/computers/{id}/keepalive | POST | Extend session timeout |
/computers/{id}/ws | GET | WebSocket connection |