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,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
315328export default new RNCallKeep ( ) ;
0 commit comments