@@ -63,23 +63,30 @@ public class SwiftConnectycubeFlutterCallKitPlugin: NSObject, FlutterPlugin {
6363 result ? ( error == nil )
6464 }
6565 }
66-
67- //TODO: remove these defaults and get as arguments
66+
6867 public func handle( _ call: FlutterMethodCall , result: @escaping FlutterResult ) {
6968 print ( " [SwiftConnectycubeFlutterCallKitPlugin][handle] method: \( call. method) " ) ;
70- let arguments = call. arguments as! Dictionary < String , Any >
71- if ( call. method == " getVoipToken " ) {
69+ let arguments = call. arguments as? Dictionary < String , Any >
70+ if call. method == " getVoipToken " {
7271 let voipToken = SwiftConnectycubeFlutterCallKitPlugin . voipController. getVoIPToken ( )
7372 result ( voipToken)
7473 }
75- else if ( call. method == " updateConfig " ) {
74+ else if call. method == " updateConfig " {
75+ guard let arguments = arguments else {
76+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
77+ return
78+ }
7679 let ringtone = arguments [ " ringtone " ] as? String
7780 let icon = arguments [ " icon " ] as? String
7881 CallKitController . updateConfig ( ringtone: ringtone, icon: icon)
7982
8083 result ( true )
8184 }
82- else if ( call. method == " showCallNotification " ) {
85+ else if call. method == " showCallNotification " {
86+ guard let arguments = arguments else {
87+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
88+ return
89+ }
8390 let callId = arguments [ " session_id " ] as! String
8491 let callType = arguments [ " call_type " ] as! Int
8592 let callInitiatorId = arguments [ " caller_id " ] as! Int
@@ -88,64 +95,95 @@ public class SwiftConnectycubeFlutterCallKitPlugin: NSObject, FlutterPlugin {
8895 let callOpponents = callOpponentsString. components ( separatedBy: " , " )
8996 . map { Int ( $0) ?? 0 }
9097 let userInfo = arguments [ " user_info " ] as? String
91-
98+
9299 SwiftConnectycubeFlutterCallKitPlugin . callController. reportIncomingCall ( uuid: callId. lowercased ( ) , callType: callType, callInitiatorId: callInitiatorId, callInitiatorName: callInitiatorName, opponents: callOpponents, userInfo: userInfo) { ( error) in
93100 print ( " [SwiftConnectycubeFlutterCallKitPlugin][handle] reportIncomingCall ERROR: \( error? . localizedDescription ?? " none " ) " )
94101 result ( error == nil )
95102 }
96103 }
97- else if ( call. method == " reportCallAccepted " ) {
98- let callId = arguments [ " session_id " ] as! String
99-
104+ else if call. method == " reportCallAccepted " {
105+ guard let arguments = arguments, let callId = arguments [ " session_id " ] as? String else {
106+ result ( FlutterError ( code: " invalid_argument " , message: " session_id was not provided. " , details: nil ) )
107+ return
108+ }
109+
100110 SwiftConnectycubeFlutterCallKitPlugin . callController. answerCall ( uuid: callId)
101111 result ( true )
102112 }
103- else if ( call. method == " reportCallFinished " ) {
113+ else if call. method == " reportCallFinished " {
114+ guard let arguments = arguments else {
115+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
116+ return
117+ }
104118 let callId = arguments [ " session_id " ] as! String
105119 let reason = arguments [ " reason " ] as! String
106120
107121
108122 SwiftConnectycubeFlutterCallKitPlugin . callController. reportCallEnded ( uuid: UUID ( uuidString: callId) !, reason: CallEndedReason . init ( rawValue: reason) !) ;
109123 result ( true ) ;
110124 }
111- else if ( call. method == " reportCallEnded " ) {
125+ else if call. method == " reportCallEnded " {
126+ guard let arguments = arguments else {
127+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
128+ return
129+ }
112130 let callId = arguments [ " session_id " ] as! String
113131 SwiftConnectycubeFlutterCallKitPlugin . callController. end ( uuid: UUID ( uuidString: callId) !)
114132 result ( true )
115133 }
116- else if ( call. method == " muteCall " ) {
134+ else if call. method == " muteCall " {
135+ guard let arguments = arguments else {
136+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
137+ return
138+ }
117139 let callId = arguments [ " session_id " ] as! String
118140 let muted = arguments [ " muted " ] as! Bool
119141
120142 SwiftConnectycubeFlutterCallKitPlugin . callController. setMute ( uuid: UUID ( uuidString: callId) !, muted: muted)
121143 result ( true )
122144 }
123- else if ( call. method == " getCallState " ) {
124- let callId = arguments [ " session_id " ] as! String
145+ else if call. method == " getCallState " {
146+ guard let arguments = arguments, let callId = arguments [ " session_id " ] as? String else {
147+ result ( FlutterError ( code: " invalid_argument " , message: " session_id was not provided. " , details: nil ) )
148+ return
149+ }
125150
126151 result ( SwiftConnectycubeFlutterCallKitPlugin . callController. getCallState ( uuid: callId) . rawValue)
127152 }
128- else if ( call. method == " setCallState " ) {
153+ else if call. method == " setCallState " {
154+ guard let arguments = arguments else {
155+ result ( FlutterError ( code: " invalid_argument " , message: " No data was provided. " , details: nil ) )
156+ return
157+ }
129158 let callId = arguments [ " session_id " ] as! String
130159 let callState = arguments [ " call_state " ] as! String
131160
132161 SwiftConnectycubeFlutterCallKitPlugin . callController. setCallState ( uuid: callId, callState: callState)
133162 result ( true )
134163 }
135164
136- else if ( call. method == " getCallData " ) {
137- let callId = arguments [ " session_id " ] as! String
165+ else if call. method == " getCallData " {
166+ guard let arguments = arguments, let callId = arguments [ " session_id " ] as? String else {
167+ result ( FlutterError ( code: " invalid_argument " , message: " session_id was not provided. " , details: nil ) )
168+ return
169+ }
138170
139171 result ( SwiftConnectycubeFlutterCallKitPlugin . callController. getCallData ( uuid: callId) )
140172 }
141- else if ( call. method == " clearCallData " ) {
142- let callId = arguments [ " session_id " ] as! String
173+ else if call. method == " clearCallData " {
174+ guard let arguments = arguments, let callId = arguments [ " session_id " ] as? String else {
175+ result ( FlutterError ( code: " invalid_argument " , message: " session_id was not provided. " , details: nil ) )
176+ return
177+ }
143178
144179 SwiftConnectycubeFlutterCallKitPlugin . callController. clearCallData ( uuid: callId)
145180 result ( true )
146181 }
147- else if ( call. method == " getLastCallId " ) {
182+ else if call. method == " getLastCallId " {
148183 result ( SwiftConnectycubeFlutterCallKitPlugin . callController. currentCallData [ " session_id " ] )
149184 }
185+ else {
186+ result ( FlutterMethodNotImplemented)
187+ }
150188 }
151189}
0 commit comments