Skip to content

Commit

Permalink
Merge pull request #426 from hiennguyen92/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hiennguyen92 committed Jan 9, 2024
2 parents 627ca03 + c59e42e commit bf128fd
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 417 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
build/

pubspec.lock

example/ios/Podfile.lock
example/pubspec.lock
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 2.0.1+1
* Add Callback AVAudioSession for WebRTC setup
* Fix issue no audio for using WebRTC

## 2.0.1-dev.2
* Add Action for onAccept

## 2.0.1-dev.1
* Add AVAudioSession Appdelegate(iOS)

## 2.0.1-dev
* Add AVAudioSession Appdelegate(iOS)

## 2.0.1

* Fixed some bugs.
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,36 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate, CallkitIncomingAppDelegate {
...

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
//Setup VOIP
let mainQueue = DispatchQueue.main
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]

//Use if using WebRTC
//RTCAudioSession.sharedInstance().useManualAudio = true
//RTCAudioSession.sharedInstance().isAudioEnabled = false
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}


// Func Call api for Accept
func onAccept(_ call: Call) {
func onAccept(_ call: Call, _ action: CXAnswerCallAction) {
let json = ["action": "ACCEPT", "data": call.data.toJSON()] as [String: Any]
print("LOG: onAccept")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done(connected WebRTC - Start counting seconds)
//action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand Down Expand Up @@ -391,6 +413,18 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
}
}
}

func didActivateAudioSession(_ audioSession: AVAudioSession) {
//Use if using WebRTC
//RTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession)
//RTCAudioSession.sharedInstance().isAudioEnabled = true
}
func didDeactivateAudioSession(_ audioSession: AVAudioSession) {
//Use if using WebRTC
//RTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession)
//RTCAudioSession.sharedInstance().isAudioEnabled = false
}
...

```
Expand Down
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

pubspec.lock
/ios/Podfile.lock
114 changes: 0 additions & 114 deletions example/ios/Podfile.lock

This file was deleted.

28 changes: 27 additions & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import UIKit
import CallKit
import AVFAudio
import PushKit
import Flutter
import flutter_callkit_incoming

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate, CallkitIncomingAppDelegate {


override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
Expand All @@ -16,6 +20,10 @@ import flutter_callkit_incoming
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]

//Use if using WebRTC
//RTCAudioSession.sharedInstance().useManualAudio = true
//RTCAudioSession.sharedInstance().isAudioEnabled = false

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Expand Down Expand Up @@ -82,13 +90,15 @@ import flutter_callkit_incoming


// Func Call api for Accept
func onAccept(_ call: Call) {
func onAccept(_ call: Call, _ action: CXAnswerCallAction) {
let json = ["action": "ACCEPT", "data": call.data.toJSON()] as [String: Any]
print("LOG: onAccept")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done(connected WebRTC - Start counting seconds)
//action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand All @@ -111,6 +121,7 @@ import flutter_callkit_incoming
}
}

// Func Call API for End
func onEnd(_ call: Call) {
let json = ["action": "END", "data": call.data.toJSON()] as [String: Any]
print("LOG: onEnd")
Expand All @@ -125,6 +136,7 @@ import flutter_callkit_incoming
}
}

// Func Call API for TimeOut
func onTimeOut(_ call: Call) {
let json = ["action": "TIMEOUT", "data": call.data.toJSON()] as [String: Any]
print("LOG: onTimeOut")
Expand All @@ -139,6 +151,20 @@ import flutter_callkit_incoming
}
}

// Func Callback Toggle Audio Session
func didActivateAudioSession(_ audioSession: AVAudioSession) {
//Use if using WebRTC
//RTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession)
//RTCAudioSession.sharedInstance().isAudioEnabled = true
}

// Func Callback Toggle Audio Session
func didDeactivateAudioSession(_ audioSession: AVAudioSession) {
//Use if using WebRTC
//RTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession)
//RTCAudioSession.sharedInstance().isAudioEnabled = false
}

func performRequest(parameters: [String: Any], completion: @escaping (Result<Any, Error>) -> Void) {
if let url = URL(string: "https://webhook.site/e32a591f-0d17-469d-a70d-33e9f9d60727") {
var request = URLRequest(url: url)
Expand Down

0 comments on commit bf128fd

Please sign in to comment.