Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!