Skip to content

Instantly share code, notes, and snippets.

@hiteshchopra11
Created April 23, 2022 19:42
Show Gist options
  • Save hiteshchopra11/4f85298955711e52df4bd6e016528f61 to your computer and use it in GitHub Desktop.
Save hiteshchopra11/4f85298955711e52df4bd6e016528f61 to your computer and use it in GitHub Desktop.
EventSourceListener
val eventSourceListener = object : EventSourceListener() {
override fun onOpen(eventSource: EventSource, response: Response) {
super.onOpen(eventSource, response)
Log.d(MainActivity.TAG, "Connection Opened")
}
override fun onClosed(eventSource: EventSource) {
super.onClosed(eventSource)
Log.d(MainActivity.TAG, "Connection Closed")
}
override fun onEvent(
eventSource: EventSource,
id: String?,
type: String?,
data: String
) {
super.onEvent(eventSource, id, type, data)
Log.d(MainActivity.TAG, "On Event Received! Data -: $data")
}
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {
super.onFailure(eventSource, t, response)
Log.d(MainActivity.TAG, "On Failure -: ${response?.body}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment