11import { NativeModules , Platform , Alert } from 'react-native' ;
22
3- import { listeners , emit } from './actions'
3+ import { listeners , emit } from './actions' ;
44
55const RNCallKeepModule = NativeModules . RNCallKeep ;
66const 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
1920export { CONSTANTS } ;
2021
2122class 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,7 +89,17 @@ 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 ) => {
@@ -92,7 +108,7 @@ class RNCallKeep {
92108 }
93109 } ;
94110
95- startCall = ( uuid , handle , contactIdentifier , handleType = 'number' , hasVideo = false ) => {
111+ startCall = ( uuid , handle , contactIdentifier , handleType = 'number' , hasVideo = false ) => {
96112 if ( ! isIOS ) {
97113 RNCallKeepModule . startCall ( uuid , handle , contactIdentifier ) ;
98114 return ;
@@ -107,15 +123,15 @@ class RNCallKeep {
107123 }
108124
109125 return RNCallKeepModule . checkPhoneAccountEnabled ( ) ;
110- }
126+ } ;
111127
112128 isConnectionServiceAvailable = async ( ) => {
113129 if ( isIOS ) {
114130 return true ;
115131 }
116132
117133 return RNCallKeepModule . isConnectionServiceAvailable ( ) ;
118- }
134+ } ;
119135
120136 reportConnectingOutgoingCallWithUUID = ( uuid ) => {
121137 //only available on iOS
@@ -145,19 +161,23 @@ class RNCallKeep {
145161 }
146162 } ;
147163
148- isCallActive = async ( uuid ) => await RNCallKeepModule . isCallActive ( uuid ) ;
164+ isCallActive = async ( uuid ) => await RNCallKeepModule . isCallActive ( uuid ) ;
165+
166+ getCalls = ( ) => {
167+ if ( isIOS ) {
168+ return RNCallKeepModule . getCalls ( ) ;
169+ }
170+ } ;
149171
150172 endCall = ( uuid ) => RNCallKeepModule . endCall ( uuid ) ;
151173
152174 endAllCalls = ( ) => RNCallKeepModule . endAllCalls ( ) ;
153175
154176 supportConnectionService = ( ) => supportConnectionService ;
155177
156- hasPhoneAccount = async ( ) =>
157- isIOS ? true : await RNCallKeepModule . hasPhoneAccount ( ) ;
178+ hasPhoneAccount = async ( ) => ( isIOS ? true : await RNCallKeepModule . hasPhoneAccount ( ) ) ;
158179
159- hasOutgoingCall = async ( ) =>
160- isIOS ? null : await RNCallKeepModule . hasOutgoingCall ( ) ;
180+ hasOutgoingCall = async ( ) => ( isIOS ? null : await RNCallKeepModule . hasOutgoingCall ( ) ) ;
161181
162182 setMutedCall = ( uuid , shouldMute ) => {
163183 RNCallKeepModule . setMutedCall ( uuid , shouldMute ) ;
@@ -166,14 +186,10 @@ class RNCallKeep {
166186 sendDTMF = ( uuid , key ) => RNCallKeepModule . sendDTMF ( uuid , key ) ;
167187
168188 checkIfBusy = ( ) =>
169- isIOS
170- ? RNCallKeepModule . checkIfBusy ( )
171- : Promise . reject ( 'RNCallKeep.checkIfBusy was called from unsupported OS' ) ;
189+ isIOS ? RNCallKeepModule . checkIfBusy ( ) : Promise . reject ( 'RNCallKeep.checkIfBusy was called from unsupported OS' ) ;
172190
173191 checkSpeaker = ( ) =>
174- isIOS
175- ? RNCallKeepModule . checkSpeaker ( )
176- : Promise . reject ( 'RNCallKeep.checkSpeaker was called from unsupported OS' ) ;
192+ isIOS ? RNCallKeepModule . checkSpeaker ( ) : Promise . reject ( 'RNCallKeep.checkSpeaker was called from unsupported OS' ) ;
177193
178194 setAvailable = ( state ) => {
179195 if ( isIOS ) {
@@ -220,7 +236,7 @@ class RNCallKeep {
220236 if ( options && options . ios ) {
221237 iosOptions = {
222238 ...options . ios ,
223- }
239+ } ;
224240 }
225241 RNCallKeepModule . updateDisplay ( uuid , displayName , handle , iosOptions ) ;
226242 } ;
@@ -238,16 +254,17 @@ class RNCallKeep {
238254 : Promise . reject ( 'RNCallKeep.reportUpdatedCall was called from unsupported OS' ) ;
239255 } ;
240256
241- _setupIOS = async ( options ) => new Promise ( ( resolve , reject ) => {
242- if ( ! options . appName ) {
243- reject ( 'RNCallKeep.setup: option "appName" is required' ) ;
244- }
245- if ( typeof options . appName !== 'string' ) {
246- reject ( 'RNCallKeep.setup: option "appName" should be of type "string"' ) ;
247- }
257+ _setupIOS = async ( options ) =>
258+ new Promise ( ( resolve , reject ) => {
259+ if ( ! options . appName ) {
260+ reject ( 'RNCallKeep.setup: option "appName" is required' ) ;
261+ }
262+ if ( typeof options . appName !== 'string' ) {
263+ reject ( 'RNCallKeep.setup: option "appName" should be of type "string"' ) ;
264+ }
248265
249- resolve ( RNCallKeepModule . setup ( options ) ) ;
250- } ) ;
266+ resolve ( RNCallKeepModule . setup ( options ) ) ;
267+ } ) ;
251268
252269 _setupAndroid = async ( options ) => {
253270 RNCallKeepModule . setup ( options ) ;
@@ -272,27 +289,26 @@ class RNCallKeep {
272289 }
273290 } ;
274291
275- _alert = async ( options , condition ) => new Promise ( ( resolve , reject ) => {
276- if ( ! condition ) {
277- return resolve ( false ) ;
278- }
292+ _alert = async ( options , condition ) =>
293+ new Promise ( ( resolve , reject ) => {
294+ if ( ! condition ) {
295+ return resolve ( false ) ;
296+ }
279297
280- Alert . alert (
281- options . alertTitle ,
282- options . alertDescription ,
283- [
284- {
285- text : options . cancelButton ,
286- onPress : reject ,
287- style : 'cancel' ,
288- } ,
289- { text : options . okButton ,
290- onPress : ( ) => resolve ( true )
291- } ,
292- ] ,
293- { cancelable : true } ,
294- ) ;
295- } ) ;
298+ Alert . alert (
299+ options . alertTitle ,
300+ options . alertDescription ,
301+ [
302+ {
303+ text : options . cancelButton ,
304+ onPress : reject ,
305+ style : 'cancel' ,
306+ } ,
307+ { text : options . okButton , onPress : ( ) => resolve ( true ) } ,
308+ ] ,
309+ { cancelable : true }
310+ ) ;
311+ } ) ;
296312
297313 backToForeground ( ) {
298314 if ( isIOS ) {
@@ -301,7 +317,6 @@ class RNCallKeep {
301317
302318 NativeModules . RNCallKeep . backToForeground ( ) ;
303319 }
304-
305320}
306321
307322export default new RNCallKeep ( ) ;
0 commit comments