0

I am create a button to make call but when I click on the call button and call the twilio connection object it doesnt work it calls the disconnect object.

here is my code

    $accountSid = 'xxxx';
$authToken  = 'xxx';

// put your TwiML Application Sid here
$appSid = 'xxxxx';
$capability = new ClientToken($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$capability->allowClientIncoming('jenny');
$token = $capability->generateToken();

      Twilio.Device.setup("<?php echo $token; ?>");

      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");

        console.log(conn.status());

      });



      Twilio.Device.disconnect(function (conn) {



        $("#log").text("Call ended");

      });
       Twilio.Device.error(function (conn) {



        $("#log").text("Call ended");

      });

   Twilio.Device.cancel(function(conn) {

        console.log(conn.parameters.From); // who canceled the call

        conn.status // => "closed"

    });

      Twilio.Device.incoming(function (conn) {

        $("#log").text("Incoming connection from " + conn.parameters.From);

        // accept the incoming connection and start two-way audio

        conn.status

       var ask = confirm("Incoming Call Please ANSWER");

       if(ask){



          console.log(conn.status());

        conn.accept();



          console.log(conn.status());

       }else{

          console.log(conn.status());

          var a = conn.status();

          console.log(a);



        // Twilio.Device.disconnectAll();

       }



      });



      function call() {



        // get the phone number to connect the call to+19082900867

                params = {"phone": $("#PhoneNumber").val(), "callerId": "+17203303808"};

               connection = Twilio.Device.connect(params);

            console.log(connection.status);



        // Twilio.Device.connect();

      }



      function hangup() {

        Twilio.Device.disconnectAll();

      }

I dont what is wrong but in the starting in show that you are ready but when I click on call button it shows you call disconnected

Mohd Mobeen
  • 75
  • 1
  • 1
  • 6
  • This looks like it is code from the [Twilio Client Quickstart](https://www.twilio.com/docs/quickstart/client/javascript), is that right? Did you manage to get the application working without changing anything? What is the code that connects your button to making the call? – philnash Mar 07 '18 at 05:43
  • Yes and Thanks for writing but I solved it. There is nothing wrong with the code – Mohd Mobeen Mar 07 '18 at 06:58
  • I am facing a similar problem, works fine locally on my machine but gets immediately disconnected on making or receiving the calls. any ideas @MohdMobeen – Shuja Ahmed Jan 06 '22 at 20:47

0 Answers0