Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/RoomParametersFetcher.java

Issue 1862423002: Update ice server provider response format in the Android AppRTCDemo app (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 for (PeerConnection.IceServer server : iceServers) { 138 for (PeerConnection.IceServer server : iceServers) {
139 Log.d(TAG, "IceServer: " + server); 139 Log.d(TAG, "IceServer: " + server);
140 if (server.uri.startsWith("turn:")) { 140 if (server.uri.startsWith("turn:")) {
141 isTurnPresent = true; 141 isTurnPresent = true;
142 break; 142 break;
143 } 143 }
144 } 144 }
145 // Request TURN servers. 145 // Request TURN servers.
146 if (!isTurnPresent) { 146 if (!isTurnPresent) {
147 LinkedList<PeerConnection.IceServer> turnServers = 147 LinkedList<PeerConnection.IceServer> turnServers =
148 requestTurnServers(roomJson.getString("turn_url")); 148 requestTurnServers(roomJson.getString("ice_server_url"));
149 for (PeerConnection.IceServer turnServer : turnServers) { 149 for (PeerConnection.IceServer turnServer : turnServers) {
150 Log.d(TAG, "TurnServer: " + turnServer); 150 Log.d(TAG, "TurnServer: " + turnServer);
151 iceServers.add(turnServer); 151 iceServers.add(turnServer);
152 } 152 }
153 } 153 }
154 154
155 SignalingParameters params = new SignalingParameters( 155 SignalingParameters params = new SignalingParameters(
156 iceServers, initiator, 156 iceServers, initiator,
157 clientId, wssUrl, wssPostUrl, 157 clientId, wssUrl, wssPostUrl,
158 offerSdp, iceCandidates); 158 offerSdp, iceCandidates);
159 events.onSignalingParametersReady(params); 159 events.onSignalingParametersReady(params);
160 } catch (JSONException e) { 160 } catch (JSONException e) {
161 events.onSignalingParametersError( 161 events.onSignalingParametersError(
162 "Room JSON parsing error: " + e.toString()); 162 "Room JSON parsing error: " + e.toString());
163 } catch (IOException e) { 163 } catch (IOException e) {
164 events.onSignalingParametersError("Room IO error: " + e.toString()); 164 events.onSignalingParametersError("Room IO error: " + e.toString());
165 } 165 }
166 } 166 }
167 167
168 // Requests & returns a TURN ICE Server based on a request URL. Must be run 168 // Requests & returns a TURN ICE Server based on a request URL. Must be run
169 // off the main thread! 169 // off the main thread!
170 private LinkedList<PeerConnection.IceServer> requestTurnServers(String url) 170 private LinkedList<PeerConnection.IceServer> requestTurnServers(String url)
171 throws IOException, JSONException { 171 throws IOException, JSONException {
172 LinkedList<PeerConnection.IceServer> turnServers = 172 LinkedList<PeerConnection.IceServer> turnServers =
173 new LinkedList<PeerConnection.IceServer>(); 173 new LinkedList<PeerConnection.IceServer>();
174 Log.d(TAG, "Request TURN from: " + url); 174 Log.d(TAG, "Request TURN from: " + url);
175 HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnecti on(); 175 HttpURLConnection connection =
176 (HttpURLConnection) new URL(url).openConnection();
177 connection.setDoOutput(true);
178 connection.setRequestProperty("REFERER", "https://appr.tc");
176 connection.setConnectTimeout(TURN_HTTP_TIMEOUT_MS); 179 connection.setConnectTimeout(TURN_HTTP_TIMEOUT_MS);
177 connection.setReadTimeout(TURN_HTTP_TIMEOUT_MS); 180 connection.setReadTimeout(TURN_HTTP_TIMEOUT_MS);
178 int responseCode = connection.getResponseCode(); 181 int responseCode = connection.getResponseCode();
179 if (responseCode != 200) { 182 if (responseCode != 200) {
180 throw new IOException("Non-200 response when requesting TURN server from " 183 throw new IOException("Non-200 response when requesting TURN server from "
181 + url + " : " + connection.getHeaderField(null)); 184 + url + " : " + connection.getHeaderField(null));
182 } 185 }
183 InputStream responseStream = connection.getInputStream(); 186 InputStream responseStream = connection.getInputStream();
184 String response = drainStream(responseStream); 187 String response = drainStream(responseStream);
185 connection.disconnect(); 188 connection.disconnect();
186 Log.d(TAG, "TURN response: " + response); 189 Log.d(TAG, "TURN response: " + response);
187 JSONObject responseJSON = new JSONObject(response); 190 JSONObject responseJSON = new JSONObject(response);
188 String username = responseJSON.getString("username"); 191 JSONArray iceServers = responseJSON.getJSONArray("iceServers");
189 String password = responseJSON.getString("password"); 192 for (int i = 0; i < iceServers.length(); ++i) {
190 JSONArray turnUris = responseJSON.getJSONArray("uris"); 193 JSONObject server = iceServers.getJSONObject(i);
191 for (int i = 0; i < turnUris.length(); i++) { 194 JSONArray turnUrls = server.getJSONArray("urls");
192 String uri = turnUris.getString(i); 195 String username =
193 turnServers.add(new PeerConnection.IceServer(uri, username, password)); 196 server.has("username") ? server.getString("username") : "";
197 String credential =
198 server.has("credential") ? server.getString("credential") : "";
199 for (int j = 0; j < turnUrls.length(); j++) {
200 String turnUrl = turnUrls.getString(j);
201 turnServers.add(new PeerConnection.IceServer(turnUrl, username,
202 credential));
203 }
194 } 204 }
195 return turnServers; 205 return turnServers;
196 } 206 }
197 207
198 // Return the list of ICE servers described by a WebRTCPeerConnection 208 // Return the list of ICE servers described by a WebRTCPeerConnection
199 // configuration string. 209 // configuration string.
200 private LinkedList<PeerConnection.IceServer> iceServersFromPCConfigJSON( 210 private LinkedList<PeerConnection.IceServer> iceServersFromPCConfigJSON(
201 String pcConfig) throws JSONException { 211 String pcConfig) throws JSONException {
202 JSONObject json = new JSONObject(pcConfig); 212 JSONObject json = new JSONObject(pcConfig);
203 JSONArray servers = json.getJSONArray("iceServers"); 213 JSONArray servers = json.getJSONArray("iceServers");
204 LinkedList<PeerConnection.IceServer> ret = 214 LinkedList<PeerConnection.IceServer> ret =
205 new LinkedList<PeerConnection.IceServer>(); 215 new LinkedList<PeerConnection.IceServer>();
206 for (int i = 0; i < servers.length(); ++i) { 216 for (int i = 0; i < servers.length(); ++i) {
207 JSONObject server = servers.getJSONObject(i); 217 JSONObject server = servers.getJSONObject(i);
208 String url = server.getString("urls"); 218 String url = server.getString("urls");
209 String credential = 219 String credential =
210 server.has("credential") ? server.getString("credential") : ""; 220 server.has("credential") ? server.getString("credential") : "";
211 ret.add(new PeerConnection.IceServer(url, "", credential)); 221 ret.add(new PeerConnection.IceServer(url, "", credential));
212 } 222 }
213 return ret; 223 return ret;
214 } 224 }
215 225
216 // Return the contents of an InputStream as a String. 226 // Return the contents of an InputStream as a String.
217 private static String drainStream(InputStream in) { 227 private static String drainStream(InputStream in) {
218 Scanner s = new Scanner(in).useDelimiter("\\A"); 228 Scanner s = new Scanner(in).useDelimiter("\\A");
219 return s.hasNext() ? s.next() : ""; 229 return s.hasNext() ? s.next() : "";
220 } 230 }
221 231
222 } 232 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698