Skip to content

Commit

Permalink
Merge pull request #99 from ConnectyCube/development
Browse files Browse the repository at this point in the history
Release 2.2.4
  • Loading branch information
TatankaConCube committed Apr 19, 2023
2 parents 5a958e6 + 4507af4 commit 4f3273c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.2.4
- (iOS) Improve the audio after accepting from the background or killed state;

## 2.2.3
- (Android) Fix calling of the `onCallRejectedWhenTerminated` and the `onCallAcceptedWhenTerminated` callbacks in the release build;

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.connectycube.flutter.connectycube_flutter_call_kit'
version '2.2.3'
version '2.2.4'

buildscript {
ext.kotlin_version = '1.6.21'
Expand Down
54 changes: 40 additions & 14 deletions ios/Classes/CallKitController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Foundation
import AVFoundation
import CallKit



enum CallEvent : String {
case answerCall = "answerCall"
case endCall = "endCall"
Expand Down Expand Up @@ -107,12 +105,13 @@ class CallKitController : NSObject {
update.supportsHolding = false
update.supportsDTMF = false

configureAudioSession(active: true)
if (self.currentCallData["session_id"] == nil || self.currentCallData["session_id"] as! String != uuid) {
print("[CallKitController][reportIncomingCall] report new call: \(uuid)")
provider.reportNewIncomingCall(with: UUID(uuidString: uuid)!, update: update) { error in
completion?(error)
if(error == nil){
self.configureAudioSession()
self.configureAudioSession(active: true)

self.currentCallData["session_id"] = uuid
self.currentCallData["call_type"] = callType
Expand Down Expand Up @@ -173,15 +172,30 @@ class CallKitController : NSObject {
self.callsData.removeAll()
}

func configureAudioSession(){
func sendAudioInterruptionNotification(){
var userInfo : [AnyHashable : Any] = [:]
let intrepEndeRaw = AVAudioSession.InterruptionType.ended.rawValue
userInfo[AVAudioSessionInterruptionTypeKey] = intrepEndeRaw
userInfo[AVAudioSessionInterruptionOptionKey] = AVAudioSession.InterruptionOptions.shouldResume.rawValue
NotificationCenter.default.post(name: AVAudioSession.interruptionNotification, object: self, userInfo: userInfo)
}

func configureAudioSession(active: Bool){
print("CallKitController: [configureAudioSession]")
let audioSession = AVAudioSession.sharedInstance()

do {
try audioSession.setCategory(AVAudioSession.Category.playback, options: AVAudioSession.CategoryOptions.allowBluetooth)
try audioSession.setMode(AVAudioSession.Mode.voiceChat)
try audioSession.setCategory(
AVAudioSession.Category.playAndRecord,
options: [
.allowBluetooth,
.allowBluetoothA2DP,
.duckOthers,
])
try audioSession.setMode(AVAudioSession.Mode.videoChat)
try audioSession.setPreferredSampleRate(44100.0)
try audioSession.setPreferredIOBufferDuration(0.005)
try audioSession.setActive(true)
try audioSession.setActive(active)
} catch {
print(error)
}
Expand Down Expand Up @@ -262,14 +276,28 @@ extension CallKitController: CXProviderDelegate {

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
print("CallKitController: Answer Call \(action.callUUID.uuidString)")
actionListener?(.answerCall, action.callUUID, currentCallData)
self.callStates[action.callUUID.uuidString.lowercased()] = .accepted

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1200)) {
self.configureAudioSession(active: true)
}

callStates[action.callUUID.uuidString.lowercased()] = .accepted
actionListener?(.answerCall, action.callUUID, self.currentCallData)

action.fulfill()
}

func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("CallKitController: Audio session activated")
self.configureAudioSession()

if(currentCallData["session_id"] != nil
&& callStates[currentCallData["session_id"] as! String] == .accepted){
sendAudioInterruptionNotification()
return
}

sendAudioInterruptionNotification()
configureAudioSession(active: true)
}

func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
Expand All @@ -279,7 +307,7 @@ extension CallKitController: CXProviderDelegate {
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
print("CallKitController: End Call")
actionListener?(.endCall, action.callUUID, currentCallData)
self.callStates[action.callUUID.uuidString.lowercased()] = .rejected
callStates[action.callUUID.uuidString.lowercased()] = .rejected
action.fulfill()
}

Expand All @@ -303,9 +331,7 @@ extension CallKitController: CXProviderDelegate {
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
print("CallKitController: Start Call")
actionListener?(.startCall, action.callUUID, currentCallData)
self.callStates[action.callUUID.uuidString.lowercased()] = .accepted
callStates[action.callUUID.uuidString.lowercased()] = .accepted
action.fulfill()
}
}


2 changes: 1 addition & 1 deletion ios/connectycube_flutter_call_kit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'connectycube_flutter_call_kit'
s.version = '2.2.3'
s.version = '2.2.4'
s.summary = 'Connectycube Call Kit plugin for flutter.'
s.description = <<-DESC
Connectycube Call Kit plugin for flutter.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: connectycube_flutter_call_kit
description: A Flutter plugin for displaying call screen when app in background or terminated.
version: 2.2.3
version: 2.2.4
homepage: https://github.com/ConnectyCube/connectycube-flutter-call-kit
issue_tracker: https://github.com/ConnectyCube/connectycube-flutter-call-kit/issues

Expand Down

0 comments on commit 4f3273c

Please sign in to comment.