Skip to content

Commit 1299eb2

Browse files
author
Quoc Khanh
committed
update doc
1 parent ea8fe8c commit 1299eb2

File tree

3 files changed

+94
-18
lines changed

3 files changed

+94
-18
lines changed

README.md

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
# react-native-incoming-call
1+
# RN Incoming Call Version 2
22

33
> 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.
44
55
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.
66

77
You could also wait for [this feature request](https://github.com/react-native-webrtc/react-native-callkeep/issues/43) from `react-native-callkeep` to be resolved and have an easier life.
88

9+
## Version 2 Breaking Changes
10+
11+
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.
12+
13+
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:
14+
15+
[x] More generic incoming call UI.
16+
17+
[x] Work nicely with all application state (foreground, background, killed, locked).
18+
19+
[x] More flexible APIs.
20+
21+
*Thanks to [jpudysz](https://github.com/jpudysz/react-native-callkeep)'s folk of react-native-callkeep, version 2 is heavily depended on it.*
22+
23+
### Migrate from v1
24+
25+
- `getLaunchParameters()` & `clearLaunchParameters()` is now replaced by `openAppFromHeadlessMode()` & `getExtrasFromHeadlessMode()`.
26+
27+
- 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.
28+
929
## Getting started
1030

1131
`$ npm install react-native-incoming-call --save`
@@ -16,48 +36,103 @@ or
1636

1737
### Addition installation step
1838

19-
In `AndroidManifest.xml`, add `<activity android:name="com.incomingcall.UnlockScreenActivity" />` line between `<application>` tag.
39+
In `AndroidManifest.xml`:
40+
41+
- Add `<activity android:name="com.incomingcall.UnlockScreenActivity" />` line between `<application>` tag.
42+
43+
- Add `<uses-permission android:name="android.permission.VIBRATE" />` permission.
44+
45+
- Also, it's recommend to put `android:launchMode="singleInstance"` in `<activity android:name=".MainActivity"...` tag to prevent duplicate activities.
2046

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

2349
`$ react-native link react-native-incoming-call`
2450

2551
## Usage
52+
53+
In `App.js`:
54+
2655
```javascript
2756
import {useEffect} from 'react';
57+
import {DeviceEventEmitter, Platform} from 'react-native';
2858
import IncomingCall from 'react-native-incoming-call';
2959

30-
// Display incoming call activity. Should be called in backgroundHandler function of react-native-firebase.
31-
IncomingCall.display(uuid, name, avatar);
32-
33-
// Dismiss current activity. Should be called when call ended.
34-
IncomingCall.dismiss();
35-
3660
// Listen to cancel and answer call events
3761
useEffect(() => {
3862
if (Platform.OS === "android") {
3963
/**
40-
* App in background or killed state, if user press answer button
41-
* IncomingCall open app and put payload to getLaunchParameters
42-
* You could start the call action here.
43-
* End call action in this case not supported yet.
64+
* App open from killed state (headless mode)
4465
*/
45-
const payload = await IncomingCall.getLaunchParameters();
66+
const payload = await IncomingCall.getExtrasFromHeadlessMode();
4667
console.log('launchParameters', payload);
47-
IncomingCall.clearLaunchParameters();
4868
if (payload) {
49-
// Start call here
69+
// Start call action here. You probably want to navigate to some CallRoom screen with the payload.uuid.
5070
}
5171

5272
/**
53-
* App in foreground: listen to call events and determine what to do next
73+
* App in foreground / background: listen to call events and determine what to do next
5474
*/
5575
DeviceEventEmitter.addListener("endCall", payload => {
5676
// End call action here
5777
});
5878
DeviceEventEmitter.addListener("answerCall", payload => {
59-
// Start call action here
79+
// Start call action here. You probably want to navigate to some CallRoom screen with the payload.uuid.
6080
});
6181
}
6282
}, []);
6383
```
84+
85+
In `index.js` or anywhere firebase background handler lies:
86+
87+
```javascript
88+
import messaging from '@react-native-firebase/messaging';
89+
import {DeviceEventEmitter} from 'react-native';
90+
import IncomingCall from 'react-native-incoming-call';
91+
92+
messaging().setBackgroundMessageHandler(async remoteMessage => {
93+
// Receive remote message
94+
if (remoteMessage?.notification?.title === 'Incoming Call') {
95+
// Display incoming call activity.
96+
IncomingCall.display(
97+
'callUUIDv4', // Call UUID v4
98+
'Quocs', // Username
99+
'https://avatars3.githubusercontent.com/u/16166195', // Avatar URL
100+
'Incomming Call' // Info text
101+
);
102+
} else if (remoteMessage?.notification?.title === 'Missed Call') {
103+
// Terminate incoming activity. Should be called when call expired.
104+
IncomingCall.dismiss();
105+
}
106+
107+
// Listen to headless action events
108+
DeviceEventEmitter.addListener("endCall", payload => {
109+
// End call action here
110+
});
111+
DeviceEventEmitter.addListener("answerCall", (payload) => {
112+
console.log('answerCall', payload);
113+
if (payload.isHeadless) {
114+
// Called from killed state
115+
IncomingCall.openAppFromHeadlessMode(payload.uuid);
116+
} else {
117+
// Called from background state
118+
IncomingCall.backToForeground();
119+
}
120+
});
121+
});
122+
```
123+
124+
## Well-known issues
125+
126+
### Incoming screen not show on android > 9:
127+
128+
You need to turn on autostart and display pop-up windows permissions manually. I'm searching for a better solution.
129+
130+
### No vibration when screen locked:
131+
132+
PR is welcomed! 😂
133+
134+
## License
135+
136+
This project is licensed under the MIT License.
137+
138+

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
android:turnScreenOn="true"
3131
android:showWhenLocked="true"
3232
android:exported="true"
33+
android:launchMode="singleInstance"
3334
android:windowSoftInputMode="adjustResize">
3435
</activity>
3536
<activity

example/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5443,7 +5443,7 @@ react-native-bootsplash@^2.2.4:
54435443

54445444
"react-native-incoming-call@git+https://github.com/bkdev98/react-native-incoming-call.git#v2":
54455445
version "2.0.0"
5446-
resolved "git+https://github.com/bkdev98/react-native-incoming-call.git#40348f0b266a19ea64d47d0d31e6859e19b37d18"
5446+
resolved "git+https://github.com/bkdev98/react-native-incoming-call.git#ea8fe8c4711fa39c316f34c5ed412de3f07a12f1"
54475447

54485448
54495449
version "0.62.2"

0 commit comments

Comments
 (0)