WebSocketListenerFlowAdapter

class WebSocketListenerFlowAdapter(bufferSize: Int = Channel.BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND)

Adapter between listener calls and a web socket "incoming" frames flow. This is to make it easier to bridge listener-based APIs with the flow-based API of Krossbow. Methods of this listener never fail, but can send failure through the frames channel to the consumers.

Constructors

Link copied to clipboard
fun WebSocketListenerFlowAdapter(bufferSize: Int = Channel.BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND)

Functions

Link copied to clipboard
suspend fun onBinaryMessage(bytes: ByteArray, isLast: Boolean = true)

Callback for binary messages (potentially partial frames).

Link copied to clipboard
suspend fun onClose(code: Int, reason: String?)

Sends a WebSocketFrame.Close to the incomingFrames flow, and completes it normally.

Link copied to clipboard
fun onError(message: String)

Fails the incomingFrames flow with a WebSocketException with the given message.

fun onError(error: Throwable?)

Fails the incomingFrames flow with a WebSocketException with the given error as cause.

Link copied to clipboard
suspend fun onPing(bytes: ByteArray)

Sends a WebSocketFrame.Ping frame to the incomingFrames flow.

Link copied to clipboard
suspend fun onPong(bytes: ByteArray)

Sends a WebSocketFrame.Pong frame to the incomingFrames flow.

Link copied to clipboard
suspend fun onTextMessage(text: CharSequence, isLast: Boolean = true)

Callback for text messages (potentially partial frames).

Properties

Link copied to clipboard
val incomingFrames: Flow<WebSocketFrame>

The flow of incoming web socket frames. This flow completes when the web socket connection is closed or an error occurs.

Sources

Link copied to clipboard