ThrillConnect JS Client
ThrillConnect Client is the glue that connects your Portal and ThrillTech systems to provide seamless experience for your players. It is designed with minimialistic, yet powerful API, that can be easily consumed and covers all the narrow and tricky edgecases of the frontend integration. It's purpose is to make your frontend development trivial and expose the full API surface with minimum effort.
On this page you can find all the relevant details on how to use the Client, as well as examples and use cases.
Client version will be aligned with service version and just like that you'll be subscribed to all the latest and greatest features of our platform.
Source
Source code is avaiable for review & fork for all ThrilTech customers. You can find the client at https://github.com/thrilltech-io/connect-client.
Initialization
Client constructor needs the host address and BrandContext. Player context can optionally be passed on initialization or later on via authenticate
method.
Additionally one can specify dev options, like the use of unsecure http/ws and client internal logs for dev convenience.
All the events of interest must be passed on to the constructor in the events
array so that client can subscribe to relevant systems on the WS channel.
Player context
Player context type provides all necessary player details for establishing the WSS connection and interacting with the Jackpots from player perspective.
type PlayerContext = {
id: string,
token: string,
currency: string,
country: string,
}
Initialization without player context
Prior to having a valid player session and auth token, one can initialize the client without PlayerContext. In this limited mode the WS events will not be available and only public REST endpoints can be used to make requests. ( see API section for what is available )
import { ThrillConnect, ConnectEvents } from "./thrillconnect.js"
const client = new ThrillConnect({
host: "localhost:11000",
brand: {
operator_id: "thrilltech",
brand_id: "brand1",
},
dev: {
secure: false
},
events: [
ConnectEvents.JackpotUpdateEvent,
ConnectEvents.RaffleWinEvent,
ConnectEvents.JackpotWinEvent,
ConnectEvents.OptInEvent,
]
})
Later on, once we have player details, we can authenticate and subscribe to full functionality of the client.
client.authenticate({
id: "player_id_token_00001",
token: "token_00001",
country: "USA",
currency: "USD",
})
Initialization with player context
Alternatively, if player details are known from the start, those can be passed directly to the client constructor.
const client = new ThrillConnect({
host: "localhost:11000",
player: {
id: "player_00001",
token: "token_00001",
country: "USA",
currency: "USD",
},
brand: {
operator_id: "thrilltech",
brand_id: "brand1",
},
dev: {
secure: false
},
events: [
ConnectEvents.JackpotUpdateEvent,
ConnectEvents.RaffleWinEvent,
ConnectEvents.JackpotWinEvent,
ConnectEvents.OptInEvent,
]
})
API
Following is a list of all the available methods on connect client.
Adding an event listener
client.on(ConnectEvent, handler)
Adding an once off event listener
client.once(ConnectEvent, handler)
Removing an event listener
client.off(ConnectEvent, handler)
Passing player context
client.authenticate(PlayerContext)
Fetching the currency multipliers
const multipliers = await client.request().getCurrencies()
Fetching the list of defined sources for the provided BrandContext
const sources = await client.request().getSources()
Getting the Jackpot instance that maps to a source
const sourceId = "sitewide-jackpot"
const instance = await client.request().getJackpotForSource(sourceId)
Getting the player OptIn status for a source
Note: PlayerContext is required for this request.
const sourceId = "sitewide-jackpot"
const status = await client.request().getOptInStatusForSource(sourceId)
Opting in/out from a source
Note: PlayerContext is required for this request. This request uses the authenticated WS channel. When jackpot allows for variable contribution, preferred contribution value can be passed as 3 parameter.
const sourceId = "sitewide-jackpot"
const optIn = true
const preferredContributionValue = undefined
client.request().optIntoSource(sourceId, optIn, preferredContributionValue)
Opting in/out from an instance
Note: PlayerContext is required for this request. This request uses the authenticated WS channel. When jackpot allows for variable contribution, preferred contribution value can be passed as 3 parameter.
const instanceId = "dd7243ea-9992-47ae-a2a6-531b3f0e2197"
const optIn = true
const preferredContributionValue = undefined
client.request().optIntoInstance(instanceId, optIn, preferredContributionValue)
Events
Client receives events via the WS connection. In order to receive an event, it needs to explicitly be listed in the list of events in the Client constructor.
All the available events are listed in ConnectEvents
.
import { ConnectEvents } from "./thrillconnect.js"
function updateTickers(e:JackpotUpdateEvent) {
console.log(e.status)
}
// subscribe to Jackpot updates
client.on(ConnectEvents.JackpotUpdateEvent, updateTickers)
// unsubscribe from Jackpot updates
client.off(ConnectEvents.JackpotUpdateEvent, updateTickers)