@@ -42,6 +42,7 @@ private let kMethodCallStopRecordFile = "Call_StopRecordFile"
4242private let kMethodCallTransferBlind = " Call_TransferBlind "
4343private let kMethodCallTransferAttended = " Call_TransferAttended "
4444private let kMethodCallUpgradeToVideo = " Call_UpgradeToVideo "
45+ private let kMethodCallAcceptVideoUpgrade = " Call_AcceptVideoUpgrade "
4546private let kMethodCallStopRingtone = " Call_StopRingtone "
4647private let kMethodCallBye = " Call_Bye "
4748
@@ -56,6 +57,7 @@ private let kMethodSubscriptionDelete = "Subscription_Delete"
5657private let kMethodDvcGetPushKitToken = " Dvc_GetPushKitToken "
5758private let kMethodDvcUpdCallKitDetails = " Dvc_UpdCallKitDetails "
5859private let kMethodDvcGetCallKitUUID = " Dvc_GetCallKitUUID "
60+ private let kMethodDvcEndCallKitCall = " Dvc_EndCallKitCall "
5961
6062private let kMethodDvcGetPlayoutNumber = " Dvc_GetPlayoutDevices "
6163private let kMethodDvcGetRecordNumber = " Dvc_GetRecordingDevices "
@@ -88,7 +90,8 @@ private let kOnCallIncoming = "OnCallIncoming"
8890private let kOnCallDtmfReceived = " OnCallDtmfReceived "
8991private let kOnCallTransferred = " OnCallTransferred "
9092private let kOnCallRedirected = " OnCallRedirected "
91- private let kOnCallVideoUpgraded = " OnCallVideoUpgraded " ;
93+ private let kOnCallVideoUpgraded = " OnCallVideoUpgraded "
94+ private let kOnCallVideoUpgradeRequested = " OnCallVideoUpgradeRequested "
9295private let kOnCallSwitched = " OnCallSwitched "
9396private let kOnCallHeld = " OnCallHeld "
9497
@@ -331,6 +334,14 @@ class SiprixEventHandler : NSObject, SiprixEventDelegate {
331334 }
332335 }
333336
337+ public func onCallVideoUpgradeRequested( _ callId: Int ) {
338+ DispatchQueue . main. async {
339+ var argsMap = [ String: Any] ( )
340+ argsMap [ kArgCallId] = callId
341+ self . _channel. invokeMethod ( kOnCallVideoUpgradeRequested, arguments: argsMap)
342+ }
343+ }
344+
334345 public func onCallHeld( _ callId: Int , holdState: HoldState ) {
335346 DispatchQueue . main. async {
336347 var argsMap = [ String: Any] ( )
@@ -639,6 +650,7 @@ public class SiprixVoipSdkPlugin: NSObject, FlutterPlugin {
639650 case kMethodCallTransferBlind : handleCallTransferBlind ( argsMap!, result: result)
640651 case kMethodCallTransferAttended : handleCallTransferAttended ( argsMap!, result: result)
641652 case kMethodCallUpgradeToVideo: handleCallUpgradeToVideo ( argsMap!, result: result)
653+ case kMethodCallAcceptVideoUpgrade: handleCallAcceptVideoUpgrade ( argsMap!, result: result)
642654 case kMethodCallStopRingtone : handleCallStopRingtone ( argsMap!, result: result)
643655 case kMethodCallBye : handleCallBye ( argsMap!, result: result)
644656
@@ -653,6 +665,7 @@ public class SiprixVoipSdkPlugin: NSObject, FlutterPlugin {
653665 case kMethodDvcGetPushKitToken : handleDvcGetPushkitToken ( argsMap!, result: result)
654666 case kMethodDvcUpdCallKitDetails : handleDvcUpdCallKitDetails ( argsMap!, result: result)
655667 case kMethodDvcGetCallKitUUID : handleDvcGetCallKitUUID ( argsMap!, result: result)
668+ case kMethodDvcEndCallKitCall : handleDvcEndCallKitCall ( argsMap!, result: result)
656669
657670 case kMethodDvcGetPlayoutNumber: handleDvcGetPlayoutNumber ( argsMap!, result: result)
658671 case kMethodDvcGetRecordNumber : handleDvcGetRecordNumber ( argsMap!, result: result)
@@ -1218,6 +1231,18 @@ public class SiprixVoipSdkPlugin: NSObject, FlutterPlugin {
12181231 }
12191232 }
12201233
1234+ func handleCallAcceptVideoUpgrade( _ args : ArgsMap , result: @escaping FlutterResult ) {
1235+ let callId = args [ kArgCallId] as? Int
1236+ let withVideo = args [ kArgWithVideo] as? Bool
1237+
1238+ if ( ( callId != nil ) &&( withVideo != nil ) ) {
1239+ let err = _siprixModule. callAcceptVideoUpgrade ( Int32 ( callId!) , withVideo: withVideo!)
1240+ sendResult ( err, result: result)
1241+ } else {
1242+ sendBadArguments ( result: result)
1243+ }
1244+ }
1245+
12211246 func handleCallBye( _ args : ArgsMap , result: @escaping FlutterResult ) {
12221247 let callId = args [ kArgCallId] as? Int
12231248
@@ -1353,6 +1378,7 @@ public class SiprixVoipSdkPlugin: NSObject, FlutterPlugin {
13531378 _callKitProvider? . sipAppUpdateCallDetails ( uuid!, callId: callId,
13541379 localizedName: localizedName, genericHandle: genericHandle, withVideo: withVideo)
13551380 }
1381+ sendResult ( kErrorCodeEOK, result: result)
13561382 }
13571383
13581384 func handleDvcGetCallKitUUID( _ args : ArgsMap , result: @escaping FlutterResult ) {
@@ -1364,7 +1390,19 @@ public class SiprixVoipSdkPlugin: NSObject, FlutterPlugin {
13641390 sendBadArguments ( result: result)
13651391 }
13661392 }
1367-
1393+
1394+ func handleDvcEndCallKitCall( _ args : ArgsMap , result: @escaping FlutterResult ) {
1395+ let uuidStr = args [ kArgCallKitUuid] as? String
1396+ let callUuid = ( uuidStr != nil ) ? UUID ( uuidString: uuidStr!) : nil
1397+
1398+ if ( callUuid != nil ) {
1399+ let err = ( _callKitProvider != nil ) ? _callKitProvider!. cxActionEndCall ( callUuid!) : kErrorCodeEOK
1400+ sendResult ( err, result: result)
1401+ } else {
1402+ sendBadArguments ( result: result)
1403+ }
1404+ }
1405+
13681406
13691407 ////////////////////////////////////////////////////////////////////////////////////////
13701408 //Siprix Devices methods implementation
@@ -1810,42 +1848,40 @@ class SiprixCxProvider : NSObject, CXProviderDelegate {
18101848
18111849 public func sipAppUpdateCallDetails( _ callKit_callUUID: UUID , callId: Int ? ,
18121850 localizedName: String ? , genericHandle: String ? , withVideo: Bool ? ) {
1813- DispatchQueue . main. async {
1814- let call = self . getCallByUUID ( callKit_callUUID)
1815- if ( call == nil ) {
1816- self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) call not found " )
1817- return
1818- }
1851+ let call = self . getCallByUUID ( callKit_callUUID)
1852+ if ( call == nil ) {
1853+ self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) call not found " )
1854+ return
1855+ }
18191856
1820- if ( callId != nil ) {
1821- //INVITE received - update SIP callId
1822- self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) ) set sipCallId: \( callId!) " )
1823- call!. setSipCallId ( callId: callId!, withVideo: withVideo)
1824-
1825- if ( call!. rejectedByCallKit) {
1826- self . proceedCxEndAction ( call!)
1827- }
1828- else if ( call!. answeredByCallKit) {
1829- self . proceedCxAnswerAction ( call!)
1830- }
1857+ if ( callId != nil ) {
1858+ //INVITE received - match SIP callId and UUID
1859+ self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) set sipCallId: \( callId!) " )
1860+ call!. setSipCallId ( callId: callId!, withVideo: withVideo)
1861+
1862+ if ( call!. rejectedByCallKit) {
1863+ self . proceedCxEndAction ( call!)
18311864 }
1832-
1833- if ( ( genericHandle != nil ) ||( localizedName != nil ) ||( withVideo != nil ) ) {
1834- self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) genericHandle: \( String ( describing: genericHandle) ) localizedName: \( String ( describing: localizedName) ) withVideo: \( String ( describing: withVideo) ) " )
1835-
1836- let update = CXCallUpdate ( )
1837- if ( genericHandle != nil ) { update. remoteHandle = CXHandle ( type: . generic, value: genericHandle!) }
1838- if ( localizedName != nil ) { update. localizedCallerName = localizedName! }
1839- if ( withVideo != nil ) { update. hasVideo = withVideo! }
1840-
1841- update. supportsUngrouping = true
1842- update. supportsGrouping = true
1843- update. supportsHolding = true
1844- update. supportsDTMF = true
1845-
1846- self . _cxProvider. reportCall ( with: call!. uuid, updated: update)
1865+ else if ( call!. answeredByCallKit) {
1866+ self . proceedCxAnswerAction ( call!)
18471867 }
18481868 }
1869+
1870+ if ( ( genericHandle != nil ) ||( localizedName != nil ) ||( withVideo != nil ) ) {
1871+ self . _siprixModule. writeLog ( " CxProvider: sipAppUpdateCallDetails uuid: \( callKit_callUUID) genericHandle: \( String ( describing: genericHandle) ) localizedName: \( String ( describing: localizedName) ) withVideo: \( String ( describing: withVideo) ) " )
1872+
1873+ let update = CXCallUpdate ( )
1874+ if ( genericHandle != nil ) { update. remoteHandle = CXHandle ( type: . generic, value: genericHandle!) }
1875+ if ( localizedName != nil ) { update. localizedCallerName = localizedName! }
1876+ if ( withVideo != nil ) { update. hasVideo = withVideo! }
1877+
1878+ update. supportsUngrouping = true
1879+ update. supportsGrouping = true
1880+ update. supportsHolding = true
1881+ update. supportsDTMF = true
1882+
1883+ self . _cxProvider. reportCall ( with: call!. uuid, updated: update)
1884+ }
18491885 }
18501886
18511887 public func onSipRedirected( origCallId: Int , relatedCallId: Int , referTo: String ) {
@@ -1930,18 +1966,33 @@ class SiprixCxProvider : NSObject, CXProviderDelegate {
19301966 return SiprixCxProvider . kECallNotFound
19311967 }
19321968
1933- func cxActionEndCall( _ callId: Int ) -> Int32 {
1969+ public func cxActionEndCall( _ callId: Int ) -> Int32 {
19341970 let call = _callsList. first ( where: { $0. id == callId} )
1935- if ( call != nil ) {
1936- let action = CXEndCallAction ( call: call!. uuid)
1937- let transaction = CXTransaction ( action: action)
1938-
1939- _cxCallCtrl. request ( transaction) { error in self . printResult ( " CXEndCall " , err: error) }
1940- return kErrorCodeEOK;
1941- }
1942- return SiprixCxProvider . kECallNotFound;
1971+ if ( call == nil ) { return SiprixCxProvider . kECallNotFound }
1972+
1973+ doEndCall ( call!. uuid)
1974+ return kErrorCodeEOK;
19431975 }
19441976
1977+ public func cxActionEndCall( _ callKit_callUUID: UUID ) -> Int32 {
1978+ let callIdx = _callsList. firstIndex ( where: { $0. uuid == callKit_callUUID} )
1979+ if ( callIdx == nil ) { return SiprixCxProvider . kECallNotFound }
1980+
1981+ doEndCall ( callKit_callUUID)
1982+ _callsList. remove ( at: callIdx!)
1983+ return kErrorCodeEOK
1984+ }
1985+
1986+ func doEndCall( _ callUUID: UUID ) {
1987+ _siprixModule. writeLog ( " CxProvider: endCall uuid: \( callUUID) ) " )
1988+
1989+ let action = CXEndCallAction ( call: callUUID)
1990+ let transaction = CXTransaction ( action: action)
1991+
1992+ _cxCallCtrl. request ( transaction) { error in self . printResult ( " CXEndCall " , err: error) }
1993+ }
1994+
1995+
19451996 func cxActionGroupCall( ) -> Int32 {
19461997 let callsWithSipId = _callsList. filter { $0. id != 0 }
19471998 if ( callsWithSipId. count >= 2 ) {
0 commit comments