| | |
| | | |
| | | @interface HDLLinphoneManager (){ |
| | | LinphoneAccountCreator *account_creator; |
| | | UIBackgroundTaskIdentifier pausedCallBgTask; |
| | | UIBackgroundTaskIdentifier incallBgTask; |
| | | NSDate *mLastKeepAliveDate; |
| | | |
| | | } |
| | | @property(strong, nonatomic) AVAudioPlayer* messagePlayer; |
| | |
| | | * grab, if any */ |
| | | // [self iterate]; |
| | | // start scheduler |
| | | |
| | | [HDLCoreManager.instance startIterateTimer]; |
| | | } |
| | | |
| | |
| | | // reload address book to prepend proxy config domain to contacts' phone number |
| | | // todo: STOP doing that! |
| | | // [[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread]; |
| | | |
| | | NSLog(@"登录成功"); |
| | | } |
| | | } |
| | |
| | | [HDLCallManager.instance terminateCallWithCall:call]; |
| | | } |
| | | -(void)acceptCall{ |
| | | // [HDLCallManager configAudioSessionWithAudioSession:[AVAudioSession sharedInstance]]; |
| | | LinphoneCall * call = linphone_core_get_current_call(theLinphoneCore); |
| | | [HDLCallManager.instance acceptCallWithCall:call hasVideo:YES]; |
| | | } |
| | |
| | | UIImage *image= [HDLLinPhoneCommon captureImageFromView:view]; |
| | | [HDLLinPhoneCommon saveImageToPhotosAlbum:image]; |
| | | } |
| | | |
| | | |
| | | -(void)removeAllAccounts{ |
| | | |
| | | const bctbx_list_t *accounts = linphone_core_get_proxy_config_list(theLinphoneCore); |
| | | size_t count = bctbx_list_size(accounts); |
| | | for (size_t i = 1; i <= count; i++, accounts = accounts->next) { |
| | | LinphoneProxyConfig *config = (LinphoneProxyConfig *)accounts->data; |
| | | if (config!=NULL) { |
| | | //移除config |
| | | linphone_core_remove_proxy_config(theLinphoneCore, config); |
| | | const LinphoneAuthInfo *ai = linphone_proxy_config_find_auth_info(config); |
| | | if (ai) { |
| | | linphone_core_remove_auth_info(theLinphoneCore, ai); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | -(void)clearConfigs{ |
| | | // const bctbx_list_t *proxies= |
| | | // linphone_core_get_proxy_config_list(theLinphoneCore); |
| | | // if (proxies==NULL) { |
| | | // return; |
| | | // } |
| | | //// NSLog(@"list:%@",list); |
| | | // while (proxies) { |
| | | // LinphoneProxyConfig *config = proxies->data; |
| | | // if (config!=NULL) { |
| | | // const LinphoneAuthInfo *ai = linphone_proxy_config_find_auth_info(config); |
| | | // if (ai) { |
| | | // linphone_core_remove_auth_info(theLinphoneCore, ai); |
| | | // } |
| | | // //移除config |
| | | // linphone_core_remove_proxy_config(theLinphoneCore, config); |
| | | // } |
| | | // |
| | | // |
| | | // proxies= proxies->next; |
| | | // } |
| | | } |
| | | |
| | | // C Function |
| | | static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyConfig *cfg, |
| | | LinphoneRegistrationState state, const char *message) { |
| | |
| | | } |
| | | } |
| | | |
| | | - (BOOL)enterBackgroundMode { |
| | | linphone_core_enter_background(theLinphoneCore); |
| | | |
| | | // LinphoneProxyConfig *proxyCfg = linphone_core_get_default_proxy_config(theLinphoneCore); |
| | | // BOOL shouldEnterBgMode = FALSE; |
| | | // |
| | | // // disable presence |
| | | // [self enableProxyPublish:NO]; |
| | | // |
| | | // // handle proxy config if any |
| | | // if (proxyCfg) { |
| | | // const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL; |
| | | // BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); |
| | | // if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"backgroundmode_preference"] || pushNotifEnabled) { |
| | | // if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { |
| | | // // For registration register |
| | | // [self refreshRegisters]; |
| | | // } |
| | | // } |
| | | // |
| | | // if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"voip_mode_preference"] && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"backgroundmode_preference"] && !pushNotifEnabled) { |
| | | // // Keep this!! Socket VoIP is deprecated after 9.0, but sometimes it's the only way to keep the phone background and receive the call. For example, when there is only local area network. |
| | | // // register keepalive |
| | | // NSLog(@"keepalive保活"); |
| | | // if ([[UIApplication sharedApplication] |
| | | // setKeepAliveTimeout:600 /*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/ |
| | | // handler:^{ |
| | | //// LOGW(@"keepalive handler"); |
| | | // self->mLastKeepAliveDate = [NSDate date]; |
| | | // if (theLinphoneCore == nil) { |
| | | //// LOGW(@"It seems that Linphone BG mode was deactivated, just skipping"); |
| | | // return; |
| | | // } |
| | | //// [_iapManager check]; |
| | | // if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { |
| | | // // For registration register |
| | | // [self refreshRegisters]; |
| | | // } |
| | | // linphone_core_iterate(theLinphoneCore); |
| | | // }]) { |
| | | // NSLog(@"keepalive handler succesfully registered"); |
| | | // } else { |
| | | //// LOGI(@"keepalive handler cannot be registered"); |
| | | // } |
| | | // shouldEnterBgMode = TRUE; |
| | | // } |
| | | // } |
| | | // |
| | | // LinphoneCall *currentCall = linphone_core_get_current_call(theLinphoneCore); |
| | | // const bctbx_list_t *callList = linphone_core_get_calls(theLinphoneCore); |
| | | // if (!currentCall // no active call |
| | | // && callList // at least one call in a non active state |
| | | // && bctbx_list_find_custom(callList, (bctbx_compare_func)comp_call_state_paused, NULL)) { |
| | | // [self startCallPausedLongRunningTask]; |
| | | // } |
| | | // if (callList) // If at least one call exist, enter normal bg mode |
| | | // shouldEnterBgMode = TRUE; |
| | | // |
| | | // // Stop the video preview |
| | | // if (theLinphoneCore) { |
| | | // linphone_core_enable_video_preview(theLinphoneCore, FALSE); |
| | | // [self iterate]; |
| | | // } |
| | | // linphone_core_stop_dtmf_stream(theLinphoneCore); |
| | | // |
| | | //// LOGI(@"Entering [%s] bg mode", shouldEnterBgMode ? "normal" : "lite"); |
| | | // if (!shouldEnterBgMode && floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { |
| | | // const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL; |
| | | // BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); |
| | | // if (pushNotifEnabled) { |
| | | //// LOGI(@"Keeping lc core to handle push"); |
| | | // return YES; |
| | | // } |
| | | // return NO; |
| | | // } |
| | | return YES; |
| | | |
| | | } |
| | | |
| | | - (void)enableProxyPublish:(BOOL)enabled { |
| | | if (linphone_core_get_global_state(theLinphoneCore) != LinphoneGlobalOn || !linphone_core_get_default_friend_list(theLinphoneCore)) { |
| | | // LOGW(@"Not changing presence configuration because linphone core not ready yet"); |
| | | return; |
| | | } |
| | | |
| | | if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"publish_presence"]) { |
| | | // set present to "tv", because "available" does not work yet |
| | | if (enabled) { |
| | | linphone_core_set_presence_model(theLinphoneCore, linphone_core_create_presence_model_with_activity(theLinphoneCore, LinphonePresenceActivityTV, NULL)); |
| | | } |
| | | |
| | | const MSList *proxies = linphone_core_get_proxy_config_list(theLinphoneCore); |
| | | while (proxies) { |
| | | LinphoneProxyConfig *cfg = proxies->data; |
| | | linphone_proxy_config_edit(cfg); |
| | | linphone_proxy_config_enable_publish(cfg, enabled); |
| | | linphone_proxy_config_done(cfg); |
| | | proxies = proxies->next; |
| | | } |
| | | // force registration update first, then update friend list subscription |
| | | [self iterate]; |
| | | } |
| | | |
| | | linphone_core_enable_friend_list_subscription(theLinphoneCore, enabled && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"use_rls_presence"]); |
| | | } |
| | | |
| | | - (void)refreshRegisters { |
| | | linphone_core_refresh_registers(theLinphoneCore); // just to make sure REGISTRATION is up to date |
| | | } |
| | | |
| | | - (void)startCallPausedLongRunningTask { |
| | | pausedCallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ |
| | | // LOGW(@"Call cannot be paused any more, too late"); |
| | | [[UIApplication sharedApplication] endBackgroundTask:self->pausedCallBgTask]; |
| | | }]; |
| | | // LOGI(@"Long running task started, remaining [%@] because at least one call is paused", |
| | | // [LinphoneUtils intervalToString:[[UIApplication sharedApplication] backgroundTimeRemaining]]); |
| | | } |
| | | |
| | | -(void)willResignActive{ |
| | | LinphoneCall *call = linphone_core_get_current_call(theLinphoneCore); |
| | | |
| | | if (!call) |
| | | return; |
| | | |
| | | /* save call context */ |
| | | HDLLinphoneManager *instance = HDLLinphoneManager.instance; |
| | | instance->currentCallContextBeforeGoingBackground.call = call; |
| | | instance->currentCallContextBeforeGoingBackground.cameraIsEnabled = linphone_call_camera_enabled(call); |
| | | |
| | | const LinphoneCallParams *params = linphone_call_get_current_params(call); |
| | | if (linphone_call_params_video_enabled(params)) |
| | | linphone_call_enable_camera(call, false); |
| | | } |
| | | |
| | | - (void)becomeActive { |
| | | linphone_core_enter_foreground(theLinphoneCore); |
| | | |
| | | [self checkNewVersion]; |
| | | |
| | | // enable presence |
| | | if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { |
| | | [self refreshRegisters]; |
| | | } |
| | | if (pausedCallBgTask) { |
| | | [[UIApplication sharedApplication] endBackgroundTask:pausedCallBgTask]; |
| | | pausedCallBgTask = 0; |
| | | } |
| | | if (incallBgTask) { |
| | | [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; |
| | | incallBgTask = 0; |
| | | } |
| | | |
| | | /*IOS specific*/ |
| | | linphone_core_start_dtmf_stream(theLinphoneCore); |
| | | [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo |
| | | completionHandler:^(BOOL granted){ |
| | | }]; |
| | | |
| | | /*start the video preview in case we are in the main view*/ |
| | | if (linphone_core_video_display_enabled(theLinphoneCore) && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"preview_preference"]) { |
| | | linphone_core_enable_video_preview(theLinphoneCore, TRUE); |
| | | } |
| | | /*check last keepalive handler date*/ |
| | | if (mLastKeepAliveDate != Nil) { |
| | | NSDate *current = [NSDate date]; |
| | | if ([current timeIntervalSinceDate:mLastKeepAliveDate] > 700) { |
| | | NSString *datestr = [mLastKeepAliveDate description]; |
| | | // LOGW(@"keepalive handler was called for the last time at %@", datestr); |
| | | } |
| | | } |
| | | |
| | | [self enableProxyPublish:YES]; |
| | | } |
| | | |
| | | - (void)checkNewVersion { |
| | | // if (!CHECK_VERSION_UPDATE) |
| | | // return; |
| | | // if (theLinphoneCore == nil) |
| | | // return; |
| | | // NSString *curVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; |
| | | // const char *curVersionCString = [curVersion cStringUsingEncoding:NSUTF8StringEncoding]; |
| | | // linphone_core_check_for_update(theLinphoneCore, curVersionCString); |
| | | } |
| | | |
| | | static int comp_call_state_paused(const LinphoneCall *call, const void *param) { |
| | | return linphone_call_get_state(call) != LinphoneCallPaused; |
| | | } |
| | | @end |