GithubHelp home page GithubHelp logo

bkdev98 / react-native-incoming-call Goto Github PK

View Code? Open in Web Editor NEW
66.0 5.0 61.0 4.31 MB

React Native module to display custom incoming call activity for Android, since iOS we have VoIP.

Java 54.02% JavaScript 22.32% Starlark 1.38% Ruby 12.27% Objective-C 10.02%
react-native-callkeep firebase-messaging voip opentok-sdk

react-native-incoming-call's Introduction

RN Incoming Call Version 2

React Native module to display custom incoming call activity, best result when using with firebase background messaging. Only for Android since iOS we have VoIP.

Yes I heard you could use self managed ConnectionService thing. But since I'm not an Android expert, this is a solution I found acceptable.

You could also wait for this feature request from react-native-callkeep to be resolved and have an easier life.

Version 2 Breaking Changes

Hello there! It's been a while since I first public version 1 of this library, which contains some bugs that I don't have much time to fix.

Luckily I got a client project which needs this feature again and now I have time to improve it and make sure all major features work. So here is most of it I guess:

  • More generic incoming call UI.

  • Work nicely with all application state (foreground, background, killed, locked).

  • More flexible APIs.

Thanks to jpudysz's folk of react-native-callkeep, version 2 is heavily depended on it.

Migrate from v1

  • getLaunchParameters() & clearLaunchParameters() is now replaced by openAppFromHeadlessMode() & getExtrasFromHeadlessMode().

  • Answer calls from background / killed state no longer open app and send launchParams, you need to listen to answerCall event from headless job and trigger backToForeground or openAppFromHeadlessMode manually.

Getting started

$ npm install react-native-incoming-call --save

or

$ yarn add react-native-incoming-call

Addition installation step

In AndroidManifest.xml:

  • Add <activity android:name="com.incomingcall.UnlockScreenActivity" /> line between <application> tag.

  • Add <uses-permission android:name="android.permission.VIBRATE" /> permission.

  • Also, it's recommend to put android:launchMode="singleInstance" in <activity android:name=".MainActivity"... tag to prevent duplicate activities.

For RN >= 0.60, it's done. Otherwise:

$ react-native link react-native-incoming-call

Usage

In App.js:

import {useEffect} from 'react';
import {DeviceEventEmitter, Platform} from 'react-native';
import IncomingCall from 'react-native-incoming-call';

// Listen to cancel and answer call events
useEffect(() => {
  if (Platform.OS === "android") {
    /**
     * App open from killed state (headless mode)
    */
    const payload = await IncomingCall.getExtrasFromHeadlessMode();
    console.log('launchParameters', payload);
    if (payload) {
      // Start call action here. You probably want to navigate to some CallRoom screen with the payload.uuid.
    }

    /**
     * App in foreground / background: listen to call events and determine what to do next
    */
    DeviceEventEmitter.addListener("endCall", payload => {
      // End call action here
    });
    DeviceEventEmitter.addListener("answerCall", payload => {
      // Start call action here. You probably want to navigate to some CallRoom screen with the payload.uuid.
    });
  }
}, []);

In index.js or anywhere firebase background handler lies:

import messaging from '@react-native-firebase/messaging';
import {DeviceEventEmitter} from 'react-native';
import IncomingCall from 'react-native-incoming-call';

messaging().setBackgroundMessageHandler(async remoteMessage => {
  // Receive remote message
  if (remoteMessage?.notification?.title === 'Incoming Call') {
    // Display incoming call activity.
    IncomingCall.display(
      'callUUIDv4', // Call UUID v4
      'Quocs', // Username
      'https://avatars3.githubusercontent.com/u/16166195', // Avatar URL
      'Incomming Call', // Info text
      20000 // Timeout for end call after 20s
    );
  } else if (remoteMessage?.notification?.title === 'Missed Call') {
    // Terminate incoming activity. Should be called when call expired.
    IncomingCall.dismiss();
  }

  // Listen to headless action events
  DeviceEventEmitter.addListener("endCall", payload => {
    // End call action here
  });
  DeviceEventEmitter.addListener("answerCall", (payload) => {
    console.log('answerCall', payload);
    if (payload.isHeadless) {
      // Called from killed state
      IncomingCall.openAppFromHeadlessMode(payload.uuid);
    } else {
      // Called from background state
      IncomingCall.backToForeground();
    }
  });
});

Well-known issues

Incoming screen not show on android > 9:

You need to turn on autostart and display pop-up windows permissions manually. I'm searching for a better solution.

No vibration when screen locked:

PR is welcomed! ๐Ÿ˜‚

License

This project is licensed under the MIT License.

[email protected]

react-native-incoming-call's People

Contributors

bkdev98 avatar icc-guerrero avatar tientruongvan1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-incoming-call's Issues

Ringtone only in the first call

I knew this issue is closed but I am still facing the issue please check that once

I am Using version 2.0.3 and facing same issue can anybody help me

"react-native-incoming-call": "^2.0.3",

Here is a previous issue link

#18

Ringtone only in the first call

I have an issue with the ringtone sound. It's only working during the first call. Anyone else?

Update:

It seems that the MediaPlayerNative is not properly initialised after being stopped. This is reported by logcat:

2021-04-20 17:09:35.359 20455-20455/com.myapp E/MediaPlayerNative: stop called in state 0, mPlayer(0x761ff6e880)
2021-04-20 17:09:35.359 20455-20455/com.myapp E/MediaPlayerNative: error (-38, 0)
2021-04-20 17:09:35.360 20455-20806/com.myapp E/MediaPlayer: Error (-38,0)

More info here: https://stackoverflow.com/questions/9008770/media-player-called-in-state-0-error-38-0

Your new version crashed

E/unknown:ReactNative: CatalystInstanceImpl caught native exception
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.finish()' on a null object reference
at com.incomingcall.UnlockScreenActivity.dismissIncoming(UnlockScreenActivity.java:137)
at com.incomingcall.IncomingCallModule.dismiss(IncomingCallModule.java:77)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:224)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:919)

Incoming call screen is not opening from background push listener.

When app is in foreground IncomingCall.display(id, "Toothie", "test"); is working properly.

But when app is in background incoming call screen is not showing. I am getting the push in background and log is printing.
I am using the react-native-notifications library to receive push.

Notifications.events().registerNotificationReceivedBackground(
(notification,completion) => {
const { title, body } = notification.payload;
console.log("Android push notification received in background", notification, title, body);
const id = uuid()
IncomingCall.display(id, "Toothie", "test");
});

the console log is getting print when push is coming in the background. but incoming call is not showing.

Start activity from background message

Hello,

thanks for this module, it's the only one I was able to use successfully. I'm using Firebase to send a notification to the app, that part is working fine, I can see the incoming message (foreground / background) etc. I'm able to start IncomingCall from foreground but it doesn't want to trigger from the background handler. This is my code:

messaging().setBackgroundMessageHandler(async remoteMessage => {      
  console.log('Message handled in the background!', remoteMessage); 
  // Display incoming call activity
  IncomingCall.display('123123', 'caller ID');  
});

I can see the log entry for the incoming message so the handler is correctly set up I think. But the call doesn't appear on the device. I might be missing something obvious, could you please help?

Thanks

Call screen keeps running until any action is taken

There should be a time limit until which the call screen will be shown. After that, it will disappear. I tried to set a timeout function with IncomingCall.dismiss() but it doesn't work.
Please help me to solve this issue

Incoming.dismiss() is not defined

Hi,
Based on the newly merged code from your source. I think you removed dismiss function. So when I call it from FE, it shows error dismiss is not defined. Can you check that again?

Fix Invoke App From Background Android 10

Hello there,, thanks for the library,, it working awesome for incoming call screen,.
I found solution for your problems, to invoke incoming call screen from locked screen in android 10, you could use full screen intent, i use it with voximplant library and it works with locked screen and killed state app,
You can follow this:
https://github.com/voximplant/android-demos/tree/master/audiocall
and using the notificationhelper.java in this link:
https://github.com/voximplant/android-demos/blob/master/audiocall/src/main/java/com/voximplant/demos/audiocall/utils/NotificationHelper.java
And also use foreground service check in those repo,.
Since I'm not android expert and new in RN so I could not make PR for this case,.

Hope this information can help you,.

Regards,
Naufan harish

Incompatible version

hello
Thank for your package, i try to setup in projet with last version of react-native, but it is incompatible

 Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"17.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.1" from [email protected]
npm ERR! node_modules/react-native-incoming-call
npm ERR!   react-native-incoming-call@"*" from the root project

If a force install, i get error with maven

BUILD FAILED in 11s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/b.gauthier/Documents/projects.apps/Wisper/node_modules/react-native-incoming-call-android/android/build.gradle' line: 23

* What went wrong:
A problem occurred evaluating project ':react-native-incoming-call-android'.
> Plugin with id 'maven' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':react-native-incoming-call-android'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

Can you help me please ?

Thank !

How to open MainActivity instead of UnlockScreenActivity

In the current version, UnlockScreenActivity pops up when a call comes in while the app is in the background.
But I want the default MainActivity to be launched, not the UnlockScreenActivity.
In that case, it seems that the incoming screen can be customized with RN javascript code.
How can I make MainActivity run instead of UnlockScreenActivity?

Access in Native Code

Hello, I am trying to access the module in the Native side of Java, as I am using OneSignal and there is no background listener in Onesignal so i extended the Notification, and i am able to show the displayIncoming method for the first time to the user, even if the device is in locked mode, but after the dismiss method is called or any other method of the decline/answer is called, it throw an error of "Attempt to invoke virtual method 'boolean com.facebook.react.bridge.ReactApplicationContext.hasCurrentActivity()' on a null object reference"
Any solution for this, I want to use the native method of displayIncoming only to show the UI, and use bridging to catch the answer/declined method only or dismiss() method?
P.S: I am not expert in Java & Android yet. any help is appreciated, Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.