Skip to main content

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://badminton.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://badminton.sportdevs.com/live/time?token={api-key}

{
"sport": "",
"match_id": "",
"specific_start_time": "",
"period_1": "",
"period_2": "",
"period_3": "",
"period_4": ""
}

3. Incident Updates - ws://badminton.sportdevs.com/live/incident?token={api-key}

{
"sport": "",
"match_id": "",
"type": "",
"text": "",
"home_score": "",
"away_score": "",
"is_live": "",
"added_time": "",
"length": "",
"player_id": "",
"player_name": "",
"player_hash_image": "",
"reason": "",
"is_home": "",
"class": "",
"player_in_id": "",
"player_in_hash_image": "",
"player_out_id": "",
"player_out_name": "",
"player_out_hash_image": "",
"assist1_id": "",
"assist1_name": "",
"assist1_hash_image": "",
"assist2_id": "",
"assist2_name": "",
"assist2_hash_image": "",
"reversed_period_time": "",
"reversed_period_time_seconds": ""
}

4. Match Status Updates - ws://badminton.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://badminton.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://badminton.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://badminton.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://badminton.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.