title: angular 9 websocket get connection status
body: <p>I wrote simple websocket connection on angular 9 .<br>
  this is example code :    </p>
  
  <pre><code>import {Injectable} from '@angular/core';
  import {webSocket} from 'rxjs/webSocket';
  import {delay, retryWhen} from 'rxjs/operators';
  
  @Injectable({
    providedIn: 'root'
  })
  export class WebSocketService {
    private host = 'ws://localhost:8080/test';
    private isConnected = false;
  
    private ws = webSocket({
      url: this.host,
      openObserver: {
        next: () =&gt; this.isConnected = true
      },
      closeObserver: {
        next: () =&gt; this.isConnected = false
      }
    });
  
    constructor() {
      this.ws
        .pipe(
          retryWhen(e =&gt; {
            delay(400);
            return e;
          })
        ).subscribe();
  
      console.log('Connection status: ' + this.isConnected);
    }
  
    public sendMessage(msg: string) {
      this.ws.next(msg);
    }
  }
  </code></pre>
  
  <p>with this code i can send message without any problem .<br>
  I want to check connection status but <code>isConnected</code> always return false !<br>
  How can fix this problem ?  </p>