Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda