| OLD | NEW |
| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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]; | 45 NSArray *turnServers = [NSArray array]; |
| 46 if (error) { | 46 if (error) { |
| 47 completionHandler(turnServers, error); | 47 completionHandler(nil, error); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data]; | 50 NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data]; |
| 51 turnServers = [RTCICEServer serversFromCEODJSONDictionary:dict]; | 51 turnServers = @[ [RTCIceServer serverFromCEODJSONDictionary:dict] ]; |
| 52 if (!turnServers) { | 52 if (!turnServers) { |
| 53 NSError *responseError = | 53 NSError *responseError = |
| 54 [[NSError alloc] initWithDomain:kARDCEODTURNClientErrorDomain | 54 [[NSError alloc] initWithDomain:kARDCEODTURNClientErrorDomain |
| 55 code:kARDCEODTURNClientErrorBadResponse | 55 code:kARDCEODTURNClientErrorBadResponse |
| 56 userInfo:@{ | 56 userInfo:@{ |
| 57 NSLocalizedDescriptionKey: @"Bad TURN response.", | 57 NSLocalizedDescriptionKey: @"Bad TURN response.", |
| 58 }]; | 58 }]; |
| 59 completionHandler(turnServers, responseError); | 59 completionHandler(turnServers, responseError); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 completionHandler(turnServers, nil); | 62 completionHandler(turnServers, nil); |
| 63 }]; | 63 }]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 @end | 66 @end |
| OLD | NEW |