Way to set loud speaker for webrtc

Hello,
I want to set react-native-webrtc to phone speaker
now when i call my stream sound play in earphone
please help me

You can do it with this plugin: https://github.com/react-native-webrtc/react-native-incall-manager

1 Like

can you explain more ?

Please read its documentation: https://github.com/react-native-webrtc/react-native-incall-manager#api

Hi all,
With “react-native-incall-manager”, we only can set “On” the “phone speaker” not (internal speaker). It means the sound like the voice call with speaker on. When you press the volume, the current audio mode is not the media volume. That’s why the quality of sound so pure and we need to control when users plugin the headphone too.
As I asked in another thread, there’s any way to change audio stream in “STREAM_MUSIC” instead of “STREAM_VOICE_CALL”

I believe there is, but you will need to modify the plugin yourself. IIRC something could be set on the audio track instance.

1 Like

Any idea about how to solve this situation?

Hey guys, were you able to fix this issue? I’m having the same issue @moonjava @saghul though im not using react-native-incall-manager yet. Still using just react-native-webrtc

On iOS, this is really simple. Inside your AppDelegate.m, do something like this:


#import <WebRTC/RTCAudioSessionConfiguration.h>


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Probably do other initialization stuff..

  // tell libwebrtc how to configure the app's AVAudioSession singleton
  RTCAudioSessionConfiguration *webRTCConfiguration = [RTCAudioSessionConfiguration webRTCConfiguration];

  webRTCConfiguration.categoryOptions = (
     AVAudioSessionCategoryOptionAllowBluetooth | 
    AVAudioSessionCategoryOptionDefaultToSpeaker
  );
  
  return YES;
}

If this is all you need, I wouldn’t recommend react-native-incall-manager. It’s overkill.

If you need to support Android, it’s a bit more complicated. I ended up copying some sample code from AppRTC that’s available here: examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java - external/webrtc - Git at Google

I believe this is the code that react-native-incall-manager was originally based on.

Hi,
I don’t understand how to apply your solution,
RTCAudioSessionConfiguration.h doesn’t existe :confused:
Is it possible to have more information?
Thanks !

This file is part of WebRTC.framework, which should be automatically linked when you install react-native-webrtc.

Thank you @jbaudanza as it helped us get the iOS side situated. For Android, we were able to default to speakerphone in a bit of a hacky way (at least for now) that was fairly easy to do.

First we added code to the MainApplication.java file in the onCreate() function:

Add this import to the top of the file:

import android.media.AudioManager;

Then modify onCreate()

  @Override
  public void onCreate() {
    // Your other content...

    AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (manager != null) {
      manager.setSpeakerphoneOn(true);
    }
  }

Lastly you will need to add the following to AndroidManifest.xml:

  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Hope this helps!

1 Like

On new version of react-native-webrtc (111.0.6), RTCAudioSessionConfiguration was removed. So do you have any solution?