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

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ARDCEODTURNClient.m

Issue 1690313002: Update iOS AppRTCDemo to use the updated Objective-C API. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update Mac demo and other changes after updating against master Created 4 years, 10 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
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
11 #import "ARDCEODTURNClient.h" 11 #import "ARDCEODTURNClient.h"
12 12
13 #import "ARDUtilities.h" 13 #import "ARDUtilities.h"
14 #import "RTCICEServer+JSON.h" 14 #import "RTCIceServer+JSON.h"
15 15
16 // TODO(tkchin): move this to a configuration object. 16 // TODO(tkchin): move this to a configuration object.
17 static NSString *kTURNOriginURLString = @"https://apprtc.appspot.com"; 17 static NSString *kTURNOriginURLString = @"https://apprtc.appspot.com";
18 static NSString *kARDCEODTURNClientErrorDomain = @"ARDCEODTURNClient"; 18 static NSString *kARDCEODTURNClientErrorDomain = @"ARDCEODTURNClient";
19 static NSInteger kARDCEODTURNClientErrorBadResponse = -1; 19 static NSInteger kARDCEODTURNClientErrorBadResponse = -1;
20 20
21 @implementation ARDCEODTURNClient { 21 @implementation ARDCEODTURNClient {
22 NSURL *_url; 22 NSURL *_url;
23 } 23 }
24 24
25 - (instancetype)initWithURL:(NSURL *)url { 25 - (instancetype)initWithURL:(NSURL *)url {
26 NSParameterAssert([url absoluteString].length); 26 NSParameterAssert([url absoluteString].length);
27 if (self = [super init]) { 27 if (self = [super init]) {
28 _url = url; 28 _url = url;
29 } 29 }
30 return self; 30 return self;
31 } 31 }
32 32
33 - (void)requestServersWithCompletionHandler: 33 - (void)requestServerWithCompletionHandler:
34 (void (^)(NSArray *turnServers, 34 (void (^)(RTCIceServer *turnServer,
35 NSError *error))completionHandler { 35 NSError *error))completionHandler {
36 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_url]; 36 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_url];
37 // We need to set origin because TURN provider whitelists requests based on 37 // We need to set origin because TURN provider whitelists requests based on
38 // origin. 38 // origin.
39 [request addValue:@"Mozilla/5.0" forHTTPHeaderField:@"user-agent"]; 39 [request addValue:@"Mozilla/5.0" forHTTPHeaderField:@"user-agent"];
40 [request addValue:kTURNOriginURLString forHTTPHeaderField:@"origin"]; 40 [request addValue:kTURNOriginURLString forHTTPHeaderField:@"origin"];
41 [NSURLConnection sendAsyncRequest:request 41 [NSURLConnection sendAsyncRequest:request
42 completionHandler:^(NSURLResponse *response, 42 completionHandler:^(NSURLResponse *response,
43 NSData *data, 43 NSData *data,
44 NSError *error) { 44 NSError *error) {
45 NSArray *turnServers = [NSArray array];
46 if (error) { 45 if (error) {
47 completionHandler(turnServers, error); 46 completionHandler(nil, error);
48 return; 47 return;
49 } 48 }
50 NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data]; 49 NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data];
51 turnServers = [RTCICEServer serversFromCEODJSONDictionary:dict]; 50 RTCIceServer *turnServer = [RTCIceServer serverFromCEODJSONDictionary:dict];
52 if (!turnServers) { 51 if (!turnServer) {
53 NSError *responseError = 52 NSError *responseError =
54 [[NSError alloc] initWithDomain:kARDCEODTURNClientErrorDomain 53 [[NSError alloc] initWithDomain:kARDCEODTURNClientErrorDomain
55 code:kARDCEODTURNClientErrorBadResponse 54 code:kARDCEODTURNClientErrorBadResponse
56 userInfo:@{ 55 userInfo:@{
57 NSLocalizedDescriptionKey: @"Bad TURN response.", 56 NSLocalizedDescriptionKey: @"Bad TURN response.",
58 }]; 57 }];
59 completionHandler(turnServers, responseError); 58 completionHandler(turnServer, responseError);
60 return; 59 return;
61 } 60 }
62 completionHandler(turnServers, nil); 61 completionHandler(turnServer, nil);
63 }]; 62 }];
64 } 63 }
65 64
66 @end 65 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698