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

Side by Side Diff: talk/examples/objc/AppRTCDemo/ARDAppEngineClient.m

Issue 1217473011: AppRTCDemo file logging. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rebase Created 5 years, 5 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 * libjingle 2 * libjingle
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 10 matching lines...) Expand all
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #import "ARDAppEngineClient.h" 28 #import "ARDAppEngineClient.h"
29 29
30 #import "ARDJoinResponse.h" 30 #import "ARDJoinResponse.h"
31 #import "ARDLogging.h"
31 #import "ARDMessageResponse.h" 32 #import "ARDMessageResponse.h"
32 #import "ARDSignalingMessage.h" 33 #import "ARDSignalingMessage.h"
33 #import "ARDUtilities.h" 34 #import "ARDUtilities.h"
34 35
35 // TODO(tkchin): move these to a configuration object. 36 // TODO(tkchin): move these to a configuration object.
36 static NSString * const kARDRoomServerHostUrl = 37 static NSString * const kARDRoomServerHostUrl =
37 @"https://apprtc.appspot.com"; 38 @"https://apprtc.appspot.com";
38 static NSString * const kARDRoomServerJoinFormat = 39 static NSString * const kARDRoomServerJoinFormat =
39 @"https://apprtc.appspot.com/join/%@"; 40 @"https://apprtc.appspot.com/join/%@";
40 static NSString * const kARDRoomServerMessageFormat = 41 static NSString * const kARDRoomServerMessageFormat =
41 @"https://apprtc.appspot.com/message/%@/%@"; 42 @"https://apprtc.appspot.com/message/%@/%@";
42 static NSString * const kARDRoomServerLeaveFormat = 43 static NSString * const kARDRoomServerLeaveFormat =
43 @"https://apprtc.appspot.com/leave/%@/%@"; 44 @"https://apprtc.appspot.com/leave/%@/%@";
44 45
45 static NSString * const kARDAppEngineClientErrorDomain = @"ARDAppEngineClient"; 46 static NSString * const kARDAppEngineClientErrorDomain = @"ARDAppEngineClient";
46 static NSInteger const kARDAppEngineClientErrorBadResponse = -1; 47 static NSInteger const kARDAppEngineClientErrorBadResponse = -1;
47 48
48 @implementation ARDAppEngineClient 49 @implementation ARDAppEngineClient
49 50
50 #pragma mark - ARDRoomServerClient 51 #pragma mark - ARDRoomServerClient
51 52
52 - (void)joinRoomWithRoomId:(NSString *)roomId 53 - (void)joinRoomWithRoomId:(NSString *)roomId
53 completionHandler:(void (^)(ARDJoinResponse *response, 54 completionHandler:(void (^)(ARDJoinResponse *response,
54 NSError *error))completionHandler { 55 NSError *error))completionHandler {
55 NSParameterAssert(roomId.length); 56 NSParameterAssert(roomId.length);
56 57
57 NSString *urlString = 58 NSString *urlString =
58 [NSString stringWithFormat:kARDRoomServerJoinFormat, roomId]; 59 [NSString stringWithFormat:kARDRoomServerJoinFormat, roomId];
59 NSURL *roomURL = [NSURL URLWithString:urlString]; 60 NSURL *roomURL = [NSURL URLWithString:urlString];
60 NSLog(@"Joining room:%@ on room server.", roomId); 61 ARDLog(@"Joining room:%@ on room server.", roomId);
61 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL]; 62 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL];
62 request.HTTPMethod = @"POST"; 63 request.HTTPMethod = @"POST";
63 __weak ARDAppEngineClient *weakSelf = self; 64 __weak ARDAppEngineClient *weakSelf = self;
64 [NSURLConnection sendAsyncRequest:request 65 [NSURLConnection sendAsyncRequest:request
65 completionHandler:^(NSURLResponse *response, 66 completionHandler:^(NSURLResponse *response,
66 NSData *data, 67 NSData *data,
67 NSError *error) { 68 NSError *error) {
68 ARDAppEngineClient *strongSelf = weakSelf; 69 ARDAppEngineClient *strongSelf = weakSelf;
69 if (error) { 70 if (error) {
70 if (completionHandler) { 71 if (completionHandler) {
(...skipping 23 matching lines...) Expand all
94 NSError *error))completionHandler { 95 NSError *error))completionHandler {
95 NSParameterAssert(message); 96 NSParameterAssert(message);
96 NSParameterAssert(roomId.length); 97 NSParameterAssert(roomId.length);
97 NSParameterAssert(clientId.length); 98 NSParameterAssert(clientId.length);
98 99
99 NSData *data = [message JSONData]; 100 NSData *data = [message JSONData];
100 NSString *urlString = 101 NSString *urlString =
101 [NSString stringWithFormat: 102 [NSString stringWithFormat:
102 kARDRoomServerMessageFormat, roomId, clientId]; 103 kARDRoomServerMessageFormat, roomId, clientId];
103 NSURL *url = [NSURL URLWithString:urlString]; 104 NSURL *url = [NSURL URLWithString:urlString];
104 NSLog(@"C->RS POST: %@", message); 105 ARDLog(@"C->RS POST: %@", message);
105 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 106 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
106 request.HTTPMethod = @"POST"; 107 request.HTTPMethod = @"POST";
107 request.HTTPBody = data; 108 request.HTTPBody = data;
108 __weak ARDAppEngineClient *weakSelf = self; 109 __weak ARDAppEngineClient *weakSelf = self;
109 [NSURLConnection sendAsyncRequest:request 110 [NSURLConnection sendAsyncRequest:request
110 completionHandler:^(NSURLResponse *response, 111 completionHandler:^(NSURLResponse *response,
111 NSData *data, 112 NSData *data,
112 NSError *error) { 113 NSError *error) {
113 ARDAppEngineClient *strongSelf = weakSelf; 114 ARDAppEngineClient *strongSelf = weakSelf;
114 if (error) { 115 if (error) {
(...skipping 25 matching lines...) Expand all
140 141
141 NSString *urlString = 142 NSString *urlString =
142 [NSString stringWithFormat:kARDRoomServerLeaveFormat, roomId, clientId]; 143 [NSString stringWithFormat:kARDRoomServerLeaveFormat, roomId, clientId];
143 NSURL *url = [NSURL URLWithString:urlString]; 144 NSURL *url = [NSURL URLWithString:urlString];
144 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 145 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
145 request.HTTPMethod = @"POST"; 146 request.HTTPMethod = @"POST";
146 NSURLResponse *response = nil; 147 NSURLResponse *response = nil;
147 NSError *error = nil; 148 NSError *error = nil;
148 // We want a synchronous request so that we know that we've left the room on 149 // We want a synchronous request so that we know that we've left the room on
149 // room server before we do any further work. 150 // room server before we do any further work.
150 NSLog(@"C->RS: BYE"); 151 ARDLog(@"C->RS: BYE");
151 [NSURLConnection sendSynchronousRequest:request 152 [NSURLConnection sendSynchronousRequest:request
152 returningResponse:&response 153 returningResponse:&response
153 error:&error]; 154 error:&error];
154 if (error) { 155 if (error) {
155 NSLog(@"Error leaving room %@ on room server: %@", 156 ARDLog(@"Error leaving room %@ on room server: %@",
156 roomId, error.localizedDescription); 157 roomId, error.localizedDescription);
157 if (completionHandler) { 158 if (completionHandler) {
158 completionHandler(error); 159 completionHandler(error);
159 } 160 }
160 return; 161 return;
161 } 162 }
162 NSLog(@"Left room:%@ on room server.", roomId); 163 ARDLog(@"Left room:%@ on room server.", roomId);
163 if (completionHandler) { 164 if (completionHandler) {
164 completionHandler(nil); 165 completionHandler(nil);
165 } 166 }
166 } 167 }
167 168
168 #pragma mark - Private 169 #pragma mark - Private
169 170
170 + (NSError *)badResponseError { 171 + (NSError *)badResponseError {
171 NSError *error = 172 NSError *error =
172 [[NSError alloc] initWithDomain:kARDAppEngineClientErrorDomain 173 [[NSError alloc] initWithDomain:kARDAppEngineClientErrorDomain
173 code:kARDAppEngineClientErrorBadResponse 174 code:kARDAppEngineClientErrorBadResponse
174 userInfo:@{ 175 userInfo:@{
175 NSLocalizedDescriptionKey: @"Error parsing response.", 176 NSLocalizedDescriptionKey: @"Error parsing response.",
176 }]; 177 }];
177 return error; 178 return error;
178 } 179 }
179 180
180 @end 181 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698