首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twilio浏览器到浏览器

Twilio浏览器到浏览器
EN

Stack Overflow用户
提问于 2016-04-30 22:13:23
回答 1查看 98关注 0票数 0

我正在通过twilio快速入门,但有一个问题-我的呼叫按钮不能触发对twilio的请求;

代码语言:javascript
复制
namespace twilioMvc.Controllers
{
    public class BrowserToBrowserController : Controller
    {
        string accountSid;
        string authToken;
        string appSid;
        string clientName;
        string token;
        public BrowserToBrowserController()
        {
            NameValueCollection manager = ConfigurationManager.GetSection("appSettings") as NameValueCollection;
            accountSid = manager["acSID"];
            authToken = manager["authToken"];
            // put your Twilio Application Sid here
            appSid = manager["appSID"];
            // put your default Twilio Client name here
            clientName = "jenny";

            var capability = new TwilioCapability(accountSid, authToken);
            capability.AllowClientOutgoing(appSid);
            capability.AllowClientIncoming(clientName);
            token = capability.GenerateToken();
        }

        public ActionResult Index(string name)
        {
            if (name != "" && name != null)
            {
                clientName = name;
            }

            var client = new Client() { clientName = clientName, token = token };
            return View("Index", client);
        }

        [HttpPost]
        public ActionResult Call(string PhoneNumber)
        {
            // put your default Twilio Client name here, for when a phone number isn't given
            string number = "jenny";

            // get the phone number from the page request parameters, if given
            if (PhoneNumber != null)
            {
                number = PhoneNumber;
            }

            var response = new XElement("Response");
            response.Add(new XElement("Dial", new XElement("Client", number)));                               

            return this.Content(response.Value, "text/xml");

        }
    }
}

以下是页面代码

代码语言:javascript
复制
@model twilioMvc.Models.Client

<!DOCTYPE html>
<html>
<head>
    <title>Hello Client Monkey 5</title>
    <script type="text/javascript"
            src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script>
    <script type="text/javascript"
            src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>
    <link href="//static0.twilio.com/resources/quickstart/client.css"
          type="text/css" rel="stylesheet" />
    <script type="text/javascript">

        Twilio.Device.setup('@Model.token');

        Twilio.Device.ready(function (device) {
            $("#log").text("Client '@Model.clientName' is ready");
        });

        Twilio.Device.error(function (error) {
            $("#log").text("Error: " + error.message);
        });

        Twilio.Device.connect(function (conn) {
            $("#log").text("Successfully established call");
        });

        Twilio.Device.disconnect(function (conn) {
            $("#log").text("Call ended");
        });

        Twilio.Device.incoming(function (conn) {
            $("#log").text("Incoming connection from " + conn.parameters.From);
            // accept the incoming connection and start two-way audio
            conn.accept();
        });

        function call() {
            // get the phone number or client to connect the call to
            params = { "PhoneNumber": $("#number").val() };
            Twilio.Device.connect(params);
        }

        function hangup() {
            Twilio.Device.disconnectAll();
        }
    </script>
</head>
<body>
    <button class="call" onclick="call();">
        Call
    </button>

    <button class="hangup" onclick="hangup();">
        Hangup
    </button>

    <input type="text" id="number" name="number"
           placeholder="Enter a phone number or client to call" />

    <div id="log">Loading pigeons...</div>
</body>
</html>

因此,当我点击我的呼叫按钮时,应该会调用twilio应用程序,然后它应该使用void route调用我的站点(在twilio站点上填写了我的应用程序部分),但有一个问题。你能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2016-05-01 14:56:48

我已经修复了为Object.assign添加浏览器多边形填充时出现的错误。但是我还有另一个问题,那就是立即挂断我的浏览器到浏览器的调用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36955932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档