linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Linphone-developers] Network reachability callback problem in Linph


From: Jehan Monnier
Subject: Re: [Linphone-developers] Network reachability callback problem in Linphone iPhone
Date: Fri, 6 Jul 2012 09:23:24 +0200

Hi Ivan,

Thanks for your notes on that topic.  I meet the same conclusion as you, a voip socket is required for the reachability callback to be invoked.

Cheers
 

Le 5 juil. 2012 à 08:55, IVAN FERNANDEZ a écrit :

Hi again,

I've been around this issue for some days, and finally the problem looks to be closely related with the NSStreamNetworkServiceTypeVoIp connection mode,

Looks like a suspended app only could listen to connectivity changes once it has established an active NSStreamNetworkServiceTypeVoIp connection with the remote server.

That explains why Reachability sample is not responding to the connectivity changes in background mode (no NSStreamNetworkServiceTypeVoIp connection within the app) and why the voip app neither responds if wifi's off on first launch...

So, looks like some kind of workaround will be needed for this one...


2012/6/28 IVAN FERNANDEZ <address@hidden>
Hi,

I've spent several days with this issue but I haven't found a complete solution... for some reason that I can't understand, network changes control for Linphone based on SCNetworkReachability API only works if there is a valid wifi connection when the app is launched (for the moment, I'm only interested in only wifi mode)

In order to simplificate and avoid some problems on changes between wwan/wifi connection, I've finally replaced the SCNetworkReachability API operations in Linphone code. 

For my workaround, I used the Reachability class provided by Apple (v2.2), with the following changes on LinphoneManager.m code:

-(void) setupNetworkReachabilityCallback: (const char*) nodeName withContext:(SCNetworkReachabilityContext*) ctx {

    //add changes observer    

   [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];

    internetReachable = [[Reachability reachabilityForInternetConnection] retain];

    [internetReachable startNotifier];

    //launch initial check

    [self reachabilityChanged: nil];

}


- (void)reachabilityChanged:(NSNotification *)notice {

    // called after network status changes

    LinphoneProxyConfig* proxy;

    linphone_core_get_default_proxy([LinphoneManager getLc], &proxy);

    BOOL isWifiOnly = [[NSUserDefaults standardUserDefaults] boolForKey:@"wifi_only_preference"];


    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];

    if (internetStatus == ReachableViaWiFi) {

        NSLog(@"Internet accesible via wifi...");

        linphone_core_set_network_reachable([LinphoneManager getLc],true);

        if (proxy)  linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES);

    }

    else if (internetStatus != NotReachable && !isWifiOnly) {

        NSLog(@"Internet accesible via wwan...");

        linphone_core_set_network_reachable([LinphoneManager getLc],true);

        if (proxy)  linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES);

    }

    else

       [[LinphoneManager instance] kickOffNetworkConnection];

}



For the moment, this workaround is working great if wifi is up when you launch the app. But if the app is launched without wifi connection -> then goes background -> then wifi goes up, the app will not register untill it is relaunched or the re-register timer (600s) expires (before that all works as espected). 

I've tried dozens of solutions, combinations, test... but that's the better approach I could get... Anyone can see a better solution to the problem?

What do you think about that code replacement? Could it bring some other problems on other scenarios?

Thanks in advanced,

IvánF



2012/6/23 Jehan Monnier <address@hidden>
Hi,
Very interesting indeed. 
Let us know the outcomes of your further findings.
Cheers


Le 20 juin 2012 à 13:48, IVAN FERNANDEZ a écrit :

Hi,

I'm facing an strange problem with the callback that detects network changes in Linphone code.

The problem is that the callback is being called correctly when the wifi goes off, but it is not called again when the wifi goes on.

I'm running two test (iPhone 4 iOS 5.1.1, Linphone 1.1.2 with TLS enabled):

1. Wifi set to ON: I run Linphone from xcode ->wait the registration in the server -> then I go to the settings and switch off wifi -> the callback is called -> ALL IS GREAT -> then I switch wifi on again... -> the callback is not called -> ;-/

2. Wifi set to OFF: I run Linphone from xcode -> no connection so the registration can not be done -> then I go to the settings and switch on wifi -> the callback is not called -> ;-/

Let's take a look to the callback:

void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* nilCtx) {

     ms_message("Network connection flag [%x]",flags);

    

     LinphoneManager* lLinphoneMgr = [LinphoneManager instance];

     SCNetworkReachabilityFlags networkDownFlags=kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic;


     if ([LinphoneManager getLc] != nil) {

          LinphoneProxyConfig* proxy;

          linphone_core_get_default_proxy([LinphoneManager getLc], &proxy);


          struct NetworkReachabilityContext* ctx = nilCtx ? ((struct NetworkReachabilityContext*)nilCtx) : 0;

        

          if ((flags == 0) | (flags & networkDownFlags)) {


                 [lLinphoneMgr kickOffNetworkConnection];

                 //COMMENTING THE FOLLOWING LINE THE PROBLEM IS PARCIALLY SOLVED !!!!!!!!!!!!

                 linphone_core_set_network_reachable([LinphoneManager getLc],false);

                 lLinphoneMgr.connectivity = none;

            

     } else {


            Connectivity  newConnectivity;

            BOOL isWifiOnly = [[NSUserDefaults standardUserDefaults] boolForKey:@"wifi_only_preference"];

            if (!ctx || ctx->testWWan)

                newConnectivity = flags & kSCNetworkReachabilityFlagsIsWWAN ? wwan:wifi;

            else

                newConnectivity = wifi;


            if (newConnectivity == wwan && proxy && isWifiOnly && (lLinphoneMgr.connectivity == newConnectivity || lLinphoneMgr.connectivity == none)) {

                    linphone_proxy_config_expires(proxy, 0);

            } else if (proxy){

                    linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES); //might be better to save the previous value

            }


            if (lLinphoneMgr.connectivity == none) {

                      linphone_core_set_network_reachable([LinphoneManager getLc],true);

            } else if (lLinphoneMgr.connectivity != newConnectivity) {

                      // connectivity has changed

                     linphone_core_set_network_reachable([LinphoneManager getLc],false);

                     if (newConnectivity == wwan && proxy && isWifiOnly) {

                              linphone_proxy_config_expires(proxy, 0);

                      } 

             linphone_core_set_network_reachable([LinphoneManager getLc],true);

              }

              lLinphoneMgr.connectivity=newConnectivity;

              ms_message("new network connectivity  of type [%s]",(newConnectivity==wifi?"wifi":"wwan"));

         }

          if (ctx && ctx->networkStateChanged) {

                  (*ctx->networkStateChanged)(lLinphoneMgr.connectivity);

            }

     }

}


The most curious thing is that if I comment the invocation to "linphone_core_set_network_reachable" that I've pointed in the callback the first test works great and the callback is called on both on/off wifi changes (what makes me suspect that the problem can be caused by a silly issue), but the second test remains failing.

¿Anyone has that point running? ¿Any ideas about why the callback is not called any more at some point? 

PD: On Android, the same test with reachability works great on all the cases.

Thanks in advanced..



_______________________________________________
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers


_______________________________________________
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers



_______________________________________________
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]