Open shubham-pal-clecotech opened 4 months ago
Hi @shubham-pal-clecotech please fill out the issue description.
@mhuynh5757 import React from 'react'; import { CallInvite, Voice, Call, CancelledCallInvite, AudioDevice, } from '@twilio/voice-react-native-sdk'; const voice = new Voice(); let call = new Call({}); var token = ''; async function login() { console.log('hiilogin'); try {
const response = await fetch( 'https://67b8-122-168-238-141.ngrok-free.app/twilio/twilio_numbers/get_mobile_app_token?id=14243468978&push_credential_sid=CR94014b9797f27bfb4e06990ae524c543', ); console.log(response, 'response'); const accessToken = await response.json(); console.log(accessToken, 'accessToken'); token = accessToken.token;
voice.on(Voice.Event.Registered, e => { console.log('Registered', e); }); const register = await voice.register(accessToken.token); console.log('registeredc', register); voice.on(Voice.Event.RegistrationFailed, e => { console.log('Registration Failed', e); }); } catch (err) { console.log(err); } }
voice.on(Voice.Event.CallInvite, callInvite => { console.log('Incoming call:', callInvite); const incomingCall = new Call(callInvite); // Now incomingCall is available for further handling console.log('afterhadnle'); });
async function connect(phoneNumber) { try { let test = await voice.connect(token, { params: { To: '14245522537', From: '14243468978', }, }); console.log(test, 'TESSSTTT'); call = test; console.log('Call initiated successfully', call); } catch (err) { console.log(err); } } // Add event handlers for the connected call call.on('connected', () => { console.log('Call connected'); });
call.on('disconnected', (call, error) => { console.log('Call disconnected', error); });
call.on('connecting', () => { console.log('Call connecting'); });
call.on('reconnected', () => { console.log('Call reconnected'); });
call.on('reconnecting', (call, error) => { console.log('Call reconnecting', error); });
call.on('ringing', () => { console.log('Call ringing'); });
call.on('connectFailure', (call, error) => { console.log('Call connect failure', error); if (error) { if (error.code) { console.log('Error Code:', error.code); } if (error.message) { console.log('Error Message:', error.message); } if (error.description) { console.log('Error Description:', error.description); } } else { console.log('No error details available'); } });
voice.on(Voice.Event.Unregistered, e => { console.log('Unregistered', e); }); voice.on(Voice.Event.Error, e => { console.log('Error', e); }); voice.on(Voice.Event.AudioDevicesUpdated, e => { console.log('AudioDevicesUpdated', e); }); voice.on(Voice.Event.CallInvite, e => { console.log('CallInvite', e); }); voice.on(Voice.Event.CallInviteAccepted, e => { console.log('CallInviteAccepted', e); }); voice.on(Voice.Event.CallInviteNotificationTapped, e => { console.log('CallInviteAccepted', e); }); voice.on(Voice.Event.CallInviteRejected, e => { console.log('CallInviteRejected', e); }); voice.on(Voice.Event.CancelledCallInvite, e => { console.log('CancelledCallInvite', e); });
async function rejectCall(event) { console.log('hiiirejectcall'); console.log('hiidisconect', event); let sid = event.twi_call_sid; console.log('siddd', sid); try { if (call && call.state === 'connecting') { await call.disconnect(); console.log('Call disconnected successfully'); } else { console.log('goinginlese'); const cancelCall = new CancelledCallInvite(sid);
console.log('Call rejected successfully', cancelCall); } } catch (error) { console.error('Error disconnecting call:', error); } }
async function callMute(e) { const isMuted = await call.mute(e); console.log('isMuted', isMuted); }
async function sendDigits(digit) { const digits = await call.sendDigits(digit); console.log('digits', digits); }
async function callDisconnect(event) { console.log('hiidisconect', event); console.log('hiidisconect', call);
const disconnect = await new Call(event).disconnect(); console.log('disconnect', disconnect); }
export {login, connect, callMute, sendDigits, callDisconnect, rejectCall}; I am trying with this i have successfully call i am getting the call but now i want to try to reject and accept an incoming call i am unable to do this how can i achieve this can you help even i am not getting the callinvite console listener i am stuck here
@shubham-pal-clecotech have you tried running our test App: https://github.com/twilio/twilio-voice-react-native/tree/main/test/app ? It allows you to accept and reject incoming calls.
Issue
Pre-submission Checklist
Description
A clear and concise description of what the issue is.
Reproduction Steps
Expected Behavior
A clear and concise description of what you expected to happen.
Actual Behavior
What actually happens.
Reproduction Frequency
Is the reproducibility of the issue deterministic? If not, what percentage of the time does the issue occur? In how many attempts was the issue observed?
Screenshots
If applicable, add screenshots to help explain your problem.
Software and Device Information
Please complete the following information.
Additional Context
Add any other context about the problem here.