gpt4 book ai didi

javascript - 如何发送 Twilio 连接并在 Twilio Client Javascript SDK 的另一个函数中接受它?

转载 作者:行者123 更新时间:2023-12-04 10:44:09 29 4
gpt4 key购买 nike

我正在使用 Twilio JS SDK 快速入门在我的网站上调用和接听电话:
https://www.twilio.com/docs/voice/client/javascript/quickstart

https://www.twilio.com/docs/voice/client/javascript/connection

当我接到电话时,我想通过单击一个按钮连接到该来电,所以这是我的代码:

HTML:

<div id="register"></div>

JS:
function capable(tkn){ //tkn is the token.
var devices;
devices = new Twilio.Device(tkn, {
// Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
// providing better audio quality in restrained network conditions. Opus will be default in 2.0.
allowIncomingWhileBusy: true,
codecPreferences: ['opus', 'pcmu'],
// Use fake DTMF tones client-side. Real tones are still sent to the other end of the call,
// but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone
// a second time and sending the tone twice. This will be default in 2.0.
fakeLocalDTMF: true,
sounds: {
incoming: 'https://www.mywebsite.com/audio/ring-ring.mp3'
}

});

devices.on('incoming', function (conn) {
console.log('Incoming connection from ' + conn.parameters.From);
var telf = conn.parameters.From;
var reg = '<div class="reg_item">';
reg += '<p>Caller: </p>' + telf;
reg += '<button onclick="answerB('+conn+');" class="btn btn-md btn-success"><i class="fa fa-phone" aria-hidden="true"></i></button>';
reg += '</div>';

$("#register").prepend(reg);
}

}

function answerB(idx){
console.log(idx);
idx.accept();
}

似乎它不能以这种方式显示此错误:

enter image description here

安慰:

enter image description here

我该如何解决?

我需要你的帮助。

谢谢你。

最佳答案

而不是这个:

console.log('Incoming connection from ' + conn.parameters.From);
var telf = conn.parameters.From;
var reg = '<div class="reg_item">';
reg += '<p>Caller: </p>' + telf;
reg += '<button onclick="answerB(' + conn + ');" class="btn btn-md btn-success"><i class="fa fa-phone" aria-hidden="true"></i></button>';
reg += '</div>';

$("#register").prepend(reg);

改为:

console.log('Incoming connection from ' + conn.parameters.From);
var telf = conn.parameters.From;
var reg = '<div class="reg_item">';
reg += '<p>Caller: </p>' + telf;
reg += '<button id="button-answer" class="btn btn-md btn-success"><i class="fa fa-phone" aria-hidden="true"></i></button>';
reg += '</div>';

$("#register").prepend(reg);
$("#button-answer").on("click", conn, answerB);

和你的 answerB 功能应该是:

function answerB(event) {
console.log(event.data);
event.data.accept();
}

如果你设法让它工作,请告诉我。

关于javascript - 如何发送 Twilio 连接并在 Twilio Client Javascript SDK 的另一个函数中接受它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59795157/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com