README.md

# webrtc_signal

Server-side WebRTC signaling over Phoenix Channels.

Channel topic: `webrtc:signal`

Events:

- Client -> Server:
  - `set_id` payload: `{ "public_id": "...", "private_id": "..." }`
  - `handshake` payload: `{ "to": "...", "handshake": <any JSON> }`

- Server -> Client:
  - `handshake` payload: `{ "from": "...", "handshake": <any JSON> }`

SetID returns:
- ok: `{ "result": "ok" }`
- error: `{ "reason": "in-use" }` or `{ "reason": "auth failed" }`

Handshake returns:
- ok: `{ "result": "delivered" }`
- error: `{ "reason": "user not found" }`

## Integrate into a Phoenix app

In your Endpoint (e.g. `lib/my_app_web/endpoint.ex`), add:

```elixir
socket "/webrtc_socket", WebrtcSignal.Socket,
  websocket: true,
  longpoll: false
```

Then your client connects to:

```
ws://HOST/webrtc_socket
wss://HOST/webrtc_socket
```

When you run multiple BEAM nodes, make sure they are connected via distributed Erlang so `:global` can see registrations across the cluster.