This guide will help you integrate the Virtual Stadium Data SDK into your application and get up and running quickly.
To integrate the Virtual Stadium Data SDK:
LoginManagerChatManagerThis guide walks you through each step with complete code examples.
SDK Version Requirements
Authentication
The SDK uses Koin for dependency injection and is automatically initialized when you start using any services.
Complete the Installation & Setup guide before proceeding.
Before using any chat functionality, you must authenticate with a JWT token using LoginManager.
Monitor the loginState flow to track authentication status and handle different login states (LOGGED_IN, ERROR, LOADING, LOGGED_OUT).
All SDK features require successful authentication. Ensure login completes before initializing chat channels.
class MainViewModel : ViewModel(), KoinComponent {
private val loginManager: LoginManager by inject()
fun initialize() {
// Monitor login state
loginManager.loginState.collect { loginState ->
when (loginState.loginStatus) {
LoginStatus.LOGGED_IN -> {
// SDK is ready to use
initializeChat()
}
LoginStatus.ERROR -> {
// Handle login error
handleLoginError(loginState.loginError)
}
// Handle other states...
}
}
// Perform login
loginManager.login("YOUR_JWT_TOKEN")
}
}Once authenticated, create and manage chat channels using ChatManager.
Use getOrAddChannel() to get an existing channel or create a new one. The method returns a ChatChannel instance for message operations.
Subscribe to various state flows:
class ChatViewModel : ViewModel(), KoinComponent {
private val chatManager: ChatManager
get() = get()
val userProvider: UserProvider
get() = get()
private val settingsProvider: SettingsProvider
get() = get()
private val channel: ChatChannel? = null
val chatSettingState: StateFlow<ChatSettings> by lazy { settingsProvider.settings }
fun initializeChannel(channelId: String) {
//Initializing channel and states!"
channel = chatManager.getOrAddChannel(channelId = channelId, getChannelStats = true)
}
fun loadPreviousPage() {
channel?.loadPreviousPage()
}
fun sendMessage(message: String) {
channel?.sendMessage(message)
}
fun replyToMessage(messageId: String, message: String) {
channel?.replyToMessage(message, messageId)
}
fun toggleReactionOnMessage(reaction: ReactionType, message: Message) {
channel?.toggleReactionOnMessage(message, reaction)
}
fun addReaction(reaction: ReactionType, message: Message) {
channel?.reactToMessage(message, reaction)
}
fun reportMessage(messageId: String, reportedSuccessfully: (Boolean) -> Unit) {
channel?.reportMessage(
messageId = messageId,
onSuccess = { reportedSuccessfully(true) },
onFailure = { reportedSuccessfully(false) },
)
}
fun shareNewBet(
betPayload: BetPayload,
showStake: Boolean,
comment: String,
) {
channel.value?.shareBet(
betPayload = betPayload,
comment = comment,
showStake = showStake,
onSuccess = {
//Successfully shared a bet
},
onFailure = {
//Failed to share bet
},
)
}
fun getAllBetShares() {
channel?.getAllBetShares()
}
fun loadMoreBetShares() {
channel?.loadMoreMyBetShares()
}
fun getMyBetShares() {
channel?.getMyBetShares()
}
fun loadMoreMyBetShares() {
channel?.loadMoreMyBetShares()
}
fun copySharedBet(messageId: String) {
channel?.copySharedBet(messageId)
}
fun filterTags(query: String) {
channel?.filterTags(query)
}
fun stopChannel(channelId: String) {
// Clear channel and states
chatManager.removeChannel(channelId)
channel = null
}
fun restartChannel() {
channel?.restart()
}
}Now you can perform basic chat operations using the ChatChannel instance.
Common operations include:
// Send a message
fun sendMessage(text: String) {
channel?.sendMessage(
message = text,
onFailure = {
// Handle send failure
}
)
}
// React to a message
fun reactToMessage(message: Message, reactionType: ReactionType) {
channel?.toggleReactionOnMessage(message, reactionType)
}
// Load previous messages
fun loadPreviousPage() {
channel?.loadPreviousPage()
}Here's the recommended integration flow:
LoginManagerChatManager.getOrAddChannel()Review all available services and their purposes.
Learn about login and user state management.
Explore messaging, reactions, and bet sharing.