From 40b3d038db18d8457645eef1ff95180b7847b7fb Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 30 Jan 2017 17:50:28 -0500 Subject: [PATCH] Disable local video in background. // FREEBIE --- Signal/src/call/CallService.swift | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index f23d13131..c312fa226 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -183,6 +183,33 @@ protocol CallServiceObserver: class { super.init() self.callUIAdapter = CallUIAdapter(callService: self, contactsManager: contactsManager, notificationsAdapter: notificationsAdapter) + + NotificationCenter.default.addObserver(self, + selector:#selector(didEnterBackground), + name:NSNotification.Name.UIApplicationDidEnterBackground, + object:nil) + NotificationCenter.default.addObserver(self, + selector:#selector(didBecomeActive), + name:NSNotification.Name.UIApplicationDidBecomeActive, + object:nil) +} + + deinit { + NotificationCenter.default.removeObserver(self) + } + + func didEnterBackground() { + AssertIsOnMainThread() + Logger.info("\(self.TAG) \(#function)") + + self.updateIsVideoEnabled() + } + + func didBecomeActive() { + AssertIsOnMainThread() + Logger.info("\(self.TAG) \(#function)") + + self.updateIsVideoEnabled() } // MARK: - Class Methods @@ -1069,6 +1096,7 @@ protocol CallServiceObserver: class { // support or emulation (http://goo.gl/rHAnC1) so don't bother // trying to open a local stream. return (!Platform.isSimulator && + UIApplication.shared.applicationState != .background && call != nil && call!.state == .connected && call!.hasLocalVideo)