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

64
Vistas
How to use the WebSocket readyState to display connection status in app header

I am creating a chat widget using svelte. I want to display the websocket is connected or not using the websocket.readyState property, the readyState values as follows

  • 0- Connecting,
  • 1- Open,
  • 2- Closing,
  • 3- Closed

the status i want to display in app header is

  • connecting while state is 0
  • online when state is 1
  • disconnected when state is 2
almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Well according this documentation you can use the events to know. MDN

0   CONNECTING  Socket has been created. The connection is not yet open.
1   OPEN    The connection is open and ready to communicate.
2   CLOSING The connection is in the process of closing.
3   CLOSED  The connection is closed or couldn't be opened.
  • so when socket = new WebSocket(url) status is CONNECTING
  • when onopen = (event) => { } status is OPEN
  • when onclose or onerror status is CLOSED
  • when invoking socket.close() status is CLOSING

It might be some other situation for CLOSING but not something I know of.

almost 4 years ago · Santiago Trujillo Denunciar
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