Taracque / ionic-plugin-callkit

Ionic/Cordova plugin for CallKit
36 stars 20 forks source link

First incoming call does not call startAudio; it has no audio #9

Closed manur closed 7 years ago

manur commented 7 years ago

Description

It seems like there's a handoff problem on the first incoming call between AudioToolbox and the CallKit delegate in this plugin.

Scenarios

:x: On the first incoming call after app initialization, no audio either way.

:heavy_check_mark: On the next and any incoming call, audio works both ways.

:heavy_check_mark: If the first call is an outgoing call, audio works on first and any successive calls.

Errors and logs

I've spent a lot of time debugging, and this particular line seems to indicate a handoff error between AudioToolbox and the app:

Apr 14 15:33:15 MyCallingApp(AudioToolbox)[2246] <Error>: 892: failed: 'ent?' (enable 3, outf< 1 ch, 44100 Hz, Int16> inf< 1 ch, 44100 Hz, Int16>)

The full log for the no-audio scenario on a first incoming call is here, with this error: https://gist.github.com/manur/46c885c20257b634a34dc24324dff55f

Here's a comparative log for a later incoming call that connects correctly, where this error does not occur: https://gist.github.com/manur/ebd81e0cb931026909cdc44d03749b07

Integration details

ionic-plugin-callkit is used in a Cordova app. The callChanged handler is used to start the audio for a call. The audioSystem callback is not used for anything right now. Also not sure how to use that callback, since it doesn't return a call UUID to start or stop audio for. Would appreciate guidance if this usage is just wrong

callKit.register(function(obj) {
        console.log("call-kit:register:call-changed", JSON.stringify(obj));
        var call = softphone.findCallByUUID(obj.uuid);

        if(obj.hasStartedConnecting && !obj.hasConnected && !obj.hasEnded) {
          if(!call.get('started')) {
              call.accept();
          }
        }
        /* other call logic for call termination etc. */

}, function(obj) {
        console.log("call-kit:register:audio-system", JSON.stringify(obj));
});

cc @sgibbons

Taracque commented 7 years ago

Try to (re)initialize your Audio in reportIncomingCall's callback, that should help. The audioSystem callback is called when the system want you to do something with your audio stream. For example, if your call is in progress, and a new call accepted, your audio should be paused, etc.

manur commented 7 years ago

Previous execution order

-- Call audio was initialized in app -- CallKit was notified via reportIncomingCall

Now, after your suggestion

-- CallKit was notified via reportIncomingCall -- In the callback of reportIncomingCall, the new call was created in the app and audio set up

Same result -> Still no audio either way.

FWIW, the error from audio toolbox, <Error>: 892: failed: 'ent?', occurs when a call is accepted, and not when it's reported to CallKit.

Would appreciate any other suggestions. I've been stuck on this for a while.

manur commented 7 years ago

Hello,

Thought I'd ask again on this thread.

Try to (re)initialize your Audio in reportIncomingCall's callback, that should help.

Could you explain in a little more detail what you mean by "re-initialize audio"? We're hooking in ionic-plugin-callkit to a WebRTC backend on iOS and Android, as I imagine is the intent for this plugin.

Would you know if there's a specific WebRTC API that corresponds to what you refer to as initializing audio, like rendering a MediaStream? We've tried most things without success so far.

Thanks again for publishing this plugin.

Taracque commented 7 years ago

On iOS you need to configure an AVAudioSession when the configureAudio event occurs. That AVAudioSession will gets elevated priority by the system. I don't exactly which RTC framework is used in your case, and how that handles audio sessions.

VinceOPS commented 7 years ago

Hello guys

I have the same issue using a port of AppRTC (from Google) for Cordova apps. "startAudio" is only fired at the second call. The very first call never triggers "startAudio" and my microphone just seems ... muted.

NB: I'm triggering my incoming calls using PushKit.

I'm using an iPhone 5 on iOS 10.2.1. Could it be related to this ?

@manur Did you manage to solve this issue?

Thanks

EDIT - I just proposed a PR with a patch which fixed the issue in my app. Please let me know if it's okay in yours too!

manur commented 7 years ago

@VinceOPS -- Thanks for submitting this update. I'll comment on your pull.

To your earlier question, the call audio issue I reported breaks the same way across iPhone 7 and iPhone 5s, the devices I had access to.

manur commented 7 years ago

@Taracque -- Resolved by pull request.