JavaScript integration example
The following class provides a complete, production-ready WebSocket client for consuming Tuniform Stream Alerts events.TuniformAlerts.js
Usage
Replace
YOUR_STREAM_TOKEN_HERE with the creator’s actual 64-character hex stream token. Each creator has a unique token available in their Stream Alerts dashboard.Best practices
Follow these guidelines to build a robust, production-ready integration:1. Handle the handshake first
1. Handle the handshake first
The first message after connection is always
{"type":"CONNECTED",...}. Process it separately from event payloads to correctly initialize your session state.2. Always auto-reconnect
2. Always auto-reconnect
Networks are unstable. Implement automatic reconnection with a 3–5 second delay on disconnect.
3. Handle unknown event types
3. Handle unknown event types
New event types may be added in the future (e.g.,
follow, raid, host). Your integration should log or ignore events with a type it doesn’t recognize, rather than crashing.4. Check boolean flags before using URLs
4. Check boolean flags before using URLs
Always check
have_tts before using tts_url, and have_voice_message before using voice_message. The URL fields may be empty strings.5. Implement idempotency
5. Implement idempotency
While rare, duplicate messages can theoretically occur. Use the
timestamp field or a client-side deduplication mechanism if you need strictly unique events.6. Keep-alive is automatic
6. Keep-alive is automatic
The server sends Ping frames at regular intervals. Standard WebSocket clients (browser
WebSocket API, libraries like ws) handle this transparently — no action needed on your side.7. Support multiple audio formats
7. Support multiple audio formats
- TTS audio files are always MP3.
- Voice messages can be MP3, WebM, OGG, or other browser-compatible formats.
Audio playback reference
| Source | Format | Field | Check |
|---|---|---|---|
| Text-to-Speech | MP3 | tts_url | have_tts === true |
| Voice Message | MP3, WebM, OGG | voice_message | have_voice_message === true |
Quick reference
WebSocket connection
Authentication and connection details.
Event payloads
Full JSON schemas for all event types.
Platform overview
Understand Tuniform’s features and context.
Support
Contact the Tuniform team for integration help.