@@ -141,7 +141,66 @@ You can use open source as well as paid STUN & TURN Services such as:
141
141
- [ STUNTMAN Open Source STUN Server Project] ( https://github.com/jselbie/stunserver )
142
142
- [ Twilio Network Traversal Service] ( https://www.twilio.com/docs/stun-turn )
143
143
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:
145
204
146
205
- User discovery and communication
147
206
- Signaling
0 commit comments