force sip account register/un-register

1,412 views
Skip to first unread message

Min Wang

unread,
Oct 15, 2013, 10:14:46 PM10/15/13
to csipsim...@googlegroups.com
HI


is there any way to force sip account do the sip register and sip un-register?

I did saw there is away to force the sipprofile to be active/un-active.

but the active/un-active account seems difference from register/un-register.


Also on the

there is API: 

pj_status_t pjsua_acc_set_registration(pjsua_acc_id acc_id,
pj_bool_t renew 
)

Update registration or perform unregistration. If registration is configured for this account, then initial SIP REGISTER will be sent when the account is added with pjsua_acc_add(). Application normally only need to call this function if it wants to manually update the registration or to unregister from the server.

Parameters:
acc_idThe account ID.
renewIf renew argument is zero, this will start unregistration process.
Returns:
PJ_SUCCESS on success, or the appropriate error code.



but it seems we do not have corresponding Java api??




Thanks

min

Mukesh Srivastav

unread,
Oct 17, 2013, 5:23:30 AM10/17/13
to csipsim...@googlegroups.com
Did you find the solution on "Unregistering the sip account " ?


--
You received this message because you are subscribed to the Google Groups "CSipSimple Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to csipsimple-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Warm Regards,
Mukesh Kumar,
Android Consultant/Freelancer,
India,Hyderabad.

Min Wang

unread,
Oct 17, 2013, 10:28:56 PM10/17/13
to csipsim...@googlegroups.com
No.

Anyone? any hint?


min

Régis Montoya

unread,
Oct 18, 2013, 2:22:29 PM10/18/13
to CSipSimple dev group
When you de-activate an account it should automatically delete the account from pjsip which results in unregistration.

What is the root reason why you'd like to perform a unregister/register?



2013/10/18 Min Wang <ser....@gmail.com>

Min Wang

unread,
Oct 20, 2013, 12:08:36 AM10/20/13
to csipsim...@googlegroups.com
HI Régis

thanks.

e.g: I have both 3G + wifi connection, 

I may just want to unregister the account from wifi interface,  turn off wifi to save some battery,
 
but I still want to be able to make a VoIP via 3G connection.

when I turn on the wifi, I want to register the sip account.

Thus I want to keep the account active, but just register/un-register from specific connections/interface.

is it possible?

thanks


min

Régis Montoya

unread,
Oct 20, 2013, 5:50:06 AM10/20/13
to CSipSimple dev group

Yes, It's already totally possible just by using settings !! :-)

If you want the app to stay registered on WiFi (and automatically start /stop when WiFi is available) just enable the setting "enable for incoming > WiFi" (and also enable for outgoing). If you want the app to automatically stop on background when it's 3g disable the setting "enable for incoming >3g" and keep the outgoing for 3g enabled.
This way the app will ensure that it will not stay registered on 3g and will just start 'on demand' when on 3g (basically when you go in a CSipSimple ui that allows to make a sip call). And it will automatically connect when WiFi is reconnected!
(Side note : keep in mind that in android to quit a user interface activity you must use the back key and not the home key.)

So all this lifetime management already exists in CSipSimple and works very well. Do not reinvent the wheel. All you need to do, is to use the configuration api of CSipSimple lib to select the lifetime behavior of the app regarding network. And that's it. Do not bother with registration etc etc. CSipSimple lib will take care of that and probably better that what you might think initially because it will manage hard network cuts and registration cleanup at next restart etc.

Advise : try to use the core app first and to understand the settings already available. The features available should already cover most real sip client needs and integration to Android. Making a custom version of the app should be only about non sip features (something only on your service) and about using the config api to automatically setup for your service (and this should normally be done using the wizard activity approach).

For anything else related to sip, it either already exists, either, if not, it probably makes sense to have in the main app. In the later case it means that you should contribute that to the core project. Just a reminder, the code of CSipSimple is GPL/LGPL (with pjsip commercial license). So in any case all source code you will modify related to sip in java must be opensourced and is a potential contribution. So when dealing with a need related to sip, thinks first about how you could contribute that if not already done. Play the game of GPL, it's what make you save money and time currently (and in the future), what make all the apps base on csipsimple (including yours) better, and what provides all users better experience, and so, what makes world better ;-).

Best regards
Regis.

Min Wang

unread,
Oct 20, 2013, 11:41:25 PM10/20/13
to csipsim...@googlegroups.com
Hi Regis

Thanks a lot for the info and advice.  Yes, we will honor the GPL/LGPL if we make the related changes.

I tried this setting ( assuming wifi/3g are handled the same way)  :
  wifi with incoming disable, 
  wifi with outgoing enabled 

  then use back key to the sip main dialpad screen, the sip account showed de-active, then re-actived, then it said sip registered. 

 According to your description, it seems should stay unregistered, only when I make an outgoing sip call it will try to register, right? is it a bug? 

Read  the code SipServic.java, there is a function:

public boolean isConnectivityValid() {
   if(prefsWrapper.getPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, false)) {
       return false;
   }
   boolean valid = prefsWrapper.isValidConnectionForIncoming();
   if(activitiesForOutgoing.size() > 0) {
       valid |= prefsWrapper.isValidConnectionForOutgoing();
   }
   return valid;
}

it seems it does not  differentiate the outgoing  and incoming setting??

Where is code that will make sure it will not stay registered on 3g/wifi if incoming is disabled? 




Thanks again!


min

Régis Montoya

unread,
Oct 21, 2013, 4:55:47 AM10/21/13
to CSipSimple dev group



2013/10/21 Min Wang <ser....@gmail.com>

Hi Regis

Thanks a lot for the info and advice.  Yes, we will honor the GPL/LGPL if we make the related changes.

I tried this setting ( assuming wifi/3g are handled the same way)  :
  wifi with incoming disable, 
  wifi with outgoing enabled 

  then use back key to the sip main dialpad screen, the sip account showed de-active, then re-actived, then it said sip registered. 

 According to your description, it seems should stay unregistered, only when I make an outgoing sip call it will try to register, right? is it a bug? 


No, when you are in csipsimple dialpad you are in a mode that is outgoing (because it's a view that allows outgoing calls (it lists possible reachable accounts for outgoing)).
If you press back when in dialpad, you'll see that csipsimple de-register and stop the service totally.

(The first unregister/re-register you see when you quit the configuration is just a restart of the service to take into account settings changed)
 

Read  the code SipServic.java, there is a function:

public boolean isConnectivityValid() {
   if(prefsWrapper.getPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, false)) {
       return false;
   }
   boolean valid = prefsWrapper.isValidConnectionForIncoming();
   if(activitiesForOutgoing.size() > 0) {
       valid |= prefsWrapper.isValidConnectionForOutgoing();
   }
   return valid;
}

it seems it does not  differentiate the outgoing  and incoming setting??

You are in the right part of the code. Let me explain why it correctly take into account incoming and outgoing :
The first test is about a global setting that completely disable the service. (It's the disconnect button in csipsimple dialer ui). It should always be false and not return here.
The "isValidConnectionForIncoming" checks if the current network state was enabled for incoming mode. If it's true, basically the function will always return true (as the other check is result is added with 'or' to the result).
Then there is the very important check you didn't get for now. "activitiesForOutgoing.size() > 0". This needs a little bit more explanation. When an activity (csipsimple dialer, the outgoing call handler or any other app that intend to make an outgoing call) wants to start the service for outgoing mode it adds itself as an "outgoing" activity. This activity is responsible to remove itself from the list of outgoing activities when it's finished. And in android an activity should finish when the back key is pressed (or when it decides to finish by itself). As consequence, all the time you are in csipsimple dialer, you have an outgoing activity ongoing. This activity tell csipsimple service that the current mode is "outgoing" and so, it will check if the network is valid for outgoing call. That's why the test here "activitiesForOutgoing.size() > 0" should be false when all activities which purpose is to do an outgoing sip call are finished. And that's why it works : the "isValidConnectionForOutgoing" is only checked if there is activities currently active for user.
When you quit the csipsimple dialer screen with the back button, csipsimple dialer screen will remove itself from current outgoing activities, csipsimple will detect there is no more activitiesForOutgoing, and the isConnectivityValid will return false, and the service will stop itself.



Mukesh Srivastav

unread,
Oct 22, 2013, 8:03:07 AM10/22/13
to csipsim...@googlegroups.com
Hello regis,

I have a thought on un-registering from APK.

I mean, we can just stop the sip service when we do a logout and also, use the 

1. Why not just just stop sip service.. some thing like,

removeAllAccounts method in the Sipservice class.

Please suggest.
Reply all
Reply to author
Forward
0 new messages