trait WebSocket[F[_]] extends AnyRef
Effectful interactions with a web socket. Interactions can happen:
- on the frame level, by sending and receiving raw WebSocketFrame s
- using the provided
receive*
methods to obtain concatenated data frames, or string/byte payloads, and thesend*
method to send string/binary frames.
The send*
and receive*
methods may result in a failed effect, with either one of WebSocketException
exceptions, or a backend-specific exception. Specifically, they will fail with WebSocketClosed if the web socket
is closed.
See the either
and eitherClose
method to lift web socket closed events to the value level.
- Alphabetic
- By Inheritance
- WebSocket
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
- abstract def isOpen(): F[Boolean]
- implicit abstract def monad: MonadError[F]
-
abstract
def
receive(): F[WebSocketFrame]
Receive the next frame from the web socket.
Receive the next frame from the web socket. This can be a data frame, or a control frame including WebSocketFrame.Close. After receiving a close frame, no further interactions with the web socket should happen.
However, not all implementations expose the close frame, and web sockets might also get closed without the proper close frame exchange. In such cases, as well as when invoking
receive
/send
after receiving a close frame, this effect will fail with the WebSocketClosed exception.*Should be only called sequentially!* (from a single thread/fiber). Because web socket frames might be fragmented, calling this method concurrently might result in threads/fibers receiving fragments of the same frame.
-
abstract
def
send(f: WebSocketFrame, isContinuation: Boolean = false): F[Unit]
Sends a web socket frame.
Sends a web socket frame. Can be safely called from multiple threads.
May result in a failed effect, in case of a network error, or if the socket is closed.
- abstract def upgradeHeaders: Headers
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
def
close(): F[Unit]
Idempotent when used sequentially.
-
def
either[T](f: ⇒ F[T]): F[Either[Option[Close], T]]
Returns an effect computing a:
Returns an effect computing a:
Left
if the web socket is closed - optionally with the received close frame (if available).Right
with the original result otherwise.
Will never fail with a WebSocketClosed.
- f
The effect describing web socket interactions.
-
def
eitherClose[T](f: ⇒ F[T]): F[Either[Close, T]]
Extracts the received close frame (if available) as the left side of an either, or returns the original result on the right.
Extracts the received close frame (if available) as the left side of an either, or returns the original result on the right.
Will fail with WebSocketClosed if the web socket is closed, but no close frame is available.
- f
The effect describing web socket interactions.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
receiveBinary(pongOnPing: Boolean): F[Array[Byte]]
Receive a single binary message (which might come from multiple, fragmented frames).
Receive a single binary message (which might come from multiple, fragmented frames). Ignores non-binary frames and returns combined results. Will fail with WebSocketClosed if the web socket is closed, or if a close frame is received.
*Should be only called sequentially!* (from a single thread/fiber).
- pongOnPing
Should a WebSocketFrame.Pong be sent when a WebSocketFrame.Ping is received.
-
def
receiveBinaryFrame(pongOnPing: Boolean = true): F[Binary]
Receive a single binary data frame, ignoring others.
Receive a single binary data frame, ignoring others. The frame might be a fragment. To receive whole messages, use receiveBinary. Will fail with WebSocketClosed if the web socket is closed, or if a close frame is received.
*Should be only called sequentially!* (from a single thread/fiber).
- pongOnPing
Should a WebSocketFrame.Pong be sent when a WebSocketFrame.Ping is received.
-
def
receiveDataFrame(pongOnPing: Boolean = true): F[Data[_]]
Receive a single data frame, ignoring others.
Receive a single data frame, ignoring others. The frame might be a fragment. Will fail with WebSocketClosed if the web socket is closed, or if a close frame is received.
*Should be only called sequentially!* (from a single thread/fiber).
- pongOnPing
Should a WebSocketFrame.Pong be sent when a WebSocketFrame.Ping is received.
-
def
receiveText(pongOnPing: Boolean = true): F[String]
Receive a single text message (which might come from multiple, fragmented frames).
Receive a single text message (which might come from multiple, fragmented frames). Ignores non-text frames and returns combined results. Will fail with WebSocketClosed if the web socket is closed, or if a close frame is received.
*Should be only called sequentially!* (from a single thread/fiber).
- pongOnPing
Should a WebSocketFrame.Pong be sent when a WebSocketFrame.Ping is received.
-
def
receiveTextFrame(pongOnPing: Boolean = true): F[Text]
Receive a single text data frame, ignoring others.
Receive a single text data frame, ignoring others. The frame might be a fragment. To receive whole messages, use receiveText. Will fail with WebSocketClosed if the web socket is closed, or if a close frame is received.
*Should be only called sequentially!* (from a single thread/fiber).
- pongOnPing
Should a WebSocketFrame.Pong be sent when a WebSocketFrame.Ping is received.
-
def
sendBinary(payload: Array[Byte]): F[Unit]
Sends a web socket frame with the given payload.
Sends a web socket frame with the given payload. Can be safely called from multiple threads.
May result in a failed effect, in case of a network error, or if the socket is closed.
-
def
sendText(payload: String): F[Unit]
Sends a web socket frame with the given payload.
Sends a web socket frame with the given payload. Can be safely called from multiple threads.
May result in a failed effect, in case of a network error, or if the socket is closed.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated