| 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 |
| 85 @end | 85 @end |
| 86 | 86 |
| 87 @implementation ARDSessionDescriptionMessage | 87 @implementation ARDSessionDescriptionMessage |
| 88 | 88 |
| 89 @synthesize sessionDescription = _sessionDescription; | 89 @synthesize sessionDescription = _sessionDescription; |
| 90 | 90 |
| 91 - (instancetype)initWithDescription:(RTCSessionDescription *)description { | 91 - (instancetype)initWithDescription:(RTCSessionDescription *)description { |
| 92 ARDSignalingMessageType type = kARDSignalingMessageTypeOffer; | 92 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer; |
| 93 NSString *typeString = description.type; | 93 RTCSdpType sdpType = description.type; |
| 94 if ([typeString isEqualToString:@"offer"]) { | 94 switch (sdpType) { |
| 95 type = kARDSignalingMessageTypeOffer; | 95 case RTCSdpTypeOffer: |
| 96 } else if ([typeString isEqualToString:@"answer"]) { | 96 messageType = kARDSignalingMessageTypeOffer; |
| 97 type = kARDSignalingMessageTypeAnswer; | 97 case RTCSdpTypeAnswer: |
| 98 } else { | 98 messageType = kARDSignalingMessageTypeAnswer; |
| 99 NSAssert(NO, @"Unexpected type: %@", typeString); | 99 case RTCSdpTypePrAnswer: |
| 100 NSAssert(NO, @"Unexpected type: %@", |
| 101 [RTCSessionDescription stringForType:sdpType]); |
| 100 } | 102 } |
| 101 if (self = [super initWithType:type]) { | 103 if (self = [super initWithType:messageType]) { |
| 102 _sessionDescription = description; | 104 _sessionDescription = description; |
| 103 } | 105 } |
| 104 return self; | 106 return self; |
| 105 } | 107 } |
| 106 | 108 |
| 107 - (NSData *)JSONData { | 109 - (NSData *)JSONData { |
| 108 return [_sessionDescription JSONData]; | 110 return [_sessionDescription JSONData]; |
| 109 } | 111 } |
| 110 | 112 |
| 111 @end | 113 @end |
| 112 | 114 |
| 113 @implementation ARDByeMessage | 115 @implementation ARDByeMessage |
| 114 | 116 |
| 115 - (instancetype)init { | 117 - (instancetype)init { |
| 116 return [super initWithType:kARDSignalingMessageTypeBye]; | 118 return [super initWithType:kARDSignalingMessageTypeBye]; |
| 117 } | 119 } |
| 118 | 120 |
| 119 - (NSData *)JSONData { | 121 - (NSData *)JSONData { |
| 120 NSDictionary *message = @{ | 122 NSDictionary *message = @{ |
| 121 @"type": @"bye" | 123 @"type": @"bye" |
| 122 }; | 124 }; |
| 123 return [NSJSONSerialization dataWithJSONObject:message | 125 return [NSJSONSerialization dataWithJSONObject:message |
| 124 options:NSJSONWritingPrettyPrinted | 126 options:NSJSONWritingPrettyPrinted |
| 125 error:NULL]; | 127 error:NULL]; |
| 126 } | 128 } |
| 127 | 129 |
| 128 @end | 130 @end |
| OLD | NEW |