WebSockets
WebSockets allow real-time updates by enabling a two-way communication channel. To access WebSockets, ensure you have added the WebSockets add-on to your subscription plan during the subscription setup process.
Available WebSocket Data Types
We offer WebSocket connections for the following data types, each providing specific updates in real-time:
1. Score Updates - ws://snooker.sportdevs.com/live/score?token={api-key}
{
"sport": "",
"match_id": "",
"score": "",
"period_1": "",
"period_2": "",
"overtime": "",
"penalties": "",
"series": "",
"aggregated": "",
"extra1": "",
"extra2": "",
"team": ""
}
2. Time Updates - ws://snooker.sportdevs.com/live/time?token={api-key}
{
"sport": "",
"match_id": "",
"specific_start_time": "",
"period_1": "",
"period_2": "",
"period_3": "",
"period_4": ""
}
3. Match Status Updates - ws://snooker.sportdevs.com/live/status?token={api-key}
{
"sport": "",
"match_id": "",
"type": "",
"reason": ""
}
Using WebSockets for Real-Time Updates
Example: Subscribing to Updates by Data Type
To receive updates for a specific data type, use the following code:
WebSockets Example:
const ws = new WebSocket('wss://snooker.sportdevs.com/live/{type}?token={api-key}', ['updates']);
ws.addEventListener('message', ev => console.log(ev.data));
Server-Sent Events Example:
const es = new EventSource('https://snooker.sportdevs.com/live/{type}?token={api-key}');
es.addEventListener('message', ev => console.log(ev.data));
Example: Subscribing to Updates for a Specific Event ID
To track changes for a particular event ID, use the following code:
WebSockets Example:
const ws = new WebSocket('wss://snooker.sportdevs.com/live/{type}/1?token={api-key}', ['updates']);
ws.addEventListener('message', ev => console.log(ev.data));
Server-Sent Events Example:
const es = new EventSource('https://snooker.sportdevs.com/live/{type}/1?token={api-key}');
es.addEventListener('message', ev => console.log(ev.data));
Additional Information
For more details about working with WebSockets and Server-Sent Events, visit the MDN Web Docs on EventSource.