tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 3 | * |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 11 | #import "ARDJoinResponse+Internal.h" |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 12 | |
| 13 | #import "ARDSignalingMessage.h" |
| 14 | #import "ARDUtilities.h" |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 15 | #import "RTCIceServer+JSON.h" |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 16 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 17 | static NSString const *kARDJoinResultKey = @"result"; |
| 18 | static NSString const *kARDJoinResultParamsKey = @"params"; |
| 19 | static NSString const *kARDJoinInitiatorKey = @"is_initiator"; |
| 20 | static NSString const *kARDJoinRoomIdKey = @"room_id"; |
| 21 | static NSString const *kARDJoinClientIdKey = @"client_id"; |
| 22 | static NSString const *kARDJoinMessagesKey = @"messages"; |
| 23 | static NSString const *kARDJoinWebSocketURLKey = @"wss_url"; |
| 24 | static NSString const *kARDJoinWebSocketRestURLKey = @"wss_post_url"; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 25 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 26 | @implementation ARDJoinResponse |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 27 | |
| 28 | @synthesize result = _result; |
| 29 | @synthesize isInitiator = _isInitiator; |
| 30 | @synthesize roomId = _roomId; |
| 31 | @synthesize clientId = _clientId; |
| 32 | @synthesize messages = _messages; |
| 33 | @synthesize webSocketURL = _webSocketURL; |
| 34 | @synthesize webSocketRestURL = _webSocketRestURL; |
| 35 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 36 | + (ARDJoinResponse *)responseFromJSONData:(NSData *)data { |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 37 | NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data]; |
| 38 | if (!responseJSON) { |
| 39 | return nil; |
| 40 | } |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 41 | ARDJoinResponse *response = [[ARDJoinResponse alloc] init]; |
| 42 | NSString *resultString = responseJSON[kARDJoinResultKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 43 | response.result = [[self class] resultTypeFromString:resultString]; |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 44 | NSDictionary *params = responseJSON[kARDJoinResultParamsKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 45 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 46 | response.isInitiator = [params[kARDJoinInitiatorKey] boolValue]; |
| 47 | response.roomId = params[kARDJoinRoomIdKey]; |
| 48 | response.clientId = params[kARDJoinClientIdKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 49 | |
| 50 | // Parse messages. |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 51 | NSArray *messages = params[kARDJoinMessagesKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 52 | NSMutableArray *signalingMessages = |
| 53 | [NSMutableArray arrayWithCapacity:messages.count]; |
| 54 | for (NSString *message in messages) { |
| 55 | ARDSignalingMessage *signalingMessage = |
| 56 | [ARDSignalingMessage messageFromJSONString:message]; |
| 57 | [signalingMessages addObject:signalingMessage]; |
| 58 | } |
| 59 | response.messages = signalingMessages; |
| 60 | |
| 61 | // Parse websocket urls. |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 62 | NSString *webSocketURLString = params[kARDJoinWebSocketURLKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 63 | response.webSocketURL = [NSURL URLWithString:webSocketURLString]; |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 64 | NSString *webSocketRestURLString = params[kARDJoinWebSocketRestURLKey]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 65 | response.webSocketRestURL = [NSURL URLWithString:webSocketRestURLString]; |
| 66 | |
| 67 | return response; |
| 68 | } |
| 69 | |
| 70 | #pragma mark - Private |
| 71 | |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 72 | + (ARDJoinResultType)resultTypeFromString:(NSString *)resultString { |
| 73 | ARDJoinResultType result = kARDJoinResultTypeUnknown; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 74 | if ([resultString isEqualToString:@"SUCCESS"]) { |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 75 | result = kARDJoinResultTypeSuccess; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 76 | } else if ([resultString isEqualToString:@"FULL"]) { |
tkchin@webrtc.org | 36401ab | 2015-01-27 21:34:39 +0000 | [diff] [blame] | 77 | result = kARDJoinResultTypeFull; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | @end |