| 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 "RTCLogging.h" | 13 #import "webrtc/base/objc/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 | 20 |
| 21 @implementation RTCICECandidate (JSON) | 21 @implementation RTCIceCandidate (JSON) |
| 22 | 22 |
| 23 + (RTCICECandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary { | 23 + (RTCIceCandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary { |
| 24 NSString *mid = dictionary[kRTCICECandidateMidKey]; | 24 NSString *mid = dictionary[kRTCICECandidateMidKey]; |
| 25 NSString *sdp = dictionary[kRTCICECandidateSdpKey]; | 25 NSString *sdp = dictionary[kRTCICECandidateSdpKey]; |
| 26 NSNumber *num = dictionary[kRTCICECandidateMLineIndexKey]; | 26 NSNumber *num = dictionary[kRTCICECandidateMLineIndexKey]; |
| 27 NSInteger mLineIndex = [num integerValue]; | 27 NSInteger mLineIndex = [num integerValue]; |
| 28 return [[RTCICECandidate alloc] initWithMid:mid index:mLineIndex sdp:sdp]; | 28 return [[RTCIceCandidate alloc] initWithSdp:sdp |
| 29 sdpMLineIndex:mLineIndex |
| 30 sdpMid:mid]; |
| 29 } | 31 } |
| 30 | 32 |
| 31 - (NSData *)JSONData { | 33 - (NSData *)JSONData { |
| 32 NSDictionary *json = @{ | 34 NSDictionary *json = @{ |
| 33 kRTCICECandidateTypeKey : kRTCICECandidateTypeValue, | 35 kRTCICECandidateTypeKey : kRTCICECandidateTypeValue, |
| 34 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), | 36 kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), |
| 35 kRTCICECandidateMidKey : self.sdpMid, | 37 kRTCICECandidateMidKey : self.sdpMid, |
| 36 kRTCICECandidateSdpKey : self.sdp | 38 kRTCICECandidateSdpKey : self.sdp |
| 37 }; | 39 }; |
| 38 NSError *error = nil; | 40 NSError *error = nil; |
| 39 NSData *data = | 41 NSData *data = |
| 40 [NSJSONSerialization dataWithJSONObject:json | 42 [NSJSONSerialization dataWithJSONObject:json |
| 41 options:NSJSONWritingPrettyPrinted | 43 options:NSJSONWritingPrettyPrinted |
| 42 error:&error]; | 44 error:&error]; |
| 43 if (error) { | 45 if (error) { |
| 44 RTCLogError(@"Error serializing JSON: %@", error); | 46 RTCLogError(@"Error serializing JSON: %@", error); |
| 45 return nil; | 47 return nil; |
| 46 } | 48 } |
| 47 return data; | 49 return data; |
| 48 } | 50 } |
| 49 | 51 |
| 50 @end | 52 @end |
| OLD | NEW |