saibotma / jitsi_meet_wrapper

Jitsi Meet Plugin for Flutter. Wrapping JitsiMeetSDK for Android and iOS.
BSD 3-Clause "New" or "Revised" License
26 stars 61 forks source link

Callkit on iOS Not Running #66

Open isnaenimus opened 1 year ago

isnaenimus commented 1 year ago

How to auto join meeting on answer call when the iPhone is locked (like in Whatsapp)?

Current Flow: When answer call, the meeting not yet joined. It should have been able to join when I answer the call even I haven't clicked the icon (jitsi_meet_example)

When click app icon (jitsi_meet_example), and it joins the meeting.

image

Code Below

in AppDelegate:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, JMCallKitListener {
    //var jitsiViewController: JitsiViewController?
    var flutterResult: FlutterResult?

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      GeneratedPluginRegistrant.register(with: self)
      let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
      let CHANNEL = FlutterMethodChannel(name: "com.flutter.callkit/callkit", binaryMessenger: controller.binaryMessenger)

      CHANNEL.setMethodCallHandler { [unowned self] (methodCall, result) in
          if methodCall.method == "callkit" {

              guard let args = methodCall.arguments else { return }

              let myArgs = args as? [String: Any]
              let strUuid = myArgs?["uuid"] as? String
              let strHandle = myArgs?["handle"] as? String
              let strDisplayName = myArgs?["displayName"] as? String
              let boolHasVideo = myArgs?["hasVideo"] as? Bool
              let uuid = UUID(uuidString: strUuid!) ?? UUID()

              print("real",uuid)

              let backgroundTaskIdentifier =
                UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
              //guard !JMCallKitProxy.hasActiveCallForUUID(uuid.uuidString) else { return }
              JMCallKitProxy.enabled = true
              //guard JMCallKitProxy.hasActiveCallForUUID(uuid.uuidString) else { return }
              configureAudioSession()

              JMCallKitProxy.configureProvider(localizedName: "Testing SDK", ringtoneSound: nil, iconTemplateImageData: nil)
              DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
                  JMCallKitProxy.reportNewIncomingCall(UUID: uuid, handle: strHandle, displayName: strDisplayName, hasVideo: boolHasVideo!, completion: {
                      (error) in UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
                  })
              }

              //result("Hi, your request has successfull")
              JMCallKitProxy.addListener(self)
              flutterResult = result
          }
      }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    func configureAudioSession() {
        let session = AVAudioSession.sharedInstance()//AVAudioSession.sharedInstance()
        do {
            try session.setCategory(.playAndRecord)
            try session.setMode(.voiceChat)
            try session.setActive(true)
        } catch let error {
            Swift.print("configureAudioSession error: \(error)")
        }
    }

    func performAnswerCall(UUID: UUID) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
            self.flutterResult!("gettoken")
        }
        print("performAnswerCall: \(UUID.uuidString)")
    }

in Dart:

void callUuid(String uuid, String handle, String displayName, bool hasVideo) async {
    var sendUuid = <String, dynamic> {
      'uuid' : uuid,
      'handle' : handle,
      'displayName' : displayName,
      'hasVideo' : hasVideo,
    };
    String value;

    try {
      value = await platform.invokeMethod("callkit", sendUuid);

      if (value == "gettoken") {
        //the code join the meeting
      }
      print(value);
    } catch (e) {
      print(e);
    }
  }
saibotma commented 1 year ago

Hey there,

please try the newest release and create a reproducible example if it still does not work.