omikit-plugin 3.3.7 β†’ 3.3.8

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.
Files changed (2) hide show
  1. package/README.md +130 -166
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -570,6 +570,7 @@ We support 2 environments. So you need set correct key in Appdelegate.
570
570
  ```
571
571
  -Android:
572
572
  + PERMISSIONS.ANDROID.RECORD_AUDIO
573
+ + PERMISSIONS.ANDROID.POST_NOTIFICATIONS
573
574
  + PERMISSIONS.ANDROID.CALL_PHONE
574
575
  + PERMISSIONS.ANDROID.CAMERA; (if you want to make Video calls)
575
576
 
@@ -579,60 +580,34 @@ We support 2 environments. So you need set correct key in Appdelegate.
579
580
 
580
581
  ```
581
582
 
582
- ### πŸ”₯ **Android 15+ Permission Management**
583
+ ### πŸ”₯ **Android Permission Management**
583
584
 
584
- **πŸ“Œ For Android 15+ (SDK 35+), additional permissions are required:**
585
+ **πŸ“Œ For Android (SDK), additional permissions are required:**
586
+
587
+ πŸ”₯ Notes:
588
+
589
+ β€’ POST_NOTIFICATIONS and RECORD_AUDIO must be requested at runtime in your code.
590
+
591
+ β€’ FOREGROUND_SERVICE* permissions only need to be declared in the manifest; Android will enforce them automatically when you call startForegroundService().
585
592
 
586
593
  ```xml
587
- <!-- Required in AndroidManifest.xml -->
594
+ <!-- Runtime permissions -->
588
595
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
596
+ <uses-permission android:name="android.permission.RECORD_AUDIO"/>
597
+
598
+ <!-- Foreground service permissions (manifest only, no runtime request needed) -->
599
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
589
600
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
590
601
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL"/>
591
- ```
592
-
593
- **πŸ“Œ Built-in Permission Functions:**
594
-
595
- βœ… **checkPermissionStatus()** - Check current permission status:
596
- ```javascript
597
- import { checkPermissionStatus } from 'omikit-plugin';
598
-
599
- const permissionStatus = await checkPermissionStatus();
600
- console.log(permissionStatus);
601
- // Output: { essentialGranted: [...], essentialMissing: [...], canMakeVoipCalls: true/false }
602
- ```
603
-
604
- βœ… **checkAndRequestPermissions()** - Request all necessary permissions:
605
- ```javascript
606
- import { checkAndRequestPermissions } from 'omikit-plugin';
607
-
608
- const isVideo = true; // Set to true if video call permissions needed
609
- const permissionsGranted = await checkAndRequestPermissions(isVideo);
610
- if (permissionsGranted) {
611
- console.log('All permissions granted!');
612
- }
613
- ```
614
-
615
- βœ… **requestPermissionsByCodes()** - Request specific permissions by error codes:
616
- ```javascript
617
- import { requestPermissionsByCodes } from 'omikit-plugin';
618
-
619
- // Request specific permissions based on error codes from OmiSDK
620
- const codes = [450, 451, 452]; // Permission error codes
621
- const result = await requestPermissionsByCodes(codes);
622
-
623
- /*
624
- Permission Code Mapping:
625
- - 450: RECORD_AUDIO permission (Android 14+)
626
- - 451: FOREGROUND_SERVICE permissions (Android 14+)
627
- - 452: POST_NOTIFICATIONS permission (Android 13+)
628
- */
629
- ```
602
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" tools:node="remove" />
630
603
 
631
- **πŸ“Œ System Alert Window Permission:**
632
- ```javascript
633
- import { requestSystemAlertWindowPermission } from 'omikit-plugin';
604
+ <service
605
+ android:name="net.gotev.sipservice.SipService"
606
+ android:foregroundServiceType="phoneCall|microphone"
607
+ tools:replace="android:foregroundServiceType"
608
+ android:exported="false"
609
+ />
634
610
 
635
- const canDrawOverlays = await requestSystemAlertWindowPermission();
636
611
  ```
637
612
 
638
613
  - βœ… Set up <a href="https://rnfirebase.io/messaging/usage">Cloud Messaging</a> plugin:
@@ -666,6 +641,69 @@ startServices();
666
641
 
667
642
  *Add the following code to the root file of your application, such as `App.js` or `index.js`*
668
643
 
644
+
645
+ πŸ“Œ **requestLoginPermissions()**
646
+
647
+ `Note`: Starting from Android 13+, certain foreground services (such as microphone or phone call) require explicit user permission before they can be started.
648
+ This means the user must grant these permissions before initiating a call or any service that relies on them.
649
+
650
+ ```TypeScript
651
+ import {
652
+ PERMISSIONS,
653
+ request,
654
+ check,
655
+ RESULTS,
656
+ requestMultiple
657
+ } from 'react-native-permissions';
658
+ import { Platform } from 'react-native';
659
+
660
+ export async function requestLoginPermissions(): Promise<boolean> {
661
+ if (Platform.OS !== 'android') return true;
662
+
663
+ const permissions: string[] = [];
664
+
665
+ // Android 13+ cαΊ§n POST_NOTIFICATIONS
666
+ if (Platform.Version >= 33) {
667
+ permissions.push(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
668
+ }
669
+
670
+ // Android 14+ vΓ  15+ cαΊ§n RECORD_AUDIO trΖ°α»›c khi start foreground service
671
+ permissions.push(PERMISSIONS.ANDROID.RECORD_AUDIO);
672
+
673
+ const statuses = await requestMultiple(permissions);
674
+
675
+ // Check kαΊΏt quαΊ£
676
+ const allGranted = Object.values(statuses).every(
677
+ status => status === RESULTS.GRANTED
678
+ );
679
+
680
+ if (!allGranted) {
681
+ console.warn('❌ Some required permissions were not granted');
682
+ return false;
683
+ }
684
+
685
+ console.log('βœ… All required permissions granted');
686
+ return true;
687
+ }
688
+ ```
689
+
690
+ Example: use func `requestLoginPermissions()`
691
+
692
+ ```TypeScript
693
+ async function handleLogin() {
694
+ const ok = await requestLoginPermissions();
695
+ if (!ok) {
696
+ // Block login, show alert
697
+ return;
698
+ }
699
+
700
+ // βœ… Safe để start service login
701
+ // initCallWithApiKey();
702
+ initCallWithUserPassword()
703
+ }
704
+ ```
705
+
706
+
669
707
  πŸ“Œ **initCallWithApiKey()**
670
708
 
671
709
  πŸ“ Notes: The information below is taken from the API, you should connect with our Technical team for support
@@ -745,65 +783,52 @@ const loginInfo = {
745
783
  };
746
784
 
747
785
  // Initialize call functionality using username and password authentication
748
- const result = await initCallWithUserPassword(loginInfo);
749
-
786
+ initCallWithUserPassword(loginInfo)
787
+ .then(result => {
788
+ console.log('initCallWithUserPassword success:', result);
750
789
 
751
- /* ❌ ❌ NOTE: Please check the user information again, if the object is not empty then you have successfully logged in.
790
+ if (result) {
791
+ // βœ… Login OMI Success
792
+ /* ❌ ❌ NOTE: Please check the user information again, if the object is not empty then you have successfully logged in.
752
793
  Otherwise, if you have not successfully logged in, you should not navigate to the call screen. When startCall with empty information, it may crash your application or not be clear when receiving the startCall error ❌❌*/
753
-
754
- // Example:
755
-
756
- if (result){
757
- const infoUser = await getCurrentUser()
758
- if (infoUser != null && Object.keys(infoUser).length > 0) {
759
- // βœ… Login OMI Success
760
- // Can navigate to call screen or start call πŸš€ πŸš€
761
- }
762
- }
763
- ```
764
-
765
- πŸ“Œ **checkCredentials()** *(OmiSDK 2.3.67+)*
766
-
767
- βœ… Description: Check credentials without maintaining connection. Useful for validating login information before actual registration.
768
-
769
- ```javascript
770
- import { checkCredentials } from 'omikit-plugin';
771
-
772
- const loginInfo = {
773
- userName: "your_username",
774
- password: "your_password",
775
- realm: "your_realm",
776
- fcmToken: "your_fcm_token",
777
- projectId: "your_project_id"
778
- };
779
-
780
- const result = await checkCredentials(loginInfo);
781
- console.log(result);
782
- // Output: { success: true/false, statusCode: number, message: string }
783
- ```
784
-
785
- πŸ“Œ **registerWithOptions()** *(OmiSDK 2.3.67+)*
786
-
787
- βœ… Description: Register with full control over notification and auto-unregister behavior.
788
-
789
- ```javascript
790
- import { registerWithOptions } from 'omikit-plugin';
791
-
792
- const loginInfo = {
793
- userName: "your_username",
794
- password: "your_password",
795
- realm: "your_realm",
796
- isVideo: true,
797
- fcmToken: "your_fcm_token",
798
- projectId: "your_project_id",
799
- showNotification: false, // Control notification display
800
- enableAutoUnregister: false // Control auto-unregister behavior
801
- };
802
-
803
- const result = await registerWithOptions(loginInfo);
804
- console.log(result);
805
- // Output: { success: true/false, statusCode: number, message: string }
806
- ```
794
+ const infoUser = await getCurrentUser()
795
+ if (infoUser != null && Object.keys(infoUser).length > 0) {
796
+ // βœ… Login OMI Success
797
+ // Can navigate to call screen or start call πŸš€ πŸš€
798
+ }
799
+ }
800
+ })
801
+ .catch(error => {
802
+ // You can log error and check cause error
803
+ console.error('initCallWithUserPassword error:', error?.code, error?.message);
804
+ if (error?.code === 'ERROR_MISSING_RECORD_AUDIO') { // Please request permission audio
805
+ requestPermission();
806
+ }
807
+ })
808
+ .finally(() => {
809
+ // Doing something
810
+ // setLoading(false);
811
+ });
812
+ ```
813
+ πŸ“ **Detailed Description of Possible Errors(error?.code)**
814
+
815
+ | **Message** | **Description** | **Next Action** |
816
+ |------------------------------------|---------------------------------------------------------------------------------|----------------------------
817
+ | `ERROR_MISSING_PARAMETERS` | Missing required parameters. Please check your configuration. | Verify all required fields are provided |
818
+ | `ERROR_INVALID_CREDENTIALS` | Invalid credentials. Please check username/password. | Double-check login info |
819
+ | `ERROR_FORBIDDEN` | Access denied. Check realm/domain permissions. | Confirm account permissions with provider |
820
+ | `ERROR_REALM_NOT_FOUND` | Realm not found. Check configuration. | Ensure realm/domain is correct |
821
+ | `ERROR_TIMEOUT` | Connection timeout | Retry with stable network |
822
+ | `ERROR_MISSING_RECORD_AUDIO` | RECORD_AUDIO permission required for Android 14+ | Ask user to grant microphone permission |
823
+ | `ERROR_MISSING_FOREGROUND_SERVICE` | FOREGROUND_SERVICE permission required | Request foreground service permission before starting service |
824
+ | `ERROR_MISSING_POST_NOTIFICATIONS` | POST_NOTIFICATIONS permission required for Android 13+ | Request notification permission before registering |
825
+ | `ERROR_SERVICE_START_FAILED` | Failed to start SIP service | Check logs and required permissions |
826
+ | `ERROR_SERVICE_NOT_AVAILABLE` | SIP service not available | Ensure service is running |
827
+ | `ERROR_SERVICE_DEGRADED` | Service degraded - may miss calls when app killed | Keep app in foreground or request proper permissions |
828
+ | `ERROR_SERVICE_UNAVAILABLE` | Service temporarily unavailable | Try again later |
829
+ | `ERROR_NETWORK_UNAVAILABLE` | Network unavailable | Check network connection |
830
+ | `ERROR_CONNECTION_TIMEOUT` | Connection timeout | Verify network and server availability |
831
+ | `ERROR_UNKNOWN` | Unknown error occurred | Check logs and report issue |
807
832
 
808
833
  πŸ“Œ **configPushNotification()**
809
834
 
@@ -825,8 +850,8 @@ configPushNotification({
825
850
  missedCallTitle: "Cuα»™c gọi nhα»‘", // Title for missed call notifications
826
851
  userNameKey: "uuid", // User identification key: options are "uuid", "full_name", or "extension"
827
852
  channelId: "com.channel.sample", // Custom notification channel ID for Android
828
- audioNotificationDescription: "", // Description for audio call notifications
829
- videoNotificationDescription: "", // Description for video call notifications
853
+ audioNotificationDescription: "Cuα»™c gọi audio", // Description for audio call notifications
854
+ videoNotificationDescription: "Cuα»™c gọi video", // Description for video call notifications
830
855
  representName: "", // Representative name to display for all incoming calls (e.g., business name)
831
856
  isUserBusy: true // By default, it is set to true. The Omicall system will continue ringing the next user if isUserBusy is true. If it is false, the call will be immediately terminated, assuming the call scenario is based on a criteria-based routing.
832
857
  });
@@ -1111,39 +1136,6 @@ const result = await startCallWithUuid({
1111
1136
  logout();
1112
1137
  ```
1113
1138
 
1114
- πŸ“Œ **hideSystemNotificationSafely()** *(OmiSDK 2.3.67+)*
1115
-
1116
- βœ… Description: Safely hide system notification and unregister after a delay.
1117
-
1118
- ```javascript
1119
- import { hideSystemNotificationSafely } from 'omikit-plugin';
1120
-
1121
- const success = await hideSystemNotificationSafely();
1122
- // Hides notification and unregisters after 2 seconds
1123
- ```
1124
-
1125
- πŸ“Œ **hideSystemNotificationOnly()** *(OmiSDK 2.3.67+)*
1126
-
1127
- βœ… Description: Hide system notification only, without unregistering.
1128
-
1129
- ```javascript
1130
- import { hideSystemNotificationOnly } from 'omikit-plugin';
1131
-
1132
- const success = await hideSystemNotificationOnly();
1133
- // Keeps registration active but hides notification
1134
- ```
1135
-
1136
- πŸ“Œ **hideSystemNotificationAndUnregister()** *(OmiSDK 2.3.67+)*
1137
-
1138
- βœ… Description: Hide notification and unregister with custom reason.
1139
-
1140
- ```javascript
1141
- import { hideSystemNotificationAndUnregister } from 'omikit-plugin';
1142
-
1143
- const success = await hideSystemNotificationAndUnregister("User logout");
1144
- // Hides notification and unregisters immediately with reason
1145
- ```
1146
-
1147
1139
  πŸ“Œ **systemAlertWindow()**
1148
1140
 
1149
1141
  βœ… Description: Check system alert window permission (only Android).
@@ -1428,34 +1420,6 @@ const onSwitchboardAnswer = (data: any) => {
1428
1420
  | `864` | Temporary block on Mobifone direction, please try again |
1429
1421
  | `865` | he advertising number is currently outside the permitted calling hours, please try again later |
1430
1422
 
1431
- # πŸ”₯ Android 15+ Compatibility Features
1432
-
1433
- ## ✨ New in Version 3.3.5+
1434
-
1435
- ### **Enhanced Permission Management**
1436
- - **Full Android 15 (SDK 35+) Support**: Automatic handling of new foreground service permissions
1437
- - **Smart Permission Requests**: Built-in functions to request specific permissions by error codes
1438
- - **Comprehensive Status Checking**: Real-time permission status monitoring
1439
- - **Version-Aware Logic**: Automatically handles Android version differences
1440
-
1441
- ### **Advanced Registration Options** *(OmiSDK 2.3.67+)*
1442
- - **Silent Registration**: Register without notifications or auto-unregister
1443
- - **Credential Validation**: Check login credentials without connecting
1444
- - **Custom Registration**: Full control over notification and unregister behavior
1445
- - **Notification Management**: Fine-grained control over system notifications
1446
-
1447
- ### **Error Code Mapping**
1448
- Complete mapping of OmiSDK status codes to user-friendly error messages:
1449
- - **450**: RECORD_AUDIO permission required for Android 14+
1450
- - **451**: FOREGROUND_SERVICE permission required
1451
- - **452**: POST_NOTIFICATIONS permission required for Android 13+
1452
- - **500-600**: Service and network error handling
1453
- - **Detailed Messages**: Customer-friendly error descriptions for easier integration
1454
-
1455
- ### **Development Workflow**
1456
- - **copy_dev.sh**: Efficient development workflow for testing native code changes
1457
- - **Automatic Build Fixes**: Handles gradle namespace issues automatically
1458
- - **Hot Reload**: Quick testing without npm publishing
1459
1423
 
1460
1424
  ### **Breaking Changes**
1461
1425
  - **Android 15+ Support**: Requires additional permissions in AndroidManifest.xml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omikit-plugin",
3
- "version": "3.3.7",
3
+ "version": "3.3.8",
4
4
  "description": "Omikit Plugin by ViHAT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",