Commit 63a17857 authored by jehan's avatar jehan

test network availability before calling

parent 722ae5a6
......@@ -72,6 +72,15 @@
-(IBAction) doAction:(id)sender {
if (sender == call) {
if (!linphone_core_is_network_reachabled(mCore)) {
UIAlertView* error = [[UIAlertView alloc] initWithTitle:@"Network Error"
message:@"There is no network connection available, enable WIFI or WWAN prior to place a call"
delegate:nil
cancelButtonTitle:@"Continue"
otherButtonTitles:nil];
[error show];
return;
}
if (!linphone_core_in_call(mCore)) {
LinphoneProxyConfig* proxyCfg;
//get default proxy
......@@ -83,9 +92,9 @@
} else if ( proxyCfg==nil){
UIAlertView* error = [[UIAlertView alloc] initWithTitle:@"Invalid sip address"
message:@"Either configure a SIP proxy server from settings prior to place a call or use a valid sip address (I.E sip:john@example.net)"
delegate:nil
cancelButtonTitle:@"Continue"
otherButtonTitles:nil];
delegate:nil
cancelButtonTitle:@"Continue"
otherButtonTitles:nil];
[error show];
} else {
......
......@@ -23,7 +23,6 @@
#import "AddressBook/ABPerson.h"
#import <AVFoundation/AVAudioSession.h>
#import <AudioToolbox/AudioToolbox.h>
#import "osip2/osip.h"
#import "ConsoleViewController.h"
#import "MoreViewController.h"
......@@ -239,6 +238,9 @@ extern void libmsilbc_init();
, [factoryConfig cStringUsingEncoding:[NSString defaultCStringEncoding]]
,self);
//initial state is network off
linphone_core_set_network_reachable(myLinphoneCore,false);
// Set audio assets
const char* lRing = [[myBundle pathForResource:@"oldphone-mono"ofType:@"wav"] cStringUsingEncoding:[NSString defaultCStringEncoding]];
linphone_core_set_ring(myLinphoneCore, lRing );
......@@ -283,18 +285,18 @@ extern void libmsilbc_init();
proxyCfg = linphone_proxy_config_new();
// add username password
osip_from_t *from;
LinphoneAddress *from = linphone_address_new(identity);
LinphoneAuthInfo *info;
osip_from_init(&from);
if (osip_from_parse(from,identity)==0){
info=linphone_auth_info_new(from->url->username,NULL,password,NULL,NULL);
if (from !=0){
info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL);
linphone_core_add_auth_info(myLinphoneCore,info);
}
osip_from_free(from);
linphone_address_destroy(from);
// configure proxy entries
linphone_proxy_config_set_identity(proxyCfg,identity);
linphone_proxy_config_set_server_addr(proxyCfg,proxy);
linphone_proxy_config_enable_register(proxyCfg,true);
if (isOutboundProxy)
linphone_proxy_config_set_route(proxyCfg,proxy);
......@@ -311,8 +313,7 @@ extern void libmsilbc_init();
LinphoneAddress* addr=linphone_address_new(linphone_proxy_config_get_addr(proxyCfg));
proxyReachability=SCNetworkReachabilityCreateWithName(nil, linphone_address_get_domain(addr));
proxyReachabilityContext.info=self;
bool result=SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack,&proxyReachabilityContext);
SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
[self doRegister];
} else if (configCheckDisable == false) {
UIAlertView* error = [[UIAlertView alloc] initWithTitle:@"Warning"
......@@ -321,7 +322,13 @@ extern void libmsilbc_init();
cancelButtonTitle:@"Continue"
otherButtonTitles:@"Never remind",nil];
[error show];
proxyReachability=SCNetworkReachabilityCreateWithName(nil, @"linphone.org");
}
SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack,&proxyReachabilityContext);
SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
//Configure Codecs
PayloadType *pt;
......@@ -441,26 +448,22 @@ extern void libmsilbc_init();
}
bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info) {
LinphoneProxyConfig* proxyCfg;
id<LinphoneTabManagerDelegate> linphoneDelegate=info;
if (linphone_core_get_default_proxy([linphoneDelegate getLinphoneCore],&proxyCfg)) {
//glob, no default proxy
return false;
}
linphone_proxy_config_edit(proxyCfg);
LinphoneCore* lc = [linphoneDelegate getLinphoneCore];
bool result = false;
if ((flags == 0) | (flags & (kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic))) {
[linphoneDelegate kickOffNetworkConnection];
}
if (flags) {
// register whatever connection type
linphone_proxy_config_enable_register(proxyCfg,TRUE);
result = true;
} else {
linphone_proxy_config_enable_register(proxyCfg,false);
result = false;
if (lc != nil) {
if ((flags == 0) | (flags & (kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic))) {
[linphoneDelegate kickOffNetworkConnection];
}
if (flags) {
linphone_core_set_network_reachable(lc,true);
result = true;
} else {
linphone_core_set_network_reachable(lc,false);
result = false;
}
}
linphone_proxy_config_done(proxyCfg);
return result;
}
-(LinphoneCore*) getLinphoneCore {
......
......@@ -28,5 +28,10 @@
<string>3.1.2</string>
<key>NSMainNibFile</key>
<string>PhoneMainView</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>wifi</string>
<string>microphone</string>
</array>
</dict>
</plist>
......@@ -7,12 +7,13 @@ mtu=0
[sip]
sip_port=5060
guess_hostname=1
contact=sip:jehanmonnier@unknown-host
contact=sip:toto@unknown-host
inc_timeout=15
use_info=0
use_ipv6=0
register_only_when_network_is_up=0
default_proxy=-1
auto_net_state_mon=0
[rtp]
audio_rtp_port=7076
......@@ -26,43 +27,4 @@ playback_dev_id=AU: Audio Unit
ringer_dev_id=AU: Audio Unit
capture_dev_id=AU: Audio Unit
[audio_codec_0]
mime=speex
rate=32000
enabled=0
[audio_codec_1]
mime=speex
rate=16000
enabled=0
[audio_codec_2]
mime=speex
rate=8000
enabled=0
[audio_codec_3]
mime=GSM
rate=22050
enabled=0
[audio_codec_4]
mime=GSM
rate=11025
enabled=0
[audio_codec_5]
mime=GSM
rate=8000
enabled=0
[audio_codec_6]
mime=PCMU
rate=8000
enabled=0
[audio_codec_7]
mime=PCMA
rate=8000
enabled=0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment