82
82
import static io .wazo .callkeep .Constants .EXTRA_CALLER_NAME ;
83
83
import static io .wazo .callkeep .Constants .EXTRA_CALL_UUID ;
84
84
import static io .wazo .callkeep .Constants .EXTRA_CALL_NUMBER ;
85
+ import static io .wazo .callkeep .Constants .EXTRA_HAS_VIDEO ;
85
86
import static io .wazo .callkeep .Constants .ACTION_END_CALL ;
86
87
import static io .wazo .callkeep .Constants .ACTION_ANSWER_CALL ;
87
88
import static io .wazo .callkeep .Constants .ACTION_MUTE_CALL ;
@@ -151,6 +152,7 @@ private RNCallKeepModule(ReactApplicationContext reactContext) {
151
152
this .reactContext = reactContext ;
152
153
delayedEvents = new WritableNativeArray ();
153
154
this .registerReceiver ();
155
+ this .fetchStoredSettings (reactContext );
154
156
}
155
157
156
158
private boolean isSelfManaged () {
@@ -177,15 +179,15 @@ public ReactApplicationContext getContext() {
177
179
178
180
public void reportNewIncomingCall (String uuid , String number , String callerName , boolean hasVideo , String payload ) {
179
181
Log .d (TAG , "[RNCallKeepModule] reportNewIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
180
- // @TODO: handle video
181
182
182
- this .displayIncomingCall (uuid , number , callerName );
183
+ this .displayIncomingCall (uuid , number , callerName , hasVideo );
183
184
184
185
// Send event to JS
185
186
WritableMap args = Arguments .createMap ();
186
187
args .putString ("handle" , number );
187
188
args .putString ("callUUID" , uuid );
188
189
args .putString ("name" , callerName );
190
+ args .putString ("hasVideo" , hasVideo );
189
191
if (payload != null ) {
190
192
args .putString ("payload" , payload );
191
193
}
@@ -308,19 +310,25 @@ public void unregisterEvents() {
308
310
309
311
@ ReactMethod
310
312
public void displayIncomingCall (String uuid , String number , String callerName ) {
313
+ this .displayIncomingCall (uuid , number , callerName , false );
314
+ }
315
+
316
+ @ ReactMethod
317
+ public void displayIncomingCall (String uuid , String number , String callerName , boolean hasVideo ) {
311
318
if (!isConnectionServiceAvailable () || !hasPhoneAccount ()) {
312
319
Log .w (TAG , "[RNCallKeepModule] displayIncomingCall ignored due to no ConnectionService or no phone account" );
313
320
return ;
314
321
}
315
322
316
- Log .d (TAG , "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
323
+ Log .d (TAG , "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName + ", hasVideo: " + hasVideo );
317
324
318
325
Bundle extras = new Bundle ();
319
326
Uri uri = Uri .fromParts (PhoneAccount .SCHEME_TEL , number , null );
320
327
321
328
extras .putParcelable (TelecomManager .EXTRA_INCOMING_CALL_ADDRESS , uri );
322
329
extras .putString (EXTRA_CALLER_NAME , callerName );
323
330
extras .putString (EXTRA_CALL_UUID , uuid );
331
+ extras .putString (EXTRA_HAS_VIDEO , String .valueOf (hasVideo ));
324
332
325
333
telecomManager .addNewIncomingCall (handle , extras );
326
334
}
@@ -344,6 +352,11 @@ public void answerIncomingCall(String uuid) {
344
352
345
353
@ ReactMethod
346
354
public void startCall (String uuid , String number , String callerName ) {
355
+ this .startCall (uuid , number , callerName , false );
356
+ }
357
+
358
+ @ ReactMethod
359
+ public void startCall (String uuid , String number , String callerName , boolean hasVideo ) {
347
360
Log .d (TAG , "[RNCallKeepModule] startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
348
361
349
362
if (!isConnectionServiceAvailable () || !hasPhoneAccount () || !hasPermissions () || number == null ) {
@@ -358,6 +371,7 @@ public void startCall(String uuid, String number, String callerName) {
358
371
callExtras .putString (EXTRA_CALLER_NAME , callerName );
359
372
callExtras .putString (EXTRA_CALL_UUID , uuid );
360
373
callExtras .putString (EXTRA_CALL_NUMBER , number );
374
+ callExtras .putString (EXTRA_HAS_VIDEO , String .valueOf (hasVideo ));
361
375
362
376
extras .putParcelable (TelecomManager .EXTRA_PHONE_ACCOUNT_HANDLE , handle );
363
377
extras .putParcelable (TelecomManager .EXTRA_OUTGOING_CALL_EXTRAS , callExtras );
@@ -996,6 +1010,14 @@ private Boolean hasPermissions() {
996
1010
}
997
1011
998
1012
private boolean hasPhoneAccount () {
1013
+ if (telecomManager == null ) {
1014
+ this .initializeTelecomManager ();
1015
+ }
1016
+
1017
+ if (isSelfManaged ()) {
1018
+ return true ;
1019
+ }
1020
+
999
1021
return isConnectionServiceAvailable () && telecomManager != null &&
1000
1022
hasPermissions () && telecomManager .getPhoneAccount (handle ) != null &&
1001
1023
telecomManager .getPhoneAccount (handle ).isEnabled ();
@@ -1080,7 +1102,7 @@ public void onReceive(Context context, Intent intent) {
1080
1102
WritableMap args = Arguments .createMap ();
1081
1103
HashMap <String , String > attributeMap = (HashMap <String , String >)intent .getSerializableExtra ("attributeMap" );
1082
1104
1083
- Log .d (TAG , "[RNCallKeepModule][onReceive] : " + intent .getAction ());
1105
+ Log .d (TAG , "[RNCallKeepModule][onReceive] " + intent .getAction ());
1084
1106
1085
1107
switch (intent .getAction ()) {
1086
1108
case ACTION_END_CALL :
@@ -1089,6 +1111,7 @@ public void onReceive(Context context, Intent intent) {
1089
1111
break ;
1090
1112
case ACTION_ANSWER_CALL :
1091
1113
args .putString ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
1114
+ args .putBoolean ("withVideo" , Boolean .valueOf (attributeMap .get (EXTRA_HAS_VIDEO )));
1092
1115
sendEventToJS ("RNCallKeepPerformAnswerCallAction" , args );
1093
1116
break ;
1094
1117
case ACTION_HOLD_CALL :
@@ -1132,6 +1155,7 @@ public void onReceive(Context context, Intent intent) {
1132
1155
args .putString ("handle" , attributeMap .get (EXTRA_CALL_NUMBER ));
1133
1156
args .putString ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
1134
1157
args .putString ("name" , attributeMap .get (EXTRA_CALLER_NAME ));
1158
+ args .putString ("hasVideo" , attributeMap .get (EXTRA_HAS_VIDEO ));
1135
1159
sendEventToJS ("RNCallKeepShowIncomingCallUi" , args );
1136
1160
break ;
1137
1161
case ACTION_WAKE_APP :
0 commit comments