anydrop/docs/signaling-protocol.md
ordinarthur 9d6e4da4ae
Some checks failed
Build & Deploy / build-and-deploy (push) Failing after 8s
feat: initial commit with full deployment setup
Includes React PWA frontend, WebSocket signaling server, shared types,
K8s manifests, Gitea CI/CD workflow, nginx config, and Dockerfiles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 10:30:45 +02:00

124 lines
2.5 KiB
Markdown

# Protocole de signaling AnyDrop
Protocole simple en JSON via WebSocket. Endpoint : `wss://ws.anydrop.arthurbarre.fr`.
Tous les messages ont un champ `type`. Les types côté client et côté serveur sont définis dans `shared/protocol.ts`.
## Messages client → serveur
### `hello`
Envoyé immédiatement après connexion. Si `joinCode` est présent, le client rejoint la room publique correspondante. Sinon il est placé dans la room LAN basée sur son IP publique.
```json
{
"type": "hello",
"joinCode": "x7k" // optionnel
}
```
### `create-public-room`
Demande la création d'une room publique avec un code court.
```json
{ "type": "create-public-room" }
```
### `signal`
Relaie un message WebRTC (offer, answer, ICE candidate) vers un autre pair de la même room.
```json
{
"type": "signal",
"to": "b2",
"data": { /* SDP ou ICE */ }
}
```
### `leave`
Le client annonce qu'il quitte (optionnel, sinon détecté par fermeture WebSocket).
```json
{ "type": "leave" }
```
## Messages serveur → client
### `welcome`
Réponse au `hello`. Fournit l'identité du client.
```json
{
"type": "welcome",
"peerId": "a1",
"displayName": "Renard Bleu",
"roomId": "lan:abc123",
"peers": [
{ "peerId": "b2", "displayName": "Tigre Rouge" }
]
}
```
### `public-room-created`
Réponse à `create-public-room`.
```json
{
"type": "public-room-created",
"code": "x7k",
"url": "https://anydrop.arthurbarre.fr/x7k",
"expiresAt": "2026-04-14T18:30:00Z"
}
```
### `peer-joined`
Un nouveau pair rejoint la room.
```json
{
"type": "peer-joined",
"peerId": "c3",
"displayName": "Ours Vert"
}
```
### `peer-left`
Un pair a quitté.
```json
{
"type": "peer-left",
"peerId": "c3"
}
```
### `signal`
Relai d'un message WebRTC reçu d'un autre pair.
```json
{
"type": "signal",
"from": "a1",
"data": { /* SDP ou ICE */ }
}
```
### `error`
Erreur générique.
```json
{
"type": "error",
"code": "room-not-found" | "room-expired" | "rate-limit",
"message": "..."
}
```
## Règles serveur
- Un client peut appartenir à **1 room LAN + 0 ou 1 room publique** simultanément.
- Un message `signal` n'est relayé que si `to` est dans au moins une des rooms du sender.
- Une room publique expire après **10 minutes sans nouveau message**.
- Le code court est généré dans l'alphabet `abcdefghjkmnpqrstuvwxyz23456789` (exclut `iloLIO01` pour lisibilité).
- Longueur par défaut : **3 caractères** ; si collision, essayer 5 fois puis passer à **4 caractères**.
- Rate limit : 10 connexions/minute par IP, 100 messages/minute par connexion.