Commit f26ffde1 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

fix: answer call on locked screen

- fix navigation to video call
- fix audio

Change-Id: I373d34ff920c59929f4b816d17bd113e820ed816
parent 8cfad345
...@@ -507,9 +507,6 @@ extension AppDelegate: PKPushRegistryDelegate { ...@@ -507,9 +507,6 @@ extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) { func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
self.accountService.pushNotificationReceived(data: payload.dictionaryPayload) self.accountService.pushNotificationReceived(data: payload.dictionaryPayload)
if #available(iOS 10.0, *) {
return
}
if UIApplication.shared.applicationState != .active { if UIApplication.shared.applicationState != .active {
self.audioService.startAVAudioSession() self.audioService.startAVAudioSession()
} }
......
...@@ -331,6 +331,9 @@ class CallViewModel: Stateable, ViewModel { ...@@ -331,6 +331,9 @@ class CallViewModel: Stateable, ViewModel {
return callUUID == self.call?.callUUID.uuidString return callUUID == self.call?.callUUID.uuidString
}).subscribe(onNext: { [unowned self] serviceEvent in }).subscribe(onNext: { [unowned self] serviceEvent in
if serviceEvent.eventType == ServiceEventType.callProviderAnswerCall { if serviceEvent.eventType == ServiceEventType.callProviderAnswerCall {
if !self.audioService.isHeadsetConnected.value {
self.switchSpeaker()
}
self.answerCall() self.answerCall()
.subscribe() .subscribe()
.disposed(by: self.disposeBag) .disposed(by: self.disposeBag)
...@@ -338,6 +341,16 @@ class CallViewModel: Stateable, ViewModel { ...@@ -338,6 +341,16 @@ class CallViewModel: Stateable, ViewModel {
self.cancelCall(stopProvider: false) self.cancelCall(stopProvider: false)
} }
}).disposed(by: self.disposeBag) }).disposed(by: self.disposeBag)
callsProvider.sharedResponseStream
.filter({ serviceEvent in
serviceEvent.eventType == .audioActivated
}).subscribe(onNext: { [unowned self] _ in
if !self.audioService.isHeadsetConnected.value {
self.isAudioOnly ?
self.audioService.overrideToReceiver() : self.audioService.overrideToSpeaker()
}
}).disposed(by: self.disposeBag)
} }
static func formattedDurationFrom(interval: Int) -> String { static func formattedDurationFrom(interval: Int) -> String {
...@@ -372,9 +385,12 @@ class CallViewModel: Stateable, ViewModel { ...@@ -372,9 +385,12 @@ class CallViewModel: Stateable, ViewModel {
} }
func answerCall() -> Completable { func answerCall() -> Completable {
if !self.audioService.isHeadsetConnected.value { guard #available(iOS 10.0, *) else {
isAudioOnly ? if !self.audioService.isHeadsetConnected.value {
self.audioService.overrideToReceiver() : self.audioService.overrideToSpeaker() isAudioOnly ?
self.audioService.overrideToReceiver() : self.audioService.overrideToSpeaker()
}
return self.callService.accept(call: call)
} }
return self.callService.accept(call: call) return self.callService.accept(call: call)
} }
......
...@@ -47,6 +47,7 @@ internal enum Asset { ...@@ -47,6 +47,7 @@ internal enum Asset {
internal static let icShowInput = ImageAsset(name: "ic_show_input") internal static let icShowInput = ImageAsset(name: "ic_show_input")
internal static let infoArrow = ImageAsset(name: "info_arrow") internal static let infoArrow = ImageAsset(name: "info_arrow")
internal static let jamiIcon = ImageAsset(name: "jamiIcon") internal static let jamiIcon = ImageAsset(name: "jamiIcon")
internal static let jamiLogo = ImageAsset(name: "jamiLogo")
internal static let leftArrow = ImageAsset(name: "left_arrow") internal static let leftArrow = ImageAsset(name: "left_arrow")
internal static let moreSettings = ImageAsset(name: "more_settings") internal static let moreSettings = ImageAsset(name: "more_settings")
internal static let pauseCall = ImageAsset(name: "pause_call") internal static let pauseCall = ImageAsset(name: "pause_call")
......
...@@ -205,8 +205,8 @@ final class AppCoordinator: Coordinator, StateableResponsive { ...@@ -205,8 +205,8 @@ final class AppCoordinator: Coordinator, StateableResponsive {
childCoordinattor.stateSubject childCoordinattor.stateSubject
.onNext(ConversationState .onNext(ConversationState
.startAudioCall(contactRingId: participant, userName: name)) .startAudioCall(contactRingId: participant, userName: name))
return
} }
return
} }
} }
} }
...@@ -231,17 +231,6 @@ class ConversationsCoordinator: Coordinator, StateableResponsive, ConversationNa ...@@ -231,17 +231,6 @@ class ConversationsCoordinator: Coordinator, StateableResponsive, ConversationNa
topController.present(callViewController, animated: true, completion: nil) topController.present(callViewController, animated: true, completion: nil)
} }
func getTopController() -> UIViewController? {
guard var topController = UIApplication.shared
.keyWindow?.rootViewController else {
return nil
}
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
return topController
}
func triggerCallNotifications(call: CallModel) { func triggerCallNotifications(call: CallModel) {
var data = [String: String]() var data = [String: String]()
data [NotificationUserInfoKeys.name.rawValue] = call.displayName data [NotificationUserInfoKeys.name.rawValue] = call.displayName
......
...@@ -111,7 +111,22 @@ extension ConversationNavigation where Self: Coordinator, Self: StateableRespons ...@@ -111,7 +111,22 @@ extension ConversationNavigation where Self: Coordinator, Self: StateableRespons
lockWhilePresenting: VCType.conversation.rawValue) lockWhilePresenting: VCType.conversation.rawValue)
} }
func getTopController() -> UIViewController? {
guard var topController = UIApplication.shared
.keyWindow?.rootViewController else {
return nil
}
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
return topController
}
func startOutgoingCall(contactRingId: String, userName: String, isAudioOnly: Bool = false) { func startOutgoingCall(contactRingId: String, userName: String, isAudioOnly: Bool = false) {
guard let topController = getTopController(),
!topController.isKind(of: (CallViewController).self) else {
return
}
DispatchQueue.main.async { DispatchQueue.main.async {
let callViewController = CallViewController.instantiate(with: self.injectionBag) let callViewController = CallViewController.instantiate(with: self.injectionBag)
callViewController.viewModel.placeCall(with: contactRingId, userName: userName, isAudioOnly: isAudioOnly) callViewController.viewModel.placeCall(with: contactRingId, userName: userName, isAudioOnly: isAudioOnly)
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "jamiLogo-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "jamiLogo-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "jamiLogo.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -40,6 +40,9 @@ class CallsProviderDelegate: NSObject { ...@@ -40,6 +40,9 @@ class CallsProviderDelegate: NSObject {
providerConfiguration.supportsVideo = true providerConfiguration.supportsVideo = true
providerConfiguration.supportedHandleTypes = [.generic, .phoneNumber] providerConfiguration.supportedHandleTypes = [.generic, .phoneNumber]
providerConfiguration.ringtoneSound = "default.wav" providerConfiguration.ringtoneSound = "default.wav"
providerConfiguration.iconTemplateImageData = UIImage(asset: Asset.jamiLogo)?.pngData()
providerConfiguration.maximumCallGroups = 1
providerConfiguration.maximumCallsPerCallGroup = 1
provider = CXProvider(configuration: providerConfiguration) provider = CXProvider(configuration: providerConfiguration)
provider?.setDelegate(self, queue: nil) provider?.setDelegate(self, queue: nil)
...@@ -74,12 +77,15 @@ extension CallsProviderDelegate { ...@@ -74,12 +77,15 @@ extension CallsProviderDelegate {
update.localizedCallerName = handleInfo.displayName update.localizedCallerName = handleInfo.displayName
update.remoteHandle = CXHandle(type: handleType, value: handleInfo.handle) update.remoteHandle = CXHandle(type: handleType, value: handleInfo.handle)
update.hasVideo = !call.isAudioOnly update.hasVideo = !call.isAudioOnly
provider?.reportNewIncomingCall(with: call.callUUID, update.supportsGrouping = false
update: update) { error in update.supportsUngrouping = false
if error == nil { update.supportsHolding = false
return self.provider?.reportNewIncomingCall(with: call.callUUID,
} update: update) { error in
completion?(error) if error == nil {
return
}
completion?(error)
} }
} }
...@@ -157,4 +163,21 @@ extension CallsProviderDelegate: CXProviderDelegate { ...@@ -157,4 +163,21 @@ extension CallsProviderDelegate: CXProviderDelegate {
self.provider?.reportCall(with: action.callUUID, updated: update) self.provider?.reportCall(with: action.callUUID, updated: update)
action.fulfill() action.fulfill()
} }
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
let serviceEventType: ServiceEventType = .audioActivated
let serviceEvent = ServiceEvent(withEventType: serviceEventType)
self.responseStream.onNext(serviceEvent)
print("didActivate")
// Start call audio media, now that the audio session has been activated after having its priority boosted.
}
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
print("didActivate")
/*
Restart any non-call related audio now that the app's audio session has been
de-activated after having its priority restored to normal.
*/
}
} }
...@@ -46,6 +46,7 @@ enum ServiceEventType { ...@@ -46,6 +46,7 @@ enum ServiceEventType {
case nameRegistrationEnded case nameRegistrationEnded
case callProviderAnswerCall case callProviderAnswerCall
case callProviderCancellCall case callProviderCancellCall
case audioActivated
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment