1.4 KiB
1.4 KiB
An Introduction to the Client
The taClient(client for short) is how most of the actions will be carried out. It is used when you want to query the database, connect to servers, and listen to things that are not saved in the state, such as live data
The stateManager is the way you would fetch tournaments, get matches, or do anything related to getting specific data that does not require a database query. It is best if you are familiar with what methods it has and how you can use them.
For the ease of this explanation let me provide an example:
onMount(async() => {
// Check if the user is logged in
if ($authTokenStore) {
// Using the client listen to events that will not be stored in the state, such as scores and song finish events
client.on('realtimeScore', handleRealtimeScoreUpdate);
client.on('songFinished', handleSongFinished);
} else {
// If the user is not authenticated, they will be thrown to the discord authentication page
window.location.href = "/discordAuth"
}
});
onDestroy(() => {
// Remove the listeners that were added on mount
client.removeListener('realtimeScore', handleRealtimeScoreUpdate);
client.removeListener('songFinished', handleSongFinished);
});
info
Example: This is an example from the page of ShyyTAUI within the match coorination page.