Skip to content

Commit 85fe7a4

Browse files
committed
WS close docs
1 parent 6eca650 commit 85fe7a4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/endpoint/websockets.md

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ When creating a `webSocketBody`, we need to provide the following parameters:
3434
By default, ping-pong frames are handled automatically, fragmented frames are combined, and close frames aren't
3535
decoded, but this can be customised through methods on `webSocketBody`.
3636

37+
## Close frames
38+
39+
If you are using the default codecs between `WebSocketFrame` and your high-level types, and you'd like to either be
40+
notified that a websocket has been closed by the client, or close it from the server side, then you should wrap your
41+
high-level type into an `Option`.
42+
43+
The default codecs map close frames to `None`, and regular (decoded text/binary) frames to `Some`. Hence, using the
44+
following definition:
45+
46+
```scala
47+
webSocketBody[Option[String], CodecFormat.TextPlain, Option[Response], CodecFormat.Json](PekkoStreams)
48+
```
49+
50+
the websocket-processing pipe will receive a `None: Option[String]` when the client closes the web socket. Moreover,
51+
if the pipe emits a `None: Option[Response]`, the web socket will be closed by the server.
52+
3753
## Raw web sockets
3854

3955
Alternatively, it's possible to obtain a raw pipe transforming `WebSocketFrame`s:

0 commit comments

Comments
 (0)