@@ -63,23 +63,30 @@ public class SwiftConnectycubeFlutterCallKitPlugin: NSObject, FlutterPlugin {
63
63
result ? ( error == nil )
64
64
}
65
65
}
66
-
67
- //TODO: remove these defaults and get as arguments
66
+
68
67
public func handle( _ call: FlutterMethodCall , result: @escaping FlutterResult ) {
69
68
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 " {
72
71
let voipToken = SwiftConnectycubeFlutterCallKitPlugin . voipController. getVoIPToken ( )
73
72
result ( voipToken)
74
73
}
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
+ }
76
79
let ringtone = arguments [ " ringtone " ] as? String
77
80
let icon = arguments [ " icon " ] as? String
78
81
CallKitController . updateConfig ( ringtone: ringtone, icon: icon)
79
82
80
83
result ( true )
81
84
}
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
+ }
83
90
let callId = arguments [ " session_id " ] as! String
84
91
let callType = arguments [ " call_type " ] as! Int
85
92
let callInitiatorId = arguments [ " caller_id " ] as! Int
@@ -88,64 +95,95 @@ public class SwiftConnectycubeFlutterCallKitPlugin: NSObject, FlutterPlugin {
88
95
let callOpponents = callOpponentsString. components ( separatedBy: " , " )
89
96
. map { Int ( $0) ?? 0 }
90
97
let userInfo = arguments [ " user_info " ] as? String
91
-
98
+
92
99
SwiftConnectycubeFlutterCallKitPlugin . callController. reportIncomingCall ( uuid: callId. lowercased ( ) , callType: callType, callInitiatorId: callInitiatorId, callInitiatorName: callInitiatorName, opponents: callOpponents, userInfo: userInfo) { ( error) in
93
100
print ( " [SwiftConnectycubeFlutterCallKitPlugin][handle] reportIncomingCall ERROR: \( error? . localizedDescription ?? " none " ) " )
94
101
result ( error == nil )
95
102
}
96
103
}
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
+
100
110
SwiftConnectycubeFlutterCallKitPlugin . callController. answerCall ( uuid: callId)
101
111
result ( true )
102
112
}
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
+ }
104
118
let callId = arguments [ " session_id " ] as! String
105
119
let reason = arguments [ " reason " ] as! String
106
120
107
121
108
122
SwiftConnectycubeFlutterCallKitPlugin . callController. reportCallEnded ( uuid: UUID ( uuidString: callId) !, reason: CallEndedReason . init ( rawValue: reason) !) ;
109
123
result ( true ) ;
110
124
}
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
+ }
112
130
let callId = arguments [ " session_id " ] as! String
113
131
SwiftConnectycubeFlutterCallKitPlugin . callController. end ( uuid: UUID ( uuidString: callId) !)
114
132
result ( true )
115
133
}
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
+ }
117
139
let callId = arguments [ " session_id " ] as! String
118
140
let muted = arguments [ " muted " ] as! Bool
119
141
120
142
SwiftConnectycubeFlutterCallKitPlugin . callController. setMute ( uuid: UUID ( uuidString: callId) !, muted: muted)
121
143
result ( true )
122
144
}
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
+ }
125
150
126
151
result ( SwiftConnectycubeFlutterCallKitPlugin . callController. getCallState ( uuid: callId) . rawValue)
127
152
}
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
+ }
129
158
let callId = arguments [ " session_id " ] as! String
130
159
let callState = arguments [ " call_state " ] as! String
131
160
132
161
SwiftConnectycubeFlutterCallKitPlugin . callController. setCallState ( uuid: callId, callState: callState)
133
162
result ( true )
134
163
}
135
164
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
+ }
138
170
139
171
result ( SwiftConnectycubeFlutterCallKitPlugin . callController. getCallData ( uuid: callId) )
140
172
}
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
+ }
143
178
144
179
SwiftConnectycubeFlutterCallKitPlugin . callController. clearCallData ( uuid: callId)
145
180
result ( true )
146
181
}
147
- else if ( call. method == " getLastCallId " ) {
182
+ else if call. method == " getLastCallId " {
148
183
result ( SwiftConnectycubeFlutterCallKitPlugin . callController. currentCallData [ " session_id " ] )
149
184
}
185
+ else {
186
+ result ( FlutterMethodNotImplemented)
187
+ }
150
188
}
151
189
}
0 commit comments