voximplant / react-native-demo

React Native Voximplant Demo
173 stars 146 forks source link

VOIP notification received not able to see incomingCall screen #74

Open ControlAndC opened 4 years ago

ControlAndC commented 4 years ago

Hi,

1) I am getting VOIP notification with below payload, What next i am supposed to do to show that incoming call screen ?

---Payload----

[RNVoipPushNotificationManager] didReceiveIncomingPushWithPayload payload.dictionaryPayload = {
    aps =     {
        "content-available" = 1;
    };
    voximplant =     {
        addr = "161.202.172.211:5090";
        "analytics_label" = "";
        callid = x6TgS5RaRiy4aol2rstyHUMq3pAzkk0Nq3DfPGNtWGQ;
        "display_name" = "Sandeep Chacuan";
        sessionid = "BC8630078246B927.1602789509.3391145_161.202.172.211";
        sipuri = "sip:user-staging-107@mentor.fdff4gdfjfadsfvoximplant.com";
        userid = "user-staging-98@mentor.urefddasgr.voximplant.com";
        video = 1;
    };
}, type = PKPushTypeVoIP

2) When app is in Foreground state i am able to to see incomingCall screen by using below code, i have noticed below i am getting CallId and CallKitUUID from ( _incomingCall = event => ) but when app is in killed state in VOIP payload i am not getting CallKitUUID and even callID format are also different

EX -

CallID in VOIP payload is (app is in killed state) callid = x6TgS5RaRiy4aol2rstyHUMq3pAzkk0Nq3DfPGNtWGQ;

CallID when app is in Foreground state ( _incomingCall = event => ) event.call.callId = '9BA4BC3CDD7714A9.1602671723.2074451',

Below code to show incoingCall view when app is in Foreground state.

this.callKitManager.showIncomingCall( event.video, event.call.getEndpoints()[0].displayName, event.call.callId, event.call.callKitUUID, );

I am also sharing my AppDelegate.m file.

3) Does below line will call RNCallKeep and show that incomingCall screen or do i need to do something?

if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && ![RNCallKeep isCallActive:uuid]) {
    NSLog(@"AppDelegate: didReceiveIncomingPush: report new incoming call to CallKit");
    NSString *callerName = [[payload.dictionaryPayload valueForKey:@"voximplant"] valueForKey:@"display_name"];
    [RNCallKeep reportNewIncomingCall:uuid handle:callerName handleType:@"generic" hasVideo:YES localizedCallerName:callerName fromPushKit:YES payload:payload.dictionaryPayload];
  }
  completion();
}

This is my AppDelegate.m

#import "AppDelegate.h"
#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <PushKit/PushKit.h>
#import <UIKit/UIKit.h>
#import "RNVoipPushNotificationManager.h"
#import "RNCallKeep.h"
#import "VIClientModule.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"Mentormatch"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  return YES;
}

// Handle updated push credentials
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
  // Register VoIP push token (a property of PKPushCredentials) with server
  [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type];
}

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type
{
  // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
}

// --- Handle incoming pushes (for ios <= 10)
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type {
  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
}

// Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry
didReceiveIncomingPushWithPayload:(PKPushPayload *)payload
                          forType:(PKPushType)type
            withCompletionHandler:(void (^)(void))completion {
  // Process the received push
  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];

  NSString *uuid = [VIClientModule uuidForPushNotification:payload.dictionaryPayload].UUIDString;

  if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
    NSLog(@"AppDelegate: didReceiveIncomingPush: application is in active state");
  }

  if ([RNCallKeep isCallActive:uuid]){
    NSLog(@"AppDelegate: didReceiveIncomingPush: call is already been reported");
  }

  if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && ![RNCallKeep isCallActive:uuid]) {
    NSLog(@"AppDelegate: didReceiveIncomingPush: report new incoming call to CallKit");
    NSString *callerName = [[payload.dictionaryPayload valueForKey:@"voximplant"] valueForKey:@"display_name"];
    [RNCallKeep reportNewIncomingCall:uuid handle:callerName handleType:@"generic" hasVideo:YES localizedCallerName:callerName fromPushKit:YES payload:payload.dictionaryPayload];
  }
  completion();
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

Thanks