RXJS:如何获取连接事件? retrywhen:如何挂钩执行?

RXJS: How to get connect event? retrywhen: how to hook into execution?

当Angular尝试连接时,我想显示"Connecting"。我可以在第一次连接时做到这一点,但我不知道如何在使用 retryWhen() 时做到这一点。我需要挂钩到实际执行然后做:

this.connectionStatus = "Connecting"

当前代码:

    this.connectionStatus = "Connecting";

    let socket = new WebSocketSubject(..);

    this.socket
      .pipe(retryWhen(errors =>
        errors.pipe(
          tap(val => {
            console.log("Retry in 10 sec", val);
          }),
          delay(10000)
        )))
      .subscribe(..);

设置延迟后的状态即可。 retryWhen 希望你 return 一个可观察对象,当这个可观察对象发出时,它将开始重试连接,即在 delay

之后开始重试
  errors.pipe(
          tap(val => {
            console.log("Retry in 10 sec", val);
          }),
          delay(10000),
          tap(()=>this.connectionStatus = "Connecting"
)
        )))