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

114
Vistas
web socket connection in angular

I have created a angular project in which my web socket connection is getting open after reloading the page otherwise it does not open. I want to start a socket as soon as user logs in and close the socket as it logs out.

Below is the socket service I created using rxjs web sockets not socket.io :

    SOCKET_URL: string = environment.webSocketEndpoint;
    ws: WebSocketSubject<any>;

    open() {
        this.ws = webSocket(`${this.SOCKET_URL}/?access_token=${this.auth.user()?.['accessToken']}&platform=web`);
    }
    emit(event: Object): void {
        this.ws.next(event);
    }

    events(): Observable<any> {
        if (this.ws === undefined ) {
            this.open();
        }

        return this.ws?.asObservable();
    }

    close() {
        this.ws.unsubscribe();
    }
}

In app.ts on nogOnit() :

if(this.auth.user()){
this.socketService.open()}
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