Match via WebSocket

Match via WebSocket

Match information available through the Match API endpoint, automatically updated and delivered to your client systems in real-time through WebSocket protocol.

Handling the data received

The Sample snippet below demonstrates how to handle the data received through a simple WebSocket client.

WebSocket

// client.js var io = require('socket.io-client') // connect to roanuz sports server var socket = io.connect('http://socket.sports.roanuz.com/cricket', {path:'/v5/websocket', reconnect: true}) // Add a connect listener socket.on('connect', function (socket) { console.log('Connected!') }) // prepare required data to access the match data var data = {} data.token = 'YOUR_ACCESS_TOKEN' // token data.match_key = 'MATCH_KEY' // match key // emit signal to connect to the room socket.emit('connect_to_match', data) // server emits 'on_match_joined' socket.on('on_match_joined', function (data) { console.log('Cricket match joined!', data.key) }) // the subscribed match content are emitted with 'on_match_update' event // since it's gzipped data, parse it to unzip it socket.on('on_match_update', function (res) { console.log('data received') console.log(JSON.parse(res)) }) // emits 'on_error' on, //match not subscribed socket.on('on_error', function (data) { console.log('not_subscribed', JSON.parse(data)) })
// client.js
var io = require('socket.io-client')
// connect to roanuz sports server
var socket = io.connect('http://socket.sports.roanuz.com/cricket', {path:'/v5/websocket', reconnect: true})

// Add a connect listener
socket.on('connect', function (socket) {
  console.log('Connected!')
})
// prepare required data to access the match data
var data = {}
data.token = 'YOUR_ACCESS_TOKEN' // token
data.match_key = 'MATCH_KEY' // match key
// emit signal to connect to the room
socket.emit('connect_to_match', data)
// server emits 'on_match_joined'
socket.on('on_match_joined', function (data) {
  console.log('Cricket match joined!', data.key)
})
// the subscribed match content are emitted with 'on_match_update' event
// since it's gzipped data, parse it to unzip it
socket.on('on_match_update', function (res) {
  console.log('data received')
  console.log(JSON.parse(res))
})
// emits 'on_error' on,
//match not subscribed
socket.on('on_error', function (data) {
  console.log('not_subscribed', JSON.parse(data))
})
icon copy