flutter-webrtc / dart-sip-ua

A dart-lang version of the SIP UA stack.
MIT License
329 stars 255 forks source link

Call is always on loudspeakers on iPhone/iOS #249

Open ShahzadUmarBaig opened 2 years ago

ShahzadUmarBaig commented 2 years ago

I am unable to use iPhone's receiver speaker for calling, even after using the example code for toggling speakers it doesn't work. I was able to achieve the toggling on Android but on iOS whatsoever, It is not switching.

Using the code: state.stream?.getAudioTracks()?.first?.enableSpeakerphone(false);

This line of code is expected to make sure the application uses the receiver only but it is using both, loudspeaker and receiver speaker on iOS devices.

I have written some native code and the debug log shows that the speaker is on the Receiver end but it is of no use.

iOS Native code in Swift:

let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSession.Category.playAndRecord,options: .allowBluetooth)try session.setMode(AVAudioSession.Mode.voiceChat)
try session.overrideOutputAudioPort(AVAudioSession.PortOverride.none)
try session.setActive(true)
} catch let error as NSError {
print("audioSession error: \(error.localizedDescription)")
}

If anyone was able to toggle speakers, please let me know.

Ant-Pinto commented 2 years ago

Hey @ShahzadUmarBaig, did you ever find a solution? After updating to the latest package version, the toggle is working for me, but its just starting the call on speakerphone. I have called the same code that my toggle button is calling when the call connects, but it still doesn't start the call on the earpiece.

I thought I had fixed it several times, but it went right back to being started on speakerphone after several device restarts...

ShahzadUmarBaig commented 2 years ago

I did not actually find a solution to this issue, but what happened to me was that the code started working magically which I had tried several times before.

I used the dart-sip-ua functionality of the speaker and it actually started working on the receiver end and switching was working as well.

I am using the BLoC pattern with this library I must mention that. What I can suggest is to make sure that there is only one instance of call available in the entire application and all functions regarding calling must be invoked on that same instance.

If you still need help, you can reply to this.

Ant-Pinto commented 2 years ago

I'm using BLoC as well, I ensured its the only instance of the call helper across the app, but I was still runing into the issue. I did find a workaround though, and I reported my findings along with the temporary workaround in this issue here - https://github.com/flutter-webrtc/dart-sip-ua/issues/259

Hopefully the author will have a better idea of where to look to fix the issue, and that they can reproduce it on their end as well

jackeychina commented 2 years ago

@ShahzadUmarBaig @Ant-Pinto Do you guys find any solution ?

ShahzadUmarBaig commented 2 years ago

I learnt one thing while working with this package is, in order to keep the calling stable you have to keep only one instance of Call class.

Call all the relevant functions on that call instance. In case you have multiple instances the calling features will break eventually.

This is how I stabilised majority of the features in calling.

jackeychina commented 2 years ago

@ShahzadUmarBaig I am using common instance only and it works for android but not working for iOS.

gregorysaml commented 1 year ago

Hello, I want to implement bloc patern with sip but idk how to do it Do i pass helper with bloc or just manage the ui? Is there any example? thanks

EduardoAlberti commented 1 year ago

check this for more info: https://github.com/flutter-webrtc/flutter-webrtc/issues/1290#issuecomment-1527925363

EliasBarrera commented 1 year ago

I have this error with the package sip_ua: ^0.5.8, any solution ?