datso / react-native-pjsip

A PJSIP module for React Native.
http://datso.github.io/react-native-pjsip
GNU General Public License v3.0
273 stars 232 forks source link

No audio sometimes on iOS device #85

Open mattyleggy opened 6 years ago

mattyleggy commented 6 years ago

I've been trying to figure this out for a while now but on iOS sometimes there's no audio being sent or heard from the device. I know nothing is being sent as well as I've listened to the call back from the SIP provider and only the audio is being sent from the non-app side (physical handset).

It can work fine for 1 call and then the next call it doesn't work.

Problem occurs with both inbound and outbound calls however it definitely seems to be more of an issue with inbound calls more often than not.

Interestingly if it happens on an outbound call and you place the call on hold from the device and then resume the call, the audio then begins working.

On android, the device audio works 100% of the time and is tested using the same SIP account.

mattyleggy commented 6 years ago

Just following up, I still haven't been able to solve this issue.

The little hack that I've done is when you answer a call on the device it immediately places the call on hold and then unholds it straight away as placing a call on hold and resuming seems to fix the issue. This isn't ideal as the person calling can hear the hold music for half a second or so. Any ideas which could point me in the right direction would be great.

I've tested the SIP account on other applications (E.g. Zoiper) and they seem to work fine.

FrankFei commented 6 years ago

I also encountered such a problem, if the iOS version is 10, the probability of occurrence is relatively high, about 30-40%, if the iOS version is 11, in the case of wifi, the basic is normal, but in the case of 4g network, about There is about 10% probability of not hearing the sound. When a voice is not heard, the person who is connected generally cannot hear the voice, and the person who hits can hear the voice of the person who spoke.

FrankFei commented 6 years ago

I use linphone(iOS) connect SIP Server,it works fine.

mattyleggy commented 6 years ago

Still trying to figure it out. I feel like it has something to do with RNCallKit but unable to prove it yet as it doesn't happen on my iOS Simulator which doesn't seem to support RNCallKit but happens on a real device.

Still trying to get a SIP packet capture to see if the issue is related to the Asterisk server.

Are you using a real device or a simulator?

FrankFei commented 6 years ago

Our company's SIP server is purchased by our company. The hardware supplier has already proved that their hardware is sending out the voice by capturing the packet, but the person who answers does not hear it.

mattyleggy commented 6 years ago

Are both people on the phone using the PjSip app?

mattyleggy commented 6 years ago

Also on the person who cannot hear the audio, try placing the call on hold and resuming and see if that activates the audio.

FrankFei commented 6 years ago

We use the phone to call and the person who answers is connected to the APP.

mattyleggy commented 6 years ago

Can you test the hold and then un-hold from the iOS app and see if that fixes the audio? I'm just trying to see if the issue is consistent. Let me know your results.

FrankFei commented 6 years ago

Is it necessary to handle hold and unhold in the code? Can you send me your hold and unhold code?

mattyleggy commented 6 years ago

Just using: endpoint.holdCall(call) and endpoint.unholdCall(call). That's also assuming that your SIP server supports placing a call on hold. Are you using the PjSip App (https://github.com/datso/react-native-pjsip-app/)?

FrankFei commented 6 years ago

The method of hold and unhold, I added in the answerCall, it seems that there is no effect! image

FrankFei commented 6 years ago

@mattyleggy Can you refer to the RNCallKit related code? I think I may have a problem with this RNCallKit call. My email: feipeng8@gmail.com

mattyleggy commented 6 years ago

This is just a test by the way, it's not a real fix... Let me know if it resolves the audio issue though. I'm also not 100% sure if RNCallKit is the problem or not by the way.

You don't need to change the RNCallKit.addEventListener('answerCall'... stuff.

But instead change the answerCall method in the pjsip.js file

export function answerCall(call) {
  return async function (dispatch, getState) {
    const endpoint = getState().pjsip.endpoint
    endpoint.answerCall(call).then(()=>{
      setTimeout(()=>{      
        endpoint.holdCall(call).then(()=>{
          setTimeout(()=>{      
              endpoint.unholdCall(call);
          },2000);
        });
      },2000);      
    })
  }
}
FrankFei commented 6 years ago

Using this method of yours, I tested it here and now the sound is normal.

FrankFei commented 6 years ago

image 我现在使用以上方法解决了!FYI

mattyleggy commented 6 years ago

I've tried a similar solution to that before with the activateAudioSession and it doesn't appear to fix it. If you keep testing it you'll find that it is still broken and you might have just has a good run with it.

On Tue, 3 Apr. 2018, 7:12 pm FrankFei, notifications@github.com wrote:

[image: image] https://user-images.githubusercontent.com/3292846/38240376-0575a304-3762-11e8-9f64-83d3e30e6108.png 我现在使用以上方法解决了!FYI

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/datso/react-native-pjsip/issues/85#issuecomment-378183140, or mute the thread https://github.com/notifications/unsubscribe-auth/ARYbsh1tR8_xRPYb8Mf5Iu9wxnjrQgZ3ks5tkz0XgaJpZM4StCxP .

FrankFei commented 6 years ago

Let's test for some time to see if there is any problem, I will tell you again.

FrankFei commented 6 years ago

With new methods, there are indeed situations where no sound can be heard

mdiflorio commented 6 years ago

Any updates on this issue? @mattyleggy @FrankFei. Did you guys manage to find a solution?

shwetadodiya commented 6 years ago

I am facing the same issue in pJsip is there any solution for this ?

dstd commented 6 years ago

To correctly fix the issue, without magic timeouts, you gotta wait for AVAudioSessionInterruptionTypeEnded of AVAudioSessionInterruptionNotification and call activateAudioSession just at that moment

mariouzae commented 5 years ago

Hi @dstd,

How can I listen for this event "AVAudioSessionInterruptionTypeEnded"?

dstd commented 5 years ago

@mariouzae well, you need to subscribe to AVAudioSessionInterruptionNotification event using addObserver method of NSNotificationCenter, and check AVAudioSessionInterruptionTypeKey in your observer.

joan2404 commented 5 years ago

I'm also experiencing this issue. If there's a call between two iOS devices, they can't hear eachother. I've changed the answerCall function with the one @mattyleggy wrote and does not solve the issue. I can hear the on hold audio but nothing more. If there's a second call, everything works.

Have you been able to solve this issue?

rohitvc commented 5 years ago

I'm also facing the same problem on IOS device. I have tried both solutions provided by @mattyleggy and @FrankFei but still no sound during call. Log of the error :-

11:50:55.307            pjsua_aud.c  ....Set sound device: capture=-1, playback=-2
11:50:55.307            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.307        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.630            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@44100/1/20ms
11:50:55.630        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.714            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@48000/1/20ms
11:50:55.714        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.776            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@32000/1/20ms
11:50:55.776        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.818            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.818        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.860            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@8000/1/20ms
11:50:55.860        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.903            pjsua_aud.c  .....Unable to open sound device: Unknown error 506637 [status=506637]
11:50:55.903            pjsua_aud.c  ....Error opening sound device: Unknown error 506637 [status=506637]
11:50:55.903            pjsua_aud.c  ...Conf connect: 0 --> 1
11:50:55.903            pjsua_aud.c  ....Set sound device: capture=-1, playback=-2
11:50:55.903            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.903        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.946            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@44100/1/20ms
11:50:55.946        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.989            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@48000/1/20ms
11:50:55.989        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.033            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@32000/1/20ms
11:50:56.033        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.075            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:56.075        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.118            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@8000/1/20ms
11:50:56.118        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.181            pjsua_aud.c  .....Unable to open sound device: Unknown error 506637 [status=506637]
11:50:56.181            pjsua_aud.c  ....Error opening sound device: Unknown error 506637 [status=506637]

P.S :- I haven't tried @dstd solution yet as i don't know how to write that in native code. Can anyone help ?

maxsolovev commented 4 years ago

I fixed that problem like this

RNCallKeep.addEventListener('answerCall', () => {
  RNCallKeep.addEventListener('didActivateAudioSession', () => {
    sipEndpoint.activateAudioSession()
    sipEndpoint.answerCall(incomingCall)
  })
})

Its work fine if you are using Callkeep

mofolo commented 4 years ago

Thank you @maxsolovev This worked for me. Using Redux to centralise the Endpoint.

DrSchmurge commented 3 years ago

I'm also facing the same problem on IOS device. I have tried both solutions provided by @mattyleggy and @FrankFei but still no sound during call. Log of the error :-

11:50:55.307            pjsua_aud.c  ....Set sound device: capture=-1, playback=-2
11:50:55.307            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.307        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.630            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@44100/1/20ms
11:50:55.630        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.714            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@48000/1/20ms
11:50:55.714        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.776            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@32000/1/20ms
11:50:55.776        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.818            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.818        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.860            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@8000/1/20ms
11:50:55.860        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.903            pjsua_aud.c  .....Unable to open sound device: Unknown error 506637 [status=506637]
11:50:55.903            pjsua_aud.c  ....Error opening sound device: Unknown error 506637 [status=506637]
11:50:55.903            pjsua_aud.c  ...Conf connect: 0 --> 1
11:50:55.903            pjsua_aud.c  ....Set sound device: capture=-1, playback=-2
11:50:55.903            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:55.903        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.946            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@44100/1/20ms
11:50:55.946        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:55.989            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@48000/1/20ms
11:50:55.989        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.033            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@32000/1/20ms
11:50:56.033        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.075            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@16000/1/20ms
11:50:56.075        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.118            pjsua_aud.c  .....Opening sound device (speaker + mic) PCM@8000/1/20ms
11:50:56.118        coreaudio_dev.c  ......Using VoiceProcessingIO audio unit
11:50:56.181            pjsua_aud.c  .....Unable to open sound device: Unknown error 506637 [status=506637]
11:50:56.181            pjsua_aud.c  ....Error opening sound device: Unknown error 506637 [status=506637]

P.S :- I haven't tried @dstd solution yet as i don't know how to write that in native code. Can anyone help ?

hi, could you please share, how did you manage to get these logs ? I am trying to watch them in Console on my macbook with iPhone connected by cable, but do not seee logs from pjsip and pjsua. Thanks in advance

linus-komnick commented 3 years ago

In my case the ringtone/ringback seems to be causing this issue. Removing it completely and making the call without any ringtones solves the audio issue. Btw, this seems to be independent of the package I'm using. react-native-incall-manager as well as react-native-sound both cause this problem. So, now I can make calls with audio transmission but no ringtone and I can make calls with ringtone but without audio transmission. I'll post the solution to this if I can find one!