Handle [misc]max_calls configuration flag inside the application

This commit is contained in:
Christophe Deschamps 2023-09-19 13:02:05 +02:00
parent 79d5e0ab8b
commit d70c60d5fa
3 changed files with 26 additions and 2 deletions

View file

@ -843,6 +843,11 @@
- (void)ConfigurationStateUpdateEvent:(NSNotification *)notif {
LinphoneConfiguringState state = [[notif.userInfo objectForKey:@"state"] intValue];
if (state == LinphoneConfiguringSuccessful) {
if (linphone_config_has_entry(LinphoneManager.instance.configDb, "misc", "max_calls")) { // Not doable on core on iOS (requires CallKit) -> flag moved to app section, and have app handle it in ProviderDelegate
linphone_config_set_int(LinphoneManager.instance.configDb, "app", "max_calls", linphone_config_get_int(LinphoneManager.instance.configDb,"misc", "max_calls",10));
linphone_config_clean_entry(LinphoneManager.instance.configDb, "misc", "max_calls");
}
[NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneConfiguringStateUpdate object:nil];
[_waitingIndicator dismissViewControllerAnimated:YES completion:nil];
UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Success", nil)

View file

@ -1810,8 +1810,11 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
factory = factoryIpad;
}
_configDb = linphone_config_new_for_shared_core(kLinphoneMsgNotificationAppGroupId.UTF8String, @"linphonerc".UTF8String, factory.UTF8String);
if (linphone_config_has_entry(_configDb, "misc", "max_calls")) { // Not doable on core on iOS (requires CallKit) -> flag moved to app section, and have app handle it in ProviderDelegate
linphone_config_set_int(_configDb, "app", "max_calls", linphone_config_get_int(_configDb,"misc", "max_calls",10));
linphone_config_clean_entry(_configDb, "misc", "max_calls");
}
}
#pragma mark - Audio route Functions
#pragma mark - Call Functions

View file

@ -98,6 +98,18 @@ class ProviderDelegate: NSObject {
let callInfo = callInfos[uuid]
let callId = callInfo?.callId
if (ConfigManager.instance().config?.hasEntry(section: "app", key: "max_calls") == 1) { // moved from misc to app section intentionally upon app start or remote configuration
if let maxCalls = ConfigManager.instance().config?.getInt(section: "app",key: "max_calls",defaultValue: 10), Core.get().callsNb > maxCalls {
Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: declining call, as max calls (\(maxCalls)) reached call-id: [\(String(describing: callId))] and UUID: [\(uuid.description)]")
decline(uuid: uuid)
DispatchQueue.main.async {
try?call?.decline(reason: .Busy)
}
return
}
}
Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: report new incoming call with call-id: [\(String(describing: callId))] and UUID: [\(uuid.description)]")
//CallManager.instance().setHeldOtherCalls(exceptCallid: callId ?? "")
provider.reportNewIncomingCall(with: uuid, update: update) { error in
@ -145,6 +157,10 @@ class ProviderDelegate: NSObject {
provider.reportCall(with: uuid, endedAt: .init(), reason: .failed)
}
func decline(uuid: UUID) {
provider.reportCall(with: uuid, endedAt: .init(), reason: .unanswered)
}
func endCallNotExist(uuid: UUID, timeout: DispatchTime) {
DispatchQueue.main.asyncAfter(deadline: timeout) {
let callId = CallManager.instance().providerDelegate.callInfos[uuid]?.callId