WebSockets are used for sending signals from the tracks during races. These are for time critical data that need to be sent with low latency, and does not need to be persisted. Only the transient channels listed on the channels list are sent over WebSockets. These channels include countdown timers, lap times and disqualifications.
STOMP (Simpe Text Oriented Message Protocol) is used as the communications protocol over the WebSockets. You can find STOMP complient client libraries for many popular languages here.
You will need to pass a valid authentication token when connecting to the endpoint. Data will only be delivered while races are ongoing. It’s recommended that you will create a new connection with a fresh authentication token every day. After 22:00 every night, no more data will be transferred until next day when the first races start.
wss://api.travsport.se/customerapi/channels/connect
/customerapi/channels/user/topic/publish
authorization (required) string - Bearer token
TimeToStart
TimeToDef
SplitTimes
PrelDisqualifiedHorses
Last500Meters
Node.js: https://github.com/Troperty/racedata-node-samples
const ws = new WebSocket(wsUrl, null, {
headers: {
authorization: `Bearer ${authToken}`
}
});
const stompClient = Stomp.over(ws);
stompClient.connect({}, onConnected, onConnectionError);
stompClient.subscribe(topic, onMessage);
// Receive a STOMP message from the server
const onMessage = (message) => {
if (message.body) {
const data = JSON.parse(message.body);
console.log(data.payload);
} else {
console.log('Received empty message');
}
};