omikit-plugin 3.3.10 → 3.3.12

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.91"
125
+ api "io.omicrm.vihat:omi-sdk:2.3.92"
126
126
 
127
127
  implementation "com.facebook.react:react-native:+" // From node_modules
128
128
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -79,7 +79,7 @@ object OmiRegistrationStatus {
79
79
  }
80
80
 
81
81
  /**
82
- * Helper functions for parameter validation
82
+ * Helper functions for parameter validation and safe OmiClient access
83
83
  */
84
84
  object ValidationHelper {
85
85
  fun validateRequired(params: Map<String, String?>, promise: Promise): Boolean {
@@ -93,6 +93,24 @@ object ValidationHelper {
93
93
  }
94
94
  return true
95
95
  }
96
+
97
+ /**
98
+ * Safe OmiClient access to prevent crashes during service shutdown
99
+ */
100
+ fun safeOmiClientAccess(context: ReactApplicationContext, action: (OmiClient) -> Unit): Boolean {
101
+ return try {
102
+ val omiClient = OmiClient.getInstance(context)
103
+ if (omiClient != null) {
104
+ action(omiClient)
105
+ true
106
+ } else {
107
+ false
108
+ }
109
+ } catch (e: Exception) {
110
+ Log.e("OMISDK", "Error accessing OmiClient: ${e.message}")
111
+ false
112
+ }
113
+ }
96
114
  }
97
115
 
98
116
  class OmikitPluginModule(reactContext: ReactApplicationContext?) :
@@ -854,32 +872,30 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
854
872
  if (audio == PackageManager.PERMISSION_GRANTED) {
855
873
  mainScope.launch {
856
874
  var callResult: OmiStartCallStatus? = null
857
- withContext(Dispatchers.Default) {
858
- try {
859
- val uuid = data.getString("usrUuid") as String
860
- val isVideo = data.getBoolean("isVideo")
861
-
862
- // Check if OmiClient instance and service are ready before making call
863
- val omiClient = OmiClient.getInstance(reactApplicationContext!!)
864
- if (omiClient == null) {
865
- callResult = null
866
- return@withContext
867
- }
868
-
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 {
869
884
  // Add small delay to ensure service is fully initialized
870
885
  kotlinx.coroutines.delay(100)
871
886
 
887
+ // Call on main thread to avoid PJSIP thread registration issues
872
888
  callResult = omiClient.startCallWithUuid(uuid = uuid, isVideo = isVideo)
873
- } catch (e: IllegalStateException) {
874
- // Handle service not ready state
875
- callResult = null
876
- } catch (e: NullPointerException) {
877
- // Handle null pointer exceptions
878
- callResult = null
879
- } catch (e: Throwable) {
880
- // Handle any other exceptions
881
- callResult = null
882
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
883
899
  }
884
900
  var statusCalltemp = callResult?.ordinal ?: 8
885
901
  map.putInt("status", statusCalltemp)
@@ -922,10 +938,12 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
922
938
 
923
939
  @ReactMethod
924
940
  fun endCall(promise: Promise) {
925
- if (isIncoming && !isAnswerCall) {
926
- OmiClient.getInstance(reactApplicationContext!!).decline()
927
- } else {
928
- OmiClient.getInstance(reactApplicationContext!!).hangUp()
941
+ ValidationHelper.safeOmiClientAccess(reactApplicationContext!!) { omiClient ->
942
+ if (isIncoming && !isAnswerCall) {
943
+ omiClient.decline()
944
+ } else {
945
+ omiClient.hangUp()
946
+ }
929
947
  }
930
948
  promise.resolve(true)
931
949
  }
@@ -935,15 +953,15 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
935
953
  Log.d("OMISDK", "➡️ rejectCall called - isIncoming: $isIncoming, isAnswerCall: $isAnswerCall")
936
954
  if (isIncoming) {
937
955
  Log.d("OMISDK", "📞 Incoming call")
938
-
939
- if (!isAnswerCall) {
940
- Log.d("OMISDK", "🚫 Declining call with declineWithCode(true)")
941
- OmiClient.getInstance(reactApplicationContext!!).declineWithCode(true) // 486 Busy Here
942
- } else {
943
- Log.d("OMISDK", "📴 Call already answered, hanging up")
944
- OmiClient.getInstance(reactApplicationContext!!).hangUp()
956
+ ValidationHelper.safeOmiClientAccess(reactApplicationContext!!) { omiClient ->
957
+ if (!isAnswerCall) {
958
+ Log.d("OMISDK", "🚫 Declining call with declineWithCode(true)")
959
+ omiClient.declineWithCode(true) // 486 Busy Here
960
+ } else {
961
+ Log.d("OMISDK", "📴 Call already answered, hanging up")
962
+ omiClient.hangUp()
963
+ }
945
964
  }
946
-
947
965
  promise.resolve(true)
948
966
  } else {
949
967
  Log.d("OMISDK", "📤 Not incoming call, skipping reject")
@@ -953,10 +971,12 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
953
971
 
954
972
  @ReactMethod
955
973
  fun dropCall(promise: Promise) {
956
- if (isIncoming && !isAnswerCall) {
957
- OmiClient.getInstance(reactApplicationContext!!).declineWithCode(false) // 603
958
- } else {
959
- OmiClient.getInstance(reactApplicationContext!!).hangUp()
974
+ ValidationHelper.safeOmiClientAccess(reactApplicationContext!!) { omiClient ->
975
+ if (isIncoming && !isAnswerCall) {
976
+ omiClient.declineWithCode(false) // 603
977
+ } else {
978
+ omiClient.hangUp()
979
+ }
960
980
  }
961
981
  promise.resolve(true)
962
982
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.10",
3
+ "version": "3.3.12",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",