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 |
11 #import "ARDSignalingMessage.h" | 11 #import "ARDSignalingMessage.h" |
12 | 12 |
13 #import "RTCLogging.h" | 13 #import "webrtc/base/objc/RTCLogging.h" |
14 | 14 |
15 #import "ARDUtilities.h" | 15 #import "ARDUtilities.h" |
16 #import "RTCICECandidate+JSON.h" | 16 #import "RTCIceCandidate+JSON.h" |
17 #import "RTCSessionDescription+JSON.h" | 17 #import "RTCSessionDescription+JSON.h" |
18 | 18 |
19 static NSString const *kARDSignalingMessageTypeKey = @"type"; | 19 static NSString const *kARDSignalingMessageTypeKey = @"type"; |
20 | 20 |
21 @implementation ARDSignalingMessage | 21 @implementation ARDSignalingMessage |
22 | 22 |
23 @synthesize type = _type; | 23 @synthesize type = _type; |
24 | 24 |
25 - (instancetype)initWithType:(ARDSignalingMessageType)type { | 25 - (instancetype)initWithType:(ARDSignalingMessageType)type { |
26 if (self = [super init]) { | 26 if (self = [super init]) { |
(...skipping 10 matching lines...) Expand all Loading... |
37 + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { | 37 + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { |
38 NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; | 38 NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; |
39 if (!values) { | 39 if (!values) { |
40 RTCLogError(@"Error parsing signaling message JSON."); | 40 RTCLogError(@"Error parsing signaling message JSON."); |
41 return nil; | 41 return nil; |
42 } | 42 } |
43 | 43 |
44 NSString *typeString = values[kARDSignalingMessageTypeKey]; | 44 NSString *typeString = values[kARDSignalingMessageTypeKey]; |
45 ARDSignalingMessage *message = nil; | 45 ARDSignalingMessage *message = nil; |
46 if ([typeString isEqualToString:@"candidate"]) { | 46 if ([typeString isEqualToString:@"candidate"]) { |
47 RTCICECandidate *candidate = | 47 RTCIceCandidate *candidate = |
48 [RTCICECandidate candidateFromJSONDictionary:values]; | 48 [RTCIceCandidate candidateFromJSONDictionary:values]; |
49 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; | 49 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; |
50 } else if ([typeString isEqualToString:@"offer"] || | 50 } else if ([typeString isEqualToString:@"offer"] || |
51 [typeString isEqualToString:@"answer"]) { | 51 [typeString isEqualToString:@"answer"]) { |
52 RTCSessionDescription *description = | 52 RTCSessionDescription *description = |
53 [RTCSessionDescription descriptionFromJSONDictionary:values]; | 53 [RTCSessionDescription descriptionFromJSONDictionary:values]; |
54 message = | 54 message = |
55 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; | 55 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; |
56 } else if ([typeString isEqualToString:@"bye"]) { | 56 } else if ([typeString isEqualToString:@"bye"]) { |
57 message = [[ARDByeMessage alloc] init]; | 57 message = [[ARDByeMessage alloc] init]; |
58 } else { | 58 } else { |
59 RTCLogError(@"Unexpected type: %@", typeString); | 59 RTCLogError(@"Unexpected type: %@", typeString); |
60 } | 60 } |
61 return message; | 61 return message; |
62 } | 62 } |
63 | 63 |
64 - (NSData *)JSONData { | 64 - (NSData *)JSONData { |
65 return nil; | 65 return nil; |
66 } | 66 } |
67 | 67 |
68 @end | 68 @end |
69 | 69 |
70 @implementation ARDICECandidateMessage | 70 @implementation ARDICECandidateMessage |
71 | 71 |
72 @synthesize candidate = _candidate; | 72 @synthesize candidate = _candidate; |
73 | 73 |
74 - (instancetype)initWithCandidate:(RTCICECandidate *)candidate { | 74 - (instancetype)initWithCandidate:(RTCIceCandidate *)candidate { |
75 if (self = [super initWithType:kARDSignalingMessageTypeCandidate]) { | 75 if (self = [super initWithType:kARDSignalingMessageTypeCandidate]) { |
76 _candidate = candidate; | 76 _candidate = candidate; |
77 } | 77 } |
78 return self; | 78 return self; |
79 } | 79 } |
80 | 80 |
81 - (NSData *)JSONData { | 81 - (NSData *)JSONData { |
82 return [_candidate JSONData]; | 82 return [_candidate JSONData]; |
83 } | 83 } |
84 | 84 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 - (NSData *)JSONData { | 119 - (NSData *)JSONData { |
120 NSDictionary *message = @{ | 120 NSDictionary *message = @{ |
121 @"type": @"bye" | 121 @"type": @"bye" |
122 }; | 122 }; |
123 return [NSJSONSerialization dataWithJSONObject:message | 123 return [NSJSONSerialization dataWithJSONObject:message |
124 options:NSJSONWritingPrettyPrinted | 124 options:NSJSONWritingPrettyPrinted |
125 error:NULL]; | 125 error:NULL]; |
126 } | 126 } |
127 | 127 |
128 @end | 128 @end |
OLD | NEW |