mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-15 14:50:39 +01:00

This CL separates the files under sdk/objc into logical directories, replacing the previous file layout under Framework/. A long term goal is to have some system set up to generate the files under sdk/objc/api (the PeerConnection API wrappers) from the C++ code. In the shorter term the goal is to abstract out shared concepts from these classes in order to make them as uniform as possible. The separation into base/, components/, and helpers/ are to differentiate between the base layer's common protocols, various utilities and the actual platform specific components. The old directory layout that resembled a framework's internal layout is not necessary, since it is generated by the framework target when building it. Bug: webrtc:9627 Change-Id: Ib084fd83f050ae980649ca99e841f4fb0580bd8f Reviewed-on: https://webrtc-review.googlesource.com/94142 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24493}
161 lines
4.5 KiB
Objective-C
161 lines
4.5 KiB
Objective-C
/*
|
|
* Copyright 2014 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 "ARDSignalingMessage.h"
|
|
|
|
#import <WebRTC/RTCLogging.h>
|
|
|
|
#import "ARDUtilities.h"
|
|
#import "RTCIceCandidate+JSON.h"
|
|
#import "RTCSessionDescription+JSON.h"
|
|
|
|
static NSString * const kARDSignalingMessageTypeKey = @"type";
|
|
static NSString * const kARDTypeValueRemoveCandidates = @"remove-candidates";
|
|
|
|
@implementation ARDSignalingMessage
|
|
|
|
@synthesize type = _type;
|
|
|
|
- (instancetype)initWithType:(ARDSignalingMessageType)type {
|
|
if (self = [super init]) {
|
|
_type = type;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSString *)description {
|
|
return [[NSString alloc] initWithData:[self JSONData]
|
|
encoding:NSUTF8StringEncoding];
|
|
}
|
|
|
|
+ (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString {
|
|
NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString];
|
|
if (!values) {
|
|
RTCLogError(@"Error parsing signaling message JSON.");
|
|
return nil;
|
|
}
|
|
|
|
NSString *typeString = values[kARDSignalingMessageTypeKey];
|
|
ARDSignalingMessage *message = nil;
|
|
if ([typeString isEqualToString:@"candidate"]) {
|
|
RTCIceCandidate *candidate =
|
|
[RTCIceCandidate candidateFromJSONDictionary:values];
|
|
message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate];
|
|
} else if ([typeString isEqualToString:kARDTypeValueRemoveCandidates]) {
|
|
RTCLogInfo(@"Received remove-candidates message");
|
|
NSArray<RTCIceCandidate *> *candidates =
|
|
[RTCIceCandidate candidatesFromJSONDictionary:values];
|
|
message = [[ARDICECandidateRemovalMessage alloc]
|
|
initWithRemovedCandidates:candidates];
|
|
} else if ([typeString isEqualToString:@"offer"] ||
|
|
[typeString isEqualToString:@"answer"]) {
|
|
RTCSessionDescription *description =
|
|
[RTCSessionDescription descriptionFromJSONDictionary:values];
|
|
message =
|
|
[[ARDSessionDescriptionMessage alloc] initWithDescription:description];
|
|
} else if ([typeString isEqualToString:@"bye"]) {
|
|
message = [[ARDByeMessage alloc] init];
|
|
} else {
|
|
RTCLogError(@"Unexpected type: %@", typeString);
|
|
}
|
|
return message;
|
|
}
|
|
|
|
- (NSData *)JSONData {
|
|
return nil;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ARDICECandidateMessage
|
|
|
|
@synthesize candidate = _candidate;
|
|
|
|
- (instancetype)initWithCandidate:(RTCIceCandidate *)candidate {
|
|
if (self = [super initWithType:kARDSignalingMessageTypeCandidate]) {
|
|
_candidate = candidate;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSData *)JSONData {
|
|
return [_candidate JSONData];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ARDICECandidateRemovalMessage
|
|
|
|
@synthesize candidates = _candidates;
|
|
|
|
- (instancetype)initWithRemovedCandidates:(
|
|
NSArray<RTCIceCandidate *> *)candidates {
|
|
NSParameterAssert(candidates.count);
|
|
if (self = [super initWithType:kARDSignalingMessageTypeCandidateRemoval]) {
|
|
_candidates = candidates;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSData *)JSONData {
|
|
return
|
|
[RTCIceCandidate JSONDataForIceCandidates:_candidates
|
|
withType:kARDTypeValueRemoveCandidates];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ARDSessionDescriptionMessage
|
|
|
|
@synthesize sessionDescription = _sessionDescription;
|
|
|
|
- (instancetype)initWithDescription:(RTCSessionDescription *)description {
|
|
ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer;
|
|
RTCSdpType sdpType = description.type;
|
|
switch (sdpType) {
|
|
case RTCSdpTypeOffer:
|
|
messageType = kARDSignalingMessageTypeOffer;
|
|
break;
|
|
case RTCSdpTypeAnswer:
|
|
messageType = kARDSignalingMessageTypeAnswer;
|
|
break;
|
|
case RTCSdpTypePrAnswer:
|
|
NSAssert(NO, @"Unexpected type: %@",
|
|
[RTCSessionDescription stringForType:sdpType]);
|
|
break;
|
|
}
|
|
if (self = [super initWithType:messageType]) {
|
|
_sessionDescription = description;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSData *)JSONData {
|
|
return [_sessionDescription JSONData];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ARDByeMessage
|
|
|
|
- (instancetype)init {
|
|
return [super initWithType:kARDSignalingMessageTypeBye];
|
|
}
|
|
|
|
- (NSData *)JSONData {
|
|
NSDictionary *message = @{
|
|
@"type": @"bye"
|
|
};
|
|
return [NSJSONSerialization dataWithJSONObject:message
|
|
options:NSJSONWritingPrettyPrinted
|
|
error:NULL];
|
|
}
|
|
|
|
@end
|