npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@huddle01/react-native-call-detection

v0.0.2

Published

Get different phone call states for iOS and Android along with incoming phone number(just for android)

Downloads

20

Readme

React Native Call Detection 🎉 🎊

npm version

This package helps to detect different call states like Incoming, Disconnected, Dialing and Connected for iOS. For android, this package will give following states, Offhook, Incoming, Disconnected and Missed. In the case of Incoming for android, the package will also provide with the incoming phone number.

Installation

Add the package to your react-native project in the following way

yarn add react-native-call-detection

Integrate into an Expo managed project

  1. Install expo-dev-client:
expo install expo-dev-client
  1. Add react-native-call-detection into the plugins array inside the app.json file of your app:
"plugins": [
  ["react-native-call-detection"],
],

For Android:-

Autolinking should work without manual changes

Usage

There are different hooks that you may get depending on the platform. Since for android you could also request the package to provide you with phone number of the caller, you will have to provide the necessary request message and the corresponding error callback. The package will request for READ_PHONE_STATE permission in android.

Its really easy to setup the package. Have a look at the following code snippet

import CallDetectorManager from 'react-native-call-detection'

startListenerTapped() {
	this.callDetector = new CallDetectorManager((event, phoneNumber)=> {
	// For iOS event will be either "Connected",
	// "Disconnected","Dialing" and "Incoming"

	// For Android event will be either "Offhook",
	// "Disconnected", "Incoming" or "Missed"
	// phoneNumber should store caller/called number


	if (event === 'Disconnected') {
	// Do something call got disconnected
	}
	else if (event === 'Connected') {
	// Do something call got connected
	// This clause will only be executed for iOS
	}
	else if (event === 'Incoming') {
	// Do something call got incoming
	}
	else if (event === 'Dialing') {
	// Do something call got dialing
	// This clause will only be executed for iOS
	}
	else if (event === 'Offhook') {
	//Device call state: Off-hook.
	// At least one call exists that is dialing,
	// active, or on hold,
	// and no calls are ringing or waiting.
	// This clause will only be executed for Android
	}
	else if (event === 'Missed') {
    	// Do something call got missed
    	// This clause will only be executed for Android
  }
},
false, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
()=>{}, // callback if your permission got denied [ANDROID] [only if you want to read incoming number] default: console.error
{
title: 'Phone State Permission',
message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
} // a custom permission request message to explain to your user, why you need the permission [recommended] - this is the default one
)
}

stopListenerTapped() {
	this.callDetector && this.callDetector.dispose();
}

Dont forget to call dispose when you don't intend to use call detection, as it will avoid memory leakages.

Example project can be used to test out the package. In the example project update the HomeComponent.js with the phone number to call

  callFriendTapped() {
  // Add the telephone num to call
    Linking.openURL('tel:5555555555')
      .catch(err => {
        console.log(err)
      });
  }

How to run an example

  1. Install node and watchman

    brew install node
    brew install watchman
    
  2. yarn

    Install yarn from npm.

     npm i -g yarn
  3. Xcode

    Install it from the App Store.

  4. React Native Debugger

    This is an electron app that bundles react devtools, redux devtools and chrome devtools configured for use with react-native.

     brew cask install react-native-debugger
  5. Once you have done all the above steps, navigate to CallDetectionExample folder and run yarn or npm install, it will fetch all the dependencies in the node_modules folder.

  6. Run the packager npm start

  7. Update the mobile number of your friend in HomeComponent.js

     callFriendTapped() {
     // Add the telephone number
    	Linking.openURL('tel:5555555555')
      .catch(err => {
        console.log(err)
      });
     }
    
  8. To run the example on iOS from terminal type react-native run-ios (This will open the simulator, since simulator doesnt have the support for calling I will advice you to connect your iOS device and the follow the below procedure for running the app through xcode)

    or you can also run the app from xcode, for that, open /CallDectionExample/ios/CallDetectionExample.xcodeproj in xcode and run on the device.

  9. To run the example on android, connect any android device to your mac then follow the below steps

    1. Navigate to android folder(./CallDectionExample/android/) folder and then run adb reverse tcp:8081 tcp:8081
    2. Navigate back to example directory(CallDectionExample) and then run react-native run-android

For any problems and doubt raise an issue.