8282import static io .wazo .callkeep .Constants .EXTRA_CALLER_NAME ;
8383import static io .wazo .callkeep .Constants .EXTRA_CALL_UUID ;
8484import static io .wazo .callkeep .Constants .EXTRA_CALL_NUMBER ;
85+ import static io .wazo .callkeep .Constants .EXTRA_HAS_VIDEO ;
8586import static io .wazo .callkeep .Constants .ACTION_END_CALL ;
8687import static io .wazo .callkeep .Constants .ACTION_ANSWER_CALL ;
8788import static io .wazo .callkeep .Constants .ACTION_MUTE_CALL ;
@@ -151,6 +152,7 @@ private RNCallKeepModule(ReactApplicationContext reactContext) {
151152 this .reactContext = reactContext ;
152153 delayedEvents = new WritableNativeArray ();
153154 this .registerReceiver ();
155+ this .fetchStoredSettings (reactContext );
154156 }
155157
156158 private boolean isSelfManaged () {
@@ -177,15 +179,15 @@ public ReactApplicationContext getContext() {
177179
178180 public void reportNewIncomingCall (String uuid , String number , String callerName , boolean hasVideo , String payload ) {
179181 Log .d (TAG , "[RNCallKeepModule] reportNewIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
180- // @TODO: handle video
181182
182- this .displayIncomingCall (uuid , number , callerName );
183+ this .displayIncomingCall (uuid , number , callerName , hasVideo );
183184
184185 // Send event to JS
185186 WritableMap args = Arguments .createMap ();
186187 args .putString ("handle" , number );
187188 args .putString ("callUUID" , uuid );
188189 args .putString ("name" , callerName );
190+ args .putString ("hasVideo" , hasVideo );
189191 if (payload != null ) {
190192 args .putString ("payload" , payload );
191193 }
@@ -308,19 +310,25 @@ public void unregisterEvents() {
308310
309311 @ ReactMethod
310312 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 ) {
311318 if (!isConnectionServiceAvailable () || !hasPhoneAccount ()) {
312319 Log .w (TAG , "[RNCallKeepModule] displayIncomingCall ignored due to no ConnectionService or no phone account" );
313320 return ;
314321 }
315322
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 );
317324
318325 Bundle extras = new Bundle ();
319326 Uri uri = Uri .fromParts (PhoneAccount .SCHEME_TEL , number , null );
320327
321328 extras .putParcelable (TelecomManager .EXTRA_INCOMING_CALL_ADDRESS , uri );
322329 extras .putString (EXTRA_CALLER_NAME , callerName );
323330 extras .putString (EXTRA_CALL_UUID , uuid );
331+ extras .putString (EXTRA_HAS_VIDEO , String .valueOf (hasVideo ));
324332
325333 telecomManager .addNewIncomingCall (handle , extras );
326334 }
@@ -344,6 +352,11 @@ public void answerIncomingCall(String uuid) {
344352
345353 @ ReactMethod
346354 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 ) {
347360 Log .d (TAG , "[RNCallKeepModule] startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName );
348361
349362 if (!isConnectionServiceAvailable () || !hasPhoneAccount () || !hasPermissions () || number == null ) {
@@ -358,6 +371,7 @@ public void startCall(String uuid, String number, String callerName) {
358371 callExtras .putString (EXTRA_CALLER_NAME , callerName );
359372 callExtras .putString (EXTRA_CALL_UUID , uuid );
360373 callExtras .putString (EXTRA_CALL_NUMBER , number );
374+ callExtras .putString (EXTRA_HAS_VIDEO , String .valueOf (hasVideo ));
361375
362376 extras .putParcelable (TelecomManager .EXTRA_PHONE_ACCOUNT_HANDLE , handle );
363377 extras .putParcelable (TelecomManager .EXTRA_OUTGOING_CALL_EXTRAS , callExtras );
@@ -996,6 +1010,14 @@ private Boolean hasPermissions() {
9961010 }
9971011
9981012 private boolean hasPhoneAccount () {
1013+ if (telecomManager == null ) {
1014+ this .initializeTelecomManager ();
1015+ }
1016+
1017+ if (isSelfManaged ()) {
1018+ return true ;
1019+ }
1020+
9991021 return isConnectionServiceAvailable () && telecomManager != null &&
10001022 hasPermissions () && telecomManager .getPhoneAccount (handle ) != null &&
10011023 telecomManager .getPhoneAccount (handle ).isEnabled ();
@@ -1080,7 +1102,7 @@ public void onReceive(Context context, Intent intent) {
10801102 WritableMap args = Arguments .createMap ();
10811103 HashMap <String , String > attributeMap = (HashMap <String , String >)intent .getSerializableExtra ("attributeMap" );
10821104
1083- Log .d (TAG , "[RNCallKeepModule][onReceive] : " + intent .getAction ());
1105+ Log .d (TAG , "[RNCallKeepModule][onReceive] " + intent .getAction ());
10841106
10851107 switch (intent .getAction ()) {
10861108 case ACTION_END_CALL :
@@ -1089,6 +1111,7 @@ public void onReceive(Context context, Intent intent) {
10891111 break ;
10901112 case ACTION_ANSWER_CALL :
10911113 args .putString ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
1114+ args .putBoolean ("withVideo" , Boolean .valueOf (attributeMap .get (EXTRA_HAS_VIDEO )));
10921115 sendEventToJS ("RNCallKeepPerformAnswerCallAction" , args );
10931116 break ;
10941117 case ACTION_HOLD_CALL :
@@ -1132,6 +1155,7 @@ public void onReceive(Context context, Intent intent) {
11321155 args .putString ("handle" , attributeMap .get (EXTRA_CALL_NUMBER ));
11331156 args .putString ("callUUID" , attributeMap .get (EXTRA_CALL_UUID ));
11341157 args .putString ("name" , attributeMap .get (EXTRA_CALLER_NAME ));
1158+ args .putString ("hasVideo" , attributeMap .get (EXTRA_HAS_VIDEO ));
11351159 sendEventToJS ("RNCallKeepShowIncomingCallUi" , args );
11361160 break ;
11371161 case ACTION_WAKE_APP :
0 commit comments