hiennguyen92 / flutter_callkit_incoming

Flutter Callkit Incoming
https://pub.dev/packages/flutter_callkit_incoming
MIT License
178 stars 308 forks source link

Custom Event [IOS] throw error #552

Open AmangeldiyevSultan opened 4 months ago

AmangeldiyevSultan commented 4 months ago

Give error in dart side: flutter: 🔥 12:13:40 | Top-level error: Bad state: No element flutter: #0 ListBase.firstWhere (dart:collection/list.dart:132:5) flutter: #1 FlutterCallkitIncoming._receiveCallEvent (package:flutter_callkit_incoming/flutter_callkit_incoming.dart:141:28) flutter: #2 _MapStream._handleData (dart:async/stream_pipe.dart:213:31) flutter: #3 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13) flutter: #4 _rootRunUnary (dart:async/zone.dart:1407:47) flutter: #5 _CustomZone.runUnary (dart:async/zone.dart:1308:19) flutter: #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1217:7) flutter: #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) flutter: #8 _DelayedData.perform (dart:async/stream_impl.dart:515:14) flutter: #9 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11) flutter: #10 _PendingEvents.schedule. (dart:async/stream_impl.dart:591:7) flutter: #11 _rootRun (dart:async/zone.dart:1391:47) flutter: #12 _CustomZone.run (dart:async/zone.dart:1301:19) flutter: #13 _CustomZone.runGuarded (dart:async/zone.dart:1209:7) flutter: #14 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1249:23) flutter: #15 _rootRun (dart:async/zone.dart:1399:13) flutter: #16 _CustomZone.run (dart:async/zone.dart:1301:19) flutter: #17 _CustomZone.runGuarded (dart:async/zone.dart:1209:7) flutter: #18 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1249:23) flutter: #19 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) flutter: #20 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Call From History in [AppDelegate.swift] // Call back from Recent history override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

    guard let handleObj = userActivity.handle else {
        return false
    }

    guard let isVideo = userActivity.isVideo else {
        return false
    }

    let objData = handleObj.getDecryptHandle()
    let nameCaller = objData["nameCaller"] as? String ?? ""
    let handle = objData["handle"] as? String ?? ""
    let data = flutter_callkit_incoming.Data(id: UUID().uuidString, nameCaller: nameCaller, handle: handle, type: isVideo ? 1 : 0)
    //set more data...
    // data.nameCaller = nameCaller
    SwiftFlutterCallkitIncomingPlugin.sharedInstance?.sendEventCustom(
        "callHistory", 
        body: [
            "ios": [
                "nameCaller": nameCaller
            ]
        ]
    )

    return super.application(application, continue: userActivity, restorationHandler: restorationHandler)
}

Event Listener in flutter side:

FlutterCallkitIncoming.onEvent.listen((CallEvent? event) { switch (event!.event) { case Event.actionCallIncoming: break; case Event.actionCallStart: break; case Event.actionCallAccept: break; case Event.actionCallDecline: break; case Event.actionCallEnded: break; case Event.actionCallTimeout: break; case Event.actionCallCallback: break; case Event.actionCallToggleHold: break; case Event.actionCallToggleMute: break; case Event.actionCallToggleDmtf: break; case Event.actionCallToggleGroup: break; case Event.actionCallToggleAudioSession: break; case Event.actionDidUpdateDevicePushTokenVoip: break; case Event.actionCallCustom: logger.info('CALL CUSTOM: ${event.body}'); } });

tatsuyaueda commented 2 weeks ago

This is a machine translated text.

I am also trying to call from the history. It seems like I can create a new event with sendEventCustom, but that doesn't seem to be the case.

There may be other ways, but once this is working.

SwiftFlutterCallkitIncomingPlugin.sharedInstance?.sendEventCustom("com.hiennv.flutter_callkit_incoming.ACTION_CALL_CUSTOM", body: ["dest": contact])

case Event.actionCallCustom: logger.info('CALL CUSTOM: ${event.body}'); // --> event.body.dest = contact