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

Unified Diff: webrtc/examples/objc/AppRTCMobile/ARDTURNClient.m

Issue 2627523004: Update ice server provider response format in iOS AppRTCMobile (Closed)
Patch Set: lower similarity and rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/examples/objc/AppRTCMobile/ARDTURNClient.m
diff --git a/webrtc/examples/objc/AppRTCMobile/ARDCEODTURNClient.m b/webrtc/examples/objc/AppRTCMobile/ARDTURNClient.m
similarity index 35%
rename from webrtc/examples/objc/AppRTCMobile/ARDCEODTURNClient.m
rename to webrtc/examples/objc/AppRTCMobile/ARDTURNClient.m
index 5be33353188737b351cd5f910c3adacaa549ba6c..05f5cd9d113420f38027ec1711de7e2cafad8608 100644
--- a/webrtc/examples/objc/AppRTCMobile/ARDCEODTURNClient.m
+++ b/webrtc/examples/objc/AppRTCMobile/ARDTURNClient.m
@@ -8,17 +8,17 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#import "ARDCEODTURNClient.h"
+#import "ARDTURNClient+Internal.h"
#import "ARDUtilities.h"
#import "RTCIceServer+JSON.h"
// TODO(tkchin): move this to a configuration object.
-static NSString *kTURNOriginURLString = @"https://apprtc.appspot.com";
-static NSString *kARDCEODTURNClientErrorDomain = @"ARDCEODTURNClient";
-static NSInteger kARDCEODTURNClientErrorBadResponse = -1;
+static NSString *kTURNRefererURLString = @"https://appr.tc";
+static NSString *kARDTURNClientErrorDomain = @"ARDTURNClient";
+static NSInteger kARDTURNClientErrorBadResponse = -1;
-@implementation ARDCEODTURNClient {
+@implementation ARDTURNClient {
NSURL *_url;
}
@@ -31,36 +31,56 @@ static NSInteger kARDCEODTURNClientErrorBadResponse = -1;
}
- (void)requestServersWithCompletionHandler:
- (void (^)(NSArray *turnServers,
- NSError *error))completionHandler {
+ (void (^)(NSArray *turnServers, NSError *error))completionHandler {
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_url];
- // We need to set origin because TURN provider whitelists requests based on
- // origin.
- [request addValue:@"Mozilla/5.0" forHTTPHeaderField:@"user-agent"];
- [request addValue:kTURNOriginURLString forHTTPHeaderField:@"origin"];
[NSURLConnection sendAsyncRequest:request
+ completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
+ if (error) {
+ completionHandler(nil, error);
+ return;
+ }
+ NSDictionary *responseDict = [NSDictionary dictionaryWithJSONData:data];
+ NSString *iceServerUrl = responseDict[@"ice_server_url"];
+ [self makeTurnServerRequestToURL:[NSURL URLWithString:iceServerUrl]
+ WithCompletionHandler:completionHandler];
+ }];
+}
+
+#pragma mark - Private
+
+- (void)makeTurnServerRequestToURL:(NSURL *)url
+ WithCompletionHandler:(void (^)(NSArray *turnServers,
+ NSError *error))completionHandler {
+ NSMutableURLRequest *iceServerRequest = [NSMutableURLRequest requestWithURL:url];
+ iceServerRequest.HTTPMethod = @"POST";
+ [iceServerRequest addValue:kTURNRefererURLString forHTTPHeaderField:@"referer"];
+ [NSURLConnection sendAsyncRequest:iceServerRequest
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error) {
- NSArray *turnServers = [NSArray array];
- if (error) {
- completionHandler(nil, error);
- return;
- }
- NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data];
- turnServers = @[ [RTCIceServer serverFromCEODJSONDictionary:dict] ];
- if (!turnServers) {
- NSError *responseError =
- [[NSError alloc] initWithDomain:kARDCEODTURNClientErrorDomain
- code:kARDCEODTURNClientErrorBadResponse
+ if (error) {
+ completionHandler(nil, error);
+ return;
+ }
+ NSDictionary *turnResponseDict = [NSDictionary dictionaryWithJSONData:data];
+ NSMutableArray *turnServers = [NSMutableArray array];
+ [turnResponseDict[@"iceServers"] enumerateObjectsUsingBlock:
+ ^(NSDictionary *obj, NSUInteger idx, BOOL *stop){
+ [turnServers addObject:[RTCIceServer serverFromJSONDictionary:obj]];
+ }];
+ if (!turnServers) {
+ NSError *responseError =
+ [[NSError alloc] initWithDomain:kARDTURNClientErrorDomain
+ code:kARDTURNClientErrorBadResponse
userInfo:@{
NSLocalizedDescriptionKey: @"Bad TURN response.",
- }];
- completionHandler(turnServers, responseError);
- return;
- }
- completionHandler(turnServers, nil);
- }];
+ }];
+ completionHandler(nil, responseError);
+ return;
+ }
+ completionHandler(turnServers, nil);
+ }];
}
@end
« no previous file with comments | « webrtc/examples/objc/AppRTCMobile/ARDCEODTURNClient.m ('k') | webrtc/examples/objc/AppRTCMobile/ARDTURNClient+Internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698