Add WebRTC setting.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-01-11 17:11:26 -05:00
parent d1aa253f87
commit 0f45f292a1
8 changed files with 23 additions and 12 deletions

View File

@ -64,6 +64,7 @@ static NSString *const TSRegistrationErrorUserInfoHTTPStatus = @"TSHTTPStatus";
+ (void)rerequestVoiceWithSuccess:(void (^)())successBlock failure:(void (^)(NSError *error))failureBlock;
- (void)verifyAccountWithCode:(NSString *)verificationCode
isWebRTCEnabled:(BOOL)isWebRTCEnabled
success:(void (^)())successBlock
failure:(void (^)(NSError *error))failureBlock;

View File

@ -181,6 +181,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)verifyAccountWithCode:(NSString *)verificationCode
isWebRTCEnabled:(BOOL)isWebRTCEnabled
success:(void (^)())successBlock
failure:(void (^)(NSError *error))failureBlock
{
@ -195,7 +196,8 @@ NS_ASSUME_NONNULL_BEGIN
TSVerifyCodeRequest *request = [[TSVerifyCodeRequest alloc] initWithVerificationCode:verificationCode
forNumber:phoneNumber
signalingKey:signalingKey
authKey:authToken];
authKey:authToken
isWebRTCEnabled:isWebRTCEnabled];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {

View File

@ -10,9 +10,10 @@
@interface TSAttributes : NSObject
+ (NSDictionary *)attributesFromStorageWithVoiceSupport;
+ (NSDictionary *)attributesFromStorage:(BOOL)isWebRTCEnabled;
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken;
serverAuthToken:(NSString *)authToken
isWebRTCEnabled:(BOOL)isWebRTCEnabled;
@end

View File

@ -13,18 +13,21 @@
@implementation TSAttributes
+ (NSDictionary *)attributesFromStorageWithVoiceSupport {
+ (NSDictionary *)attributesFromStorage:(BOOL)isWebRTCEnabled {
return [self attributesWithSignalingKey:[TSStorageManager signalingKey]
serverAuthToken:[TSStorageManager serverAuthToken]];
serverAuthToken:[TSStorageManager serverAuthToken]
isWebRTCEnabled:isWebRTCEnabled];
}
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken
isWebRTCEnabled:(BOOL)isWebRTCEnabled
{
return @{
@"signalingKey" : signalingKey,
@"AuthKey" : authToken,
@"voice" : [NSNumber numberWithBool:YES], // all Signal-iOS clients support voice
@"voice" : @(YES), // all Signal-iOS clients support voice
@"video" : @(isWebRTCEnabled),
@"registrationId" : [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]]
};
}

View File

@ -10,6 +10,6 @@
@interface TSUpdateAttributesRequest : TSRequest
- (instancetype)initWithUpdatedAttributesWithVoice;
- (instancetype)initWithUpdatedAttributes:(BOOL)isWebRTCEnabled;
@end

View File

@ -12,13 +12,13 @@
@implementation TSUpdateAttributesRequest
- (instancetype)initWithUpdatedAttributesWithVoice {
- (instancetype)initWithUpdatedAttributes:(BOOL)isWebRTCEnabled {
NSString *endPoint = [textSecureAccountsAPI stringByAppendingString:textSecureAttributesAPI];
self = [super initWithURL:[NSURL URLWithString:endPoint]];
if (self) {
[self setHTTPMethod:@"PUT"];
[self.parameters addEntriesFromDictionary:[TSAttributes attributesFromStorageWithVoiceSupport]];
[self.parameters addEntriesFromDictionary:[TSAttributes attributesFromStorage:isWebRTCEnabled]];
}
return self;

View File

@ -13,7 +13,8 @@
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
forNumber:(NSString *)phoneNumber
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey;
authKey:(NSString *)authKey
isWebRTCEnabled:(BOOL)isWebRTCEnabled;
@property (nonatomic, readonly) NSString *numberToValidate;

View File

@ -16,13 +16,16 @@
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
forNumber:(NSString *)phoneNumber
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey {
authKey:(NSString *)authKey
isWebRTCEnabled:(BOOL)isWebRTCEnabled {
self = [super
initWithURL:[NSURL URLWithString:[NSString
stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]]];
NSDictionary *attributes =
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey];
[TSAttributes attributesWithSignalingKey:signalingKey
serverAuthToken:authKey
isWebRTCEnabled:isWebRTCEnabled];
_numberToValidate = phoneNumber;
[self.parameters addEntriesFromDictionary:attributes];