Skip to content

Commit b0b4ed4

Browse files
Update README.md
1 parent bd25bde commit b0b4ed4

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,66 @@ You can use open source as well as paid STUN & TURN Services such as:
141141
- [STUNTMAN Open Source STUN Server Project](https://github.com/jselbie/stunserver)
142142
- [Twilio Network Traversal Service](https://www.twilio.com/docs/stun-turn)
143143

144-
In the real world, WebRTC needs servers to fulfill four types of server-side functionality such as:
144+
**Request and Response Architecture of STUN/TURN Services:**
145+
146+
A REST API to Access the TURN Services basically involves the following steps such as:
147+
148+
**Request:**
149+
150+
The request includes the following parameters, specified in the URL:
151+
152+
- service: specifies the desired service (turn)
153+
- username: an optional user id to be associated with the
154+
- credentials
155+
- key: if an API key is used for authentication, the API key
156+
157+
**Example:**
158+
```
159+
GET /?service=turn&username=mbzrxpgjys
160+
```
161+
162+
**Response:**
163+
164+
The response is returned with content-type "application/json", and consists of a JSON object with the following parameters:
165+
166+
- username
167+
- password
168+
- ttl
169+
- uris
170+
171+
**Example:**
172+
173+
```
174+
{
175+
"username" : "12334939:mbzrxpgjys",
176+
"password" : "adfsaflsjfldssia",
177+
"ttl" : 86400,
178+
"uris" : [
179+
"turn:1.2.3.4:9991?transport=udp",
180+
"turn:1.2.3.4:9992?transport=tcp",
181+
"turns:1.2.3.4:443?transport=tcp"
182+
]
183+
}
184+
```
185+
186+
**WebRTC Interactions:**
187+
188+
The returned JSON is parsed into an `IceServer` object, and supplied as part to use when creating a `PeerConnection` as follows:
189+
190+
```
191+
List<PeerConnection.IceServer> iceServers = new LinkedList<>();
192+
for (int i = 0; i < example.iceServers.size(); i++) {
193+
if (!example.iceServers.get(i).username.isEmpty())
194+
iceServers.add(new PeerConnection.IceServer(example.iceServers.get(i).url, example.iceServers.get(i).username, example.iceServers.get(i).credential));
195+
else
196+
iceServers.add(new PeerConnection.IceServer(example.iceServers.get(i).url));
197+
}
198+
199+
constraints = new MediaConstraints();
200+
peerConnection = peerConnectionFactory.createPeerConnection(iceServers, constraints, peerConnectionObserver);
201+
```
202+
203+
In general, WebRTC needs servers to fulfill four types of server-side functionality such as:
145204

146205
- User discovery and communication
147206
- Signaling

0 commit comments

Comments
 (0)