Skip to content

Commit

Permalink
Fix Android incoming calls when app is killed (#13)
Browse files Browse the repository at this point in the history
* Fix incoming calls when app is killed on Android

* Upgrade version
  • Loading branch information
MrHertal authored Dec 10, 2020
1 parent 1bd9362 commit 9a425e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ PODS:
- React-cxxreact (= 0.63.3)
- React-jsi (= 0.63.3)
- React-jsinspector (0.63.3)
- react-native-twilio-phone (1.3.1):
- react-native-twilio-phone (1.3.2):
- React
- TwilioVoice (~> 6.0)
- React-RCTActionSheet (0.63.3):
Expand Down Expand Up @@ -552,7 +552,7 @@ SPEC CHECKSUMS:
React-jsi: df07aa95b39c5be3e41199921509bfa929ed2b9d
React-jsiexecutor: b56c03e61c0dd5f5801255f2160a815f4a53d451
React-jsinspector: 8e68ffbfe23880d3ee9bafa8be2777f60b25cbe2
react-native-twilio-phone: 59170b6a4bb5733df41e7ddb9722a52cac477f00
react-native-twilio-phone: 7475c5b7c601fc7b6683c0cf07418804abe2f415
React-RCTActionSheet: 53ea72699698b0b47a6421cb1c8b4ab215a774aa
React-RCTAnimation: 1befece0b5183c22ae01b966f5583f42e69a83c2
React-RCTBlob: 0b284339cbe4b15705a05e2313a51c6d8b51fa40
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-twilio-phone",
"version": "1.3.1",
"version": "1.3.2",
"description": "Twilio Voice React Native module.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
50 changes: 36 additions & 14 deletions src/RNTwilioPhone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ class RNTwilioPhone {
return;
}

RNCallKeep.backToForeground();
RNCallKeep.registerPhoneAccount();
RNCallKeep.registerAndroidEvents();
RNCallKeep.setAvailable(true);

RNTwilioPhone.listenTwilioPhone();
RNTwilioPhone.listenCallKeep();

TwilioPhone.handleMessage(remoteMessage.data);
});
Expand Down Expand Up @@ -187,6 +192,8 @@ class RNTwilioPhone {
}

private static listenTwilioPhone() {
RNTwilioPhone.removeTwilioPhoneListeners();

const subscriptions = [
twilioPhoneEmitter.addListener(
EventType.CallInvite,
Expand Down Expand Up @@ -270,6 +277,8 @@ class RNTwilioPhone {
}

private static listenCallKeep() {
RNTwilioPhone.removeCallKeepListeners();

if (Platform.OS === 'ios') {
RNCallKeep.addEventListener(
'didDisplayIncomingCall',
Expand Down Expand Up @@ -344,22 +353,35 @@ class RNTwilioPhone {
);

return () => {
if (Platform.OS === 'ios') {
RNCallKeep.removeEventListener('didDisplayIncomingCall');
RNCallKeep.removeEventListener('didResetProvider');
RNCallKeep.removeEventListener('didActivateAudioSession');
RNCallKeep.removeEventListener('didDeactivateAudioSession');
}

RNCallKeep.removeEventListener('didReceiveStartCallAction');
RNCallKeep.removeEventListener('answerCall');
RNCallKeep.removeEventListener('endCall');
RNCallKeep.removeEventListener('didPerformSetMutedCallAction');
RNCallKeep.removeEventListener('didToggleHoldCallAction');
RNCallKeep.removeEventListener('didPerformDTMFAction');
RNTwilioPhone.removeCallKeepListeners();
};
}

private static removeTwilioPhoneListeners() {
twilioPhoneEmitter.removeAllListeners(EventType.CallInvite);
twilioPhoneEmitter.removeAllListeners(EventType.CancelledCallInvite);
twilioPhoneEmitter.removeAllListeners(EventType.CallRinging);
twilioPhoneEmitter.removeAllListeners(EventType.CallConnected);
twilioPhoneEmitter.removeAllListeners(EventType.CallDisconnected);
twilioPhoneEmitter.removeAllListeners(EventType.CallDisconnectedError);
}

private static removeCallKeepListeners() {
if (Platform.OS === 'ios') {
RNCallKeep.removeEventListener('didDisplayIncomingCall');
RNCallKeep.removeEventListener('didResetProvider');
RNCallKeep.removeEventListener('didActivateAudioSession');
RNCallKeep.removeEventListener('didDeactivateAudioSession');
}

RNCallKeep.removeEventListener('didReceiveStartCallAction');
RNCallKeep.removeEventListener('answerCall');
RNCallKeep.removeEventListener('endCall');
RNCallKeep.removeEventListener('didPerformSetMutedCallAction');
RNCallKeep.removeEventListener('didToggleHoldCallAction');
RNCallKeep.removeEventListener('didPerformDTMFAction');
}

private static async registerTwilioPhone(deviceToken: string) {
try {
const accessToken = await RNTwilioPhone.fetchAccessToken();
Expand Down

0 comments on commit 9a425e0

Please sign in to comment.