Merge branch 'charlesmchen/callViewDelay' into hotfix/2.15.2

pull/1/head
Matthew Chen 8 years ago
commit 96faa080c0

@ -728,6 +728,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
callOnViewAppearing:(BOOL)callOnViewAppearing callOnViewAppearing:(BOOL)callOnViewAppearing
{ {
// TODO: Do this synchronously if we're already on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
MessagesViewController *mvc = [[MessagesViewController alloc] initWithNibName:@"MessagesViewController" MessagesViewController *mvc = [[MessagesViewController alloc] initWithNibName:@"MessagesViewController"
bundle:nil]; bundle:nil];
@ -736,11 +737,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
callOnViewAppearing:callOnViewAppearing]; callOnViewAppearing:callOnViewAppearing];
self.lastThread = thread; self.lastThread = thread;
if (self.presentedViewController) { [self pushTopLevelViewController:mvc animateDismissal:YES animatePresentation:YES];
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController pushViewController:mvc animated:YES];
}); });
} }
@ -799,6 +796,10 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
// Perform the first step. // Perform the first step.
if (self.presentedViewController) { if (self.presentedViewController) {
if ([self.presentedViewController isKindOfClass:[CallViewController class]]) {
OWSProdInfo([OWSAnalyticsEvents errorCouldNotPresentViewDueToCall]);
return;
}
[self.presentedViewController dismissViewControllerAnimated:animateDismissal completion:dismissNavigationBlock]; [self.presentedViewController dismissViewControllerAnimated:animateDismissal completion:dismissNavigationBlock];
} else { } else {
dismissNavigationBlock(); dismissNavigationBlock();

@ -144,8 +144,10 @@ protocol CallServiceObserver: class {
if let oldValue = oldValue { if let oldValue = oldValue {
DeviceSleepManager.sharedInstance.removeBlock(blockObject: oldValue) DeviceSleepManager.sharedInstance.removeBlock(blockObject: oldValue)
} }
stopAnyCallTimer()
if let call = call { if let call = call {
DeviceSleepManager.sharedInstance.addBlock(blockObject: call) DeviceSleepManager.sharedInstance.addBlock(blockObject: call)
self.startCallTimer()
} }
} }
@ -911,8 +913,6 @@ protocol CallServiceObserver: class {
call.state = .connected call.state = .connected
self.startActiveCallTimer(call: call)
// We don't risk transmitting any media until the remote client has admitted to being connected. // We don't risk transmitting any media until the remote client has admitted to being connected.
peerConnectionClient.setAudioEnabled(enabled: !call.isMuted) peerConnectionClient.setAudioEnabled(enabled: !call.isMuted)
peerConnectionClient.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack()) peerConnectionClient.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack())
@ -1432,7 +1432,6 @@ protocol CallServiceObserver: class {
self.call?.removeAllObservers() self.call?.removeAllObservers()
self.call = nil self.call = nil
self.stopAnyActiveCallTimer()
self.sendIceUpdatesImmediately = true self.sendIceUpdatesImmediately = true
Logger.info("\(TAG) clearing pendingIceUpdateMessages") Logger.info("\(TAG) clearing pendingIceUpdateMessages")
self.pendingIceUpdateMessages = [] self.pendingIceUpdateMessages = []
@ -1574,9 +1573,8 @@ protocol CallServiceObserver: class {
// MARK: CallViewController Timer // MARK: CallViewController Timer
var activeCallTimer: Timer? var activeCallTimer: Timer?
func startActiveCallTimer(call: SignalCall) { func startCallTimer() {
AssertIsOnMainThread() AssertIsOnMainThread()
assert(call.state == .connected)
if self.activeCallTimer != nil { if self.activeCallTimer != nil {
owsFail("\(TAG) activeCallTimer should only be set once per call") owsFail("\(TAG) activeCallTimer should only be set once per call")
@ -1589,29 +1587,38 @@ protocol CallServiceObserver: class {
return return
} }
guard call == strongSelf.call else { guard let call = strongSelf.call else {
owsFail("\(strongSelf.TAG) call has since ended. Timer should have been invalidated.") owsFail("\(strongSelf.TAG) call has since ended. Timer should have been invalidated.")
timer.invalidate() timer.invalidate()
return return
} }
strongSelf.ensureCallScreenVisible(call: call) strongSelf.ensureCallScreenPresented(call: call)
} }
} }
func ensureCallScreenVisible(call: SignalCall) { func ensureCallScreenPresented(call: SignalCall) {
guard nil != UIApplication.shared.frontmostViewController as? CallViewController else { guard let connectedDate = call.connectedDate else {
owsFail("\(TAG) in \(#function) CallViewController should already be visible.") // Ignore; call hasn't connected yet.
self.callUIAdapter.showCall(call) return
}
let kMaxViewPresentationDelay = 2.5
guard fabs(connectedDate.timeIntervalSinceNow) > kMaxViewPresentationDelay else {
// Ignore; call connected recently.
return return
} }
Logger.debug("\(TAG) in \(#function) already visible.") guard nil != UIApplication.shared.frontmostViewController as? CallViewController else {
OWSProdError(OWSAnalyticsEvents.callServiceCallViewCouldNotPresent(), file:#file, function:#function, line:#line)
owsFail("\(TAG) in \(#function) Call terminated due to call view presentation delay.")
self.terminateCall()
return
}
} }
func stopAnyActiveCallTimer() { func stopAnyCallTimer() {
AssertIsOnMainThread() AssertIsOnMainThread()
assert(self.call == nil)
self.activeCallTimer?.invalidate() self.activeCallTimer?.invalidate()
self.activeCallTimer = nil self.activeCallTimer = nil

@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)callServiceCallUnexpectedlyIdle; + (NSString *)callServiceCallUnexpectedlyIdle;
+ (NSString *)callServiceCallViewCouldNotPresent;
+ (NSString *)callServiceCouldNotCreatePeerConnectionClientPromise; + (NSString *)callServiceCouldNotCreatePeerConnectionClientPromise;
+ (NSString *)callServiceCouldNotCreateReadyToSendIceUpdatesPromise; + (NSString *)callServiceCouldNotCreateReadyToSendIceUpdatesPromise;
@ -72,6 +74,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)errorAttachmentRequestFailed; + (NSString *)errorAttachmentRequestFailed;
+ (NSString *)errorCouldNotPresentViewDueToCall;
+ (NSString *)errorEnableVideoCallingRequestFailed; + (NSString *)errorEnableVideoCallingRequestFailed;
+ (NSString *)errorGetDevicesFailed; + (NSString *)errorGetDevicesFailed;

@ -72,6 +72,11 @@ NS_ASSUME_NONNULL_BEGIN
return @"call_service_call_unexpectedly_idle"; return @"call_service_call_unexpectedly_idle";
} }
+ (NSString *)callServiceCallViewCouldNotPresent
{
return @"call_service_call_view_could_not_present";
}
+ (NSString *)callServiceCouldNotCreatePeerConnectionClientPromise + (NSString *)callServiceCouldNotCreatePeerConnectionClientPromise
{ {
return @"call_service_could_not_create_peer_connection_client_promise"; return @"call_service_could_not_create_peer_connection_client_promise";
@ -162,6 +167,11 @@ NS_ASSUME_NONNULL_BEGIN
return @"error_attachment_request_failed"; return @"error_attachment_request_failed";
} }
+ (NSString *)errorCouldNotPresentViewDueToCall
{
return @"error_could_not_present_view_due_to_call";
}
+ (NSString *)errorEnableVideoCallingRequestFailed + (NSString *)errorEnableVideoCallingRequestFailed
{ {
return @"error_enable_video_calling_request_failed"; return @"error_enable_video_calling_request_failed";

Loading…
Cancel
Save