Chromium Code Reviews| 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 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 urlString = | 50 urlString = |
| 51 [NSString stringWithFormat:kARDRoomServerJoinFormat, roomId]; | 51 [NSString stringWithFormat:kARDRoomServerJoinFormat, roomId]; |
| 52 } | 52 } |
| 53 | 53 |
| 54 NSURL *roomURL = [NSURL URLWithString:urlString]; | 54 NSURL *roomURL = [NSURL URLWithString:urlString]; |
| 55 RTCLog(@"Joining room:%@ on room server.", roomId); | 55 RTCLog(@"Joining room:%@ on room server.", roomId); |
| 56 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL]; | 56 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL]; |
| 57 request.HTTPMethod = @"POST"; | 57 request.HTTPMethod = @"POST"; |
| 58 __weak ARDAppEngineClient *weakSelf = self; | 58 __weak ARDAppEngineClient *weakSelf = self; |
| 59 [NSURLConnection sendAsyncRequest:request | 59 [NSURLConnection sendAsyncRequest:request |
| 60 completionHandler:^(NSURLResponse *response, | 60 completionHandler:^(NSURLResponse *response, NSData *data, NSE rror *error) { |
| 61 NSData *data, | 61 ARDAppEngineClient *strongSelf = weakSelf; |
| 62 NSError *error) { | 62 if (error) { |
| 63 ARDAppEngineClient *strongSelf = weakSelf; | 63 if (completionHandler) { |
| 64 if (error) { | 64 completionHandler(nil, error); |
| 65 if (completionHandler) { | 65 } |
| 66 completionHandler(nil, error); | 66 return; |
| 67 } | 67 } |
| 68 return; | 68 ARDJoinResponse *joinResponse = [ARDJoinResponse responseFro mJSONData:data]; |
| 69 } | 69 if (!joinResponse) { |
| 70 ARDJoinResponse *joinResponse = | 70 if (completionHandler) { |
| 71 [ARDJoinResponse responseFromJSONData:data]; | 71 NSError *error = [[self class] badResponseError]; |
| 72 if (!joinResponse) { | 72 completionHandler(nil, error); |
| 73 if (completionHandler) { | 73 } |
| 74 NSError *error = [[self class] badResponseError]; | 74 return; |
| 75 completionHandler(nil, error); | 75 } |
| 76 } | 76 if (completionHandler) { |
| 77 return; | 77 completionHandler(joinResponse, nil); |
| 78 } | 78 } |
| 79 if (completionHandler) { | 79 |
|
daniela-webrtc
2017/03/29 12:25:56
Nit: remove extra line
kthelgason
2017/03/29 12:35:24
Done.
| |
| 80 completionHandler(joinResponse, nil); | 80 }]; |
| 81 } | |
| 82 }]; | |
| 83 } | 81 } |
| 84 | 82 |
| 85 - (void)sendMessage:(ARDSignalingMessage *)message | 83 - (void)sendMessage:(ARDSignalingMessage *)message |
| 86 forRoomId:(NSString *)roomId | 84 forRoomId:(NSString *)roomId |
| 87 clientId:(NSString *)clientId | 85 clientId:(NSString *)clientId |
| 88 completionHandler:(void (^)(ARDMessageResponse *response, | 86 completionHandler:(void (^)(ARDMessageResponse *response, |
| 89 NSError *error))completionHandler { | 87 NSError *error))completionHandler { |
| 90 NSParameterAssert(message); | 88 NSParameterAssert(message); |
| 91 NSParameterAssert(roomId.length); | 89 NSParameterAssert(roomId.length); |
| 92 NSParameterAssert(clientId.length); | 90 NSParameterAssert(clientId.length); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 clientId:(NSString *)clientId | 129 clientId:(NSString *)clientId |
| 132 completionHandler:(void (^)(NSError *error))completionHandler { | 130 completionHandler:(void (^)(NSError *error))completionHandler { |
| 133 NSParameterAssert(roomId.length); | 131 NSParameterAssert(roomId.length); |
| 134 NSParameterAssert(clientId.length); | 132 NSParameterAssert(clientId.length); |
| 135 | 133 |
| 136 NSString *urlString = | 134 NSString *urlString = |
| 137 [NSString stringWithFormat:kARDRoomServerLeaveFormat, roomId, clientId]; | 135 [NSString stringWithFormat:kARDRoomServerLeaveFormat, roomId, clientId]; |
| 138 NSURL *url = [NSURL URLWithString:urlString]; | 136 NSURL *url = [NSURL URLWithString:urlString]; |
| 139 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | 137 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; |
| 140 request.HTTPMethod = @"POST"; | 138 request.HTTPMethod = @"POST"; |
| 141 NSURLResponse *response = nil; | 139 |
| 142 NSError *error = nil; | 140 RTCLog(@"C->RS: BYE"); |
| 141 __block NSError *error = nil; | |
| 142 | |
| 143 // We want a synchronous request so that we know that we've left the room on | 143 // We want a synchronous request so that we know that we've left the room on |
| 144 // room server before we do any further work. | 144 // room server before we do any further work. |
| 145 RTCLog(@"C->RS: BYE"); | 145 dispatch_semaphore_t sem = dispatch_semaphore_create(0); |
| 146 [NSURLConnection sendSynchronousRequest:request | 146 [NSURLConnection sendAsyncRequest:request |
|
daniela-webrtc
2017/03/29 12:25:56
Is it gonna be too much work to update to NSURLSes
kthelgason
2017/03/29 12:35:25
This is actually using NSURLSession, it's calling
| |
| 147 returningResponse:&response | 147 completionHandler:^(NSURLResponse *response, NSData *data, NSE rror *e) { |
| 148 error:&error]; | 148 if (e) { |
| 149 error = e; | |
| 150 } | |
| 151 dispatch_semaphore_signal(sem); | |
| 152 }]; | |
| 153 | |
| 154 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); | |
| 149 if (error) { | 155 if (error) { |
| 150 RTCLogError(@"Error leaving room %@ on room server: %@", | 156 RTCLogError(@"Error leaving room %@ on room server: %@", roomId, error.local izedDescription); |
| 151 roomId, error.localizedDescription); | |
| 152 if (completionHandler) { | 157 if (completionHandler) { |
| 153 completionHandler(error); | 158 completionHandler(error); |
| 154 } | 159 } |
| 155 return; | 160 return; |
| 156 } | 161 } |
| 157 RTCLog(@"Left room:%@ on room server.", roomId); | 162 RTCLog(@"Left room:%@ on room server.", roomId); |
| 158 if (completionHandler) { | 163 if (completionHandler) { |
| 159 completionHandler(nil); | 164 completionHandler(nil); |
| 160 } | 165 } |
| 161 } | 166 } |
| 162 | 167 |
| 163 #pragma mark - Private | 168 #pragma mark - Private |
| 164 | 169 |
| 165 + (NSError *)badResponseError { | 170 + (NSError *)badResponseError { |
| 166 NSError *error = | 171 NSError *error = |
| 167 [[NSError alloc] initWithDomain:kARDAppEngineClientErrorDomain | 172 [[NSError alloc] initWithDomain:kARDAppEngineClientErrorDomain |
| 168 code:kARDAppEngineClientErrorBadResponse | 173 code:kARDAppEngineClientErrorBadResponse |
| 169 userInfo:@{ | 174 userInfo:@{ |
| 170 NSLocalizedDescriptionKey: @"Error parsing response.", | 175 NSLocalizedDescriptionKey: @"Error parsing response.", |
| 171 }]; | 176 }]; |
| 172 return error; | 177 return error; |
| 173 } | 178 } |
| 174 | 179 |
| 175 @end | 180 @end |
| OLD | NEW |