omikit-plugin 3.3.20 → 3.3.22

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 CHANGED
@@ -235,7 +235,6 @@ public class MainActivity extends ReactActivity {
235
235
 
236
236
  ### ✅ For React Native > 0.74
237
237
 
238
-
239
238
  ```kotlin
240
239
  class MainActivity : ReactActivity() {
241
240
  // your config ....
@@ -243,6 +242,14 @@ class MainActivity : ReactActivity() {
243
242
  override fun onCreate(savedInstanceState: Bundle?) {
244
243
  super.onCreate(savedInstanceState)
245
244
 
245
+ intent?.let { intentData ->
246
+ try {
247
+ OmikitPluginModule.Companion.handlePickupIntentEarly(this, intentData)
248
+ } catch (e: Exception) {
249
+ Log.e("MainActivity", "⚠️ PICKUP-FIX: Error handling early intent: ${e.message}")
250
+ }
251
+ }
252
+
246
253
  val reactInstanceManager: ReactInstanceManager = reactNativeHost.reactInstanceManager
247
254
  val currentContext = reactInstanceManager.currentReactContext
248
255
  if (currentContext != null && currentContext is ReactApplicationContext) {
@@ -263,21 +270,31 @@ class MainActivity : ReactActivity() {
263
270
  }
264
271
 
265
272
  override fun onNewIntent(intent: Intent?) {
266
- super.onNewIntent(intent)
267
- if (intent != null) {
268
- reactApplicationContext?.let {
269
- OmikitPluginModule.Companion.onGetIntentFromNotification(it, intent, this)
270
- } ?: Log.e("MainActivity", "ReactApplicationContext has not been initialized in onNewIntent.")
271
- } else {
272
- Log.e("MainActivity", "Intent in onNewIntent is null.")
273
- }
273
+ super.onNewIntent(intent)
274
+ intent?.let { newIntent ->
275
+ Log.d("MainActivity", "🚀 PICKUP-FIX: New intent received (warm start)")
276
+ // IMPORTANT: Update the activity's intent to the new one
277
+ setIntent(newIntent)
278
+ try {
279
+ // Try to handle immediately if React context is ready
280
+ reactApplicationContext?.let {
281
+ OmikitPluginModule.Companion.onGetIntentFromNotification(it, newIntent, this)
282
+ } ?: run {
283
+ OmikitPluginModule.Companion.handlePickupIntentEarly(this, newIntent)
284
+ }
285
+ } catch (e: Exception) {
286
+ Log.e("MainActivity", "❌ PICKUP-FIX: Error in onNewIntent: ${e.message}")
287
+ }
288
+ } ?: Log.e("MainActivity", "Intent in onNewIntent is null.")
274
289
  }
290
+
275
291
  override fun onResume() {
276
292
  super.onResume()
277
- reactApplicationContext?.let {
293
+ reactApplicationContext?.let { context ->
278
294
  OmikitPluginModule.Companion.onResume(this)
279
- intent?.let { intent ->
280
- OmikitPluginModule.Companion.onGetIntentFromNotification(it, intent, this)
295
+ // Handle intent if exists (already updated by onNewIntent or from onCreate)
296
+ intent?.let { intentData ->
297
+ OmikitPluginModule.Companion.onGetIntentFromNotification(context, intentData, this)
281
298
  }
282
299
  } ?: Log.e("MainActivity", "ReactApplicationContext has not been initialized in onResume.")
283
300
  }
@@ -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.4.6"
125
+ api "io.omicrm.vihat:omi-sdk:2.4.15"
126
126
 
127
127
  implementation "com.facebook.react:react-native:+" // From node_modules
128
128
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -869,8 +869,8 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
869
869
  } else {
870
870
  mainScope.launch {
871
871
  Log.d("getInitialCall RN", "🔄 Retrying in 2s... (Attempts left: $counter)")
872
- delay(1000) // Chờ 2 giây
873
- getInitialCall(counter - 1, promise) // Gọi lại hàm đệ quy
872
+ delay(1000) // Wait 2 seconds
873
+ getInitialCall(counter - 1, promise) // Retry recursively
874
874
  }
875
875
  }
876
876
  return
@@ -883,6 +883,26 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
883
883
  }
884
884
 
885
885
  val typeNumber = OmiKitUtils().checkTypeNumber(phoneNumber ?: "")
886
+ val statusPendingCall = OmiKitUtils().getStatusPendingCall(context)
887
+
888
+ // 🔥 CRITICAL FIX: Auto-answer if user already clicked pickup button
889
+ // statusPendingCall: 0 = no action, 2 = incoming (opened notification), 5 = accepted (clicked pickup)
890
+ val shouldAutoAnswer = call.direction == "inbound" &&
891
+ !call.isAccepted &&
892
+ call.state == 3 &&
893
+ statusPendingCall == 5 // 5 = User clicked pickup (CONFIRMED)
894
+
895
+ if (shouldAutoAnswer) {
896
+ Log.d("getInitialCall RN", "🚀 AUTO-ANSWER: User clicked pickup (statusPendingCall=$statusPendingCall), answering call immediately")
897
+ try {
898
+ OmiClient.getInstance(context).pickUp()
899
+ Log.d("getInitialCall RN", "✅ AUTO-ANSWER: Call answered successfully")
900
+
901
+ // Status already cleared by getStatusPendingCall()
902
+ } catch (e: Exception) {
903
+ Log.e("getInitialCall RN", "❌ AUTO-ANSWER: Failed to answer call: ${e.message}", e)
904
+ }
905
+ }
886
906
 
887
907
  val map: WritableMap = WritableNativeMap().apply {
888
908
  putString("callerNumber", phoneNumber)
@@ -892,9 +912,9 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
892
912
  putBoolean("muted", false)
893
913
  putBoolean("isVideo", call.isVideo ?: false)
894
914
  putString("typeNumber", typeNumber)
915
+ putBoolean("autoAnswered", shouldAutoAnswer) // Add flag for RN side
895
916
  }
896
917
 
897
- val statusPendingCall = OmiKitUtils().getStatusPendingCall(context)
898
918
  if (call.state == 3 && statusPendingCall != 0) {
899
919
  call.state = statusPendingCall
900
920
  }
@@ -904,7 +924,6 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
904
924
  if (statusPendingCall == 2 && call.state != 5) {
905
925
  Log.d("getInitialCall RN", "🚀 Incoming Receive Triggered ($statusPendingCall)")
906
926
 
907
-
908
927
  val eventMap: WritableMap = WritableNativeMap().apply {
909
928
  putBoolean("isVideo", call.isVideo ?: false)
910
929
  putBoolean("incoming", true)
@@ -1364,6 +1383,47 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
1364
1383
  }
1365
1384
  }
1366
1385
 
1386
+ /**
1387
+ * 🔥 CRITICAL FIX: Handle pickup intent EARLY (before React Native ready)
1388
+ * This method can be called from onCreate/onNewIntent when React context is not ready yet
1389
+ * It will save the pickup state to SharedPreferences for later processing in getInitialCall()
1390
+ */
1391
+ fun handlePickupIntentEarly(act: Activity, intent: Intent) {
1392
+ try {
1393
+ val isIncoming = intent.getBooleanExtra(SipServiceConstants.ACTION_IS_INCOMING_CALL, false)
1394
+ if (!isIncoming) {
1395
+ Log.d("PICKUP-FIX", "Not an incoming call intent, skipping")
1396
+ return
1397
+ }
1398
+
1399
+ val isAcceptedCall = intent.getBooleanExtra(
1400
+ SipServiceConstants.ACTION_ACCEPT_INCOMING_CALL, false
1401
+ )
1402
+
1403
+ Log.d("PICKUP-FIX", "🚀 Early intent handler - isIncoming: $isIncoming, isAccepted: $isAcceptedCall")
1404
+
1405
+ // Save to SharedPreferences so getInitialCall() can detect it later
1406
+ // setStatusPendingCall(true) → saves status=5 (CONFIRMED)
1407
+ // setStatusPendingCall(false) → saves status=2 (INCOMING)
1408
+ OmiKitUtils().setStatusPendingCall(act, isAcceptedCall)
1409
+ Log.d("PICKUP-FIX", "✅ Saved pickup state to SharedPreferences (isAccepted=$isAcceptedCall)")
1410
+
1411
+ if (isAcceptedCall) {
1412
+ // Try to answer immediately if possible (may fail if SDK not ready)
1413
+ try {
1414
+ OmiClient.getInstance(act, true)?.let { client ->
1415
+ client.pickUp()
1416
+ Log.d("PICKUP-FIX", "✅ Successfully answered call immediately")
1417
+ } ?: Log.w("PICKUP-FIX", "⚠️ OmiClient not ready, will auto-answer in getInitialCall()")
1418
+ } catch (e: Exception) {
1419
+ Log.w("PICKUP-FIX", "⚠️ Cannot answer immediately (SDK not ready): ${e.message}. Will auto-answer in getInitialCall()")
1420
+ }
1421
+ }
1422
+ } catch (e: Exception) {
1423
+ Log.e("PICKUP-FIX", "❌ Error in handlePickupIntentEarly: ${e.message}", e)
1424
+ }
1425
+ }
1426
+
1367
1427
  fun onGetIntentFromNotification(
1368
1428
  context: ReactApplicationContext,
1369
1429
  intent: Intent,
@@ -35,7 +35,7 @@ Pod::Spec.new do |s|
35
35
  # Thêm dependency bắt buộc
36
36
  s.dependency "React-Core"
37
37
 
38
- s.dependency "OmiKit", "1.8.45"
38
+ s.dependency "OmiKit", "1.8.47"
39
39
 
40
40
 
41
41
  s.requires_arc = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.20",
3
+ "version": "3.3.22",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",