cybex-dev / twilio_voice

Flutter Twilio Voice Plugin
https://twilio-voice-web.web.app/
MIT License
39 stars 78 forks source link

'twilio_voice/events' channel sent a message from native to Flutter on a non-platform thread #207

Open Asfichi opened 7 months ago

Asfichi commented 7 months ago

Thanks for the good work and all the efforts. The app is working on android fine, I can also make call using iphone, but the audio cuts off throughout and becomes intermittent. The app's Events log shows CallEvent.hold and CallEvent.unhold continuously until I end the call.

This error is from xcode that I put here separately: 2023-11-25 16:15:00.240774+0300 Runner[8076:3050156] [VERBOSE-2:shell.cc(1004)] The 'twilio_voice/events' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

The xcode log after I make a call: 2023-11-25 16:15:00.208340+0300 Runner[8076:3049819] flutter: starting call to +254726880858 2023-11-25 16:15:00.240540+0300 Runner[8076:3050156] LOG|StartCallAction transaction request successful 2023-11-25 16:15:00.240774+0300 Runner[8076:3050156] [VERBOSE-2:shell.cc(1004)] The 'twilio_voice/events' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information. 2023-11-25 16:15:00.243281+0300 Runner[8076:3049819] flutter: StartCallAction transaction request successful 2023-11-25 16:15:00.244178+0300 Runner[8076:3049819] flutter: StartCallAction transaction request successful 2023-11-25 16:15:00.247264+0300 Runner[8076:3049439] LOG|provider:performStartCallAction: 2023-11-25 16:15:00.258843+0300 Runner[8076:3049819] flutter: provider:performStartCallAction: 2023-11-25 16:15:00.259116+0300 Runner[8076:3049819] flutter: provider:performStartCallAction: 2023-11-25 16:15:00.617458+0300 Runner[8076:3049439] LOG|provider:didActivateAudioSession: 2023-11-25 16:15:00.618359+0300 Runner[8076:3049819] flutter: provider:didActivateAudioSession: 2023-11-25 16:15:00.618502+0300 Runner[8076:3049819] flutter: provider:didActivateAudioSession: 2023-11-25 16:15:01.645354+0300 Runner[8076:3049439] Ringing|+254735318399|+254726880858|Outgoing 2023-11-25 16:15:01.650941+0300 Runner[8076:3049819] flutter: Ringing - From: +254735318399, To: +254726880858, Direction: CallDirection.outgoing 2023-11-25 16:15:01.651402+0300 Runner[8076:3049819] flutter: Ringing - From: +254735318399, To: +254726880858, Direction: CallDirection.outgoing 2023-11-25 16:15:06.620245+0300 Runner[8076:3049439] Connected|+254735318399|+254726880858|Outgoing 2023-11-25 16:15:06.620369+0300 Runner[8076:3049439] LOG|provider:performAnswerVoiceCall() successful 2023-11-25 16:15:06.623711+0300 Runner[8076:3049819] flutter: Connected - From: +254735318399, To: +254726880858, StartOn: 2023-11-25 16:15:06.621554, Direction: CallDirection.outgoing 2023-11-25 16:15:06.623855+0300 Runner[8076:3049819] flutter: Connected - From: +254735318399, To: +254726880858, StartOn: 2023-11-25 16:15:06.623819, Direction: CallDirection.outgoing 2023-11-25 16:15:06.624191+0300 Runner[8076:3049819] flutter: provider:performAnswerVoiceCall() successful 2023-11-25 16:15:06.624282+0300 Runner[8076:3049819] flutter: provider:performAnswerVoiceCall() successful 2023-11-25 16:15:06.673478+0300 Runner[8076:3049439] AVAudioSession setAggregatedIOPreference:error: Error Domain=NSOSStatusErrorDomain Code=560030580 "Operation not permitted while session has running audio I/Os" UserInfo={NSLocalizedDescription=Operation not permitted while session has running audio I/Os} 2023-11-25 16:15:08.412381+0300 Runner[8076:3049439] AVAudioSession setAggregatedIOPreference:error: Error Domain=NSOSStatusErrorDomain Code=560030580 "Operation not permitted while session has running audio I/Os" UserInfo={NSLocalizedDescription=Operation not permitted while session has running audio I/Os} 2023-11-25 16:15:13.558103+0300 Runner[8076:3050020] ERROR:Twilio:Platform : Failed to send request, status code: 400 2023-11-25 16:15:20.377700+0300 Runner[8076:3049439] LOG|hangUp method invoked 2023-11-25 16:15:20.377952+0300 Runner[8076:3049439] LOG|performEndCallAction method invoked 2023-11-25 16:15:20.378416+0300 Runner[8076:3049819] flutter: hangUp method invoked 2023-11-25 16:15:20.378507+0300 Runner[8076:3049819] flutter: hangUp method invoked 2023-11-25 16:15:20.378585+0300 Runner[8076:3049819] flutter: performEndCallAction method invoked 2023-11-25 16:15:20.378629+0300 Runner[8076:3049819] flutter: performEndCallAction method invoked 2023-11-25 16:15:20.379380+0300 Runner[8076:3050156] Call Ended 2023-11-25 16:15:20.387524+0300 Runner[8076:3049439] LOG|provider:performEndCallAction: 2023-11-25 16:15:20.387607+0300 Runner[8076:3049439] LOG|provider:performEndCallAction: disconnecting call 2023-11-25 16:15:20.387711+0300 Runner[8076:3049819] flutter: provider:performEndCallAction: 2023-11-25 16:15:20.387800+0300 Runner[8076:3049819] flutter: provider:performEndCallAction: 2023-11-25 16:15:20.387924+0300 Runner[8076:3049819] flutter: provider:performEndCallAction: disconnecting call 2023-11-25 16:15:20.388031+0300 Runner[8076:3049819] flutter: provider:performEndCallAction: disconnecting call 2023-11-25 16:15:21.444156+0300 Runner[8076:3050373] ERROR:Twilio:[Core](MediaFactoryImpl::signaling 0x0x2801dc700) : Peer Connection is Closed or destroyed 2023-11-25 16:15:21.508747+0300 Runner[8076:3049439] LOG|provider:didDeactivateAudioSession:

cybex-dev commented 7 months ago

Hi @Asfichi,

Thanks for reporting this issue - I have yet to run into it.

Could you please provide additional information on when, how it occurs. iOS device type, version and an MVCe if possible.

Asfichi commented 7 months ago

Thanks for your help. Here's additional information.

I’m using the example code (https://github.com/cybex-dev/twilio_voice/tree/master/example).   I’ve configured firebase for access token generation and it is working fine. Access token registration also works fine, and the ui_call_screen loads and all mobile permissions are done.   When I type the number to be called in the text input and press ‘place-call’ button, it successfully places the call both for Android and iPhone.   There is no error with the Android phone and the communication is very good. But When I try the same with iPhone, the error I mentioned occurred and the sound is intermittent.   I tried to figure out the problem, I’ve researched a lot and finally asking for help here. I don’t know whether it is an issue, but I suspect I may be missing something related with the iOS configuration anything to do with it.   With Android, the native ui call screen takes over after I place the call, but with iPhone, the native call screen ui doesn’t take over. Is it supposed to show the native ui call screen with iPhone?   For the access token generation firebase function, I’ve tried  apple push credential for release also, although it doesn’t affect outgoing call.   I’m using iPhone 8 plus iOS 16.7.2 in debugging with Flutter. I tried both connections via cable and via network as well.   The Twilio call log shows success.   A screenshot of the ui_call_screen during calling is attached and the intermittent voice I tried to record also.

Intermittent voice recorded google drive link: https://drive.google.com/file/d/1833TLnQzjeioH73UU-6ZpqOdVKsWJ8z3/view?usp=sharing

iPhone screenshoot iphone sc3

cybex-dev commented 7 months ago

@Asfichi thank you for the most detailed of instructions - this is very helpful.

I will need to take a deeper look into possible causes.


Initial thoughts:

2023-11-25 16:15:08.412381+0300 Runner[8076:3049439] AVAudioSession setAggregatedIOPreference:error: Error Domain=NSOSStatusErrorDomain Code=560030580 "Operation not permitted while session has running audio I/Os" UserInfo={NSLocalizedDescription=Operation not permitted while session has running audio I/Os}

There are a number of older iOS references (iOS 10.x) referring to it being a AVAudioSessionErrorCodeIsBusy error code, I cannot confirm this at the moment with new iOS versions i.e. >16.4 though an SO thread seems to suggest that there may be an Audio Session conflict.

I suspect this might be a symptom of an underlying problem by looks of other issues present in your log output.

Are you able to confirm these issues on another iOS device or simulator (available on Xcode +14)?

haduong825 commented 7 months ago

Hi @cybex-dev,

Do you have any idea to fix that? I got that problem too. It occurred when I use 2 my iPhones (iPhone 6s 15.7, iPhone 13 Promax 17.2)

Thank you so much

dhananjay6898 commented 6 months ago

Hi @Asfichi, @haduong825 , @cybex-dev Did you found any workaround for this, I'm getting this issue on my both devices iPhone 11 and 12 mini both are on iOS 17+

Thank you so much.

haduong825 commented 6 months ago

Hi @Asfichi, @haduong825 , @cybex-dev Did you found any workaround for this, I'm getting this issue on my both devices iPhone 11 and 12 mini both are on iOS 17+

Thank you so much.

Hi @dhananjay6898 , For example app, you shoud comment unhold feature, It will be greater than. You can checkout my repo with lastest sdk from twilio too. https://github.com/haduong825/twilio_voice

jd-bus commented 1 month ago

@cybex-dev I confirm that I am experiencing the same issue

I have tried both debug and release build mode in XCode and facing same issue

jd-bus commented 1 month ago

@haduong825 I tried your repo with latest update and it didn't fix the hold issue.

For example app, you shoud comment unhold feature,

Can you clarify that one? Which change should I make? Do you have a diff? Thanks so much.

jd-bus commented 1 month ago

ah i see this worked for me

diff --git a/example/lib/screens/widgets/call_features.dart b/example/lib/screens/widgets/call_features.dart
index 190ceab..14c373e 100644
--- a/example/lib/screens/widgets/call_features.dart
+++ b/example/lib/screens/widgets/call_features.dart
@@ -61,8 +61,8 @@ class _CallControlsState extends State<CallControls> {
     _subscription = _tv.callEventsListener.listen((event) {
       _events.add(event);
       switch (event) {
-        case CallEvent.unhold:
-        case CallEvent.hold:
+        /*case CallEvent.unhold:
+        case CallEvent.hold:*/
         case CallEvent.unmute:
         case CallEvent.mute:
         case CallEvent.speakerOn:
@@ -107,7 +107,7 @@ class _CallControlsState extends State<CallControls> {
   void _updateStates() {
     // get all states from call
     _tv.call.isMuted().then((value) => stateMute = value ?? false);
-    _tv.call.isHolding().then((value) => stateHold = value ?? false);
+    // _tv.call.isHolding().then((value) => stateHold = value ?? false);
     _tv.call.isOnSpeaker().then((value) => stateSpeaker = value ?? false);
     _tv.call.isBluetoothOn().then((value) => stateBluetooth = value ?? false);