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

admin2025-04-26  9

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745658122a312572.html

最新回复(0)