Prevent device lock during calls.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent d1683acdd3
commit ce9d9befb3

@ -137,6 +137,7 @@ protocol CallServiceObserver: class {
call?.addObserverAndSyncState(observer: self) call?.addObserverAndSyncState(observer: self)
updateIsVideoEnabled() updateIsVideoEnabled()
updateLockTimerEnabling()
Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(call)") Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(call)")
@ -1103,7 +1104,7 @@ protocol CallServiceObserver: class {
internal func stateDidChange(call: SignalCall, state: CallState) { internal func stateDidChange(call: SignalCall, state: CallState) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("\(self.TAG) \(#function): \(state)") Logger.info("\(self.TAG) \(#function): \(state)")
self.updateIsVideoEnabled() updateIsVideoEnabled()
} }
internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) { internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) {
@ -1188,7 +1189,7 @@ protocol CallServiceObserver: class {
observers = [] observers = []
} }
func fireDidUpdateVideoTracks() { private func fireDidUpdateVideoTracks() {
AssertIsOnMainThread() AssertIsOnMainThread()
let localVideoTrack = self.localVideoTrack let localVideoTrack = self.localVideoTrack
@ -1198,14 +1199,16 @@ protocol CallServiceObserver: class {
observer.value?.didUpdateVideoTracks(localVideoTrack:localVideoTrack, observer.value?.didUpdateVideoTracks(localVideoTrack:localVideoTrack,
remoteVideoTrack:remoteVideoTrack) remoteVideoTrack:remoteVideoTrack)
} }
}
private func updateLockTimerEnabling() {
AssertIsOnMainThread()
// Prevent screen from dimming during video call. // Prevent screen from dimming during call.
// //
// fireDidUpdateVideoTracks() is called by the video track setters, // Note that this state has no effect if app is in the background.
// which are cleared when the call ends. That ensures that this timer let hasCall = call != nil
// will be re-enabled. UIApplication.shared.isIdleTimerDisabled = hasCall
let hasLocalOrRemoteVideo = localVideoTrack != nil || remoteVideoTrack != nil
UIApplication.shared.isIdleTimerDisabled = hasLocalOrRemoteVideo
} }
} }

Loading…
Cancel
Save