3

I am trying to follow the steps here https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-php/blob/main/quickstart.js

I don't know they Have changed the Javascript SDJ to 2.0 or something. I was familiar with the previous library but it is depreciated. Can someone help me to figure out what's going on I don't know why I am getting this error

Attempting to call Phone numbere here...
backend.js:19648 Setting up VSP
backend.js:19648 Initializing transport backoff using config:  {factor: 2, initialDelay: 100, maxDelay: 20000, randomisationFactor: 0.4}
backend.js:19648 WSTransport.open() called...
backend.js:19648 Attempting to connect...
backend.js:19648 Closing and cleaning up WebSocket...
backend.js:19648 No WebSocket to clean up.
backend.js:19648 WebSocket opened successfully.
backend.js:19648 Setting token and publishing listen
backend.js:19648 Received error:  TransportError: TransportError (31009): No transport available to send or receive messages

JWT Token generation

$identity = uniqid();
        $this->app->bind(
            AccessToken::class,
            function ($app,$identity) {
                $accountSid = '';
                $apiKey = '';
                $apiSecret = '';

                return new AccessToken($accountSid, $apiKey, $apiSecret, 3600, $identity);
            }
        );

Javascript

setupClient() {
             axios.post("/twilio/token", {
                forPage: window.location.pathname,
                _token: $('meta[name="csrf-token"]').attr('content')
            }).then((response) => {
                // console.log(Device.Device(response.token));
                  device = new device(response.data.token, {
                          logLevel: 1,
                          answerOnBridge: true,
                          // 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.
                          codecPreferences: ["codec", "pcmu"],
                        });
                    device.updateToken(response.data.token);
                    //this.getAudioDevices()
                    this.addDeviceListeners(device);

                    this.makeOutgoingCall(device)




            });

        },

 makeOutgoingCall(device) {
    var params = {
      // get the phone number to call from the DOM
      phone: 'Phone here',
    };

    if (device) {
      console.log(`Attempting to call ${params.phone} ...`);

      // Twilio.Device.connect() returns a Call object
      const call = device.connect({ params });

      // add listeners to the Call
      // "accepted" means the call has finished connecting and the state is now "open"
      // call.addListener("accept", updateUIAcceptedCall);
      // call.addListener("disconnect", updateUIDisconnectedCall);
    } else {
      console.log("Unable to make call.");
    }
  },
Qaisar Mughal
  • 43
  • 1
  • 6
  • Why are you creating the device object with the token and then immediately trying to update the token? What happens if you don't do that? – philnash Dec 03 '21 at 06:39
  • I'm currently having the same problem and can't figure it out. It seems no matter what I pass for the token I get this error still (which makes me think it's not the token as even the string "asdf" causes same error). I even tried the beta release of the voice-sdk (2.0.1-RC4) without any success :/ My websocket connection sends empty strings back and forth until the server sends `{payload: {error: {code: 31003, message: "Timed out waiting for LISTEN"}}, type: "error", version: ""}` – Skylord123 Dec 03 '21 at 16:19
  • I fixed this for me. I am using the bootstrap theme SmartAdmin and found their javascript was overriding the `window.WebSocket` function. There was an option at the top of my JS file for `trackWebSockets` that when turned to `false` fixed this issue. So check to see if you're `window.WebSocket` is being over-ridden or messed with. – Skylord123 Dec 06 '21 at 21:48

0 Answers0