Search code examples
iphoneios5ios-simulatorpjsip

How to implement mute functionality in a PJSIP call on iOS


I wanted to implement Mute button in my call. I am working on a VOIP application for iPhone. Now when a call comes and user picks up, I want to display a Mute button so the user can mute the call or conference. I did the same through the PJSIP API.

-(int) mutethecall
{
    pj_status_t status =   pjsua_conf_adjust_rx_level (0,0);
    status = pjsua_conf_adjust_tx_level (0,0);
    return (PJ_SUCCESS == status);
}
-(int) unmutethecall
{
    pj_status_t status =   pjsua_conf_adjust_rx_level (0,1);
    status = pjsua_conf_adjust_tx_level (0,1);
    return (PJ_SUCCESS == status);
}

The problem is that while this code is working for one to one call, it's not working for conference scenarios.

I wonder if I could turn off the mic directly: could I implement the same using iOS bypassing the PJSIP API?

Is this possible?


Solution

  • You can completely disconnect the microphone from the conference using pjsua_conf_disconnect and pjsua_conf_connect when you want to unmute.

    Here's some Objective-C code that does the trick:

    +(void)muteMicrophone
    {
        @try {
            if( pjsipConfAudioId != 0 ) {
                NSLog(@"WC_SIPServer microphone disconnected from call");
                pjsua_conf_disconnect(0, pjsipConfAudioId);
            }
        }
        @catch (NSException *exception) {
            NSLog(@"Unable to mute microphone: %@", exception);
        }
    }
    
    +(void)unmuteMicrophone
    {
        @try {
            if( pjsipConfAudioId != 0 ) {
                NSLog(@"WC_SIPServer microphone reconnected to call");
                pjsua_conf_connect(0,pjsipConfAudioId);
            }
        }
        @catch (NSException *exception) {
            NSLog(@"Unable to un-mute microphone: %@", exception);
        }
    }
    

    Note that the pjsipConfAudioID was retrieved when the call was established, again in Objective-C...

    static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
    {
        pjsua_call_info ci;
        PJ_UNUSED_ARG(e);
        pjsua_call_get_info(call_id, &ci);
        pjsipConfAudioId = ci.conf_slot;
        ...
    }
    

    Hope that helps!