From f4453eb995831745acfd8ce2a433be03e973c8ac Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 21 Feb 2017 11:10:57 -0500 Subject: [PATCH] Enable WebRTC-based audio and video calls by default. // FREEBIE --- Podfile | 4 +- Podfile.lock | 7 +- Signal/src/Models/AccountManager.swift | 2 - Signal/src/call/OutboundCallInitiator.swift | 9 +-- .../src/environment/PropertyListPreferences.h | 5 -- .../src/environment/PropertyListPreferences.m | 15 ---- Signal/src/environment/VersionMigrations.m | 4 +- .../AdvancedSettingsTableViewController.m | 69 +------------------ Signal/test/Models/AccountManagerTest.swift | 34 ++++----- 9 files changed, 28 insertions(+), 121 deletions(-) diff --git a/Podfile b/Podfile index ffd1c3806..6665c0f11 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,8 @@ target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' #pod 'AxolotlKit', path: '../SignalProtocolKit' - pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' - #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', :branch => 'charlesmchen/rateLimitingErrorMessage' + #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' + pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', :branch => 'charlesmchen/webrtcByDefault' #pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'OpenSSL' pod 'PastelogKit', '~> 1.3' diff --git a/Podfile.lock b/Podfile.lock index bf499e8de..ae8e05b2b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -123,7 +123,7 @@ DEPENDENCIES: - PastelogKit (~> 1.3) - PureLayout - SCWaveformView (~> 1.0) - - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) + - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`, branch `charlesmchen/webrtcByDefault`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) - ZXingObjC @@ -131,6 +131,7 @@ EXTERNAL SOURCES: AxolotlKit: :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: + :branch: charlesmchen/webrtcByDefault :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -140,7 +141,7 @@ CHECKOUT OPTIONS: :commit: a3c843cc8a423c5924c663490978f81dba34d04e :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :commit: c72e8f8e2f0b63a9ec86a27532b8fbfc3c99395a + :commit: f1b71ea64b80c370b28b00f0d53fd5f9d49601d8 :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf @@ -172,6 +173,6 @@ SPEC CHECKSUMS: YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f ZXingObjC: bbf7b8f0cf8933fdd33eb4f9f46e22308552869b -PODFILE CHECKSUM: 23ca4df281ad1e794af6967db2047f43df88e96a +PODFILE CHECKSUM: 473f742acb194322c317b63a1b5db6ca0864a0f1 COCOAPODS: 1.1.1 diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index 29692943b..b3e6c0344 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -54,9 +54,7 @@ class AccountManager: NSObject { private func registerForTextSecure(verificationCode: String) -> Promise { return Promise { fulfill, reject in - let isWebRTCEnabled = Environment.preferences().isWebRTCEnabled() self.textSecureAccountManager.verifyAccount(withCode:verificationCode, - isWebRTCEnabled:isWebRTCEnabled, success:fulfill, failure:reject) } diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index bd741f0e8..cb027e231 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -65,11 +65,6 @@ import Foundation */ public func initiateCall(recipientId: String) -> Bool { - let localWantsWebRTC = Environment.preferences().isWebRTCEnabled() - if !localWantsWebRTC { - return self.initiateRedphoneCall(recipientId: recipientId) - } - // A temporary unique id used to identify this call during the let callToken = NSUUID().uuidString presentCallInterstitial(callToken:callToken) @@ -97,9 +92,9 @@ import Foundation } let remoteWantsWebRTC = recipient.supportsWebRTC - Logger.debug("\(self.TAG) localWantsWebRTC: \(localWantsWebRTC), remoteWantsWebRTC: \(remoteWantsWebRTC)") + Logger.debug("\(self.TAG) remoteWantsWebRTC: \(remoteWantsWebRTC)") - if localWantsWebRTC, remoteWantsWebRTC { + if remoteWantsWebRTC { _ = self.initiateWebRTCAudioCall(recipientId: recipientId) } else { _ = self.initiateRedphoneCall(recipientId: recipientId) diff --git a/Signal/src/environment/PropertyListPreferences.h b/Signal/src/environment/PropertyListPreferences.h index 4693a5a88..357a6cb0d 100644 --- a/Signal/src/environment/PropertyListPreferences.h +++ b/Signal/src/environment/PropertyListPreferences.h @@ -66,11 +66,6 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog; #pragma mark - Calling -#pragma mark WebRTC - -- (BOOL)isWebRTCEnabled; -- (void)setIsWebRTCEnabled:(BOOL)flag; - #pragma mark Callkit - (BOOL)isCallKitEnabled; diff --git a/Signal/src/environment/PropertyListPreferences.m b/Signal/src/environment/PropertyListPreferences.m index 4923b7223..1709f5bbc 100644 --- a/Signal/src/environment/PropertyListPreferences.m +++ b/Signal/src/environment/PropertyListPreferences.m @@ -22,7 +22,6 @@ NSString *const PropertyListPreferencesKeyPlaySoundInForeground = @"Notification NSString *const PropertyListPreferencesKeyHasRegisteredVoipPush = @"VOIPPushEnabled"; NSString *const PropertyListPreferencesKeyLastRecordedPushToken = @"LastRecordedPushToken"; NSString *const PropertyListPreferencesKeyLastRecordedVoipToken = @"LastRecordedVoipToken"; -NSString *const PropertyListPreferencesKeyWebRTCEnabled = @"WebRTCEnabled"; NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled"; @implementation PropertyListPreferences @@ -170,20 +169,6 @@ NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled"; #pragma mark - Calling -#pragma mark WebRTC - -- (BOOL)isWebRTCEnabled -{ - NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyWebRTCEnabled]; - // Currently default to NO. - return preference ? [preference boolValue] : NO; -} - -- (void)setIsWebRTCEnabled:(BOOL)flag -{ - [self setValueForKey:PropertyListPreferencesKeyWebRTCEnabled toValue:@(flag)]; -} - #pragma mark CallKit - (BOOL)isCallKitEnabled diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index 49e9cb3c8..4f173368d 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -152,9 +152,7 @@ __block BOOL success; - BOOL isWebRTCEnabled = [Environment.preferences isWebRTCEnabled]; - TSUpdateAttributesRequest *request = - [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributes:isWebRTCEnabled]; + TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributesWithVoice]; [[TSNetworkManager sharedManager] makeRequest:request success:^(NSURLSessionDataTask *task, id responseObject) { success = YES; diff --git a/Signal/src/view controllers/AdvancedSettingsTableViewController.m b/Signal/src/view controllers/AdvancedSettingsTableViewController.m index 467207ea5..cf5a1cddf 100644 --- a/Signal/src/view controllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/view controllers/AdvancedSettingsTableViewController.m @@ -18,13 +18,11 @@ NS_ASSUME_NONNULL_BEGIN @interface AdvancedSettingsTableViewController () -@property (nonatomic) UITableViewCell *enableWebRTCCell; @property (nonatomic) UITableViewCell *enableCallKitCell; @property (nonatomic) UITableViewCell *enableLogCell; @property (nonatomic) UITableViewCell *submitLogCell; @property (nonatomic) UITableViewCell *registerPushCell; -@property (nonatomic) UISwitch *enableWebRTCSwitch; @property (nonatomic) UISwitch *enableCallKitSwitch; @property (nonatomic) UISwitch *enableLogSwitch; @property (nonatomic, readonly) BOOL supportsCallKit; @@ -59,18 +57,6 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { [self useOWSBackButton]; - // WebRTC - self.enableWebRTCCell = [[UITableViewCell alloc] init]; - self.enableWebRTCCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_WEBRTC", - @"This setting is used to switch between new-style WebRTC calling and old-style RedPhone calling."); - self.enableWebRTCCell.userInteractionEnabled = YES; - self.enableWebRTCSwitch = [UISwitch new]; - [self.enableWebRTCSwitch setOn:[Environment.preferences isWebRTCEnabled]]; - [self.enableWebRTCSwitch addTarget:self - action:@selector(didToggleEnableWebRTCSwitch:) - forControlEvents:UIControlEventTouchUpInside]; - self.enableWebRTCCell.accessoryView = self.enableWebRTCSwitch; - // CallKit opt-out self.enableCallKitCell = [UITableViewCell new]; self.enableCallKitCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_CALLKIT_TITLE", @"Short table cell label"); @@ -113,7 +99,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { case AdvancedSettingsTableViewControllerSectionLogging: return self.enableLogSwitch.isOn ? 2 : 1; case AdvancedSettingsTableViewControllerSectionCalling: - return ([Environment.preferences isWebRTCEnabled] && self.supportsCallKit) ? 2 : 1; + return self.supportsCallKit ? 2 : 1; case AdvancedSettingsTableViewControllerSectionPushNotifications: return 1; default: @@ -141,8 +127,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)section; switch (settingsSection) { case AdvancedSettingsTableViewControllerSectionCalling: - // We only show the CallKit setting if WebRTC is enabled. - if ([Environment.preferences isWebRTCEnabled] && [self supportsCallKit]) { + if ([self supportsCallKit]) { return NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer."); } default: @@ -165,8 +150,6 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { case AdvancedSettingsTableViewControllerSectionCalling: switch (indexPath.row) { case 0: - return self.enableWebRTCCell; - case 1: OWSAssert(self.supportsCallKit); return self.enableCallKitCell; default: @@ -210,54 +193,6 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { #pragma mark - Actions -- (void)didToggleEnableWebRTCSwitch:(UISwitch *)sender { - static long long enableWebRTCRequestCounter = 0; - long long enableWebRTCRequestId = ++enableWebRTCRequestCounter; - - __weak AdvancedSettingsTableViewController *weakSelf = self; - BOOL isWebRTCEnabled = sender.isOn; - DDLogInfo(@"%@ User set WebRTC calling to: %@", self.tag, (isWebRTCEnabled ? @"ON" : @"OFF")); - TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributes:isWebRTCEnabled]; - [[TSNetworkManager sharedManager] makeRequest:request - success:^(NSURLSessionDataTask *task, id responseObject) { - - // Use the request id to ignore obsolete requests, e.g. if the - // user repeatedly changes the setting faster than the requests - // can complete. - if (enableWebRTCRequestCounter != enableWebRTCRequestId) { - return; - } - - // Only update the local setting if the request succeeds; - // otherwise local and service state will fall out of sync - // with every network failure. - [Environment.preferences setIsWebRTCEnabled:isWebRTCEnabled]; - - [weakSelf.tableView reloadData]; - } - failure:^(NSURLSessionDataTask *task, NSError *error) { - DDLogError(@"Updating attributes failed with error: %@", error.description); - - AdvancedSettingsTableViewController *strongSelf = weakSelf; - // Use the request id to ignore obsolete requests, e.g. if the - // user repeatedly changes the setting faster than the requests - // can complete. - if (!strongSelf || - enableWebRTCRequestCounter != enableWebRTCRequestId) { - return; - } - - // Restore switch to previous state. - [strongSelf.enableLogSwitch setOn:!isWebRTCEnabled]; - - // Alert. - SignalAlertView(NSLocalizedString(@"SETTINGS_ADVANCED_WEBRTC_FAILED_TITLE", - @"The title of the alert shown when updates to the WebRTC property fail."), - NSLocalizedString(@"SETTINGS_ADVANCED_WEBRTC_FAILED_MESSAGE", - @"The message of the alert shown when updates to the WebRTC property fail.")); - }]; -} - - (void)didToggleEnableLogSwitch:(UISwitch *)sender { if (!sender.isOn) { [[DebugLogger sharedLogger] wipeLogs]; diff --git a/Signal/test/Models/AccountManagerTest.swift b/Signal/test/Models/AccountManagerTest.swift index 77fb4ca5c..13025e428 100644 --- a/Signal/test/Models/AccountManagerTest.swift +++ b/Signal/test/Models/AccountManagerTest.swift @@ -1,24 +1,25 @@ -// Created by Michael Kirk on 10/26/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// import XCTest import PromiseKit -struct VerificationFailedError : Error { } -struct FailedToGetRPRegistrationTokenError : Error { } -struct FailedToRegisterWithRedphoneError : Error { } +struct VerificationFailedError: Error { } +struct FailedToGetRPRegistrationTokenError: Error { } +struct FailedToRegisterWithRedphoneError: Error { } -enum PushNotificationRequestResult : String { +enum PushNotificationRequestResult: String { case FailTSOnly = "FailTSOnly", FailRPOnly = "FailRPOnly", FailBoth = "FailBoth", Succeed = "Succeed" } -class FailingTSAccountManager : TSAccountManager { +class FailingTSAccountManager: TSAccountManager { let phoneNumberAwaitingVerification = "+13235555555" - override func verifyAccount(withCode: String, isWebRTCEnabled: Bool, success: @escaping () -> Void, failure: @escaping (Error) -> Void) -> Void { + override func verifyAccount(withCode: String, success: @escaping () -> Void, failure: @escaping (Error) -> Void) { failure(VerificationFailedError()) } @@ -31,8 +32,8 @@ class FailingTSAccountManager : TSAccountManager { } } -class VerifyingTSAccountManager : FailingTSAccountManager { - override func verifyAccount(withCode: String, isWebRTCEnabled: Bool, success: @escaping () -> Void, failure: @escaping (Error) -> Void) -> Void { +class VerifyingTSAccountManager: FailingTSAccountManager { + override func verifyAccount(withCode: String, success: @escaping () -> Void, failure: @escaping (Error) -> Void) { success() } @@ -41,19 +42,19 @@ class VerifyingTSAccountManager : FailingTSAccountManager { } } -class TokenObtainingTSAccountManager : VerifyingTSAccountManager { +class TokenObtainingTSAccountManager: VerifyingTSAccountManager { override func obtainRPRegistrationToken(success: @escaping (String) -> Void, failure failureBlock: @escaping (Error) -> Void) { success("fakeRegistrationToken") } } -class FailingRPAccountManager : RPAccountManager { +class FailingRPAccountManager: RPAccountManager { override func register(withTsToken tsToken: String, success: @escaping () -> Void, failure: @escaping (Error) -> Void) { - failure(FailedToRegisterWithRedphoneError()); + failure(FailedToRegisterWithRedphoneError()) } } -class SuccessfulRPAccountManager : RPAccountManager { +class SuccessfulRPAccountManager: RPAccountManager { override func register(withTsToken tsToken: String, success: @escaping () -> Void, failure: @escaping (Error) -> Void) { if tsToken == "fakeRegistrationToken" { success() @@ -179,7 +180,7 @@ class AccountManagerTest: XCTestCase { }.catch { error in XCTFail("Unexpected error: \(error)") } - + self.waitForExpectations(timeout: 1.0, handler: nil) } @@ -187,12 +188,11 @@ class AccountManagerTest: XCTestCase { let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, redPhoneAccountManager: rpAccountManager) - let expectation = self.expectation(description: "should fail") accountManager.updatePushTokens(pushToken: PushNotificationRequestResult.FailTSOnly.rawValue, voipToken: "whatever").then { XCTFail("Expected to fail.") - }.catch { error in + }.catch { _ in expectation.fulfill() }