Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
Why is this instance of a class being converted to a regular object in JavaScript?

I am making an app with WebSockets in Node.js. In order to run certain things asynchronously, I wrapped some async code in an async function and then ran it.

However, the issue is that whenever this portion is ran, the code throws an error that call.createTransport is not a function. This function is clearly defined in the Call class and works when I call it outside of this context.

I proceeded to log the call and found that before running the async function, the call object was an instance of Call, but inside the async function it is a regular JavaScript object, with the properties but not the methods defined.

I am completely stuck on this issue. I am running Node.js 16 LTS.

(async (call, produce, consume) => {
    let sendTransport;
    if (produce) {
        sendTransport = await call.createTransport();
    }
    let receiveTransport;
    if (consume) {
        receiveTransport = await call.createTransport();
    }
    return { sendTransport, receiveTransport };
})(client.call, produce, consume).then(({ sendTransport, receiveTransport }) => {
    callClients.set(sId, {
        ...client,
        produce: true,
        sendTransport,
        receiveTransport
    });
    s.send(JSON.stringify({
        type: CallEventType.TRANSPORT,
        data: {
            sendTransport,
            receiveTransport
        }
    }));
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda