WebSocketListenerFlowAdapter

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

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.

Note: this class is not thread-safe. The callbacks must not be called concurrently.

Constructors

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

Properties

Link copied to clipboard

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

Functions

Link copied to clipboard
suspend fun onBinaryMessage(isLast: Boolean = true, writeData: Sink.() -> Unit)
suspend fun onBinaryMessage(bytes: ByteString, 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: ByteString)

Sends a WebSocketFrame.Ping frame with the given bytes to the incomingFrames flow.

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

Sends a WebSocketFrame.Pong frame with the given bytes to the incomingFrames flow.

Link copied to clipboard
suspend fun onTextMessage(isLast: Boolean = true, writeData: Sink.() -> Unit)
suspend fun onTextMessage(text: String, isLast: Boolean = true)

Callback for text messages (potentially partial frames).