Skip to content

Commit c34ae22

Browse files
Merge branch 'master' of https://github.com/react-native-webrtc/react-native-callkeep into speakerOutputAndroid
2 parents 3fc6c55 + b22521f commit c34ae22

File tree

6 files changed

+167
-68
lines changed

6 files changed

+167
-68
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ RNCallKeep.setup(options).then(accepted => {});
7070
- `ringtoneSound`: string (optional)
7171
If provided, it will be played when incoming calls received; the system will use the default ringtone if this is not provided
7272
- `includesCallsInRecents`: boolean (optional)
73-
If provided, calls will be shown in the recent calls when true and not when false (ios 11 and above)
73+
If provided, calls will be shown in the recent calls when true and not when false (ios 11 and above) (Default: true)
7474
- `maximumCallGroups`: string (optional)
7575
If provided, the maximum number of call groups supported by this application (Default: 3)
7676
- `maximumCallsPerCallGroup`: string (optional)
@@ -187,13 +187,33 @@ RNCallKeep.isCallActive(uuid);
187187
- `uuid`: string
188188
- The `uuid` used for `startCall` or `displayIncomingCall`
189189

190+
191+
### getCalls
192+
193+
_This feature is available only on IOS._
194+
195+
Returns a Promise. The result will be an array with all current calls and their states.
196+
197+
```js
198+
RNCallKeep.getCalls();
199+
200+
response:
201+
[{
202+
callUUID: "E26B14F7-2CDF-48D0-9925-532199AE7C48"
203+
hasConnected: true
204+
hasEnded: false
205+
onHold: false
206+
outgoing: false
207+
}]
208+
```
209+
190210
### displayIncomingCall
191211

192212
Display system UI for incoming calls
193213

194-
````js
214+
```js
195215
RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
196-
````
216+
```
197217

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

219239
### answerIncomingCall
220-
_This feature is available only on Android._
221240

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

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

801-
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).
820+
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).
802821

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

android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import android.os.Handler;
3434
import android.speech.tts.Voice;
3535
import androidx.annotation.Nullable;
36-
import android.support.v4.app.NotificationCompat;
36+
import androidx.core.app.NotificationCompat;
3737
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
3838
import android.telecom.CallAudioState;
3939
import android.telecom.Connection;

example/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,9 +2565,9 @@ inherits@2, [email protected], inherits@^2.0.3, inherits@~2.0.3:
25652565
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
25662566

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

25722572
inline-style-prefixer@^5.0.3:
25732573
version "5.1.0"

index.d.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare module 'react-native-callkeep' {
2323
maximumCallGroups?: string,
2424
maximumCallsPerCallGroup?: string,
2525
ringtoneSound?: string,
26+
includesCallsInRecents?: boolean
2627
},
2728
android: {
2829
alertTitle: string,
@@ -40,12 +41,23 @@ declare module 'react-native-callkeep' {
4041
export type DidDisplayIncomingCallPayload = string | undefined;
4142
export type DidPerformSetMutedCallActionPayload = boolean;
4243

44+
export const CONSTANTS: {
45+
END_CALL_REASONS: {
46+
FAILED: 1,
47+
REMOTE_ENDED: 2,
48+
UNANSWERED: 3,
49+
ANSWERED_ELSEWHERE: 4,
50+
DECLINED_ELSEWHERE: 5 | 2,
51+
MISSED: 2 | 6
52+
}
53+
};
54+
4355
export default class RNCallKeep {
4456
static addEventListener(type: Events, handler: (args: any) => void): void
4557

4658
static removeEventListener(type: Events): void
4759

48-
static setup(options: IOptions): Promise<void>
60+
static setup(options: IOptions): Promise<boolean>
4961

5062
static hasDefaultPhoneAccount(): boolean
5163

@@ -103,8 +115,13 @@ declare module 'react-native-callkeep' {
103115

104116
static setReachable(): void
105117

118+
/**
119+
* @description isCallActive method is available only on iOS.
120+
*/
106121
static isCallActive(uuid: string): Promise<boolean>
107122

123+
static getCalls(): Promise<object>
124+
108125
/**
109126
* @description supportConnectionService method is available only on Android.
110127
*/

index.js

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NativeModules, Platform, Alert } from 'react-native';
22

3-
import { listeners, emit } from './actions'
3+
import { listeners, emit } from './actions';
44

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

1920
export { CONSTANTS };
2021

2122
class RNCallKeep {
22-
2323
constructor() {
2424
this._callkeepEventHandlers = new Map();
2525
}
@@ -55,7 +55,6 @@ class RNCallKeep {
5555
RNCallKeepModule.registerPhoneAccount();
5656
};
5757

58-
5958
registerAndroidEvents = () => {
6059
if (isIOS) {
6160
return;
@@ -71,7 +70,14 @@ class RNCallKeep {
7170
return;
7271
};
7372

74-
displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null) => {
73+
displayIncomingCall = (
74+
uuid,
75+
handle,
76+
localizedCallerName = '',
77+
handleType = 'number',
78+
hasVideo = false,
79+
options = null
80+
) => {
7581
if (!isIOS) {
7682
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
7783
return;
@@ -83,16 +89,24 @@ class RNCallKeep {
8389
let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true);
8490
let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true);
8591

86-
RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, supportsHolding, supportsDTMF, supportsGrouping, supportsUngrouping);
92+
RNCallKeepModule.displayIncomingCall(
93+
uuid,
94+
handle,
95+
handleType,
96+
hasVideo,
97+
localizedCallerName,
98+
supportsHolding,
99+
supportsDTMF,
100+
supportsGrouping,
101+
supportsUngrouping
102+
);
87103
};
88104

89105
answerIncomingCall = (uuid) => {
90-
if (!isIOS) {
91-
RNCallKeepModule.answerIncomingCall(uuid);
92-
}
106+
RNCallKeepModule.answerIncomingCall(uuid);
93107
};
94108

95-
startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false ) => {
109+
startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => {
96110
if (!isIOS) {
97111
RNCallKeepModule.startCall(uuid, handle, contactIdentifier);
98112
return;
@@ -107,15 +121,15 @@ class RNCallKeep {
107121
}
108122

109123
return RNCallKeepModule.checkPhoneAccountEnabled();
110-
}
124+
};
111125

112126
isConnectionServiceAvailable = async () => {
113127
if (isIOS) {
114128
return true;
115129
}
116130

117131
return RNCallKeepModule.isConnectionServiceAvailable();
118-
}
132+
};
119133

120134
reportConnectingOutgoingCallWithUUID = (uuid) => {
121135
//only available on iOS
@@ -145,19 +159,23 @@ class RNCallKeep {
145159
}
146160
};
147161

148-
isCallActive = async(uuid) => await RNCallKeepModule.isCallActive(uuid);
162+
isCallActive = async (uuid) => await RNCallKeepModule.isCallActive(uuid);
163+
164+
getCalls = () => {
165+
if (isIOS) {
166+
return RNCallKeepModule.getCalls();
167+
}
168+
};
149169

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

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

154174
supportConnectionService = () => supportConnectionService;
155175

156-
hasPhoneAccount = async () =>
157-
isIOS ? true : await RNCallKeepModule.hasPhoneAccount();
176+
hasPhoneAccount = async () => (isIOS ? true : await RNCallKeepModule.hasPhoneAccount());
158177

159-
hasOutgoingCall = async () =>
160-
isIOS ? null : await RNCallKeepModule.hasOutgoingCall();
178+
hasOutgoingCall = async () => (isIOS ? null : await RNCallKeepModule.hasOutgoingCall());
161179

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

176194
checkIfBusy = () =>
177-
isIOS
178-
? RNCallKeepModule.checkIfBusy()
179-
: Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');
195+
isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');
180196

181197
checkSpeaker = () =>
182-
isIOS
183-
? RNCallKeepModule.checkSpeaker()
184-
: Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');
198+
isIOS ? RNCallKeepModule.checkSpeaker() : Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');
185199

186200
setAvailable = (state) => {
187201
if (isIOS) {
@@ -228,7 +242,7 @@ class RNCallKeep {
228242
if (options && options.ios) {
229243
iosOptions = {
230244
...options.ios,
231-
}
245+
};
232246
}
233247
RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions);
234248
};
@@ -246,16 +260,17 @@ class RNCallKeep {
246260
: Promise.reject('RNCallKeep.reportUpdatedCall was called from unsupported OS');
247261
};
248262

249-
_setupIOS = async (options) => new Promise((resolve, reject) => {
250-
if (!options.appName) {
251-
reject('RNCallKeep.setup: option "appName" is required');
252-
}
253-
if (typeof options.appName !== 'string') {
254-
reject('RNCallKeep.setup: option "appName" should be of type "string"');
255-
}
263+
_setupIOS = async (options) =>
264+
new Promise((resolve, reject) => {
265+
if (!options.appName) {
266+
reject('RNCallKeep.setup: option "appName" is required');
267+
}
268+
if (typeof options.appName !== 'string') {
269+
reject('RNCallKeep.setup: option "appName" should be of type "string"');
270+
}
256271

257-
resolve(RNCallKeepModule.setup(options));
258-
});
272+
resolve(RNCallKeepModule.setup(options));
273+
});
259274

260275
_setupAndroid = async (options) => {
261276
RNCallKeepModule.setup(options);
@@ -280,27 +295,26 @@ class RNCallKeep {
280295
}
281296
};
282297

283-
_alert = async (options, condition) => new Promise((resolve, reject) => {
284-
if (!condition) {
285-
return resolve(false);
286-
}
298+
_alert = async (options, condition) =>
299+
new Promise((resolve, reject) => {
300+
if (!condition) {
301+
return resolve(false);
302+
}
287303

288-
Alert.alert(
289-
options.alertTitle,
290-
options.alertDescription,
291-
[
292-
{
293-
text: options.cancelButton,
294-
onPress: reject,
295-
style: 'cancel',
296-
},
297-
{ text: options.okButton,
298-
onPress: () => resolve(true)
299-
},
300-
],
301-
{ cancelable: true },
302-
);
303-
});
304+
Alert.alert(
305+
options.alertTitle,
306+
options.alertDescription,
307+
[
308+
{
309+
text: options.cancelButton,
310+
onPress: reject,
311+
style: 'cancel',
312+
},
313+
{ text: options.okButton, onPress: () => resolve(true) },
314+
],
315+
{ cancelable: true }
316+
);
317+
});
304318

305319
backToForeground() {
306320
if (isIOS) {
@@ -309,7 +323,6 @@ class RNCallKeep {
309323

310324
NativeModules.RNCallKeep.backToForeground();
311325
}
312-
313326
}
314327

315328
export default new RNCallKeep();

0 commit comments

Comments
 (0)