twilio / twilio-voice-react-native

Other
72 stars 27 forks source link

iOS Call Invite not working #368

Closed ErfanOrangetoolz closed 4 months ago

ErfanOrangetoolz commented 4 months ago

Issue

Hii, In our React Native application, we have encountered an issue where voice registration seems to be successful, but the functionality to initiate invite calls is failing. This problem specifically arises when utilizing an older version of React Native along with an older version of the Twilio package. Interestingly, the older versions of both React Native and Twilio work seamlessly, but upon updating either or both, the invite call feature fails to function properly.

  const [token, setToken] = useState<any>('');
  const createCallRef = useRef<any>({
    uuid: '',
    customParameters: '',
    from: '',
    sid: '',
    to: '',
    isMuted: false,
    isOnHold: false,
  });
  const callRef = useRef<any>(null);
  const getAceesstoken = async () => {
    return rootApi(
      'GET',
      userApiEndPoint.userTwilioAccessToken + '?type=apn&timeLimit=86400', //fcm
    );
  };
  const voice = new Voice();

  // Allow incoming calls
  const register = async () => {
    try {
      const {body, status} = await getAceesstoken();
      if (status) {
        await voice.initializePushRegistry();
        setToken(body);
        await voice.register(body.token);
        console.log('Device Registrated');
      }
    } catch (error: any) {
      console.log({error});
    }
  };
  const makeCallHandler = async () => {
    const data = {
      to: '+000000000000',
      from: '+1111111111111111',
      identity: token.identity,
      token: token.token,
    };
    const callConnectResponse: any = await voice.connect(token.token, {
      contactHandle: data.identity,
      params: {
        recipientType: 'client',
        To: data.to,
        From: data.from,
      },
    });
    if (callConnectResponse) {
      createCallRef.current.uuid = callConnectResponse._uuid;
      createCallRef.current.customParameters =
        callConnectResponse._customParameters;
      createCallRef.current.sid = callConnectResponse._sid;
      createCallRef.current.from = data.from;
      createCallRef.current.to = data.to;
      createCallRef.current.isMuted = false;
      createCallRef.current.isOnHold = false;
      createCallEvent({
        callConnect: callConnectResponse,
        data,
        actionType: 'out',
        callRef,
      });
    }
  };
  const createCallEvent = ({
    callConnect: callOut,
    callInvite: callIn,
    data,
    actionType = 'in',
  }: any) => {
    try {
      const newCallRes = new Call({
        uuid: actionType === 'in' ? callIn._uuid : callOut._uuid,
        customParameters:
          actionType === 'in'
            ? callIn._customParameters
            : callOut._customParameters,
        from: actionType === 'in' ? callIn._from : data.from,
        sid: actionType === 'in' ? callIn._callSid : callOut._sid,
        to: actionType === 'in' ? callIn._to : data.to,
        isMuted: false,
        isOnHold: false,
      });
      if (newCallRes) {
        callRef.current = newCallRes;
      } else {
        console.log('Error');
      }
    } catch (error) {
      console.log(error);
    }
  };
  voice.on(Voice.Event.CallInvite, (callInvite: CallInvite) => {
    console.log('Call Invite');
    callInvite.accept();
  });

  useEffect(() => {
    register();
  }, []);

Pre-submission Checklist

Reproduction Steps

  1. Generate Release File and test but not working

Expected Behavior

Open CallKit

Actual Behavior

Open CallKit and accept call.

Reproduction Frequency

100%

Screenshots

If applicable, add screenshots to help explain your problem.

Software and Device Information

Please complete the following information.

shrutigarg-reactnative commented 1 month ago

How did it get solved @ErfanOrangetoolz