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

137
Vistas
socket.io on client side not listening to server events

The socket have to listen to the server when i send a new message.
The messages arrive because when i refresh the page i can see them.
Server side socket i know is working find because in other frontend app the same client socket is working find.
This socket is called every time the user select a new chat in the web.

Here is the socket service in my app:

import openSocket from "socket.io-client";

function connectToSocket() {
    return openSocket("http://localhost:8080");
}

export default connectToSocket;

And here is the code executed when user select a chat:

// how i am importing the socket
import openSocket from "../../Services/socket-io"

async function fetchMessages(ticketId) {
    try {
        const { data } = await api.get("/messages/" + ticketId, {
            params: { pageNumber },
        });

        if (ticketId === data.ticket.id) {
            await loadMessages(data, ticketId);
        }

        listenMessages(ticketId);

    } catch (err) {
        Toast.ToastError("Error trying to load messages");
    }
};

function listenMessages(ticketId) {
    const socket = openSocket();

    socket.on("connect", () => socket.emit("joinChatBox", ticketId));

    socket.on("appMessage", (data) => {
      if (data.action === "create") {       
        console.log(data);
      }

      if (data.action === "update") {
        console.log(data);
      }
    });
}

What i already tried:
Use the same socket version both in client and server (3.0.5).
Calling listenMessages every time a message is sent.
socket.io-client version 4.

about 4 years ago · Santiago Gelvez
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