omikit-plugin 3.3.12 → 3.3.15

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.
@@ -122,7 +122,7 @@ dependencies {
122
122
  implementation("androidx.work:work-runtime:2.8.1")
123
123
  implementation "androidx.security:security-crypto:1.1.0-alpha06"
124
124
  // api 'vn.vihat.omicall:omi-sdk:2.3.23'
125
- api "io.omicrm.vihat:omi-sdk:2.3.92"
125
+ api "io.omicrm.vihat:omi-sdk:2.3.94"
126
126
 
127
127
  implementation "com.facebook.react:react-native:+" // From node_modules
128
128
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -119,10 +119,60 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
119
119
  private var isIncoming: Boolean = false
120
120
  private var isAnswerCall: Boolean = false
121
121
  private var permissionPromise: Promise? = null
122
+
123
+ // Call state management to prevent concurrent calls
124
+ private var isCallInProgress: Boolean = false
125
+ private var lastCallTime: Long = 0
126
+ private val callCooldownMs: Long = 2000 // 2 seconds cooldown between calls
127
+ private val callStateLock = Any()
122
128
 
123
129
  override fun getName(): String {
124
130
  return NAME
125
131
  }
132
+
133
+ /**
134
+ * Check if we can start a new call (no concurrent calls, cooldown passed)
135
+ */
136
+ private fun canStartNewCall(): Boolean {
137
+ synchronized(callStateLock) {
138
+ val currentTime = System.currentTimeMillis()
139
+ val timeSinceLastCall = currentTime - lastCallTime
140
+
141
+ // Check if call is in progress or cooldown not passed
142
+ if (isCallInProgress) {
143
+ Log.d("OMISDK", "🚫 Call blocked: Call already in progress")
144
+ return false
145
+ }
146
+
147
+ if (timeSinceLastCall < callCooldownMs) {
148
+ Log.d("OMISDK", "🚫 Call blocked: Cooldown period (${callCooldownMs - timeSinceLastCall}ms remaining)")
149
+ return false
150
+ }
151
+
152
+ return true
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Mark call as started
158
+ */
159
+ private fun markCallStarted() {
160
+ synchronized(callStateLock) {
161
+ isCallInProgress = true
162
+ lastCallTime = System.currentTimeMillis()
163
+ Log.d("OMISDK", "📞 Call started, marking in progress")
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Mark call as ended
169
+ */
170
+ private fun markCallEnded() {
171
+ synchronized(callStateLock) {
172
+ isCallInProgress = false
173
+ Log.d("OMISDK", "📴 Call ended, clearing in progress flag")
174
+ }
175
+ }
126
176
 
127
177
 
128
178
  private val handler = Handler(Looper.getMainLooper())
@@ -184,6 +234,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
184
234
  // Reset call state variables
185
235
  isIncoming = false
186
236
  isAnswerCall = false
237
+ // Clear call progress state when remote party ends call
238
+ markCallEnded()
187
239
  Log.d("OMISDK", "=>> onCallEnd AFTER RESET - isIncoming: $isIncoming, isAnswerCall: $isAnswerCall")
188
240
 
189
241
  // Kiểm tra kiểu dữ liệu trước khi ép kiểu để tránh lỗi
@@ -710,15 +762,14 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
710
762
  fun initCallWithApiKey(data: ReadableMap, promise: Promise) {
711
763
  mainScope.launch {
712
764
  var loginResult = false
713
- val usrName = data.getString("fullName")
714
- val usrUuid = data.getString("usrUuid")
715
- val apiKey = data.getString("apiKey")
765
+ val usrName = data.getString("fullName") ?: ""
766
+ val usrUuid = data.getString("usrUuid") ?: ""
767
+ val apiKey = data.getString("apiKey") ?: ""
716
768
  val isVideo = data.getBoolean("isVideo") ?: false
717
769
  val phone = data.getString("phone")
718
- val firebaseToken = data.getString("fcmToken") as String
770
+ val firebaseToken = data.getString("fcmToken") ?: ""
719
771
  val projectId = data.getString("projectId") ?: ""
720
772
 
721
- requestPermission(isVideo)
722
773
  withContext(Dispatchers.Default) {
723
774
  try {
724
775
  // Validate required parameters
@@ -742,10 +793,11 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
742
793
  loginResult = OmiClient.registerWithApiKey(
743
794
  apiKey ?: "",
744
795
  usrName ?: "",
745
- phone ?: "",
746
796
  usrUuid ?: "",
797
+ phone ?: "",
747
798
  isVideo,
748
- firebaseToken
799
+ firebaseToken,
800
+ projectId
749
801
  )
750
802
 
751
803
  if (loginResult) {
@@ -868,39 +920,22 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
868
920
  reactApplicationContext!!,
869
921
  Manifest.permission.RECORD_AUDIO
870
922
  )
923
+ Log.d("OMISDK", "📤 Start Call With UUID")
871
924
  val map: WritableMap = WritableNativeMap()
872
925
  if (audio == PackageManager.PERMISSION_GRANTED) {
873
926
  mainScope.launch {
874
- var callResult: OmiStartCallStatus? = null
875
- try {
876
- val uuid = data.getString("usrUuid") as String
877
- val isVideo = data.getBoolean("isVideo")
878
-
879
- // Check if OmiClient instance and service are ready before making call
880
- val omiClient = OmiClient.getInstance(reactApplicationContext!!)
881
- if (omiClient == null) {
882
- callResult = null
883
- } else {
884
- // Add small delay to ensure service is fully initialized
885
- kotlinx.coroutines.delay(100)
886
-
887
- // Call on main thread to avoid PJSIP thread registration issues
888
- callResult = omiClient.startCallWithUuid(uuid = uuid, isVideo = isVideo)
889
- }
890
- } catch (e: IllegalStateException) {
891
- // Handle service not ready state
892
- callResult = null
893
- } catch (e: NullPointerException) {
894
- // Handle null pointer exceptions
895
- callResult = null
896
- } catch (e: Throwable) {
897
- // Handle any other exceptions including PJSIP thread issues
898
- callResult = null
927
+ val uuid = data.getString("usrUuid") ?: ""
928
+ val isVideo = data.getBoolean("isVideo") ?: false;
929
+
930
+ val startCallResult =
931
+ OmiClient.getInstance(reactApplicationContext!!).startCallWithUuid(uuid, isVideo)
932
+ var statusCalltemp = startCallResult.value as Int;
933
+ if (startCallResult.value == 200 || startCallResult.value == 407) {
934
+ statusCalltemp = 8
899
935
  }
900
- var statusCalltemp = callResult?.ordinal ?: 8
901
936
  map.putInt("status", statusCalltemp)
902
937
  map.putString("_id", "")
903
- map.putString("message", messageCall(statusCalltemp) as String)
938
+ map.putString("message", messageCall(startCallResult.value) as String)
904
939
  promise.resolve(map)
905
940
  }
906
941
  } else {
@@ -911,6 +946,7 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
911
946
  }
912
947
  }
913
948
 
949
+
914
950
  @ReactMethod
915
951
  fun joinCall(promise: Promise) {
916
952
  val appContext = reactApplicationContext.applicationContext
@@ -945,6 +981,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
945
981
  omiClient.hangUp()
946
982
  }
947
983
  }
984
+ // Clear call state when ending call
985
+ markCallEnded()
948
986
  promise.resolve(true)
949
987
  }
950
988
 
@@ -962,6 +1000,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
962
1000
  omiClient.hangUp()
963
1001
  }
964
1002
  }
1003
+ // Clear call state when rejecting call
1004
+ markCallEnded()
965
1005
  promise.resolve(true)
966
1006
  } else {
967
1007
  Log.d("OMISDK", "📤 Not incoming call, skipping reject")
@@ -978,6 +1018,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
978
1018
  omiClient.hangUp()
979
1019
  }
980
1020
  }
1021
+ // Clear call state when dropping call
1022
+ markCallEnded()
981
1023
  promise.resolve(true)
982
1024
  }
983
1025
 
@@ -490,13 +490,26 @@ func startCall(_ phoneNumber: String, isVideo: Bool, completion: @escaping (_: S
490
490
  if let jsonString = OmiUtils.convertDictionaryToJson(dictionary: dataToSend) {
491
491
  completion(jsonString)
492
492
  } else {
493
- completion("Conversion to JSON failed")
493
+ completion("{\"status\": \"error\", \"message\": \"JSON conversion failed\"}")
494
494
  }
495
495
  return
496
496
 
497
497
  }
498
498
 
499
499
  return
500
+ } else {
501
+ var dataToSend: [String: Any] = [
502
+ "status": 0,
503
+ "_id": "",
504
+ "message": "INVALID_UUID",
505
+ "message_detail": "UUID does not exist"
506
+ ]
507
+ if let jsonString = OmiUtils.convertDictionaryToJson(dictionary: dataToSend) {
508
+ completion(jsonString)
509
+ } else {
510
+ completion("{\"status\": \"error\", \"message\": \"JSON conversion failed\"}")
511
+ }
512
+ return
500
513
  }
501
514
  }
502
515
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.12",
3
+ "version": "3.3.15",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",