Skip to content

Commit

Permalink
Prevent device lock during calls.
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
charlesmchen committed Feb 7, 2017
1 parent 6e7c18b commit d135f2e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Signal/src/call/CallService.swift
Expand Up @@ -137,6 +137,7 @@ protocol CallServiceObserver: class {
call?.addObserverAndSyncState(observer: self)

updateIsVideoEnabled()
updateLockTimerEnabling()

Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(call)")

Expand Down Expand Up @@ -1103,7 +1104,7 @@ protocol CallServiceObserver: class {
internal func stateDidChange(call: SignalCall, state: CallState) {
AssertIsOnMainThread()
Logger.info("\(self.TAG) \(#function): \(state)")
self.updateIsVideoEnabled()
updateIsVideoEnabled()
}

internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) {
Expand Down Expand Up @@ -1188,7 +1189,7 @@ protocol CallServiceObserver: class {
observers = []
}

func fireDidUpdateVideoTracks() {
private func fireDidUpdateVideoTracks() {
AssertIsOnMainThread()

let localVideoTrack = self.localVideoTrack
Expand All @@ -1198,14 +1199,16 @@ protocol CallServiceObserver: class {
observer.value?.didUpdateVideoTracks(localVideoTrack:localVideoTrack,
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,
// which are cleared when the call ends. That ensures that this timer
// will be re-enabled.
let hasLocalOrRemoteVideo = localVideoTrack != nil || remoteVideoTrack != nil
UIApplication.shared.isIdleTimerDisabled = hasLocalOrRemoteVideo
// Note that this state has no effect if app is in the background.
let hasCall = call != nil
UIApplication.shared.isIdleTimerDisabled = hasCall
}
}

Expand Down

0 comments on commit d135f2e

Please sign in to comment.