Skip to content

Instantly share code, notes, and snippets.

@samiuelson
Created May 6, 2020 13:30
Show Gist options
  • Save samiuelson/8569f8eb1bad49b49fdc440315d76d9b to your computer and use it in GitHub Desktop.
Save samiuelson/8569f8eb1bad49b49fdc440315d76d9b to your computer and use it in GitHub Desktop.
class LiveStreamViewModel() : ViewModel() {
private val chatClient = ChatClient.instance()
private val _viewState = MutableLiveData<State>()
private lateinit var channelController: ChannelController
val viewState: LiveData<State> = _viewState
init {
chatClient.setUser(chatUser, USER_TOKEN, object : InitConnectionListener() {
override fun onSuccess(data: ConnectionData) {
channelController = chatClient.channel(CHANNEL_TYPE, CHANNEL_ID)
requestChannel()
subscribeToNewMessageEvent()
}
override fun onError(error: ChatError) {
_viewState.postValue(State.Error("User setting error"))
Timber.e(error)
}
})
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment