javascript - browser call - Twilio.js in Struts2 (Java) -


new struts2 , twilio.js (api sdk) here needing guidance.

i have double checked twilio credentials, created access token , got accepted on browser, "[device]: stream ready" on console log. when try dial number using twilio.device.connect(~), console log shows {code: 31002, message: "connection declined", connection: a}. don't know on logs. have setup voice url of twiml app on twilio account , test connection ngrok https.

//activate call start             var connection = null;             $("#activate-calls").click(function(){                  $("#answer").hide();                 $("#hangup").hide();                 $("#reject").hide();                  $.getjson('activatecalls').done(                          function (data) {                              // log('got token.');                               console.log('token: ' + data.data.token);                                // setup twilio.device                               twilio.device.setup(data.data.token, {debug: true});                               twilio.device.ready(function (device) {                                     $("#log").text("ready");                                 });                               twilio.device.error(function (error) {                                     $("#log").text("error: " + error.message);                                 });                               twilio.device.connect(function (conn) {                                      $("#log").text("successfully established call");                                     $("#call").hide();                                     $("#reject").hide();                                     $("#hangup").show();                                  });                               twilio.device.disconnect(function (conn) {                                     $("#log").text("call ended. ready new incoming/ outgoing calls.");                                     $("#hangup").hide();                                     $("#call").show();                                 });                                   twilio.device.incoming(function(conn) {                                     // set reference current                                     // connection when receive                                     // incoming call                                     alert("ringring");                                     connection = conn;                                     $("#log").text("incoming call " + conn.parameters.from);                                     $("#answer").show();                                     $("#call").hide();                                     $("#reject").show();                                      // clear reference                                     // connection when disconnected.                                     connection.disconnect(function() {                                         connection = null;                                     })                                 });                                  twilio.device.cancel(function(conn) {                                     $("#log").text("ready");                                     $("#answer").hide();                                     $("#reject").hide();                                     $("#call").show();                                 });                                 $("#reject").click(function() {                                     $("#log").text("incoming call rejected. ready new incoming/ outgoing calls.");                                     connection.reject();                                     $("#answer").hide();                                     $("#reject").hide();                                     $("#call").show();                                   });                                  $("#answer").click(function() {                                     // if there's no pending connection,                                     // there's nothing do.                                     if (!connection) { return; }                                      // update interface                                     $("#answer").hide();                                     $("#call").show();                                     $("#log").text("call accepted");                                      // accept current connection.                                     connection.accept();                                 });                                  $("#call").click(function() {                                     // phone number connect call                                     params = {"phonenumber": $("#number").val()};                                     twilio.device.connect(params);                                 });                                  $("#hangup").click(function() {                                     twilio.device.disconnectall();                                     $("#log").text("ready");                                 });                              }                    );               });               //activate call end 

the jsp/html looks this..

<div align="center">                 <div class="form-inline">                     <div class="input-group">                         <div class="input-group-addon"><img src="https://www.twilio.com/bundles/favicons/img/twilio_16.png" /></div>                         <input type="text" class="form-control" id="number" name="number">                     </div>                      <button class="btn btn-success" id="answer">accept</button>                      <button class="btn btn-success" id="call">call</button>                      <button class="btn btn-danger" id="hangup">hangup</button>                      <button class="btn btn-danger" id="reject">reject</button>                   </div>                 <br>                 <div id="log" class="alert-info" style="width: 347px; font-size: large;"></div>             </div> 

my action class on activecalls create token this:

public string execute(){      logger.debug("mci> activatecallsaction.execute");      string identity = "johnny";      list<scope> scopes = new arraylist<>();     scopes.add(new incomingclientscope(identity));     scopes.add(new outgoingclientscope.builder(app_sid).build());       jwt jwt = new clientcapability.builder(account_sid, auth_token).scopes(scopes).build();      string token = jwt.tojwt();     logger.debug("token: " + token);      hashmap<string, string> json = new hashmap<>();     json.put("identity", identity);     json.put("token", token);     data = json;      logger.debug(json.get("token") + "-" + json.get("identity"));        return "success"; } 

i can post complete error console logs if needed. tia!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -