omikit-plugin 2.3.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -41
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/omikitplugin/OmikitPluginModule.kt +133 -93
- package/android/src/main/java/com/omikitplugin/constants/constant.kt +2 -3
- package/android/src/main/java/com/omikitplugin/state/CallState.kt +12 -0
- package/ios/CallProcess/CallManager.swift +191 -216
- package/ios/CallProcess/CallState.swift +17 -0
- package/ios/Constant/Constant.swift +2 -6
- package/ios/Library/OmikitPlugin.m +18 -0
- package/ios/Library/OmikitPlugin.swift +42 -20
- package/lib/commonjs/index.js +22 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/omi_call_state.js +18 -0
- package/lib/commonjs/omi_call_state.js.map +1 -0
- package/lib/commonjs/omi_start_call_status.js +21 -0
- package/lib/commonjs/omi_start_call_status.js.map +1 -0
- package/lib/commonjs/omikit.js +15 -10
- package/lib/commonjs/omikit.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/omi_call_state.js +11 -0
- package/lib/module/omi_call_state.js.map +1 -0
- package/lib/module/omi_start_call_status.js +14 -0
- package/lib/module/omi_start_call_status.js.map +1 -0
- package/lib/module/omikit.js +12 -10
- package/lib/module/omikit.js.map +1 -1
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/omi_call_state.d.ts +10 -0
- package/lib/typescript/omi_call_state.d.ts.map +1 -0
- package/lib/typescript/omi_start_call_status.d.ts +13 -0
- package/lib/typescript/omi_start_call_status.d.ts.map +1 -0
- package/lib/typescript/omikit.d.ts +7 -6
- package/lib/typescript/omikit.d.ts.map +1 -1
- package/omikit-plugin.podspec +1 -1
- package/package.json +1 -1
- package/src/index.tsx +2 -0
- package/src/omi_call_state.tsx +9 -0
- package/src/omi_start_call_status.tsx +12 -0
- package/src/omikit.tsx +16 -11
|
@@ -20,6 +20,7 @@ class CallManager {
|
|
|
20
20
|
var isSpeaker = false
|
|
21
21
|
private var guestPhone : String = ""
|
|
22
22
|
private var lastStatusCall : String?
|
|
23
|
+
private var tempCallInfo : [String: Any]?
|
|
23
24
|
|
|
24
25
|
/// Get instance
|
|
25
26
|
static func shareInstance() -> CallManager {
|
|
@@ -43,31 +44,41 @@ class CallManager {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
func configNotification(data: [String: Any]) {
|
|
48
|
+
let user = UserDefaults.standard
|
|
49
|
+
if let title = data["missedCallTitle"] as? String, let message = data["prefixMissedCallMessage"] as? String {
|
|
50
|
+
user.set(title, forKey: "omicall/missedCallTitle")
|
|
51
|
+
user.set(message, forKey: "omicall/prefixMissedCallMessage")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
private func requestPermission(isVideo: Bool) {
|
|
47
56
|
AVCaptureDevice.requestAccess(for: .audio) { _ in
|
|
48
|
-
print("request audio")
|
|
57
|
+
// print("request audio")
|
|
49
58
|
}
|
|
50
59
|
if isVideo {
|
|
51
60
|
AVCaptureDevice.requestAccess(for: .video) { _ in
|
|
52
|
-
print("request video")
|
|
61
|
+
// print("request video")
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
func initWithApiKeyEndpoint(params: [String: Any]) -> Bool {
|
|
58
67
|
//request permission
|
|
59
|
-
var result =
|
|
68
|
+
var result = false
|
|
60
69
|
if let usrUuid = params["usrUuid"] as? String, let fullName = params["fullName"] as? String, let apiKey = params["apiKey"] as? String {
|
|
61
70
|
result = OmiClient.initWithUUID(usrUuid, fullName: fullName, apiKey: apiKey)
|
|
62
71
|
}
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
if (result) {
|
|
73
|
+
let isVideo = (params["isVideo"] as? Bool) ?? true
|
|
74
|
+
requestPermission(isVideo: isVideo)
|
|
75
|
+
}
|
|
65
76
|
return result
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
|
|
69
80
|
func initWithUserPasswordEndpoint(params: [String: Any]) -> Bool {
|
|
70
|
-
if let userName = params["userName"] as? String, let password = params["password"] as? String, let realm = params["realm"] as? String
|
|
81
|
+
if let userName = params["userName"] as? String, let password = params["password"] as? String, let realm = params["realm"] as? String {
|
|
71
82
|
OmiClient.initWithUsername(userName, password: password, realm: realm)
|
|
72
83
|
}
|
|
73
84
|
let isVideo = (params["isVideo"] as? Bool) ?? true
|
|
@@ -75,51 +86,6 @@ class CallManager {
|
|
|
75
86
|
return true
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
func registerNotificationCenter() {
|
|
79
|
-
DispatchQueue.main.async { [weak self] in
|
|
80
|
-
guard let self = self else { return }
|
|
81
|
-
NotificationCenter.default.removeObserver(CallManager.instance!)
|
|
82
|
-
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
83
|
-
selector: #selector(self.callStateChanged(_:)),
|
|
84
|
-
name: NSNotification.Name.OMICallStateChanged,
|
|
85
|
-
object: nil
|
|
86
|
-
)
|
|
87
|
-
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
88
|
-
selector: #selector(self.callDealloc(_:)),
|
|
89
|
-
name: NSNotification.Name.OMICallDealloc,
|
|
90
|
-
object: nil
|
|
91
|
-
)
|
|
92
|
-
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
93
|
-
selector: #selector(self.switchBoardAnswer(_:)),
|
|
94
|
-
name: NSNotification.Name.OMICallSwitchBoardAnswer,
|
|
95
|
-
object: nil
|
|
96
|
-
)
|
|
97
|
-
NotificationCenter.default.addObserver(CallManager.instance!, selector: #selector(self.updateNetworkHealth(_:)), name: NSNotification.Name.OMICallNetworkQuality, object: nil)
|
|
98
|
-
self.showMissedCall()
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@objc func updateNetworkHealth(_ notification: NSNotification) {
|
|
103
|
-
guard let userInfo = notification.userInfo,
|
|
104
|
-
let state = userInfo[OMINotificationNetworkStatusKey] as? Int else {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
OmikitPlugin.instance.sendEvent(withName: CALL_QUALITY, body: ["quality": state])
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
func configNotification(data: [String: Any]) {
|
|
111
|
-
let user = UserDefaults.standard
|
|
112
|
-
if let prefix = data["prefix"] as? String, let userNameKey = data["userNameKey"] as? String {
|
|
113
|
-
user.set(prefix, forKey: KEY_OMI_PREFIX)
|
|
114
|
-
user.set(userNameKey, forKey: KEY_OMI_USER_NAME_KEY)
|
|
115
|
-
}
|
|
116
|
-
if let title = data["missedCallTitle"] as? String, let message = data["prefixMissedCallMessage"] as? String {
|
|
117
|
-
let user = UserDefaults.standard
|
|
118
|
-
user.set(title, forKey: "omicall/missedCallTitle")
|
|
119
|
-
user.set(message, forKey: "omicall/prefixMissedCallMessage")
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
89
|
func showMissedCall() {
|
|
124
90
|
OmiClient.setMissedCall { call in
|
|
125
91
|
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
@@ -139,19 +105,44 @@ class CallManager {
|
|
|
139
105
|
"omisdkIsVideo": call.isVideo,
|
|
140
106
|
]
|
|
141
107
|
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
|
|
142
|
-
//getting the notification request
|
|
143
108
|
let id = Int.random(in: 0..<10000000)
|
|
144
109
|
let request = UNNotificationRequest(identifier: "\(id)", content: content, trigger: trigger)
|
|
145
|
-
//adding the notification to notification center
|
|
146
110
|
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
|
|
147
111
|
default:
|
|
148
|
-
break
|
|
112
|
+
break
|
|
149
113
|
}
|
|
150
114
|
}
|
|
151
115
|
}
|
|
152
116
|
}
|
|
153
117
|
|
|
154
118
|
|
|
119
|
+
func registerNotificationCenter(showMissedCall: Bool) {
|
|
120
|
+
DispatchQueue.main.async { [weak self] in
|
|
121
|
+
guard let self = self else { return }
|
|
122
|
+
NotificationCenter.default.removeObserver(CallManager.instance!)
|
|
123
|
+
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
124
|
+
selector: #selector(self.callStateChanged(_:)),
|
|
125
|
+
name: NSNotification.Name.OMICallStateChanged,
|
|
126
|
+
object: nil
|
|
127
|
+
)
|
|
128
|
+
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
129
|
+
selector: #selector(self.callDealloc(_:)),
|
|
130
|
+
name: NSNotification.Name.OMICallDealloc,
|
|
131
|
+
object: nil
|
|
132
|
+
)
|
|
133
|
+
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
134
|
+
selector: #selector(self.switchBoardAnswer(_:)),
|
|
135
|
+
name: NSNotification.Name.OMICallSwitchBoardAnswer,
|
|
136
|
+
object: nil
|
|
137
|
+
)
|
|
138
|
+
NotificationCenter.default.addObserver(CallManager.instance!, selector: #selector(self.updateNetworkHealth(_:)), name: NSNotification.Name.OMICallNetworkQuality, object: nil)
|
|
139
|
+
NotificationCenter.default.addObserver(CallManager.instance!, selector: #selector(self.audioChanged(_:)), name: NSNotification.Name.OMICallAudioRouteChange, object: nil)
|
|
140
|
+
if (showMissedCall) {
|
|
141
|
+
self.showMissedCall()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
155
146
|
func registerVideoEvent() {
|
|
156
147
|
DispatchQueue.main.async {
|
|
157
148
|
NotificationCenter.default.addObserver(CallManager.instance!,
|
|
@@ -168,13 +159,23 @@ class CallManager {
|
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
161
|
|
|
171
|
-
@objc func
|
|
162
|
+
@objc func audioChanged(_ notification: NSNotification) {
|
|
172
163
|
guard let userInfo = notification.userInfo,
|
|
173
|
-
let
|
|
164
|
+
let audioInfo = userInfo[OMINotificationCurrentAudioRouteKey] as? [[String: String]] else {
|
|
174
165
|
return;
|
|
175
166
|
}
|
|
176
|
-
|
|
177
|
-
|
|
167
|
+
OmikitPlugin.instance?.sendEvent(withName: AUDIO_CHANGE, body: [
|
|
168
|
+
"data": audioInfo,
|
|
169
|
+
])
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@objc func updateNetworkHealth(_ notification: NSNotification) {
|
|
174
|
+
guard let userInfo = notification.userInfo,
|
|
175
|
+
let state = userInfo[OMINotificationNetworkStatusKey] as? Int else {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_QUALITY, body: ["quality": state])
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
@objc func videoUpdate(_ notification: NSNotification) {
|
|
@@ -183,9 +184,6 @@ class CallManager {
|
|
|
183
184
|
return;
|
|
184
185
|
}
|
|
185
186
|
switch (state) {
|
|
186
|
-
case 0:
|
|
187
|
-
OmikitPlugin.instance.sendEvent(withName: LOCAL_VIDEO_READY, body: nil)
|
|
188
|
-
break
|
|
189
187
|
case 1:
|
|
190
188
|
OmikitPlugin.instance.sendEvent(withName: REMOTE_VIDEO_READY, body: nil)
|
|
191
189
|
break
|
|
@@ -194,123 +192,154 @@ class CallManager {
|
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
@objc func
|
|
195
|
+
@objc func switchBoardAnswer(_ notification: NSNotification) {
|
|
198
196
|
guard let userInfo = notification.userInfo,
|
|
199
|
-
let
|
|
197
|
+
let sip = userInfo[OMINotificationSIPKey] as? String else {
|
|
200
198
|
return;
|
|
201
199
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
self.guestPhone = ""
|
|
211
|
-
DispatchQueue.main.async {
|
|
212
|
-
OmikitPlugin.instance.sendEvent(withName: CALL_END, body: callInfo)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
200
|
+
guestPhone = sip
|
|
201
|
+
OmikitPlugin.instance.sendEvent(withName: SWITCHBOARD_ANSWER, body: ["sip": sip])
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@objc func callDealloc(_ notification: NSNotification) {
|
|
205
|
+
if (tempCallInfo != nil) {
|
|
206
|
+
tempCallInfo!["status"] = CallState.disconnected.rawValue
|
|
207
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: tempCallInfo!)
|
|
215
208
|
}
|
|
216
209
|
}
|
|
217
210
|
|
|
218
211
|
@objc fileprivate func callStateChanged(_ notification: NSNotification) {
|
|
219
212
|
guard let userInfo = notification.userInfo,
|
|
220
|
-
let call = userInfo[OMINotificationUserInfoCallKey] as? OMICall
|
|
213
|
+
let call = userInfo[OMINotificationUserInfoCallKey] as? OMICall,
|
|
214
|
+
let callState = userInfo[OMINotificationUserInfoCallStateKey] as? Int else {
|
|
221
215
|
return;
|
|
222
216
|
}
|
|
223
|
-
print("call state")
|
|
224
|
-
print(call.callState)
|
|
225
|
-
switch (
|
|
226
|
-
case .calling:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
217
|
+
// print("call state")
|
|
218
|
+
// print(call.callState)
|
|
219
|
+
switch (callState) {
|
|
220
|
+
case OMICallState.calling.rawValue:
|
|
221
|
+
// NSLog("Outgoing call, in CALLING state, with UUID \(call.uuid)")
|
|
222
|
+
var callInfo = baseInfoFromCall(call: call)
|
|
223
|
+
callInfo["status"] = CallState.calling.rawValue
|
|
224
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
230
225
|
break
|
|
231
|
-
case .early:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
226
|
+
case OMICallState.early.rawValue:
|
|
227
|
+
var callInfo = baseInfoFromCall(call: call)
|
|
228
|
+
callInfo["status"] = CallState.early.rawValue
|
|
229
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
235
230
|
break
|
|
236
|
-
case .connecting:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
231
|
+
case OMICallState.connecting.rawValue:
|
|
232
|
+
var callInfo = baseInfoFromCall(call: call)
|
|
233
|
+
callInfo["status"] = CallState.connecting.rawValue
|
|
234
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
235
|
+
break
|
|
236
|
+
case OMICallState.hold.rawValue:
|
|
237
|
+
var callInfo = baseInfoFromCall(call: call)
|
|
238
|
+
callInfo["status"] = CallState.hold.rawValue
|
|
239
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
240
240
|
break
|
|
241
|
-
case .confirmed:
|
|
242
|
-
NSLog("Outgoing call, in CONFIRMED state, with UUID: \(call
|
|
241
|
+
case OMICallState.confirmed.rawValue:
|
|
242
|
+
// NSLog("Outgoing call, in CONFIRMED state, with UUID: \(call)")
|
|
243
243
|
if (videoManager == nil && call.isVideo) {
|
|
244
244
|
videoManager = OMIVideoViewManager.init()
|
|
245
245
|
}
|
|
246
246
|
isSpeaker = call.isVideo
|
|
247
247
|
lastStatusCall = "answered"
|
|
248
|
-
|
|
248
|
+
var callInfo = baseInfoFromCall(call: call)
|
|
249
|
+
callInfo["status"] = CallState.confirmed.rawValue
|
|
250
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
249
251
|
OmikitPlugin.instance.sendMuteStatus()
|
|
250
|
-
OmikitPlugin.instance.sendSpeakerStatus()
|
|
251
252
|
break
|
|
252
|
-
case .
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
case OMICallState.incoming.rawValue:
|
|
254
|
+
guestPhone = call.callerNumber ?? ""
|
|
255
|
+
DispatchQueue.main.async {[weak self] in
|
|
256
|
+
guard let self = self else { return }
|
|
257
|
+
let state: UIApplication.State = UIApplication.shared.applicationState
|
|
258
|
+
if (state == .active) {
|
|
259
|
+
var callInfo = self.baseInfoFromCall(call: call)
|
|
260
|
+
callInfo["status"] = CallState.incoming.rawValue
|
|
261
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
262
|
+
}
|
|
257
263
|
}
|
|
258
|
-
|
|
264
|
+
break
|
|
265
|
+
case OMICallState.disconnected.rawValue:
|
|
266
|
+
// if (!call.connected) {
|
|
267
|
+
// NSLog("Call never connected, in DISCONNECTED state, with UUID: \(call.uuid)")
|
|
268
|
+
// } else if (!call.userDidHangUp) {
|
|
269
|
+
// NSLog("Call remotly ended, in DISCONNECTED state, with UUID: \(call.uuid)")
|
|
270
|
+
// }
|
|
271
|
+
tempCallInfo = getCallInfo(call: call)
|
|
259
272
|
if (videoManager != nil) {
|
|
260
273
|
videoManager = nil
|
|
261
274
|
}
|
|
262
275
|
lastStatusCall = nil
|
|
263
276
|
guestPhone = ""
|
|
264
|
-
|
|
265
|
-
OmikitPlugin.instance.sendEvent(withName:
|
|
266
|
-
|
|
267
|
-
case .incoming:
|
|
268
|
-
guestPhone = call.callerNumber ?? ""
|
|
269
|
-
OmikitPlugin.instance.sendEvent(withName: INCOMING_RECEIVED, body: ["isVideo": call.isVideo, "callerNumber": call.callerNumber ?? ""])
|
|
277
|
+
tempCallInfo!["status"] = CallState.disconnected.rawValue
|
|
278
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: tempCallInfo!)
|
|
279
|
+
tempCallInfo = nil
|
|
270
280
|
break
|
|
271
281
|
default:
|
|
272
|
-
NSLog("Default call state")
|
|
273
282
|
break
|
|
274
283
|
}
|
|
275
284
|
}
|
|
276
285
|
|
|
286
|
+
private func getCallInfo(call: OMICall) -> [String: Any] {
|
|
287
|
+
var direction = "outbound"
|
|
288
|
+
if (guestPhone.count < 10) {
|
|
289
|
+
direction = "inbound"
|
|
290
|
+
}
|
|
291
|
+
let user = OmiClient.getCurrentSip()
|
|
292
|
+
let status = call.callState == .confirmed ? "answered" : "no_answered"
|
|
293
|
+
let timeEnd = Int(Date().timeIntervalSince1970)
|
|
294
|
+
return [
|
|
295
|
+
"transaction_id" : call.omiId,
|
|
296
|
+
"direction" : direction,
|
|
297
|
+
"source_number" : user,
|
|
298
|
+
"destination_number" : guestPhone,
|
|
299
|
+
"time_start_to_answer" : call.createDate,
|
|
300
|
+
"time_end" : timeEnd,
|
|
301
|
+
"sip_user": user,
|
|
302
|
+
"disposition" : lastStatusCall == nil ? "no_answered" : "answered",
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
|
|
277
307
|
/// Start call
|
|
278
|
-
func startCall(_ phoneNumber: String, isVideo: Bool) ->
|
|
308
|
+
func startCall(_ phoneNumber: String, isVideo: Bool, completion: @escaping (_ : Int) -> Void) {
|
|
279
309
|
guestPhone = phoneNumber
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return OmiClient.startVideoCall(phoneNumber)
|
|
310
|
+
OmiClient.startCall(phoneNumber, isVideo: isVideo) { status in
|
|
311
|
+
DispatchQueue.main.async {
|
|
312
|
+
completion(status.rawValue)
|
|
284
313
|
}
|
|
285
|
-
return OmiClient.startCall(phoneNumber)
|
|
286
314
|
}
|
|
287
|
-
return false
|
|
288
315
|
}
|
|
289
316
|
|
|
290
317
|
/// Start call
|
|
291
|
-
func startCallWithUuid(_ uuid: String, isVideo: Bool) ->
|
|
292
|
-
let
|
|
293
|
-
if
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return OmiClient.startVideoCall(phone)
|
|
318
|
+
func startCallWithUuid(_ uuid: String, isVideo: Bool, completion: @escaping (_ : Int) -> Void) {
|
|
319
|
+
let phoneNumber = OmiClient.getPhone(uuid)
|
|
320
|
+
if let phone = phoneNumber {
|
|
321
|
+
guestPhone = phoneNumber ?? ""
|
|
322
|
+
OmiClient.startCall(phone, isVideo: isVideo) { status in
|
|
323
|
+
DispatchQueue.main.async {
|
|
324
|
+
completion(status.rawValue)
|
|
299
325
|
}
|
|
300
|
-
return OmiClient.startCall(phone)
|
|
301
326
|
}
|
|
327
|
+
return
|
|
302
328
|
}
|
|
303
|
-
|
|
329
|
+
completion(OMIStartCallStatus.invalidUuid.rawValue)
|
|
304
330
|
}
|
|
305
331
|
|
|
306
332
|
func endAvailableCall() -> [String: Any] {
|
|
307
333
|
guard let call = getAvailableCall() else {
|
|
308
|
-
|
|
334
|
+
let callInfo = [
|
|
335
|
+
"status": CallState.disconnected.rawValue,
|
|
336
|
+
]
|
|
337
|
+
OmikitPlugin.instance.sendEvent(withName: CALL_STATE_CHANGED, body: callInfo)
|
|
309
338
|
return [:]
|
|
310
339
|
}
|
|
311
|
-
|
|
340
|
+
tempCallInfo = getCallInfo(call: call)
|
|
312
341
|
omiLib.callManager.end(call)
|
|
313
|
-
return
|
|
342
|
+
return tempCallInfo!
|
|
314
343
|
}
|
|
315
344
|
|
|
316
345
|
func endAllCalls() {
|
|
@@ -358,81 +387,16 @@ class CallManager {
|
|
|
358
387
|
OmikitPlugin.instance.sendSpeakerStatus()
|
|
359
388
|
}
|
|
360
389
|
|
|
361
|
-
func
|
|
362
|
-
OmiClient.
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
func getCurrentUser(completion: @escaping (([String: Any]) -> Void)) {
|
|
366
|
-
let prefs = UserDefaults.standard
|
|
367
|
-
if let user = prefs.value(forKey: "User") as? String {
|
|
368
|
-
getUserInfo(phone: user, completion: completion)
|
|
369
|
-
}
|
|
390
|
+
func getAudioOutputs() -> [[String: String]] {
|
|
391
|
+
return OmiClient.getAudioInDevices()
|
|
370
392
|
}
|
|
371
393
|
|
|
372
|
-
func
|
|
373
|
-
|
|
394
|
+
func setAudioOutputs(portType: String) {
|
|
395
|
+
return OmiClient.setAudioOutputs(portType)
|
|
374
396
|
}
|
|
375
397
|
|
|
376
|
-
func
|
|
377
|
-
|
|
378
|
-
completion(account)
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
func inputs() -> [[String: String]] {
|
|
383
|
-
let inputs = AVAudioSession.sharedInstance().availableInputs ?? []
|
|
384
|
-
let results = inputs.map { item in
|
|
385
|
-
return [
|
|
386
|
-
"name": item.portName,
|
|
387
|
-
"id": item.uid,
|
|
388
|
-
]
|
|
389
|
-
}
|
|
390
|
-
return results
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
func setInput(id: String) {
|
|
394
|
-
let inputs = AVAudioSession.sharedInstance().availableInputs ?? []
|
|
395
|
-
if let newOutput = inputs.first(where: {$0.uid == id}) {
|
|
396
|
-
try? AVAudioSession.sharedInstance().setPreferredInput(newOutput)
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
func outputs() -> [[String: String]] {
|
|
401
|
-
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs
|
|
402
|
-
var results = outputs.map { item in
|
|
403
|
-
return [
|
|
404
|
-
"name": item.portName,
|
|
405
|
-
"id": item.uid,
|
|
406
|
-
]
|
|
407
|
-
}
|
|
408
|
-
let hasSpeaker = results.contains{ $0["name"] == "Speaker" }
|
|
409
|
-
if (!hasSpeaker) {
|
|
410
|
-
results.append([
|
|
411
|
-
"name": "Speaker",
|
|
412
|
-
"id": "Speaker",
|
|
413
|
-
])
|
|
414
|
-
} else {
|
|
415
|
-
results.append([
|
|
416
|
-
"name": "Off Speaker",
|
|
417
|
-
"id": "Off Speaker",
|
|
418
|
-
])
|
|
419
|
-
}
|
|
420
|
-
return results
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
func setOutput(id: String) {
|
|
424
|
-
if (id == "Speaker") {
|
|
425
|
-
try? AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
|
|
426
|
-
return
|
|
427
|
-
}
|
|
428
|
-
if (id == "Off Speaker") {
|
|
429
|
-
try? AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
|
|
430
|
-
return
|
|
431
|
-
}
|
|
432
|
-
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs
|
|
433
|
-
if let newOutput = outputs.first(where: {$0.uid == id}) {
|
|
434
|
-
try? AVAudioSession.sharedInstance().setPreferredInput(newOutput)
|
|
435
|
-
}
|
|
398
|
+
func getCurrentAudio() -> [[String: String]] {
|
|
399
|
+
return OmiClient.getCurrentAudio()
|
|
436
400
|
}
|
|
437
401
|
|
|
438
402
|
//video call
|
|
@@ -463,24 +427,35 @@ class CallManager {
|
|
|
463
427
|
return videoManager.createView(forVideoRemote: frame)
|
|
464
428
|
}
|
|
465
429
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
430
|
+
func logout() {
|
|
431
|
+
OmiClient.logout()
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
func getCurrentUser(completion: @escaping (([String: Any]) -> Void)) {
|
|
435
|
+
if let sip = OmiClient.getCurrentSip() {
|
|
436
|
+
getUserInfo(phone: sip, completion: completion)
|
|
437
|
+
} else {
|
|
438
|
+
completion([:])
|
|
470
439
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
func getGuestUser(completion: @escaping (([String: Any]) -> Void)) {
|
|
443
|
+
getUserInfo(phone: guestPhone, completion: completion)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
func getUserInfo(phone: String, completion: @escaping (([String: Any]) -> Void)) {
|
|
447
|
+
if let account = OmiClient.getAccountInfo(phone) as? [String: Any] {
|
|
448
|
+
completion(account)
|
|
449
|
+
} else {
|
|
450
|
+
completion([:])
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private func baseInfoFromCall(call: OMICall) -> [String: Any] {
|
|
475
455
|
return [
|
|
476
|
-
"
|
|
477
|
-
"
|
|
478
|
-
"
|
|
479
|
-
"destination_number" : guestPhone,
|
|
480
|
-
"time_start_to_answer" : call.createDate,
|
|
481
|
-
"time_end" : timeEnd,
|
|
482
|
-
"sip_user": user,
|
|
483
|
-
"disposition" : lastStatusCall == nil ? "no_answered" : "answered",
|
|
456
|
+
"callerNumber": call.callerNumber,
|
|
457
|
+
"isVideo": call.isVideo,
|
|
458
|
+
"transactionId": call.omiId,
|
|
484
459
|
]
|
|
485
460
|
}
|
|
486
461
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CallState.swift
|
|
3
|
+
// omicall_flutter_plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by PRO 2019 16' on 25/05/2023.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
enum CallState: Int {
|
|
10
|
+
case calling = 0
|
|
11
|
+
case early
|
|
12
|
+
case connecting
|
|
13
|
+
case confirmed
|
|
14
|
+
case incoming
|
|
15
|
+
case disconnected
|
|
16
|
+
case hold
|
|
17
|
+
}
|
|
@@ -36,15 +36,11 @@ let GET_GUEST_USER = "GET_GUEST_USER"
|
|
|
36
36
|
let GET_USER_INFO = "GET_USER_INFO"
|
|
37
37
|
|
|
38
38
|
//LISTENER
|
|
39
|
-
let
|
|
40
|
-
let CALL_END = "CALL_END"
|
|
41
|
-
let INCOMING_RECEIVED = "INCOMING_RECEIVED"
|
|
42
|
-
let VIDEO = "VIDEO"
|
|
39
|
+
let CALL_STATE_CHANGED = "CALL_STATE_CHANGED"
|
|
43
40
|
let SPEAKER = "SPEAKER"
|
|
44
41
|
let MUTED = "MUTED"
|
|
45
|
-
let LOCAL_VIDEO_READY = "LOCAL_VIDEO_READY"
|
|
46
42
|
let REMOTE_VIDEO_READY = "REMOTE_VIDEO_READY"
|
|
47
43
|
let CLICK_MISSED_CALL = "CLICK_MISSED_CALL"
|
|
48
44
|
let SWITCHBOARD_ANSWER = "SWITCHBOARD_ANSWER"
|
|
49
45
|
let CALL_QUALITY = "CALL_QUALITY"
|
|
50
|
-
|
|
46
|
+
let AUDIO_CHANGE = "AUDIO_CHANGE"
|
|
@@ -60,25 +60,43 @@ RCT_EXTERN_METHOD(switchOmiCamera:
|
|
|
60
60
|
RCT_EXTERN_METHOD(toggleOmiVideo:
|
|
61
61
|
(RCTPromiseResolveBlock)resolve
|
|
62
62
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
63
|
+
|
|
63
64
|
RCT_EXTERN_METHOD(logout:
|
|
64
65
|
(RCTPromiseResolveBlock)resolve
|
|
65
66
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
67
|
+
|
|
66
68
|
RCT_EXTERN_METHOD(registerVideoEvent:
|
|
67
69
|
(RCTPromiseResolveBlock)resolve
|
|
68
70
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
71
|
+
|
|
69
72
|
RCT_EXTERN_METHOD(removeVideoEvent:
|
|
70
73
|
(RCTPromiseResolveBlock)resolve
|
|
71
74
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
75
|
+
|
|
72
76
|
RCT_EXTERN_METHOD(getCurrentUser:
|
|
73
77
|
(RCTPromiseResolveBlock)resolve
|
|
74
78
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
79
|
+
|
|
75
80
|
RCT_EXTERN_METHOD(getGuestUser:
|
|
76
81
|
(RCTPromiseResolveBlock)resolve
|
|
77
82
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
83
|
+
|
|
78
84
|
RCT_EXTERN_METHOD(getUserInfo: (id)data
|
|
79
85
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
80
86
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
81
87
|
|
|
88
|
+
RCT_EXTERN_METHOD(getAudio:
|
|
89
|
+
(RCTPromiseResolveBlock)resolve
|
|
90
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
91
|
+
|
|
92
|
+
RCT_EXTERN_METHOD(setAudio: (id)data
|
|
93
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
94
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
95
|
+
|
|
96
|
+
RCT_EXTERN_METHOD(getCurrentAudio:
|
|
97
|
+
(RCTPromiseResolveBlock)resolve
|
|
98
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
99
|
+
|
|
82
100
|
+ (BOOL)requiresMainQueueSetup
|
|
83
101
|
{
|
|
84
102
|
return YES;
|