EXAMPLES
Listening Some BetVision Events
An example of an Event listener loading the auth token and listening for betslip interaction You need to have a listener to receive the events that the Multibet Widget will send When the player sends their bet in the "Add to betslip" action.
An example of how the code will look that listens to the video player events:
window.addEventListener('geniussportsmessagebus', async (event: Event) => {
let typedEvent = event as unknown as GeniusSportsEvent
if (typedEvent.detail.type = 'multibet-event') {
switch(typedEvent.detail.body.command) {
case "addToBetslip":
/**
* {
* command: 'addToBetslip',
* sportsbookMarketContext: tradingPlatformMetadata,
* sportsbookFixtureId: tradingPlatformFixtureId,
* sportsbookMarketId: tradingPlatformId,
* marketId: id,
* decimalPrice: totalOdds
* }
*/
break;
case "removeFromBetslip":
break;
case "placeBet":
/**
* {
* command: 'placeBet',
* sportsbookMarketContext: tradingPlatformMetadata,
* sportsbookFixtureId: tradingPlatformFixtureId,
* sportsbookMarketId: tradingPlatformId,
* marketId: id,
* decimalPrice: totalOdds,
* stake: 100
* }
*/
}
} else if (typedEvent.detail.type === 'player_ready') {
const playerReadyEvent = typedEvent as PlayerReadyEvent
const deliveryType = playerReadyEvent.detail.body.deliveryType
const streamId = playerReadyEvent.detail.body.streamId
const deliveryId = playerReadyEvent.detail.body.deliveryId
const geniusSportsFixtureId = playerReadyEvent.detail.body.geniusSportsFixtureId
const dataToPost = {
endUserSessionId: document.cookie, //user session id
region: 'CO', //region
device: 'DESKTOP', //device
}
postData(
`${domain}/v3/fixtures/${geniusSportsFixtureId}/live-streams/${streamId}/deliveries/${deliveryType}/${deliveryId}`,
dataToPost
)
.then((data) => {
console.log('Token data arrived', JSON.stringify(data))
// @ts-ignore
GeniusLivePlayer.player.start(data)
})
.catch((error) => {
console.error(error)
})
}
})
async function postData(url = '', data = { }) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'include', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer',
body: JSON.stringify(data),
})
return response.json()
}