最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

reactjs - React js With Vite not able to setup device on twilio voice - Stack Overflow

matteradmin8PV0评论

I am trying to create an app where user can dial a number using twilio sdk. I have installed the SDK, and then have set up the device using the token.

The device is getting initiazed. BUt it should ideally go into device.on event. Unfortunately that is not happening.

I have tried the token and the implementation using vaniall Javascript, and that implementation is working perfectly fine.

this is my code

import { Device } from "@twilio/voice-sdk";


try {
      const newDevice = new Device(token, {
        codecPreferences: ["opus", "pcmu"],
        fakeLocalDTMF: true,
        debug: "all", // Increase logging verbosity
      });
      console.log("here--->77", newDevice);
      newDevice.on("ready", () => {
        console.log("here--->78");
        setIsReady(true);
        setStatus("Ready");
      });
      newDevice.on("connect", () => setStatus("Connected"));
      newDevice.on("disconnect", () => {
        console.log("here--->83");
        setStatus("Disconnected");
      });
      newDevice.on("error", (err) => {
        console.log(err);
        setError(err.message);
      });
      newDevice.on("ringing", () => {
        console.error("ringing");
        setStatus("Ringing");
      });
      newDevice.on("reject", () => {
        console.error("Call was rejected");
        setStatus("Rejected");
      });
      setDevice(newDevice);
} catch (err) {
      console.error("Error initializing device:", err);
      setError("Failed to initialize Twilio device");
}

In the console, I can see here--->77 But then the execution stops. I dont get anything. Not even an error.

Post a comment

comment list (0)

  1. No comments so far