Chromium Code Reviews| Index: webrtc/api/objc/RTCSessionDescription.mm |
| diff --git a/webrtc/api/objc/RTCSessionDescription.mm b/webrtc/api/objc/RTCSessionDescription.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6b93b8262fa240e19c4326f52e5501074488fce3 |
| --- /dev/null |
| +++ b/webrtc/api/objc/RTCSessionDescription.mm |
| @@ -0,0 +1,92 @@ |
| +/* |
| + * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#import "RTCSessionDescription.h" |
| + |
| +#import "webrtc/api/objc/RTCSessionDescription+Private.h" |
| +#import "webrtc/base/objc/NSString+StdString.h" |
| +#import "webrtc/base/objc/RTCLogging.h" |
| + |
| +@implementation RTCSessionDescription |
| + |
| +@synthesize type = _type; |
| +@synthesize sdp = _sdp; |
| + |
| +- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { |
| + NSParameterAssert(sdp.length); |
| + if (self = [super init]) { |
| + _type = type; |
| + _sdp = [sdp copy]; |
| + } |
| + return self; |
| +} |
| + |
| +- (NSString *)description { |
| + return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@", |
| + [[self class] stringForType:_type], |
| + _sdp]; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (webrtc::SessionDescriptionInterface *)nativeDescription { |
| + webrtc::SdpParseError error; |
| + |
| + NSString *typeString = [[self class] stringForType:_type]; |
| + webrtc::SessionDescriptionInterface *description = |
| + webrtc::CreateSessionDescription(typeString.stdString, |
| + _sdp.stdString, |
| + &error); |
| + |
| + if (!description) { |
| + RTCLog(@"Failed to create session description: %s\nline: %s", |
| + error.description.c_str(), |
| + error.line.c_str()); |
| + } |
| + |
| + return description; |
| +} |
| + |
| +- (instancetype)initWithNativeDescription: |
| + (webrtc::SessionDescriptionInterface *)description { |
| + NSParameterAssert(description); |
| + std::string sdp; |
| + description->ToString(&sdp); |
| + NSString *typeString = [NSString stringForStdString:description->type()]; |
| + |
| + return [self initWithType:[[self class] typeForString:typeString] |
| + sdp:[NSString stringForStdString:sdp]]; |
| +} |
| + |
| ++ (NSString *)stringForType:(RTCSdpType)type { |
| + switch (type) { |
| + case RTCSdpTypeOffer: |
| + return @"offer"; |
| + case RTCSdpTypePrAnswer: |
| + return @"pranswer"; |
| + case RTCSdpTypeAnswer: |
| + return @"answer"; |
| + } |
| +} |
| + |
| ++ (RTCSdpType)typeForString:(NSString *)string { |
| + NSParameterAssert(string.length); |
| + if ([string isEqualToString:@"offer"]) { |
| + return RTCSdpTypeOffer; |
| + } else if ([string isEqualToString:@"pranswer"]) { |
| + return RTCSdpTypePrAnswer; |
| + } else if ([string isEqualToString:@"answer"]) { |
| + return RTCSdpTypeAnswer; |
| + } else { |
| + NSAssert(false, @"|string| is not a known SDP type."); |
|
hjon
2016/01/05 22:16:20
tkchin@ What do you think about this method? Conce
|
| + } |
| +} |
| + |
| +@end |