Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-native-callkeep into speakerOutputAndroid
  • Loading branch information
vtn-dev-prithipal committed Mar 19, 2021
2 parents 3fc6c55 + b22521f commit c34ae22
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 68 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ RNCallKeep.setup(options).then(accepted => {});
- `ringtoneSound`: string (optional)
If provided, it will be played when incoming calls received; the system will use the default ringtone if this is not provided
- `includesCallsInRecents`: boolean (optional)
If provided, calls will be shown in the recent calls when true and not when false (ios 11 and above)
If provided, calls will be shown in the recent calls when true and not when false (ios 11 and above) (Default: true)
- `maximumCallGroups`: string (optional)
If provided, the maximum number of call groups supported by this application (Default: 3)
- `maximumCallsPerCallGroup`: string (optional)
Expand Down Expand Up @@ -187,13 +187,33 @@ RNCallKeep.isCallActive(uuid);
- `uuid`: string
- The `uuid` used for `startCall` or `displayIncomingCall`


### getCalls

_This feature is available only on IOS._

Returns a Promise. The result will be an array with all current calls and their states.

```js
RNCallKeep.getCalls();

response:
[{
callUUID: "E26B14F7-2CDF-48D0-9925-532199AE7C48"
hasConnected: true
hasEnded: false
onHold: false
outgoing: false
}]
```

### displayIncomingCall

Display system UI for incoming calls

````js
```js
RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
````
```

- `uuid`: string
- An `uuid` that should be stored and re-used for `stopCall`.
Expand All @@ -217,7 +237,6 @@ RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
- `android`: object (currently no-op)

### answerIncomingCall
_This feature is available only on Android._

Use this to tell the sdk a user answered a call from the app UI.

Expand Down Expand Up @@ -798,7 +817,7 @@ In some case your application can be unreachable :
- when the user kill the application
- when it's in background since a long time (eg: after ~5mn the os will kill all connections).

To be able to wake up your application to display the incoming call, you can use [https://github.com/ianlin/react-native-voip-push-notification](react-native-voip-push-notification) on iOS or BackgroundMessaging from [react-native-firebase](https://rnfirebase.io/messaging/usage#receiving-messages)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background).
To be able to wake up your application to display the incoming call, you can use [https://github.com/react-native-webrtc/react-native-voip-push-notification](react-native-voip-push-notification) on iOS or BackgroundMessaging from [react-native-firebase](https://rnfirebase.io/messaging/usage#receiving-messages)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background).

You have to send a push to your application, like with Firebase for Android and with a library supporting PushKit pushes for iOS.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import android.os.Handler;
import android.speech.tts.Voice;
import androidx.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.telecom.CallAudioState;
import android.telecom.Connection;
Expand Down
6 changes: 3 additions & 3 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2565,9 +2565,9 @@ inherits@2, [email protected], inherits@^2.0.3, inherits@~2.0.3:
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

ini@~1.3.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
version "1.3.7"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84"
integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==

inline-style-prefixer@^5.0.3:
version "5.1.0"
Expand Down
19 changes: 18 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare module 'react-native-callkeep' {
maximumCallGroups?: string,
maximumCallsPerCallGroup?: string,
ringtoneSound?: string,
includesCallsInRecents?: boolean
},
android: {
alertTitle: string,
Expand All @@ -40,12 +41,23 @@ declare module 'react-native-callkeep' {
export type DidDisplayIncomingCallPayload = string | undefined;
export type DidPerformSetMutedCallActionPayload = boolean;

export const CONSTANTS: {
END_CALL_REASONS: {
FAILED: 1,
REMOTE_ENDED: 2,
UNANSWERED: 3,
ANSWERED_ELSEWHERE: 4,
DECLINED_ELSEWHERE: 5 | 2,
MISSED: 2 | 6
}
};

export default class RNCallKeep {
static addEventListener(type: Events, handler: (args: any) => void): void

static removeEventListener(type: Events): void

static setup(options: IOptions): Promise<void>
static setup(options: IOptions): Promise<boolean>

static hasDefaultPhoneAccount(): boolean

Expand Down Expand Up @@ -103,8 +115,13 @@ declare module 'react-native-callkeep' {

static setReachable(): void

/**
* @description isCallActive method is available only on iOS.
*/
static isCallActive(uuid: string): Promise<boolean>

static getCalls(): Promise<object>

/**
* @description supportConnectionService method is available only on Android.
*/
Expand Down
121 changes: 67 additions & 54 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NativeModules, Platform, Alert } from 'react-native';

import { listeners, emit } from './actions'
import { listeners, emit } from './actions';

const RNCallKeepModule = NativeModules.RNCallKeep;
const isIOS = Platform.OS === 'ios';
Expand All @@ -13,13 +13,13 @@ const CONSTANTS = {
UNANSWERED: 3,
ANSWERED_ELSEWHERE: 4,
DECLINED_ELSEWHERE: isIOS ? 5 : 2, // make declined elsewhere link to "Remote ended" on android because that's kinda true
MISSED: isIOS ? 2 : 6 }
MISSED: isIOS ? 2 : 6,
},
};

export { CONSTANTS };

class RNCallKeep {

constructor() {
this._callkeepEventHandlers = new Map();
}
Expand Down Expand Up @@ -55,7 +55,6 @@ class RNCallKeep {
RNCallKeepModule.registerPhoneAccount();
};


registerAndroidEvents = () => {
if (isIOS) {
return;
Expand All @@ -71,7 +70,14 @@ class RNCallKeep {
return;
};

displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null) => {
displayIncomingCall = (
uuid,
handle,
localizedCallerName = '',
handleType = 'number',
hasVideo = false,
options = null
) => {
if (!isIOS) {
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
return;
Expand All @@ -83,16 +89,24 @@ class RNCallKeep {
let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true);
let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true);

RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, supportsHolding, supportsDTMF, supportsGrouping, supportsUngrouping);
RNCallKeepModule.displayIncomingCall(
uuid,
handle,
handleType,
hasVideo,
localizedCallerName,
supportsHolding,
supportsDTMF,
supportsGrouping,
supportsUngrouping
);
};

answerIncomingCall = (uuid) => {
if (!isIOS) {
RNCallKeepModule.answerIncomingCall(uuid);
}
RNCallKeepModule.answerIncomingCall(uuid);
};

startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false ) => {
startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => {
if (!isIOS) {
RNCallKeepModule.startCall(uuid, handle, contactIdentifier);
return;
Expand All @@ -107,15 +121,15 @@ class RNCallKeep {
}

return RNCallKeepModule.checkPhoneAccountEnabled();
}
};

isConnectionServiceAvailable = async () => {
if (isIOS) {
return true;
}

return RNCallKeepModule.isConnectionServiceAvailable();
}
};

reportConnectingOutgoingCallWithUUID = (uuid) => {
//only available on iOS
Expand Down Expand Up @@ -145,19 +159,23 @@ class RNCallKeep {
}
};

isCallActive = async(uuid) => await RNCallKeepModule.isCallActive(uuid);
isCallActive = async (uuid) => await RNCallKeepModule.isCallActive(uuid);

getCalls = () => {
if (isIOS) {
return RNCallKeepModule.getCalls();
}
};

endCall = (uuid) => RNCallKeepModule.endCall(uuid);

endAllCalls = () => RNCallKeepModule.endAllCalls();

supportConnectionService = () => supportConnectionService;

hasPhoneAccount = async () =>
isIOS ? true : await RNCallKeepModule.hasPhoneAccount();
hasPhoneAccount = async () => (isIOS ? true : await RNCallKeepModule.hasPhoneAccount());

hasOutgoingCall = async () =>
isIOS ? null : await RNCallKeepModule.hasOutgoingCall();
hasOutgoingCall = async () => (isIOS ? null : await RNCallKeepModule.hasOutgoingCall());

setMutedCall = (uuid, shouldMute) => {
RNCallKeepModule.setMutedCall(uuid, shouldMute);
Expand All @@ -174,14 +192,10 @@ class RNCallKeep {
toggleAudioRouteSpeaker = (uuid, useSpeaker) => isIOS ? null : RNCallKeepModule.toggleAudioRouteSpeaker(uuid, useSpeaker);

checkIfBusy = () =>
isIOS
? RNCallKeepModule.checkIfBusy()
: Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');
isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');

checkSpeaker = () =>
isIOS
? RNCallKeepModule.checkSpeaker()
: Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');
isIOS ? RNCallKeepModule.checkSpeaker() : Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');

setAvailable = (state) => {
if (isIOS) {
Expand Down Expand Up @@ -228,7 +242,7 @@ class RNCallKeep {
if (options && options.ios) {
iosOptions = {
...options.ios,
}
};
}
RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions);
};
Expand All @@ -246,16 +260,17 @@ class RNCallKeep {
: Promise.reject('RNCallKeep.reportUpdatedCall was called from unsupported OS');
};

_setupIOS = async (options) => new Promise((resolve, reject) => {
if (!options.appName) {
reject('RNCallKeep.setup: option "appName" is required');
}
if (typeof options.appName !== 'string') {
reject('RNCallKeep.setup: option "appName" should be of type "string"');
}
_setupIOS = async (options) =>
new Promise((resolve, reject) => {
if (!options.appName) {
reject('RNCallKeep.setup: option "appName" is required');
}
if (typeof options.appName !== 'string') {
reject('RNCallKeep.setup: option "appName" should be of type "string"');
}

resolve(RNCallKeepModule.setup(options));
});
resolve(RNCallKeepModule.setup(options));
});

_setupAndroid = async (options) => {
RNCallKeepModule.setup(options);
Expand All @@ -280,27 +295,26 @@ class RNCallKeep {
}
};

_alert = async (options, condition) => new Promise((resolve, reject) => {
if (!condition) {
return resolve(false);
}
_alert = async (options, condition) =>
new Promise((resolve, reject) => {
if (!condition) {
return resolve(false);
}

Alert.alert(
options.alertTitle,
options.alertDescription,
[
{
text: options.cancelButton,
onPress: reject,
style: 'cancel',
},
{ text: options.okButton,
onPress: () => resolve(true)
},
],
{ cancelable: true },
);
});
Alert.alert(
options.alertTitle,
options.alertDescription,
[
{
text: options.cancelButton,
onPress: reject,
style: 'cancel',
},
{ text: options.okButton, onPress: () => resolve(true) },
],
{ cancelable: true }
);
});

backToForeground() {
if (isIOS) {
Expand All @@ -309,7 +323,6 @@ class RNCallKeep {

NativeModules.RNCallKeep.backToForeground();
}

}

export default new RNCallKeep();
Loading

0 comments on commit c34ae22

Please sign in to comment.