Fix speakerphone vs. WebRTC AND Fix CallService edge cases.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 1b66e0ba26
commit 0f85284b82

@ -951,7 +951,8 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
// Do nothing. // Do nothing.
} }
internal func didUpdateVideoTracks(localVideoTrack: RTCVideoTrack?, internal func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
remoteVideoTrack: RTCVideoTrack?) { remoteVideoTrack: RTCVideoTrack?) {
AssertIsOnMainThread() AssertIsOnMainThread()

@ -87,7 +87,13 @@ import AVFoundation
ensureIsEnabled(call: call) ensureIsEnabled(call: call)
} }
private func ensureIsEnabled(call: SignalCall) { private func ensureIsEnabled(call: SignalCall?) {
guard let call = call else {
setAudioSession(category: AVAudioSessionCategoryPlayback,
mode: AVAudioSessionModeDefault)
return
}
// Auto-enable speakerphone when local video is enabled. // Auto-enable speakerphone when local video is enabled.
if call.hasLocalVideo { if call.hasLocalVideo {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
@ -105,6 +111,12 @@ import AVFoundation
// MARK: - Service action handlers // MARK: - Service action handlers
public func didUpdateVideoTracks(call: SignalCall?) {
Logger.verbose("\(TAG) in \(#function)")
self.ensureIsEnabled(call: call)
}
public func handleState(call: SignalCall) { public func handleState(call: SignalCall) {
assert(Thread.isMainThread) assert(Thread.isMainThread)
@ -151,6 +163,7 @@ import AVFoundation
private func handleAnswering(call: SignalCall) { private func handleAnswering(call: SignalCall) {
Logger.debug("\(TAG) \(#function)") Logger.debug("\(TAG) \(#function)")
stopPlayingAnySounds() stopPlayingAnySounds()
self.ensureIsEnabled(call: call)
} }
private func handleRemoteRinging(call: SignalCall) { private func handleRemoteRinging(call: SignalCall) {

@ -91,7 +91,8 @@ protocol CallServiceObserver: class {
/** /**
* Fired whenever the local or remote video track become active or inactive. * Fired whenever the local or remote video track become active or inactive.
*/ */
func didUpdateVideoTracks(localVideoTrack: RTCVideoTrack?, func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
remoteVideoTrack: RTCVideoTrack?) remoteVideoTrack: RTCVideoTrack?)
} }
@ -896,13 +897,6 @@ protocol CallServiceObserver: class {
func setIsMuted(isMuted: Bool) { func setIsMuted(isMuted: Bool) {
AssertIsOnMainThread() AssertIsOnMainThread()
guard let peerConnectionClient = self.peerConnectionClient else {
// This should never happen; return to a known good state.
assertionFailure("\(TAG) peerConnectionClient was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: .assertionError(description:"\(TAG) peerConnectionClient unexpectedly nil in \(#function)"))
return
}
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // This should never happen; return to a known good state.
assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") assertionFailure("\(TAG) call was unexpectedly nil in \(#function)")
@ -911,6 +905,12 @@ protocol CallServiceObserver: class {
} }
call.isMuted = isMuted call.isMuted = isMuted
guard let peerConnectionClient = self.peerConnectionClient else {
// The peer connection might not be created yet.
return
}
peerConnectionClient.setAudioEnabled(enabled: !isMuted) peerConnectionClient.setAudioEnabled(enabled: !isMuted)
} }
@ -952,13 +952,6 @@ protocol CallServiceObserver: class {
return return
} }
guard let peerConnectionClient = self.peerConnectionClient else {
// This should never happen; return to a known good state.
assertionFailure("\(TAG) peerConnectionClient was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: .assertionError(description:"\(TAG) peerConnectionClient unexpectedly nil in \(#function)"))
return
}
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // This should never happen; return to a known good state.
assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") assertionFailure("\(TAG) call was unexpectedly nil in \(#function)")
@ -967,6 +960,12 @@ protocol CallServiceObserver: class {
} }
call.hasLocalVideo = hasLocalVideo call.hasLocalVideo = hasLocalVideo
guard let peerConnectionClient = self.peerConnectionClient else {
// The peer connection might not be created yet.
return
}
peerConnectionClient.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack()) peerConnectionClient.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack())
} }
@ -1288,9 +1287,11 @@ protocol CallServiceObserver: class {
observers.append(Weak(value: observer)) observers.append(Weak(value: observer))
// Synchronize observer with current call state // Synchronize observer with current call state
let call = self.call
let localVideoTrack = self.localVideoTrack let localVideoTrack = self.localVideoTrack
let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil
observer.didUpdateVideoTracks(localVideoTrack:localVideoTrack, observer.didUpdateVideoTracks(call:call,
localVideoTrack:localVideoTrack,
remoteVideoTrack:remoteVideoTrack) remoteVideoTrack:remoteVideoTrack)
} }
@ -1313,11 +1314,13 @@ protocol CallServiceObserver: class {
private func fireDidUpdateVideoTracks() { private func fireDidUpdateVideoTracks() {
AssertIsOnMainThread() AssertIsOnMainThread()
let call = self.call
let localVideoTrack = self.localVideoTrack let localVideoTrack = self.localVideoTrack
let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil
for observer in observers { for observer in observers {
observer.value?.didUpdateVideoTracks(localVideoTrack:localVideoTrack, observer.value?.didUpdateVideoTracks(call:call,
localVideoTrack:localVideoTrack,
remoteVideoTrack:remoteVideoTrack) remoteVideoTrack:remoteVideoTrack)
} }
} }

@ -217,11 +217,11 @@ extension CallUIAdaptee {
call?.addObserverAndSyncState(observer: audioService) call?.addObserverAndSyncState(observer: audioService)
} }
internal func didUpdateVideoTracks(localVideoTrack: RTCVideoTrack?, internal func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
remoteVideoTrack: RTCVideoTrack?) { remoteVideoTrack: RTCVideoTrack?) {
AssertIsOnMainThread() AssertIsOnMainThread()
// Do nothing. audioService.didUpdateVideoTracks(call:call)
} }
} }

Loading…
Cancel
Save