chenqiyang
2021-08-27 6a63c4281fbe7e17103115320cd276397d733081
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
//  CoreManager.swift
//  VoipTest
//
//  Created by StevStark on 2020/11/11.
//
 
import Foundation
//import linphonesw
 
@objc class HDLCoreManager: NSObject {
    static var theCoreManager: HDLCoreManager?
    var lc: Core?
    private var mIterateTimer: Timer?
 
    @objc static func instance() -> HDLCoreManager {
        if (theCoreManager == nil) {
            theCoreManager = HDLCoreManager()
        }
        return theCoreManager!
    }
 
    @objc func setCore(core: OpaquePointer) {
        lc = Core.getSwiftObject(cObject: core)
    }
 
    @objc private func iterate() {
 
//        var coreIterateTaskId:UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier(rawValue: 0)
//        coreIterateTaskId=UIApplication.shared.beginBackgroundTask(expirationHandler: {
//            UIApplication.shared.endBackgroundTask(coreIterateTaskId)
//        })
        
        lc?.iterate()
        
//        if coreIterateTaskId != UIBackgroundTaskIdentifier.invalid {
//            UIApplication.shared.endBackgroundTask(coreIterateTaskId)
//        }
    }
 
    @objc func startIterateTimer() {
        if (mIterateTimer?.isValid ?? false) {
          
            return
        }
        mIterateTimer = Timer.scheduledTimer(timeInterval: 0.02, target: self, selector: #selector(self.iterate), userInfo: nil, repeats: true)
     
 
    }
 
    @objc func stopIterateTimer() {
        if let timer = mIterateTimer {
            timer.invalidate()
        }
    }
    
    @objc func stopLinphoneCore() {
        if (lc?.callsNb == 0) {
            stopIterateTimer()
            lc?.stop()
        }
    }
//    
//    @objc func removeConfig(config:ProxyConfig) {
//        if (lc != nil) {
//            lc?.removeProxyConfig(config: config)
//        }
//    }
}