Skip to content

Commit ab86933

Browse files
committed
update README for new api
1 parent 3ba3301 commit ab86933

File tree

4 files changed

+73
-15
lines changed

4 files changed

+73
-15
lines changed

README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ var pc = new RTCPeerConnection({
4545
});
4646
```
4747

48-
The [example directory](https://github.com/lambdaclass/webrtc-server/tree/master/example)
49-
contains a full Cowboy application using `webrtc_server` and a simple
48+
The [examples/simple](https://github.com/lambdaclass/webrtc-server/tree/master/examples/simple)
49+
directory contains a full Cowboy application using `webrtc_server` and a
5050
browser client that establishes a WebRTC connection using the
5151
Signaling and ICE servers.
5252

@@ -106,6 +106,13 @@ Both callbacks receive the same arguments:
106106
`infinity` to disable idle timeouts.
107107

108108
## Signaling API reference
109+
110+
The signaling API is used by web socket clients to exchange the
111+
necessary information to establish a WebRTC peer connection. See
112+
the
113+
[examples](https://github.com/lambdaclass/webrtc-server/tree/master/examples)
114+
for context on how this API is used.
115+
109116
### Authentication
110117
After connection, an authentication JSON message should be sent:
111118

@@ -119,23 +126,71 @@ After connection, an authentication JSON message should be sent:
119126
}
120127
```
121128

122-
The server will reply with this payload:
129+
The server will assign a `peer_id` to the client and reply:
130+
131+
``` json
132+
{
133+
"event": "authenticated",
134+
"data": {
135+
"peer_id": "bxCBrwyL3Ar7Nw=="
136+
}
137+
}
138+
```
139+
140+
The rest of the peers in the room will receive a `joined` event:
123141

124142
``` json
125143
{
126144
"event": "joined",
127145
"data": {
128146
"username": "john",
129-
"peer_id": "bxCBrwyL3Ar7Nw==",
130-
"peers": ["7nN1q/qarRnejQ=="]
147+
"peer_id": "bxCBrwyL3Ar7Nw=="
148+
}
149+
}
150+
```
151+
152+
Similarly, when a client leaves the room, the rest of the peers will
153+
receive a `left` event:
154+
155+
``` json
156+
{
157+
"event": "left",
158+
"data": {
159+
"username": "john",
160+
"peer_id": "bxCBrwyL3Ar7Nw=="
131161
}
132162
}
133163
```
134164

135-
### Room messages
165+
### Signaling messages
166+
167+
After authentication, all messages sent by the client should be
168+
signaling messages addressed to a specific peer in the room, including a `to`
169+
field. The event and data are opaque to the server (they can be
170+
ice candidates, session descriptions, or whatever clients need to
171+
exchange). For example:
136172

137-
After authentication, any (non ping) message sent will be forwarded to
138-
the rest of the clients connected to the room.
173+
``` json
174+
{
175+
"event": "candidate",
176+
"to": "458/53WAkeu+tQ==",
177+
"data": {
178+
...
179+
}
180+
}
181+
```
182+
183+
The addressed peer will receive this payload:
184+
185+
``` json
186+
{
187+
"event": "candidate",
188+
"from": "bxCBrwyL3Ar7Nw==",
189+
"data": {
190+
...
191+
}
192+
}
193+
```
139194

140195
### Ping
141196
To send a keepalive message to prevent idle connections to be droped

examples/multi/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# WebRTC example
2-
3-
Simple Cowboy application that serves an HTML client for WebRTC.
4-
Connections are established by two peers that enter in the same room URL.
5-
The client connects to the signaling and ICE servers provided by webrtc_server.
1+
# WebRTC multi-party example
2+
3+
Cowboy application that serves an HTML client for WebRTC.
4+
An unlimited number of peers can join a conversation by entering the
5+
same room URL.
6+
A mesh topology is used, meaning that if there are N peers, each one
7+
will maintain N - 1 RTC peer connections. This is CPU intensive and
8+
will work with a low number of peers.
69

710
## Run in development
811

examples/simple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# WebRTC example
1+
# WebRTC simple example
22

33
Simple Cowboy application that serves an HTML client for WebRTC.
44
Connections are established by two peers that enter in the same room URL.

src/webrtc_ws_handler.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ join_room(Room, Username, PeerId) ->
128128
run_callback(join_callback, Room, Username, OtherNames),
129129

130130
%% broadcast peer joined to the rest of the peers in the room
131-
Message = reply_text(joined, #{peer_id => PeerId}),
131+
Message = reply_text(joined, #{peer_id => PeerId, username => Username}),
132132
lists:foreach(fun({Pid, _}) -> Pid ! Message end, OtherMembers).
133133

134134
run_callback(Type, Room, Username, CurrentUsers) ->

0 commit comments

Comments
 (0)