我正在使用React Native应用程序使用Twilio可编程语音呼叫进行呼叫,我能够将其集成到android系统中,但呼叫功能无法正常工作
await TwilioVoice.initWithToken(token)
returns return "initialized:true"
But
TwilioVoice.addEventListener('deviceReady', () => {
this.setState({ twilioInited: true });
});
is not working
to make a call even if I have manually set it to true but no response on
makeCall button
shown in blow code
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,TouchableOpacity,
PermissionsAndroid} from 'react-native';
import TwilioVoice from 'react-native-twilio-programmable-voice';
await TwilioVoice.initWithToken(token)
returns return "initialized:true"
But
TwilioVoice.addEventListener('deviceReady', () => {
this.setState({ twilioInited: true });
});
is not working
to make a call even if I have manually set it to true but no response on
makeCall button
shown in blow code
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,TouchableOpacity,
PermissionsAndroid} from 'react-native';
import TwilioVoice from 'react-native-twilio-programmable-voice';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component
<Props>
{
state = {
twilioInited: false
};
getAuthToken = () => {
return fetch('http.api.?pincode=Test&method=access_token&format=json', { //replace c2a19b17.ngrok.io with your link (from Step 1)
method: 'get',
})
.then(response => response.text())
.catch((error) => console.error(error));
}
getMicrophonePermission = () => {
const audioPermission = PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
return PermissionsAndroid.check(audioPermission).then(async result => {
if (!result) {
const granted = await PermissionsAndroid.request(audioPermission, {
title: 'Microphone Permission',
message: 'App needs access to you microphone ' + 'so you can talk with other users.',
});
}
});
}
/*async componentWillMount() {
const token = await this.getAuthToken();
alert(token);
// or
TwilioVoice.initWithToken(token);
TwilioVoice.Device.connect({To: '+12054764217'});
TwilioVoice.addEventListener('deviceReady', () => {
this.setState({ twilioInited: true });
});
}*/
initTwilio = async () => {
const token = await this.getAuthToken();
if (Platform.OS === 'android') {
await this.getMicrophonePermission();
}
const success = await TwilioVoice.initWithToken(token)
alert(JSON.stringify(success));// return "initialized:true"
TwilioVoice.addEventListener('deviceReady', () => {
this.setState({ twilioInited: true });
});
if (Platform.OS === 'ios') { //required for ios
TwilioVoice.configureCallKit({
appName: 'ReactNativeTwilioExampleApp',
});
}
};
makeCall = () => TwilioVoice.connect({'To': '+12054764217'})
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={() =>
this.initTwilio()}>
<View>
<Text>Init Twilio</Text>
</View>
</TouchableOpacity>
<TouchableOpacity disabled={!this.state.twilioInited} onPress={() =>
this.makeCall()}>
<View>
<Text>Make call ({this.state.twilioInited ? 'ready' : 'not ready'})</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
答案 0 :(得分:1)
如果将Twilio的voice-quickstart-server-node用作服务器,请确保将request.body.to和request.query.to更改为request.body.To和request.query.To。该代码区分大小写,需要进行更改才能进行调用。有关使用connect()进行呼叫的可行示例,请查看https://medium.com/@edzh1/create-a-twilio-voip-calls-in-a-react-native-app-35a729a9613d