Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNCallKeep.addEventListener() not working. #53

Closed
dreamdev21 opened this issue May 30, 2019 · 6 comments
Closed

RNCallKeep.addEventListener() not working. #53

dreamdev21 opened this issue May 30, 2019 · 6 comments

Comments

@dreamdev21
Copy link

dreamdev21 commented May 30, 2019

Hi, guys.
I have tried more times to debug catch events and output result, but all RNCallKeep.addEventListener subscriptions are not working.
Maybe I have some missing configuration?
I am testing TextNow voip services on my phone and mac.
Here is my code.

import React, { Component } from 'react';
import {
  View,
  Dimensions,
  PermissionsAndroid,
  Platform,
  Text,
  TouchableOpacity
} from 'react-native';
import PropTypes from 'prop-types';
import Contacts from 'react-native-contacts';
import Icon from 'react-native-vector-icons/FontAwesome';
import RNCallKeep from 'react-native-callkeep';
import uuid from 'uuid';
import { AppContext, Navbar } from 'app/components';
import styles from './style';

const dm = Dimensions.get('screen');
class MainScreen extends Component {
  constructor(props) {
    super(props);

    this.state = {
      lastCallNumber: ''
    };
    this.currentCallId = null;

    // Initialise RNCallKeep
    const options = {
      ios: {
        appName: 'Nope'
      },
      android: {
        alertTitle: 'Permissions required',
        alertDescription:
          'This application needs to access your phone accounts',
        cancelButton: 'Cancel',
        okButton: 'ok'
      }
    };

    try {
      RNCallKeep.setup(options);
      RNCallKeep.setAvailable(true); // Only used for Android, see doc above.
    } catch (err) {
      console.error('initializeCallKeep error:', err.message);
    }

    // Add RNCallKeep Events
    RNCallKeep.addEventListener('didReceiveStartCallAction', this.onNativeCall);
    RNCallKeep.addEventListener('answerCall', this.onAnswerCallAction);
    RNCallKeep.addEventListener('endCall', this.onEndCallAction);
    RNCallKeep.addEventListener(
      'didDisplayIncomingCall',
      this.onIncomingCallDisplayed
    );
    RNCallKeep.addEventListener(
      'didPerformSetMutedCallAction',
      this.onToggleMute
    );
    RNCallKeep.addEventListener(
      'didActivateAudioSession',
      this.audioSessionActivated
    );
  }

  onNativeCall = ({ handle }) => {
    // Your normal start call action
    alert('call');
    RNCallKeep.startCall(this.getCurrentCallId(), handle);
  };

  onAnswerCallAction = ({ callUUID }) => {
    // called when the user answer the incoming call
  };

  onEndCallAction = ({ callUUID }) => {
    RNCallKeep.endCall(this.getCurrentCallId());

    this.currentCallId = null;
  };

  onIncomingCallDisplayed = (error) => {

    alert('call');
    // You will get this event after RNCallKeep finishes showing incoming call UI
    // You can check if there was an error while displaying
  };

  onToggleMute = (muted) => {
    // Called when the system or the user mutes a call
  };

  audioSessionActivated = (data) => {
    // you might want to do following things when receiving this event:
    // - Start playing ringback if it is an outgoing call
  };

  getCurrentCallId = () => {
    if (!this.currentCallId) {
      this.currentCallId = uuid.v4();
    }

    return this.currentCallId;
  };

  async componentDidMount() {
    this.reload();
    if (Platform.OS === 'android') {
      PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_CONTACTS, {
        title: 'Contacts',
        message: 'This app would like to view your contacts.'
      }).then(() => {
        Contacts.getAll((err, contacts) => {
          if (err === 'denied') {
            // error
            throw err;
          } else {
            // contacts returned in Array
            this.parseContacts(contacts);
          }
        });
      });
    } else {
      Contacts.getAll((err, contacts) => {
        if (err) {
          throw err;
        }
        // contacts returned
     
      });
    }
  }

  reload = async () => {
    await this.context.showLoading();

    this.context.hideLoading();
  };

  leftHandler = () => {
    this.props.navigation.toggleDrawer();
  };

  upVote() {
    alert('Yep!');
  }

  downVote() {
    alert('Nope!');
  }

  render() {
    return (
      <View style={styles.container}>
        <Navbar
          left="ios-menu"
          leftHandler={this.leftHandler}
          title="Dashboard"
        />
        <View style={styles.container}>
          <Text style={styles.title}>Nope</Text>
          <Text style={styles.description}>Please rate the calls below:</Text>
          <View style={styles.box}>
            <Text style={styles.description}>Was this call legit?</Text>
            <Text style={styles.description}>{this.state.lastCallNumber}</Text>
          </View>
          <View style={styles.voteBox}>
            <View style={styles.leftBox}>
              <TouchableOpacity onPress={() => this.upVote()}>
                <Text style={styles.voteTitle}>
                  Yep
                  <Icon name="thumbs-up" size={30} color="grey" />
                </Text>
              </TouchableOpacity>
            </View>
            <View style={styles.rightBox}>
              <TouchableOpacity onPress={() => this.downVote()}>
                <Text style={styles.voteTitle}>
                  Nope!
                  <Icon name="thumbs-down" size={30} color="grey" />
                </Text>
              </TouchableOpacity>
            </View>
          </View>
        </View>
      </View>
    );
  }
}

MainScreen.contextType = AppContext;

MainScreen.propTypes = {
  navigation: PropTypes.object
};

export default MainScreen;

iOS and Android packages are correctly imported and running without any errors.
But can't catch event as I desired.
Thanks.

@dreamdev21
Copy link
Author

Hi, Any update about this issue?

@danjenkins
Copy link
Collaborator

Thats odd @webmasterdragon - have you looked at the debugging on ios? It should tell you when the event was raised. https://github.com/react-native-webrtc/react-native-callkeep/blob/master/ios/RNCallKeep/RNCallKeep.m#L402 for example. I can't see anything glaringly obviously wrong

@dreamdev21
Copy link
Author

dreamdev21 commented Jun 12, 2019

Thanks for your reply.
I have some questions: @danjenkins

  • Does this library support voip && real phone numbers?
  • Is this working on android?
  • Does this support get incoming phone numbers and block call?

@danjenkins
Copy link
Collaborator

How do you mean voip and real phone numbers? If you mean handling phone calls to replace your dialer on android - it doesn't support that. Its used in conjunction with a voip app which makes and handles its own calls.

Yes

If you mean get events when an incoming PSTN/Cellular call comes in and block it - no

@dreamdev21
Copy link
Author

Thanks.

@ShahVivek
Copy link

@webmasterdragon, I am facing the same issue. I have followed the installation and linking process and added code in AppDelegate, index and other relevant files. I have implemented
RNCallKeep.setup(options); and added listener for RNCallKeep. But still, none of my listeners gets called on both android and iOS.
For iOS maybe it requires the implementation of VOIP push from backend side. But I can't figure out what's wrong with android side.
@danjenkins or @webmasterdragon Do you have any idea or do you suggest any configuration that maybe I missed.

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

No branches or pull requests

3 participants