Chromium Code Reviews| 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 "RTCIceCandidate+JSON.h" | 11 #import "RTCIceCandidate+JSON.h" |
| 12 | 12 |
| 13 #import "WebRTC/RTCLogging.h" | 13 #import "WebRTC/RTCLogging.h" |
| 14 | 14 |
| 15 static NSString const *kRTCICECandidateTypeKey = @"type"; | 15 static NSString const *kRTCICECandidateTypeKey = @"type"; |
| 16 static NSString const *kRTCICECandidateTypeValue = @"candidate"; | 16 static NSString const *kRTCICECandidateTypeValue = @"candidate"; |
| 17 static NSString const *kRTCICECandidateMidKey = @"id"; | 17 static NSString const *kRTCICECandidateMidKey = @"id"; |
| 18 static NSString const *kRTCICECandidateMLineIndexKey = @"label"; | 18 static NSString const *kRTCICECandidateMLineIndexKey = @"label"; |
| 19 static NSString const *kRTCICECandidateSdpKey = @"candidate"; | 19 static NSString const *kRTCICECandidateSdpKey = @"candidate"; |
| 20 static NSString const *kRTCICECandidatesTypeKey = @"candidates"; | 20 static NSString const *kRTCICECandidatesTypeKey = @"candidates"; |
| 21 static NSString const *kRTCICECandidatesServerUrlKey = @"url"; | |
|
Taylor Brandstetter
2017/02/13 23:53:00
Candidate server URLs don't need to be signaled, s
Zhi Huang
2017/02/14 19:09:08
Done.
| |
| 21 | 22 |
| 22 | 23 |
| 23 @implementation RTCIceCandidate (JSON) | 24 @implementation RTCIceCandidate (JSON) |
| 24 | 25 |
| 25 + (RTCIceCandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary { | 26 + (RTCIceCandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary { |
| 26 NSString *mid = dictionary[kRTCICECandidateMidKey]; | 27 NSString *mid = dictionary[kRTCICECandidateMidKey]; |
| 27 NSString *sdp = dictionary[kRTCICECandidateSdpKey]; | 28 NSString *sdp = dictionary[kRTCICECandidateSdpKey]; |
| 28 NSNumber *num = dictionary[kRTCICECandidateMLineIndexKey]; | 29 NSNumber *num = dictionary[kRTCICECandidateMLineIndexKey]; |
| 29 NSInteger mLineIndex = [num integerValue]; | 30 NSInteger mLineIndex = [num integerValue]; |
| 31 NSString *url = dictionary[kRTCICECandidatesServerUrlKey]; | |
| 30 return [[RTCIceCandidate alloc] initWithSdp:sdp | 32 return [[RTCIceCandidate alloc] initWithSdp:sdp |
| 31 sdpMLineIndex:mLineIndex | 33 sdpMLineIndex:mLineIndex |
| 32 sdpMid:mid]; | 34 sdpMid:mid |
| 35 serverUrl:url]; | |
| 33 } | 36 } |
| 34 | 37 |
| 35 + (NSData *)JSONDataForIceCandidates:(NSArray<RTCIceCandidate *> *)candidates | 38 + (NSData *)JSONDataForIceCandidates:(NSArray<RTCIceCandidate *> *)candidates |
| 36 withType:(NSString *)typeValue { | 39 withType:(NSString *)typeValue { |
| 37 NSMutableArray *jsonCandidates = | 40 NSMutableArray *jsonCandidates = |
| 38 [NSMutableArray arrayWithCapacity:candidates.count]; | 41 [NSMutableArray arrayWithCapacity:candidates.count]; |
| 39 for (RTCIceCandidate *candidate in candidates) { | 42 for (RTCIceCandidate *candidate in candidates) { |
| 40 NSDictionary *jsonCandidate = [candidate JSONDictionary]; | 43 NSDictionary *jsonCandidate = [candidate JSONDictionary]; |
| 41 [jsonCandidates addObject:jsonCandidate]; | 44 [jsonCandidates addObject:jsonCandidate]; |
| 42 } | 45 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 67 [candidates addObject:candidate]; | 70 [candidates addObject:candidate]; |
| 68 } | 71 } |
| 69 return candidates; | 72 return candidates; |
| 70 } | 73 } |
| 71 | 74 |
| 72 - (NSData *)JSONData { | 75 - (NSData *)JSONData { |
| 73 NSDictionary *json = @{ | 76 NSDictionary *json = @{ |
| 74 kRTCICECandidateTypeKey : kRTCICECandidateTypeValue, | 77 kRTCICECandidateTypeKey : kRTCICECandidateTypeValue, |
| 75 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), | 78 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), |
| 76 kRTCICECandidateMidKey : self.sdpMid, | 79 kRTCICECandidateMidKey : self.sdpMid, |
| 77 kRTCICECandidateSdpKey : self.sdp | 80 kRTCICECandidateSdpKey : self.sdp, |
| 81 kRTCICECandidatesServerUrlKey : self.serverUrl | |
| 78 }; | 82 }; |
| 79 NSError *error = nil; | 83 NSError *error = nil; |
| 80 NSData *data = | 84 NSData *data = |
| 81 [NSJSONSerialization dataWithJSONObject:json | 85 [NSJSONSerialization dataWithJSONObject:json |
| 82 options:NSJSONWritingPrettyPrinted | 86 options:NSJSONWritingPrettyPrinted |
| 83 error:&error]; | 87 error:&error]; |
| 84 if (error) { | 88 if (error) { |
| 85 RTCLogError(@"Error serializing JSON: %@", error); | 89 RTCLogError(@"Error serializing JSON: %@", error); |
| 86 return nil; | 90 return nil; |
| 87 } | 91 } |
| 88 return data; | 92 return data; |
| 89 } | 93 } |
| 90 | 94 |
| 91 - (NSDictionary *)JSONDictionary{ | 95 - (NSDictionary *)JSONDictionary{ |
| 92 NSDictionary *json = @{ | 96 NSDictionary *json = @{ |
| 93 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), | 97 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), |
| 94 kRTCICECandidateMidKey : self.sdpMid, | 98 kRTCICECandidateMidKey : self.sdpMid, |
| 95 kRTCICECandidateSdpKey : self.sdp | 99 kRTCICECandidateSdpKey : self.sdp, |
| 100 kRTCICECandidatesServerUrlKey : self.serverUrl | |
| 96 }; | 101 }; |
| 97 return json; | 102 return json; |
| 98 } | 103 } |
| 99 | 104 |
| 100 @end | 105 @end |
| OLD | NEW |