Skip to main content

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:
The first message after connection is always {"type":"CONNECTED",...}. Process it separately from event payloads to correctly initialize your session state.
Networks are unstable. Implement automatic reconnection with a 3–5 second delay on disconnect.
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.
Always check have_tts before using tts_url, and have_voice_message before using voice_message. The URL fields may be empty strings.
While rare, duplicate messages can theoretically occur. Use the timestamp field or a client-side deduplication mechanism if you need strictly unique events.
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.
  • TTS audio files are always MP3.
  • Voice messages can be MP3, WebM, OGG, or other browser-compatible formats.
Ensure your audio player supports these formats for full compatibility.

Audio playback reference


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.