Last active
June 12, 2023 17:54
-
-
Save raystatic/4105c28bf88c25ab2d80f34562b99082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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