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.
Files changed (40) hide show
  1. package/README.md +129 -41
  2. package/android/build.gradle +4 -1
  3. package/android/src/main/java/com/omikitplugin/OmikitPluginModule.kt +133 -93
  4. package/android/src/main/java/com/omikitplugin/constants/constant.kt +2 -3
  5. package/android/src/main/java/com/omikitplugin/state/CallState.kt +12 -0
  6. package/ios/CallProcess/CallManager.swift +191 -216
  7. package/ios/CallProcess/CallState.swift +17 -0
  8. package/ios/Constant/Constant.swift +2 -6
  9. package/ios/Library/OmikitPlugin.m +18 -0
  10. package/ios/Library/OmikitPlugin.swift +42 -20
  11. package/lib/commonjs/index.js +22 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/omi_call_state.js +18 -0
  14. package/lib/commonjs/omi_call_state.js.map +1 -0
  15. package/lib/commonjs/omi_start_call_status.js +21 -0
  16. package/lib/commonjs/omi_start_call_status.js.map +1 -0
  17. package/lib/commonjs/omikit.js +15 -10
  18. package/lib/commonjs/omikit.js.map +1 -1
  19. package/lib/module/index.js +2 -0
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/module/omi_call_state.js +11 -0
  22. package/lib/module/omi_call_state.js.map +1 -0
  23. package/lib/module/omi_start_call_status.js +14 -0
  24. package/lib/module/omi_start_call_status.js.map +1 -0
  25. package/lib/module/omikit.js +12 -10
  26. package/lib/module/omikit.js.map +1 -1
  27. package/lib/typescript/index.d.ts +2 -0
  28. package/lib/typescript/index.d.ts.map +1 -1
  29. package/lib/typescript/omi_call_state.d.ts +10 -0
  30. package/lib/typescript/omi_call_state.d.ts.map +1 -0
  31. package/lib/typescript/omi_start_call_status.d.ts +13 -0
  32. package/lib/typescript/omi_start_call_status.d.ts.map +1 -0
  33. package/lib/typescript/omikit.d.ts +7 -6
  34. package/lib/typescript/omikit.d.ts.map +1 -1
  35. package/omikit-plugin.podspec +1 -1
  36. package/package.json +1 -1
  37. package/src/index.tsx +2 -0
  38. package/src/omi_call_state.tsx +9 -0
  39. package/src/omi_start_call_status.tsx +12 -0
  40. package/src/omikit.tsx +16 -11
@@ -12,12 +12,12 @@ import android.provider.Settings
12
12
  import android.util.Log
13
13
  import androidx.annotation.RequiresApi
14
14
  import androidx.core.app.ActivityCompat
15
- import androidx.core.app.ActivityCompat.startActivityForResult
16
15
  import androidx.core.content.ContextCompat
17
16
  import com.facebook.react.ReactActivity
18
17
  import com.facebook.react.bridge.*
19
18
  import com.facebook.react.modules.core.RCTNativeAppEventEmitter
20
19
  import com.omikitplugin.constants.*
20
+ import com.omikitplugin.state.CallState
21
21
  import kotlinx.coroutines.CoroutineScope
22
22
  import kotlinx.coroutines.Dispatchers
23
23
  import kotlinx.coroutines.launch
@@ -25,7 +25,9 @@ import kotlinx.coroutines.withContext
25
25
  import vn.vihat.omicall.omisdk.OmiAccountListener
26
26
  import vn.vihat.omicall.omisdk.OmiClient
27
27
  import vn.vihat.omicall.omisdk.OmiListener
28
+ import vn.vihat.omicall.omisdk.service.NotificationService
28
29
  import vn.vihat.omicall.omisdk.utils.OmiSDKUtils
30
+ import vn.vihat.omicall.omisdk.utils.OmiStartCallStatus
29
31
  import vn.vihat.omicall.omisdk.utils.SipServiceConstants
30
32
 
31
33
 
@@ -37,41 +39,49 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
37
39
  return NAME
38
40
  }
39
41
 
40
- override fun incomingReceived(callerId: Int, phoneNumber: String?, isVideo: Boolean?) {
42
+ override fun incomingReceived(callerId: Int?, phoneNumber: String?, isVideo: Boolean?) {
41
43
  val map: WritableMap = WritableNativeMap()
42
44
  map.putBoolean("isVideo", isVideo ?: true)
43
45
  map.putString("callerNumber", phoneNumber)
44
- sendEvent(INCOMING_RECEIVED, map)
46
+ map.putInt("status", CallState.incoming.value)
47
+ sendEvent(CALL_STATE_CHANGED, map)
45
48
  Log.d("omikit", "incomingReceived: ")
46
49
  }
47
50
 
48
- override fun onCallEnd(callInfo: Any?, statusCode: Int) {
49
- if (callInfo is Map<*, *>) {
50
- val call = callInfo as Map<*, *>
51
- val map: WritableMap = WritableNativeMap()
52
- val timeStartToAnswer = call["time_start_to_answer"] as Long?
53
- val timeEnd = call["time_end"] as Long
54
- map.putString("transaction_id", call["transaction_id"] as String?)
55
- map.putString("direction", call["direction"] as String)
56
- map.putString("source_number", call["source_number"] as String)
57
- map.putString("destination_number", call["destination_number"] as String)
58
- map.putDouble("time_start_to_answer", (timeStartToAnswer ?: 0).toDouble())
59
- map.putDouble("time_end", timeEnd.toDouble())
60
- map.putString("sip_user", call["sip_user"] as String)
61
- map.putString("disposition", call["disposition"] as String)
62
- sendEvent(CALL_END, map)
63
- } else {
64
- sendEvent(CALL_END, null)
65
- }
66
- }
67
-
68
- override fun networkHealth(mos: Float, quality: Int) {
51
+ override fun networkHealth(stat: Map<String, *>, quality: Int) {
69
52
  val map: WritableMap = WritableNativeMap()
70
53
  map.putInt("quality", quality)
71
- map.putDouble("mos", mos.toDouble())
72
54
  sendEvent(CALL_QUALITY, map)
73
55
  }
74
56
 
57
+ override fun onAudioChanged(audioInfo: Map<String, Any>) {
58
+ val audio: WritableMap = WritableNativeMap()
59
+ audio.putString("name", audioInfo["name"] as String)
60
+ audio.putInt("type", audioInfo["type"] as Int)
61
+ val map: WritableMap = WritableNativeMap()
62
+ val writeList = WritableNativeArray()
63
+ writeList.pushMap(audio)
64
+ map.putArray("data", writeList)
65
+ sendEvent(AUDIO_CHANGE, map)
66
+ }
67
+
68
+ override fun onCallEnd(callInfo: MutableMap<String, Any?>, statusCode: Int) {
69
+ val call = callInfo as Map<*, *>
70
+ val map: WritableMap = WritableNativeMap()
71
+ val timeStartToAnswer = call["time_start_to_answer"] as Long?
72
+ val timeEnd = call["time_end"] as Long
73
+ map.putString("transaction_id", call["transaction_id"] as String?)
74
+ map.putString("direction", call["direction"] as String)
75
+ map.putString("source_number", call["source_number"] as String)
76
+ map.putString("destination_number", call["destination_number"] as String)
77
+ map.putDouble("time_start_to_answer", (timeStartToAnswer ?: 0).toDouble())
78
+ map.putDouble("time_end", timeEnd.toDouble())
79
+ map.putString("sip_user", call["sip_user"] as String)
80
+ map.putString("disposition", call["disposition"] as String)
81
+ map.putInt("status", CallState.disconnected.value)
82
+ sendEvent(CALL_STATE_CHANGED, map)
83
+ }
84
+
75
85
  override fun onCallEstablished(
76
86
  callerId: Int,
77
87
  phoneNumber: String?,
@@ -85,31 +95,43 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
85
95
  map.putString("callerNumber", phoneNumber)
86
96
  map.putBoolean("isVideo", isVideo ?: true)
87
97
  map.putString("transactionId", transactionId)
88
- sendEvent(CALL_ESTABLISHED, map)
98
+ map.putInt("status", CallState.confirmed.value)
99
+ sendEvent(CALL_STATE_CHANGED, map)
89
100
  }, 500)
90
101
  }
91
102
 
92
- override fun onConnectionTimeout() {
93
- // sendEvent("onConnectionTimeout", null)
103
+ override fun onConnecting() {
104
+ val map: WritableMap = WritableNativeMap()
105
+ map.putString("callerNumber", "")
106
+ map.putBoolean("isVideo", NotificationService.isVideo)
107
+ map.putString("transactionId", "")
108
+ map.putInt("status", CallState.connecting.value)
109
+ sendEvent(CALL_STATE_CHANGED, map)
94
110
  }
95
111
 
112
+
96
113
  override fun onHold(isHold: Boolean) {
97
- // val map: WritableMap = WritableNativeMap()
98
- // map.putBoolean("isHold", isHold)
99
- // sendEvent(HOLD, map)
100
114
  }
101
115
 
102
116
  override fun onMuted(isMuted: Boolean) {
103
- // val map: WritableMap = WritableNativeMap()
104
- // map.putBoolean("isMuted", isMuted)
105
- // sendEvent(MUTED, map)
106
117
  }
107
118
 
108
119
  override fun onOutgoingStarted(callerId: Int, phoneNumber: String?, isVideo: Boolean?) {
109
-
120
+ val map: WritableMap = WritableNativeMap()
121
+ map.putString("callerNumber", "")
122
+ map.putBoolean("isVideo", NotificationService.isVideo)
123
+ map.putString("transactionId", "")
124
+ map.putInt("status", CallState.calling.value)
125
+ sendEvent(CALL_STATE_CHANGED, map)
110
126
  }
111
127
 
112
- override fun onRinging() {
128
+ override fun onRinging(callerId: Int, transactionId: String?) {
129
+ val map: WritableMap = WritableNativeMap()
130
+ map.putString("callerNumber", "")
131
+ map.putBoolean("isVideo", false)
132
+ map.putString("transactionId", transactionId ?: "")
133
+ map.putInt("status", CallState.early.value)
134
+ sendEvent(CALL_STATE_CHANGED, map)
113
135
  }
114
136
 
115
137
  override fun onSwitchBoardAnswer(sip: String) {
@@ -125,8 +147,6 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
125
147
  private val accountListener = object : OmiAccountListener {
126
148
  override fun onAccountStatus(online: Boolean) {
127
149
  Log.d("aaa", "Account status $online")
128
- // initResult?.success(online)
129
- // initResult = null
130
150
  }
131
151
  }
132
152
 
@@ -135,7 +155,7 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
135
155
  reactApplicationContext!!.addActivityEventListener(this)
136
156
  Handler(Looper.getMainLooper()).post {
137
157
  OmiClient(context = reactApplicationContext!!)
138
- OmiClient.instance.setListener(this)
158
+ OmiClient.instance.addCallStateListener(this)
139
159
  }
140
160
  }
141
161
 
@@ -152,12 +172,14 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
152
172
  promise.resolve(result)
153
173
  }
154
174
 
175
+ @RequiresApi(Build.VERSION_CODES.M)
155
176
  @ReactMethod
156
177
  fun openSystemAlertSetting(promise: Promise) {
157
178
  val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
158
179
  Uri.parse("package:" + reactApplicationContext.packageName))
159
180
  intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
160
181
  reactApplicationContext.startActivity(intent)
182
+ promise.resolve(true)
161
183
  }
162
184
 
163
185
  @ReactMethod
@@ -173,6 +195,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
173
195
  val userImage = data.getString("userImage")
174
196
  val userNameKey = data.getString("userNameKey")
175
197
  val channelId = data.getString("channelId")
198
+ val audioNotificationDescription = data.getString("audioNotificationDescription")
199
+ val videoNotificationDescription = data.getString("videoNotificationDescription")
176
200
  OmiClient.instance.configPushNotification(
177
201
  notificationIcon = notificationIcon ?: "",
178
202
  prefix = prefix ?: "Cuộc gọi tới từ: ",
@@ -182,9 +206,13 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
182
206
  backImage = backImage ?: "ic_back",
183
207
  userImage = userImage ?: "calling_face",
184
208
  prefixMissedCallMessage = prefixMissedCallMessage ?: "Cuộc gọi nhỡ từ",
185
- missedCallTitle = prefixMissedCallMessage ?: "Cuộc gọi nhỡ",
186
209
  userNameKey = userNameKey ?: "extension",
187
210
  channelId = channelId ?: "",
211
+ ringtone = null,
212
+ fullScreenUserImage = userImage ?: "calling_face",
213
+ showUserInfoInFullScreen = false,
214
+ audioNotificationDescription = audioNotificationDescription,
215
+ videoNotificationDescription = videoNotificationDescription
188
216
  )
189
217
  promise.resolve(true)
190
218
  }
@@ -202,8 +230,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
202
230
  OmiClient.register(
203
231
  userName,
204
232
  password,
205
- isVideo,
206
233
  realm,
234
+ isVideo,
207
235
  host,
208
236
  )
209
237
  }
@@ -220,6 +248,7 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
220
248
  val usrUuid = data.getString("usrUuid")
221
249
  val apiKey = data.getString("apiKey")
222
250
  val isVideo = data.getBoolean("isVideo")
251
+ val phone = data.getString("phone")
223
252
  withContext(Dispatchers.Default) {
224
253
  try {
225
254
  if (usrName != null && usrUuid != null && apiKey != null) {
@@ -227,7 +256,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
227
256
  apiKey = apiKey,
228
257
  userName = usrName,
229
258
  uuid = usrUuid,
230
- isVideo,
259
+ phone = phone ?: "",
260
+ isVideo = isVideo,
231
261
  )
232
262
  }
233
263
  } catch (_: Throwable) {
@@ -243,7 +273,17 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
243
273
  @ReactMethod
244
274
  fun getInitialCall(promise: Promise) {
245
275
  currentActivity?.runOnUiThread {
246
- promise.resolve(false)
276
+ val call = OmiClient.instance.getCurrentCallInfo()
277
+ if (call != null) {
278
+ val map: WritableMap = WritableNativeMap()
279
+ map.putString("callerNumber", call["callerNumber"] as String)
280
+ map.putInt("status", call["status"] as Int)
281
+ map.putBoolean("muted", call["muted"] as Boolean)
282
+ map.putBoolean("isVideo", call["isVideo"] as Boolean)
283
+ promise.resolve(map)
284
+ } else {
285
+ promise.resolve(false)
286
+ }
247
287
  }
248
288
  }
249
289
 
@@ -293,7 +333,7 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
293
333
  )
294
334
  if (audio == PackageManager.PERMISSION_GRANTED) {
295
335
  mainScope.launch {
296
- var callResult = false
336
+ var callResult: OmiStartCallStatus? = null
297
337
  withContext(Dispatchers.Default) {
298
338
  try {
299
339
  val uuid = data.getString("usrUuid") as String
@@ -321,24 +361,19 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
321
361
  @ReactMethod
322
362
  fun endCall(promise: Promise) {
323
363
  currentActivity?.runOnUiThread {
324
- val callInfo = OmiClient.instance.hangUp()
325
- if (callInfo is Map<*, *>) {
326
- val call = callInfo as Map<*, *>
327
- val map: WritableMap = WritableNativeMap()
328
- val timeStartToAnswer = call["time_start_to_answer"] as Long?
329
- val timeEnd = call["time_end"] as Long
330
- map.putString("transaction_id", call["transaction_id"] as String?)
331
- map.putString("direction", call["direction"] as String)
332
- map.putString("source_number", call["source_number"] as String)
333
- map.putString("destination_number", call["destination_number"] as String)
334
- map.putDouble("time_start_to_answer", (timeStartToAnswer ?: 0).toDouble())
335
- map.putDouble("time_end", timeEnd.toDouble())
336
- map.putString("sip_user", call["sip_user"] as String)
337
- map.putString("disposition", call["disposition"] as String)
338
- sendEvent(CALL_END, map)
339
- } else {
340
- promise.resolve(null)
341
- }
364
+ val call = OmiClient.instance.hangUp()
365
+ val map: WritableMap = WritableNativeMap()
366
+ val timeStartToAnswer = call?.get("time_start_to_answer") as Long?
367
+ val timeEnd = call?.get("time_end") as Long
368
+ map.putString("transaction_id", call["transaction_id"] as String?)
369
+ map.putString("direction", call["direction"] as String)
370
+ map.putString("source_number", call["source_number"] as String)
371
+ map.putString("destination_number", call["destination_number"] as String)
372
+ map.putDouble("time_start_to_answer", (timeStartToAnswer ?: 0).toDouble())
373
+ map.putDouble("time_end", timeEnd.toDouble())
374
+ map.putString("sip_user", call["sip_user"] as String)
375
+ map.putString("disposition", call["disposition"] as String)
376
+ promise.resolve(map)
342
377
  }
343
378
  }
344
379
 
@@ -401,34 +436,6 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
401
436
  }
402
437
  }
403
438
 
404
- @ReactMethod
405
- fun omiInputs(promise: Promise) {
406
- currentActivity?.runOnUiThread {
407
- val inputs = OmiClient.instance.getAudioInputs()
408
- val allAudios = inputs.map {
409
- mapOf(
410
- "name" to it.first,
411
- "id" to it.second,
412
- )
413
- }.toTypedArray()
414
- promise.resolve(allAudios)
415
- }
416
- }
417
-
418
- @ReactMethod
419
- fun omiOutputs(promise: Promise) {
420
- currentActivity?.runOnUiThread {
421
- val inputs = OmiClient.instance.getAudioOutputs()
422
- val allAudios = inputs.map {
423
- mapOf(
424
- "name" to it.first,
425
- "id" to it.second,
426
- )
427
- }.toTypedArray()
428
- promise.resolve(allAudios)
429
- }
430
- }
431
-
432
439
  @ReactMethod
433
440
  fun logout(promise: Promise) {
434
441
  mainScope.launch {
@@ -517,6 +524,37 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
517
524
  }
518
525
  }
519
526
 
527
+ @ReactMethod
528
+ fun getAudio(promise: Promise) {
529
+ val inputs = OmiClient.instance.getAudioOutputs()
530
+ val writeList = WritableNativeArray()
531
+ inputs.forEach {
532
+ val map = WritableNativeMap()
533
+ map.putString("name", it["name"] as String)
534
+ map.putInt("type", it["type"] as Int)
535
+ writeList.pushMap(map)
536
+ }
537
+ promise.resolve(writeList)
538
+ }
539
+
540
+ @ReactMethod
541
+ fun getCurrentAudio(promise: Promise) {
542
+ val currentAudio = OmiClient.instance.getCurrentAudio()
543
+ val map: WritableMap = WritableNativeMap()
544
+ map.putString("name", currentAudio["name"] as String)
545
+ map.putInt("type", currentAudio["type"] as Int)
546
+ val writeList = WritableNativeArray()
547
+ writeList.pushMap(map)
548
+ promise.resolve(writeList)
549
+ }
550
+
551
+ @ReactMethod
552
+ fun setAudio(data: ReadableMap, promise: Promise) {
553
+ val portType = data.getInt("portType")
554
+ OmiClient.instance.setAudio(portType)
555
+ promise.resolve(true)
556
+ }
557
+
520
558
  companion object {
521
559
  const val NAME = "OmikitPlugin"
522
560
  fun onDestroy() {
@@ -536,9 +574,11 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
536
574
  }
537
575
 
538
576
  private fun sendEvent(eventName: String?, params: Any?) {
539
- currentActivity!!.runOnUiThread {
540
- reactApplicationContext.getJSModule(RCTNativeAppEventEmitter::class.java)
541
- .emit(eventName, params)
577
+ if (currentActivity != null) {
578
+ currentActivity!!.runOnUiThread {
579
+ reactApplicationContext.getJSModule(RCTNativeAppEventEmitter::class.java)
580
+ .emit(eventName, params)
581
+ }
542
582
  }
543
583
  }
544
584
 
@@ -26,12 +26,11 @@ const val GET_GUEST_USER = "GET_GUEST_USER"
26
26
  const val GET_USER_INFO = "GET_USER_INFO"
27
27
 
28
28
  //LISTENER
29
- const val CALL_ESTABLISHED = "CALL_ESTABLISHED"
30
- const val CALL_END = "CALL_END"
31
- const val INCOMING_RECEIVED = "INCOMING_RECEIVED"
29
+ const val CALL_STATE_CHANGED = "CALL_STATE_CHANGED"
32
30
  const val VIDEO = "VIDEO"
33
31
  const val SPEAKER = "SPEAKER"
34
32
  const val MUTED = "MUTED"
35
33
  const val CLICK_MISSED_CALL = "CLICK_MISSED_CALL"
36
34
  const val SWITCHBOARD_ANSWER = "SWITCHBOARD_ANSWER"
37
35
  const val CALL_QUALITY = "CALL_QUALITY"
36
+ const val AUDIO_CHANGE = "AUDIO_CHANGE"
@@ -0,0 +1,12 @@
1
+ package com.omikitplugin.state
2
+
3
+ enum class CallState(_value: Int) {
4
+ calling(0),
5
+ early(1),
6
+ connecting(2),
7
+ confirmed(3),
8
+ incoming(4),
9
+ disconnected(5);
10
+
11
+ val value = _value
12
+ }