Index: webrtc/examples/objc/AppRTCDemo/RTCSessionDescription+JSON.m |
diff --git a/webrtc/examples/objc/AppRTCDemo/RTCSessionDescription+JSON.m b/webrtc/examples/objc/AppRTCDemo/RTCSessionDescription+JSON.m |
index b5655e0e8224d129672d4886616896acd37d7b74..9a7bb5142463ea22e89fcf15439f20052b452934 100644 |
--- a/webrtc/examples/objc/AppRTCDemo/RTCSessionDescription+JSON.m |
+++ b/webrtc/examples/objc/AppRTCDemo/RTCSessionDescription+JSON.m |
@@ -15,17 +15,42 @@ static NSString const *kRTCSessionDescriptionSdpKey = @"sdp"; |
@implementation RTCSessionDescription (JSON) |
++ (NSString *)stringForType:(RTCSdpType)type { |
hjon_webrtc
2016/02/12 17:34:56
Both this class and ARDSignalingMessage currently
|
+ switch (type) { |
+ case RTCSdpTypeOffer: |
+ return @"offer"; |
+ case RTCSdpTypePrAnswer: |
+ return @"pranswer"; |
+ case RTCSdpTypeAnswer: |
+ return @"answer"; |
+ } |
+} |
+ |
++ (RTCSdpType)typeForString:(NSString *)string { |
+ if ([string isEqualToString:@"offer"]) { |
+ return RTCSdpTypeOffer; |
+ } else if ([string isEqualToString:@"pranswer"]) { |
+ return RTCSdpTypePrAnswer; |
+ } else if ([string isEqualToString:@"answer"]) { |
+ return RTCSdpTypeAnswer; |
+ } else { |
+ return RTCSdpTypeOffer; |
+ } |
+} |
+ |
+ (RTCSessionDescription *)descriptionFromJSONDictionary: |
(NSDictionary *)dictionary { |
- NSString *type = dictionary[kRTCSessionDescriptionTypeKey]; |
+ NSString *typeString = dictionary[kRTCSessionDescriptionTypeKey]; |
+ RTCSdpType type = [[self class] typeForString:typeString]; |
NSString *sdp = dictionary[kRTCSessionDescriptionSdpKey]; |
return [[RTCSessionDescription alloc] initWithType:type sdp:sdp]; |
} |
- (NSData *)JSONData { |
+ NSString *type = [[self class] stringForType:self.type]; |
NSDictionary *json = @{ |
- kRTCSessionDescriptionTypeKey : self.type, |
- kRTCSessionDescriptionSdpKey : self.description |
+ kRTCSessionDescriptionTypeKey : type, |
+ kRTCSessionDescriptionSdpKey : self.sdp |
}; |
return [NSJSONSerialization dataWithJSONObject:json options:0 error:nil]; |
} |