Skip to content

Commit

Permalink
Improve socket.md documentation (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruurtjan authored Nov 16, 2022
1 parent 6229ad8 commit cac1e98
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/v1.x/dsl/socket/socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ a `Response` we return `Unit`, because we use the channel (which is available in

## Channel

Essentially whenever there is a connection created between a server and client a channel is created on both sides. The
Essentially, whenever there is a connection created between a server and client a channel is created on both sides. The
channel is a low level api that allows us to send and receive arbitrary messages.

When we upgrade a Http connection to WebSocket, we create a specialized channel that only allows websocket frames to be
sent and received. The access to channel is available thru the `ChannelEvent` api.
sent and received. The access to channel is available through the `ChannelEvent` api.

## ChannelEvents

A `ChannelEvent` is an immutable, type-safe representation of an event that's happened on a channel and it looks like
this
A `ChannelEvent` is an immutable, type-safe representation of an event that's happened on a channel, and it looks like
this:

```scala
case class ChannelEvent[A, B](channel: Channel[A], event: Event[B])
```

It contains two elements — The **Channel** on which the event was triggered and the actual **Event** that was triggered.
It contains two elements — The **Channel** on which the event was triggered, and the actual **Event** that was triggered.
The
type param `A` on the Channel represents the kind of message one can **write** using the channel and the type param `B`
type param `A` on the Channel represents the kind of message one can **write** using the channel, and the type param `B`
represents the kind of messages that can be received on the channel.

The type `WebSocketChannelEvent` is a type alias to `ChannelEvent[WebsocketFrame, WebSocketFrame]`. Meaning a channel
that only accepts `WebSocketFrame` and produces `WebSocketFrame` type of messages.
that only accepts and produces `WebSocketFrame` typed messages.

## Using `Http`

Expand All @@ -56,7 +56,7 @@ only interested in the `ChannelRead` event. There are other life cycle events su
and `ChannelUnregistered` that one might want to hook onto for some other use cases.

The main benefit of using `Http` is that one can write custom middlewares that can process incoming and outgoing
messages easily, for eg:
messages, for example:

```scala
val userAction = Http.collect[ChannelEvent[Action, Command]] {
Expand All @@ -71,7 +71,7 @@ val socket = userAction @@ codec

## SocketApp

The `Http` that accepts `WebSocketChannelEvent` isn't enough to create a websocket connection. There some other settings
The `Http` that accepts `WebSocketChannelEvent` isn't enough to create a websocket connection. There are some other settings
that one might need to configure in a websocket connection, things such as `handshakeTimeout` or `subProtocol` etc. For
those purposes a Http of the type `Http[R, E, WebSocketChannelEvent, Unit]` needs to converted into a `SocketApp` using
the `toSocketApp` method first, before it can be sent as a response. Consider the following example where we set a few
Expand Down

0 comments on commit cac1e98

Please sign in to comment.