# Send messages on the socket (https://orgasm.dev/docs/events/receiveSocketMessages)

# Send messages on the socket

`receive`, channel Live session socket: `wss://orgasm.dev/v1/live-sessions/{sessionId}/ws`

orgasm.dev receives stimulation reports and resume requests over the WebSocket.

`stimulation` is the socket form of `POST /v1/live-sessions/{sessionId}/stimulation`. `resume` replays events after the given `id` without reconnecting.

Connect with `?token=` and the session's client token, or an
`Authorization` header with the secret key or the client token where
your client can set one. View tokens read the stream instead, since
they never go in a URL. Add `?after=` to replay from an event,
`?types=` to filter, and `?frames=face` for `face.frame`. orgasm.dev
sends each event as one JSON text frame, in `sequence` order. A socket
counts toward the session's 12 streams; another is refused with a
`socket.error` (`rate_limited`) and closed.

The client may send `stimulation` reports and a `resume` request;
anything else is answered with a `socket.error` frame and the socket
stays open. The server closes the socket with code 1000 after the
final `session.status`, and with 1008 when its token stops working.

## Messages

### `stimulation`: Stimulation report

The client reports that stimulation started, stopped or changed.

A stimulation report, as on `POST /v1/live-sessions/{sessionId}/stimulation`: every field but `state` is optional, one you omit keeps the value you last reported, and `null` clears it. Each reaches the session's readers as `stimulation.updated`.

Fields:

- `action` (`"stimulation"`, required)
- `state` (`on` | `off`, required)
- `intensity` (number | null)
- `level` (number | null)
- `levelMax` (number | null)
- `channels` (array | null)
- `mode` (string | null)
- `modeLabel` (string | null)
- `device` (any)
- `drive` (`auto` | `manual` | `hold` | `paused` | `null`)
- `streamTimeS` (number)

Example (Stimulation started at 40 % intensity.):

```json
{
  "action": "stimulation",
  "state": "on",
  "intensity": 0.4
}
```

### `resume`: Resume

The client asks for missed events again.

Ask for every event after `after` to be sent again, in order.

Fields:

- `action` (`"resume"`, required)
- `after` (string, required)

Example (Replay everything after the onset call.):

```json
{
  "action": "resume",
  "after": "evt_4q7m2k9x8w1c3n6b5v0z"
}
```