Incoming audio/video call with call keep when phone is locked or app is killed

Viewed 1188

React Native Callkeep with Twilio: Case 1 - App open( foreground) audio-video call coming with native UI ( Callkeep) working fine Case 2 - App open ( background ) audio-video call coming with native UI ( Callkeep) working fine Case 3 - App Close( Kill state) audio-video call not coming with native UI ( Callkeep) not working Case 4 - App open Phone Lock audio-video call coming with native UI ( Callkeep) working fine But when answer call then native call UI appear on-screen phone not unlock and not load our app

1 Answers

Question from your question: Can you please tell me how are you displaying incoming calls when the app is in the background or killed?

I'm also using React Native Callkeep and Twilio for Video Calling.

Found Solution to this

This is working for us for both iOS and Android even when the app is explicitly killed by the user.

Using-

  1. https://github.com/zo0r/react-native-push-notification
  2. https://github.com/react-native-push-notification-ios/push-notification-ios (do the complete setup required for these two packages)

APN Request

$url = "https://api.sandbox.push.apple.com/3/device/<device_token>";
$headers = array(
    "apns-push-type: voip",
    "apns-expiration: 10",
    "apns-topic: com.example.app.voip", // .voip as suffix to bundleID
    "apns-collapse-id: lcall", 
    "Content-Type: application/x-www-form-urlencoded",
);
$certificate_file = config('pushnotification.apn.certificate');
$payloadArray['aps'] = [
    'alert' => [
        'title' => "Calling title",
        'body' => "Calling body",
    ],
    'badge' => 1,
    "content-available" => 1
];
$data = json_encode($payloadArray);
$client = new Client();
$response = $client->post($url, [
    'headers' => $headers,
    'cert' => $certificate_file,
    'curl' => [
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
    ],
    'body'=> $data,
]);

Read official for apns-push-type- https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns

FCM Request

$url = "https://fcm.googleapis.com/fcm/send";
$headers = array(
    'Authorization' => 'key=<fcm_server_key',
    'Content-Type' => 'application/json'
);
$payloadArray = [
    "to" => "<device_token>",
    "data" => [
        "title"=> "Calling Title",
        "body" => "Calling Body",
    ]
];
$data = json_encode($payloadArray);
$client = new Client();
$response = $client->post($url, [
    'headers' => $headers,
    'curl' => [
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    ],
    'body'=> $data,
]);
Related