1
1
import { NativeModules , Platform , Alert } from 'react-native' ;
2
2
3
- import { listeners , emit } from './actions'
3
+ import { listeners , emit } from './actions' ;
4
4
5
5
const RNCallKeepModule = NativeModules . RNCallKeep ;
6
6
const isIOS = Platform . OS === 'ios' ;
@@ -13,13 +13,13 @@ const CONSTANTS = {
13
13
UNANSWERED : 3 ,
14
14
ANSWERED_ELSEWHERE : 4 ,
15
15
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
+ } ,
17
18
} ;
18
19
19
20
export { CONSTANTS } ;
20
21
21
22
class RNCallKeep {
22
-
23
23
constructor ( ) {
24
24
this . _callkeepEventHandlers = new Map ( ) ;
25
25
}
@@ -55,7 +55,6 @@ class RNCallKeep {
55
55
RNCallKeepModule . registerPhoneAccount ( ) ;
56
56
} ;
57
57
58
-
59
58
registerAndroidEvents = ( ) => {
60
59
if ( isIOS ) {
61
60
return ;
@@ -71,7 +70,14 @@ class RNCallKeep {
71
70
return ;
72
71
} ;
73
72
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
+ ) => {
75
81
if ( ! isIOS ) {
76
82
RNCallKeepModule . displayIncomingCall ( uuid , handle , localizedCallerName ) ;
77
83
return ;
@@ -83,7 +89,17 @@ class RNCallKeep {
83
89
let supportsGrouping = ! ! ( options ?. ios ?. supportsGrouping ?? true ) ;
84
90
let supportsUngrouping = ! ! ( options ?. ios ?. supportsUngrouping ?? true ) ;
85
91
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
+ ) ;
87
103
} ;
88
104
89
105
answerIncomingCall = ( uuid ) => {
@@ -92,7 +108,7 @@ class RNCallKeep {
92
108
}
93
109
} ;
94
110
95
- startCall = ( uuid , handle , contactIdentifier , handleType = 'number' , hasVideo = false ) => {
111
+ startCall = ( uuid , handle , contactIdentifier , handleType = 'number' , hasVideo = false ) => {
96
112
if ( ! isIOS ) {
97
113
RNCallKeepModule . startCall ( uuid , handle , contactIdentifier ) ;
98
114
return ;
@@ -107,15 +123,15 @@ class RNCallKeep {
107
123
}
108
124
109
125
return RNCallKeepModule . checkPhoneAccountEnabled ( ) ;
110
- }
126
+ } ;
111
127
112
128
isConnectionServiceAvailable = async ( ) => {
113
129
if ( isIOS ) {
114
130
return true ;
115
131
}
116
132
117
133
return RNCallKeepModule . isConnectionServiceAvailable ( ) ;
118
- }
134
+ } ;
119
135
120
136
reportConnectingOutgoingCallWithUUID = ( uuid ) => {
121
137
//only available on iOS
@@ -145,19 +161,23 @@ class RNCallKeep {
145
161
}
146
162
} ;
147
163
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
+ } ;
149
171
150
172
endCall = ( uuid ) => RNCallKeepModule . endCall ( uuid ) ;
151
173
152
174
endAllCalls = ( ) => RNCallKeepModule . endAllCalls ( ) ;
153
175
154
176
supportConnectionService = ( ) => supportConnectionService ;
155
177
156
- hasPhoneAccount = async ( ) =>
157
- isIOS ? true : await RNCallKeepModule . hasPhoneAccount ( ) ;
178
+ hasPhoneAccount = async ( ) => ( isIOS ? true : await RNCallKeepModule . hasPhoneAccount ( ) ) ;
158
179
159
- hasOutgoingCall = async ( ) =>
160
- isIOS ? null : await RNCallKeepModule . hasOutgoingCall ( ) ;
180
+ hasOutgoingCall = async ( ) => ( isIOS ? null : await RNCallKeepModule . hasOutgoingCall ( ) ) ;
161
181
162
182
setMutedCall = ( uuid , shouldMute ) => {
163
183
RNCallKeepModule . setMutedCall ( uuid , shouldMute ) ;
@@ -166,14 +186,10 @@ class RNCallKeep {
166
186
sendDTMF = ( uuid , key ) => RNCallKeepModule . sendDTMF ( uuid , key ) ;
167
187
168
188
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' ) ;
172
190
173
191
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' ) ;
177
193
178
194
setAvailable = ( state ) => {
179
195
if ( isIOS ) {
@@ -220,7 +236,7 @@ class RNCallKeep {
220
236
if ( options && options . ios ) {
221
237
iosOptions = {
222
238
...options . ios ,
223
- }
239
+ } ;
224
240
}
225
241
RNCallKeepModule . updateDisplay ( uuid , displayName , handle , iosOptions ) ;
226
242
} ;
@@ -238,16 +254,17 @@ class RNCallKeep {
238
254
: Promise . reject ( 'RNCallKeep.reportUpdatedCall was called from unsupported OS' ) ;
239
255
} ;
240
256
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
+ }
248
265
249
- resolve ( RNCallKeepModule . setup ( options ) ) ;
250
- } ) ;
266
+ resolve ( RNCallKeepModule . setup ( options ) ) ;
267
+ } ) ;
251
268
252
269
_setupAndroid = async ( options ) => {
253
270
RNCallKeepModule . setup ( options ) ;
@@ -272,27 +289,26 @@ class RNCallKeep {
272
289
}
273
290
} ;
274
291
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
+ }
279
297
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
+ } ) ;
296
312
297
313
backToForeground ( ) {
298
314
if ( isIOS ) {
@@ -301,7 +317,6 @@ class RNCallKeep {
301
317
302
318
NativeModules . RNCallKeep . backToForeground ( ) ;
303
319
}
304
-
305
320
}
306
321
307
322
export default new RNCallKeep ( ) ;
0 commit comments