Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-android-sinch

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-android-sinch

react native android module for sinch flash call

  • 1.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-75%
Maintainers
2
Weekly downloads
 
Created
Source

react-native-android-sinch

React Native Android module for Sinch Flash Call

Installation

npm install react-native-android-sinch
yarn add react-native-android-sinch

Sinch version

com.sinch.android.sdk.verification:verification-flashcall:2.1.14

Note

The android.permission.INTERNET permission is required for the Verification SDK to work. 
To handle flash call verification automatically android.permission.READ_CALL_LOG is needed.
In case of seamless method SDK needs android.permission.
CHANGE_NETWORK_STATE to be able to automatically switch to mobile data for API calls connected with the verification process. 
Additionally, SDK collects phone metadata information connected with sim cards or phone software version, 
which are then used to handle early verification rejection rules. 
For this module to be fully functional android.permission.ACCESS_NETWORK_STATE and android.permission.READ_PHONE_STATE should be granted. 
These permissions however are not essential.

Usage

Importing the Module

import SinchFlashCall, { PermissionStatus, VerificationMethodType } from 'react-native-android-sinch';

Requesting Permissions

You need to request necessary permissions for the module to function properly. Here are the methods to request individual permissions and essential permissions.

// Request individual permissions
const requestInternetPermission = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestInternetPermission();
  console.log('Internet Permission:', status);
};

const requestReadCallLogPermission = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestReadCallLogPermission();
  console.log('Read Call Log Permission:', status);
};

const requestChangeNetworkStatePermission = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestChangeNetworkStatePermission();
  console.log('Change Network State Permission:', status);
};

const requestAccessNetworkStatePermission = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestAccessNetworkStatePermission();
  console.log('Access Network State Permission:', status);
};

const requestReadPhoneStatePermission = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestReadPhoneStatePermission();
  console.log('Read Phone State Permission:', status);
};

// Request essential permissions
/**
 * @description Request essential permissions for the app to function properly.
 * This includes:
 * - Manifest.permission.READ_PHONE_STATE
 * - Manifest.permission.ACCESS_NETWORK_STATE
 * - Manifest.permission.READ_CALL_LOG
 * - Manifest.permission.INTERNET
 */
const requestEssentialPermissions = async () => {
  const status: PermissionStatus = await SinchFlashCall.requestEssentialPermissions();
  console.log('Essential Permissions:', status);
};

// Example usage
requestInternetPermission();
requestReadCallLogPermission();
requestChangeNetworkStatePermission();
requestAccessNetworkStatePermission();
requestReadPhoneStatePermission();
requestEssentialPermissions();

Initializing Verification

Ensure that the phone number is in E.164 format. The essential permissions should be requested before calling this function.

const initVerification = async () => {
  try {
    const result = await SinchFlashCall.initVerification('+12051111111', 'appKeyValue', 'appSecret');
    console.log('Verification initiated:', result);
  } catch (error) {
    console.error('Verification initiation error:', error);
  }
};

// Example usage
initVerification();

Verifying Code

If the SDK fails to intercept the call automatically, you can verify the code manually using the received call number.

const verifyCode = async (code, methodType) => {
  try {
    const result = await SinchFlashCall.verifyCode(code, methodType);
    console.log('Code verified:', result);
  } catch (error) {
    console.error('Verify code error:', error);
  }
};

// Example usage
verifyCode('12345', 'FLASHCALL');

Stopping Verification

Stop the ongoing verification process if needed.

const stopVerification = async () => {
  try {
    const result = await SinchFlashCall.stopVerification();
    console.log('Verification stopped:', result);
  } catch (error) {
    console.error('Stop verification error:', error);
  }
};

// Example usage
stopVerification();

Getting the Last Call Number from Call Log

Retrieve the last call number from the call log to use in manual verification.

const getLastCallNumberFromCallLog = async () => {
  try {
    const number = await SinchFlashCall.getLastCallNumberFromCallLog();
    console.log('Last call number:', number);
  } catch (error) {
    console.error('Get last call number error:', error);
  }
};

// Example usage
getLastCallNumberFromCallLog();

Adding Event Listeners

Subscribe to events during the verification process.

const addListener = () => {
  SinchFlashCall.addListener("verificationSuccess", (data) => {
    console.log("verificationSuccess", data);
  });
  
  SinchFlashCall.addListener("verificationFailed", (data) => {
    console.log("verificationFailed", data);
  });
};

// Example usage
addListener();

Removing Event Listeners

Remove event listeners when they are no longer needed.

const removeListener = () => {
  SinchFlashCall.removeListener("verificationSuccess");
  SinchFlashCall.removeListener("verificationFailed");
};

// Example usage
removeListener();

Removing All Event Listeners

Remove all event listeners at once.

const removeAllListeners = () => {
  SinchFlashCall.removeAllListeners();
};

// Example usage
removeAllListeners();

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library


Keywords

FAQs

Package last updated on 11 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc