Skip to content

Conversation

manuquentin
Copy link
Contributor

Based on #169


Proof of concept to handle issue with JS not initialized on start to fix #107

Described in details here: #107 (comment)

Example usage:

import { each, compact, last, get } from 'lodash';

RNCallKeep.addEventListener(
  'didLoadWithEvents',
  this.onDidLoadWithNativeEvents
);

onDidLoadWithNativeEvents(events) {
  const validEvents = compact(events);
  let callDataToAdd = null;
  let callDataToAnswer = null;
  let callDataToReject = null;
  let callDataToInitiateCall = null;
  each(compact(validEvents), event => {
    const { name, data } = event;
    if (name === 'RNCallKeepDidDisplayIncomingCall') {
      callDataToAdd = data;
      callDataToAnswer = null;
      callDataToReject = null;
    }
    if (name === 'RNCallKeepPerformAnswerCallAction') {
      callDataToReject = null;
      callDataToAnswer = data;
    }
    if (name === 'RNCallKeepPerformEndCallAction') {
      callDataToAnswer = null;
      callDataToReject = data;
    }
  });

  const lastEventName = get(last(validEvents), 'name');
  if (lastEventName === 'RNCallKeepDidReceiveStartCallAction') {
    callDataToInitiateCall = get(last(validEvents), 'data');
    callDataToAnswer = null;
    if (!callDataToReject) {
      callDataToAdd = null;
    }
  }

  if (callDataToAdd) {
    this.onDisplayIncomingCall(callDataToAdd);
    if (callDataToReject) {
      this.onEndCall(callDataToReject);
    }
    if (callDataToAnswer) {
      this.onAnswerCall(callDataToAnswer);
    }
  }
  if (callDataToInitiateCall) {
    this.onStartCall(callDataToAnswer);
  }
}

index.js Outdated

this.addEventListener('didLoadWithEvents', (events) => {
events.forEach(event => {
emit(evemt.name, event.data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
emit(evemt.name, event.data);
emit(event.name, event.data);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS 13] callKit displayed from AppDelegate.m before incoming call listeners
2 participants