omikit-plugin 3.3.9 → 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.90"
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,18 +872,32 @@ 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")
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)
861
886
 
862
- callResult = OmiClient.getInstance(reactApplicationContext!!)
863
- .startCallWithUuid(uuid = uuid, isVideo = isVideo)
864
- } catch (_: Throwable) {
865
-
887
+ // Call on main thread to avoid PJSIP thread registration issues
888
+ callResult = omiClient.startCallWithUuid(uuid = uuid, isVideo = isVideo)
866
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
867
899
  }
868
- var statusCalltemp = callResult?.ordinal ?: 7
900
+ var statusCalltemp = callResult?.ordinal ?: 8
869
901
  map.putInt("status", statusCalltemp)
870
902
  map.putString("_id", "")
871
903
  map.putString("message", messageCall(statusCalltemp) as String)
@@ -906,10 +938,12 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
906
938
 
907
939
  @ReactMethod
908
940
  fun endCall(promise: Promise) {
909
- if (isIncoming && !isAnswerCall) {
910
- OmiClient.getInstance(reactApplicationContext!!).decline()
911
- } else {
912
- OmiClient.getInstance(reactApplicationContext!!).hangUp()
941
+ ValidationHelper.safeOmiClientAccess(reactApplicationContext!!) { omiClient ->
942
+ if (isIncoming && !isAnswerCall) {
943
+ omiClient.decline()
944
+ } else {
945
+ omiClient.hangUp()
946
+ }
913
947
  }
914
948
  promise.resolve(true)
915
949
  }
@@ -919,15 +953,15 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
919
953
  Log.d("OMISDK", "➡️ rejectCall called - isIncoming: $isIncoming, isAnswerCall: $isAnswerCall")
920
954
  if (isIncoming) {
921
955
  Log.d("OMISDK", "📞 Incoming call")
922
-
923
- if (!isAnswerCall) {
924
- Log.d("OMISDK", "🚫 Declining call with declineWithCode(true)")
925
- OmiClient.getInstance(reactApplicationContext!!).declineWithCode(true) // 486 Busy Here
926
- } else {
927
- Log.d("OMISDK", "📴 Call already answered, hanging up")
928
- 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
+ }
929
964
  }
930
-
931
965
  promise.resolve(true)
932
966
  } else {
933
967
  Log.d("OMISDK", "📤 Not incoming call, skipping reject")
@@ -937,10 +971,12 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
937
971
 
938
972
  @ReactMethod
939
973
  fun dropCall(promise: Promise) {
940
- if (isIncoming && !isAnswerCall) {
941
- OmiClient.getInstance(reactApplicationContext!!).declineWithCode(false) // 603
942
- } else {
943
- OmiClient.getInstance(reactApplicationContext!!).hangUp()
974
+ ValidationHelper.safeOmiClientAccess(reactApplicationContext!!) { omiClient ->
975
+ if (isIncoming && !isAnswerCall) {
976
+ omiClient.declineWithCode(false) // 603
977
+ } else {
978
+ omiClient.hangUp()
979
+ }
944
980
  }
945
981
  promise.resolve(true)
946
982
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.9",
3
+ "version": "3.3.12",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",