Skip to content

Instantly share code, notes, and snippets.

@raystatic
Last active June 12, 2023 17:54
Show Gist options
  • Save raystatic/4105c28bf88c25ab2d80f34562b99082 to your computer and use it in GitHub Desktop.
Save raystatic/4105c28bf88c25ab2d80f34562b99082 to your computer and use it in GitHub Desktop.
private val sseClient = OkHttpClient.Builder()
.connectTimeout(6, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.MINUTES)
.writeTimeout(10, TimeUnit.MINUTES)
.build()
private val sseRequest = Request.Builder()
.url(EVENTSURL)
.header("Accept", "application/json")
.addHeader("Accept", "text/event-stream")
.build()
private val sseEventSourceListener = object : EventSourceListener() {
override fun onClosed(eventSource: EventSource) {}
override fun onEvent(eventSource: EventSource, id: String?, type: String?, data: String) { }
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {}
override fun onOpen(eventSource: EventSource, response: Response) {}
}
private fun initEventSource() {
EventSources.createFactory(sseClient)
.newEventSource(request = sseRequest, listener = sseEventSourceListener)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment