Move iterate timer to swift file

This commit is contained in:
Paul Cartier 2020-03-17 10:26:05 +01:00
parent 179d2718e8
commit e0e8d35a19
7 changed files with 92 additions and 26 deletions

View file

@ -37,7 +37,7 @@ import AVFoundation
static var theCallManager: CallManager?
let providerDelegate: ProviderDelegate! // to support callkit
let callController: CXCallController! // to support callkit
let manager: CoreManager! // callbacks of the linphonecore
let manager: CoreManagerDelegate! // callbacks of the linphonecore
var lc: Core?
@objc var speakerBeforePause : Bool = false
@objc var speakerEnabled : Bool = false
@ -49,7 +49,7 @@ import AVFoundation
fileprivate override init() {
providerDelegate = ProviderDelegate()
callController = CXCallController()
manager = CoreManager()
manager = CoreManagerDelegate()
}
@objc static func instance() -> CallManager {
@ -348,9 +348,27 @@ import AVFoundation
Log.directLog(BCTBX_LOG_WARNING, text: "CallKit: Unable to config audio session because : \(error)")
}
}
@objc func terminateCall(call: OpaquePointer?) { // TODO PAUL : needs to be tested with CallKit changes
if (call == nil) {
Log.directLog(BCTBX_LOG_ERROR, text: "Can not terminate null call!")
return
}
let call = Call.getSwiftObject(cObject: call!)
do {
try call.terminate()
Log.directLog(BCTBX_LOG_DEBUG, text: "Call terminated")
} catch {
Log.directLog(BCTBX_LOG_ERROR, text: "Failed to terminate call")
}
if (UIApplication.shared.applicationState == .background) {
CoreManager.instance().stopIterateTimer()
lc!.stop()
}
}
}
class CoreManager: CoreDelegate {
class CoreManagerDelegate: CoreDelegate {
static var speaker_already_enabled : Bool = false
override func onCallStateChanged(lc: Core, call: Call, cstate: Call.State, message: String) {
@ -361,7 +379,7 @@ class CoreManager: CoreDelegate {
let video = call.params?.videoEnabled ?? false
// we keep the speaker auto-enabled state in this static so that we don't
// force-enable it on ICE re-invite if the user disabled it.
CoreManager.speaker_already_enabled = false
CoreManagerDelegate.speaker_already_enabled = false
if (call.userData == nil) {
let appData = CallAppData()
@ -419,7 +437,7 @@ class CoreManager: CoreDelegate {
if (CallManager.instance().speakerBeforePause) {
CallManager.instance().speakerBeforePause = false
CallManager.instance().setSpeakerEnabled(enable: true)
CoreManager.speaker_already_enabled = true
CoreManagerDelegate.speaker_already_enabled = true
}
break
case .OutgoingRinging:
@ -440,7 +458,7 @@ class CoreManager: CoreDelegate {
case .End,
.Error:
UIDevice.current.isProximityMonitoringEnabled = false
CoreManager.speaker_already_enabled = false
CoreManagerDelegate.speaker_already_enabled = false
if (CallManager.instance().lc!.callsNb == 0) {
CallManager.instance().setSpeakerEnabled(enable: false)
// disable this because I don't find anygood reason for it: _bluetoothAvailable = FALSE;
@ -487,9 +505,9 @@ class CoreManager: CoreDelegate {
}
if (cstate == .IncomingReceived || cstate == .OutgoingInit || cstate == .Connected || cstate == .StreamsRunning) {
if (video && !CoreManager.speaker_already_enabled && !CallManager.instance().bluetoothEnabled) {
if (video && !CoreManagerDelegate.speaker_already_enabled && !CallManager.instance().bluetoothEnabled) {
CallManager.instance().setSpeakerEnabled(enable: true)
CoreManager.speaker_already_enabled = true
CoreManagerDelegate.speaker_already_enabled = true
}
}

View file

@ -120,7 +120,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (IBAction)onDeclineClick:(id)sender {
LinphoneCall *call = linphone_core_get_current_call(LC);
if (call) {
[LinphoneManager.instance terminateCall:call];
[CallManager.instance terminateCallWithCall:call];
}
}

55
Classes/CoreManager.swift Normal file
View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
*
* This file is part of linphone-iphone
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Foundation
import linphonesw
@objc class CoreManager: NSObject {
static var theCoreManager: CoreManager?
var lc: Core?
private var mIterateTimer: Timer?
@objc static func instance() -> CoreManager {
if (theCoreManager == nil) {
theCoreManager = CoreManager()
}
return theCoreManager!
}
@objc func setCore(core: OpaquePointer) {
lc = Core.getSwiftObject(cObject: core)
}
@objc private func iterate() {
lc?.iterate()
}
@objc func startIterateTimer() {
mIterateTimer = Timer.scheduledTimer(timeInterval: 0.02, target: self, selector: #selector(self.iterate), userInfo: nil, repeats: true)
Log.directLog(BCTBX_LOG_DEBUG, text: "start iterate timer")
}
@objc func stopIterateTimer() {
if let timer = mIterateTimer {
timer.invalidate()
Log.directLog(BCTBX_LOG_DEBUG, text: "stop iterate timer")
}
}
}

View file

@ -149,7 +149,6 @@ typedef struct _LinphoneManagerSounds {
- (void)send:(NSString *)replyText toChatRoom:(LinphoneChatRoom *)room;
- (void)call:(const LinphoneAddress *)address;
- (void)terminateCall:(LinphoneCall *)call;
+(id)getMessageAppDataForKey:(NSString*)key inMessage:(LinphoneChatMessage*)msg;
+(void)setValueInMessageAppData:(id)value forKey:(NSString*)key inMessage:(LinphoneChatMessage*)msg;

View file

@ -1408,12 +1408,11 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat
- (void)startLinphoneCore {
linphone_core_start([LinphoneManager getLc]);
mIterateTimer =
[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(iterate) userInfo:nil repeats:YES];
[CoreManager.instance startIterateTimer];
}
- (void)stopLinphoneCore {
[mIterateTimer invalidate];
[CoreManager.instance stopIterateTimer];
linphone_core_stop([LinphoneManager getLc]);
}
@ -1464,6 +1463,7 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat
linphone_core_add_callbacks(theLinphoneCore, cbs);
[CallManager.instance setCoreWithCore:theLinphoneCore];
[CoreManager.instance setCoreWithCore:theLinphoneCore];
[ConfigManager.instance setDbWithDb:_configDb];
linphone_core_start(theLinphoneCore);
@ -1507,12 +1507,11 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat
* grab, if any */
[self iterate];
// start scheduler
mIterateTimer =
[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(iterate) userInfo:nil repeats:YES];
[CoreManager.instance startIterateTimer];
}
- (void)destroyLinphoneCore {
[mIterateTimer invalidate];
[CoreManager.instance stopIterateTimer];
// just in case
[self removeCTCallCenterCb];
@ -2003,13 +2002,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
[CallManager.instance startCallWithAddr:iaddr isSas:FALSE];
}
- (void)terminateCall:(LinphoneCall *)call {// TODO PAUL : needs to be tested with CallKit changes
linphone_call_terminate(call);
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
[LinphoneManager.instance stopLinphoneCore];
}
}
#pragma mark - Property Functions
- (void)setPushKitToken:(NSData *)pushKitToken {

View file

@ -20,6 +20,8 @@
#import "UIHangUpButton.h"
#import "LinphoneManager.h"
#import "linphoneapp-Swift.h"
@implementation UIHangUpButton
#pragma mark - Static Functions
@ -97,11 +99,11 @@
LinphoneManager.instance.conf = TRUE;
linphone_core_terminate_conference(LC);
} else if (currentcall != NULL) {
[LinphoneManager.instance terminateCall:currentcall];
[CallManager.instance terminateCallWithCall:currentcall];
} else {
const MSList *calls = linphone_core_get_calls(LC);
if (bctbx_list_size(calls) == 1) { // Only one call
[LinphoneManager.instance terminateCall:(LinphoneCall *)(calls->data)];
[CallManager.instance terminateCallWithCall:(calls->data)];
}
}
}

View file

@ -821,7 +821,7 @@ static RootViewManager *rootViewManagerInstance = nil;
}
- (void)incomingCallDeclined:(LinphoneCall *)call {
[LinphoneManager.instance terminateCall:call];
[CallManager.instance terminateCallWithCall:call];
}
#pragma mark - Chat room Functions