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 "WebRTC/RTCLogging.h" | 13 #import "WebRTC/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 static NSString * const kARDTypeValueRemoveCandidates = @"remove-candidates"; |
20 | 21 |
21 @implementation ARDSignalingMessage | 22 @implementation ARDSignalingMessage |
22 | 23 |
23 @synthesize type = _type; | 24 @synthesize type = _type; |
24 | 25 |
25 - (instancetype)initWithType:(ARDSignalingMessageType)type { | 26 - (instancetype)initWithType:(ARDSignalingMessageType)type { |
26 if (self = [super init]) { | 27 if (self = [super init]) { |
27 _type = type; | 28 _type = type; |
28 } | 29 } |
29 return self; | 30 return self; |
(...skipping 10 matching lines...) Expand all Loading... |
40 RTCLogError(@"Error parsing signaling message JSON."); | 41 RTCLogError(@"Error parsing signaling message JSON."); |
41 return nil; | 42 return nil; |
42 } | 43 } |
43 | 44 |
44 NSString *typeString = values[kARDSignalingMessageTypeKey]; | 45 NSString *typeString = values[kARDSignalingMessageTypeKey]; |
45 ARDSignalingMessage *message = nil; | 46 ARDSignalingMessage *message = nil; |
46 if ([typeString isEqualToString:@"candidate"]) { | 47 if ([typeString isEqualToString:@"candidate"]) { |
47 RTCIceCandidate *candidate = | 48 RTCIceCandidate *candidate = |
48 [RTCIceCandidate candidateFromJSONDictionary:values]; | 49 [RTCIceCandidate candidateFromJSONDictionary:values]; |
49 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; | 50 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; |
| 51 } else if ([typeString isEqualToString:kARDTypeValueRemoveCandidates]) { |
| 52 RTCLogInfo(@"Received remove-candidates message"); |
| 53 NSArray<RTCIceCandidate *> *candidates = |
| 54 [RTCIceCandidate candidatesFromJSONDictionary:values]; |
| 55 message = [[ARDICECandidateRemovalMessage alloc] |
| 56 initWithRemovedCandidates:candidates]; |
50 } else if ([typeString isEqualToString:@"offer"] || | 57 } else if ([typeString isEqualToString:@"offer"] || |
51 [typeString isEqualToString:@"answer"]) { | 58 [typeString isEqualToString:@"answer"]) { |
52 RTCSessionDescription *description = | 59 RTCSessionDescription *description = |
53 [RTCSessionDescription descriptionFromJSONDictionary:values]; | 60 [RTCSessionDescription descriptionFromJSONDictionary:values]; |
54 message = | 61 message = |
55 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; | 62 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; |
56 } else if ([typeString isEqualToString:@"bye"]) { | 63 } else if ([typeString isEqualToString:@"bye"]) { |
57 message = [[ARDByeMessage alloc] init]; | 64 message = [[ARDByeMessage alloc] init]; |
58 } else { | 65 } else { |
59 RTCLogError(@"Unexpected type: %@", typeString); | 66 RTCLogError(@"Unexpected type: %@", typeString); |
(...skipping 17 matching lines...) Expand all Loading... |
77 } | 84 } |
78 return self; | 85 return self; |
79 } | 86 } |
80 | 87 |
81 - (NSData *)JSONData { | 88 - (NSData *)JSONData { |
82 return [_candidate JSONData]; | 89 return [_candidate JSONData]; |
83 } | 90 } |
84 | 91 |
85 @end | 92 @end |
86 | 93 |
| 94 @implementation ARDICECandidateRemovalMessage |
| 95 |
| 96 @synthesize candidates = _candidates; |
| 97 |
| 98 - (instancetype)initWithRemovedCandidates:( |
| 99 NSArray<RTCIceCandidate *> *)candidates { |
| 100 NSParameterAssert(candidates.count); |
| 101 if (self = [super initWithType:kARDSignalingMessageTypeCandidateRemoval]) { |
| 102 _candidates = candidates; |
| 103 } |
| 104 return self; |
| 105 } |
| 106 |
| 107 - (NSData *)JSONData { |
| 108 return |
| 109 [RTCIceCandidate JSONDataForIceCandidates:_candidates |
| 110 withType:kARDTypeValueRemoveCandidates]; |
| 111 } |
| 112 |
| 113 @end |
| 114 |
87 @implementation ARDSessionDescriptionMessage | 115 @implementation ARDSessionDescriptionMessage |
88 | 116 |
89 @synthesize sessionDescription = _sessionDescription; | 117 @synthesize sessionDescription = _sessionDescription; |
90 | 118 |
91 - (instancetype)initWithDescription:(RTCSessionDescription *)description { | 119 - (instancetype)initWithDescription:(RTCSessionDescription *)description { |
92 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer; | 120 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer; |
93 RTCSdpType sdpType = description.type; | 121 RTCSdpType sdpType = description.type; |
94 switch (sdpType) { | 122 switch (sdpType) { |
95 case RTCSdpTypeOffer: | 123 case RTCSdpTypeOffer: |
96 messageType = kARDSignalingMessageTypeOffer; | 124 messageType = kARDSignalingMessageTypeOffer; |
(...skipping 27 matching lines...) Expand all Loading... |
124 - (NSData *)JSONData { | 152 - (NSData *)JSONData { |
125 NSDictionary *message = @{ | 153 NSDictionary *message = @{ |
126 @"type": @"bye" | 154 @"type": @"bye" |
127 }; | 155 }; |
128 return [NSJSONSerialization dataWithJSONObject:message | 156 return [NSJSONSerialization dataWithJSONObject:message |
129 options:NSJSONWritingPrettyPrinted | 157 options:NSJSONWritingPrettyPrinted |
130 error:NULL]; | 158 error:NULL]; |
131 } | 159 } |
132 | 160 |
133 @end | 161 @end |
OLD | NEW |