OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2014 Google Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright notice, | |
9 * this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
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, | |
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 | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #import "ARDJoinResponse+Internal.h" | |
29 | |
30 #import "ARDSignalingMessage.h" | |
31 #import "ARDUtilities.h" | |
32 #import "RTCICEServer+JSON.h" | |
33 | |
34 static NSString const *kARDJoinResultKey = @"result"; | |
35 static NSString const *kARDJoinResultParamsKey = @"params"; | |
36 static NSString const *kARDJoinInitiatorKey = @"is_initiator"; | |
37 static NSString const *kARDJoinRoomIdKey = @"room_id"; | |
38 static NSString const *kARDJoinClientIdKey = @"client_id"; | |
39 static NSString const *kARDJoinMessagesKey = @"messages"; | |
40 static NSString const *kARDJoinWebSocketURLKey = @"wss_url"; | |
41 static NSString const *kARDJoinWebSocketRestURLKey = @"wss_post_url"; | |
42 | |
43 @implementation ARDJoinResponse | |
44 | |
45 @synthesize result = _result; | |
46 @synthesize isInitiator = _isInitiator; | |
47 @synthesize roomId = _roomId; | |
48 @synthesize clientId = _clientId; | |
49 @synthesize messages = _messages; | |
50 @synthesize webSocketURL = _webSocketURL; | |
51 @synthesize webSocketRestURL = _webSocketRestURL; | |
52 | |
53 + (ARDJoinResponse *)responseFromJSONData:(NSData *)data { | |
54 NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data]; | |
55 if (!responseJSON) { | |
56 return nil; | |
57 } | |
58 ARDJoinResponse *response = [[ARDJoinResponse alloc] init]; | |
59 NSString *resultString = responseJSON[kARDJoinResultKey]; | |
60 response.result = [[self class] resultTypeFromString:resultString]; | |
61 NSDictionary *params = responseJSON[kARDJoinResultParamsKey]; | |
62 | |
63 response.isInitiator = [params[kARDJoinInitiatorKey] boolValue]; | |
64 response.roomId = params[kARDJoinRoomIdKey]; | |
65 response.clientId = params[kARDJoinClientIdKey]; | |
66 | |
67 // Parse messages. | |
68 NSArray *messages = params[kARDJoinMessagesKey]; | |
69 NSMutableArray *signalingMessages = | |
70 [NSMutableArray arrayWithCapacity:messages.count]; | |
71 for (NSString *message in messages) { | |
72 ARDSignalingMessage *signalingMessage = | |
73 [ARDSignalingMessage messageFromJSONString:message]; | |
74 [signalingMessages addObject:signalingMessage]; | |
75 } | |
76 response.messages = signalingMessages; | |
77 | |
78 // Parse websocket urls. | |
79 NSString *webSocketURLString = params[kARDJoinWebSocketURLKey]; | |
80 response.webSocketURL = [NSURL URLWithString:webSocketURLString]; | |
81 NSString *webSocketRestURLString = params[kARDJoinWebSocketRestURLKey]; | |
82 response.webSocketRestURL = [NSURL URLWithString:webSocketRestURLString]; | |
83 | |
84 return response; | |
85 } | |
86 | |
87 #pragma mark - Private | |
88 | |
89 + (ARDJoinResultType)resultTypeFromString:(NSString *)resultString { | |
90 ARDJoinResultType result = kARDJoinResultTypeUnknown; | |
91 if ([resultString isEqualToString:@"SUCCESS"]) { | |
92 result = kARDJoinResultTypeSuccess; | |
93 } else if ([resultString isEqualToString:@"FULL"]) { | |
94 result = kARDJoinResultTypeFull; | |
95 } | |
96 return result; | |
97 } | |
98 | |
99 @end | |
OLD | NEW |