我已将 Twilio 视频通话功能集成到 React Native 的博览会应用程序中。但当尝试整合声音时,它不起作用。我已经从后端创建了语音令牌并将其传递到前端移动应用程序,但是当使用“voice.connect”时,我没有得到任何响应
后端代码:
export const getVoiceAccessToken = async (context: Context, roomName?: string) => {
try {
const config = await context.getConfig();
// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
outgoingApplicationSid: config.twilioTwimlAppSid,
incomingAllow: false
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(config.accountSid, config.twilioApiKey, config.twilioAuthtoken, {
identity: "+916282952623",
ttl: TOKEN_TTL_IN_SECONDS
});
token.addGrant(voiceGrant);
context.logger.info("createVoiceToken", "voice token created successfully", token.toJwt());
return token.toJwt();
} catch (error) {
context.logger.info("createVoiceToken", "some error occured", error);
}
};
前端代码:
const makeCall = async () => {
if (route.params.token) {
try {
console.log("inside makeCall TOKEN:", route.params.token);
console.log(voice, "voice");
const outgoingCall = await voice.connect(route.params.token, {
params: {
To: "+916282952623",
recipientType: "ios",
},
});
console.log("Call initiated:", outgoingCall);
// Handle call events (optional)
outgoingCall.on(TwilioCall.Event.ConnectFailure, (error) =>
console.error("ConnectFailure:", error)
);
outgoingCall.on(TwilioCall.Event.Reconnecting, (error) =>
console.error("Reconnecting:", error)
);
} catch (error) {
console.error("Error making call:", error);
}
} else {
console.error("No token available");
}
};
在前端代码中,我可以在
voice.connect
承诺之前看到日志,直到控制台,但之后我没有得到任何响应。我也尝试过使用物理设备。
您只需将此配置添加到您的 app.json 或 app.config.js 文件中:
"ios": {
...your_ios_config,
"infoPlist": {
"UIBackgroundModes": [
"audio",
"fetch",
"location",
"remote-notification",
"voip"
],
"NSMicrophoneUsageDescription": "This app requires access to the microphone to make voice calls.",
"com.apple.developer.pushkit.unrestricted-voip": true
}
}