omikit-plugin 3.3.12 → 3.3.14

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
@@ -869,6 +921,16 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
869
921
  Manifest.permission.RECORD_AUDIO
870
922
  )
871
923
  val map: WritableMap = WritableNativeMap()
924
+
925
+ // Check if we can start a new call first
926
+ if (!canStartNewCall()) {
927
+ map.putInt("status", 8) // HAVE_ANOTHER_CALL
928
+ map.putString("_id", "")
929
+ map.putString("message", messageCall(8) as String)
930
+ promise.resolve(map)
931
+ return
932
+ }
933
+
872
934
  if (audio == PackageManager.PERMISSION_GRANTED) {
873
935
  mainScope.launch {
874
936
  var callResult: OmiStartCallStatus? = null
@@ -876,26 +938,38 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
876
938
  val uuid = data.getString("usrUuid") as String
877
939
  val isVideo = data.getBoolean("isVideo")
878
940
 
941
+ // Mark call as started before making the actual call
942
+ markCallStarted()
943
+
879
944
  // Check if OmiClient instance and service are ready before making call
880
945
  val omiClient = OmiClient.getInstance(reactApplicationContext!!)
881
946
  if (omiClient == null) {
882
947
  callResult = null
948
+ markCallEnded() // Clean up state
883
949
  } else {
884
950
  // Add small delay to ensure service is fully initialized
885
- kotlinx.coroutines.delay(100)
951
+ kotlinx.coroutines.delay(200) // Increased delay for better stability
886
952
 
887
953
  // Call on main thread to avoid PJSIP thread registration issues
888
954
  callResult = omiClient.startCallWithUuid(uuid = uuid, isVideo = isVideo)
955
+
956
+ // If call failed, mark as ended
957
+ if (callResult == null || callResult.ordinal <= 7) { // 0-7 are failure statuses
958
+ markCallEnded()
959
+ }
889
960
  }
890
961
  } catch (e: IllegalStateException) {
891
962
  // Handle service not ready state
892
963
  callResult = null
964
+ markCallEnded()
893
965
  } catch (e: NullPointerException) {
894
966
  // Handle null pointer exceptions
895
967
  callResult = null
968
+ markCallEnded()
896
969
  } catch (e: Throwable) {
897
970
  // Handle any other exceptions including PJSIP thread issues
898
971
  callResult = null
972
+ markCallEnded()
899
973
  }
900
974
  var statusCalltemp = callResult?.ordinal ?: 8
901
975
  map.putInt("status", statusCalltemp)
@@ -945,6 +1019,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
945
1019
  omiClient.hangUp()
946
1020
  }
947
1021
  }
1022
+ // Clear call state when ending call
1023
+ markCallEnded()
948
1024
  promise.resolve(true)
949
1025
  }
950
1026
 
@@ -962,6 +1038,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
962
1038
  omiClient.hangUp()
963
1039
  }
964
1040
  }
1041
+ // Clear call state when rejecting call
1042
+ markCallEnded()
965
1043
  promise.resolve(true)
966
1044
  } else {
967
1045
  Log.d("OMISDK", "📤 Not incoming call, skipping reject")
@@ -978,6 +1056,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
978
1056
  omiClient.hangUp()
979
1057
  }
980
1058
  }
1059
+ // Clear call state when dropping call
1060
+ markCallEnded()
981
1061
  promise.resolve(true)
982
1062
  }
983
1063
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.12",
3
+ "version": "3.3.14",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",