private async refreshToken()

in src/directLineStreaming.ts [158:186]


  private async refreshToken(firstCall = true, retryCount = 0) {
    await this.waitUntilOnline();

    let numberOfAttempts = 0;
    while(numberOfAttempts < MAX_RETRY_COUNT) {
      numberOfAttempts++;
      await new Promise(r => setTimeout(r, refreshTokenInterval));
      try {
        const res = await fetch(`${this.domain}/tokens/refresh`, {method: "POST", headers: this.commonHeaders()});
        if (res.ok) {
          numberOfAttempts = 0;
          const {token} = await res.json();
          this.token = token;
        } else {
          if (res.status === 403 || res.status === 403) {
            console.error(`Fatal error while refreshing the token: ${res.status} ${res.statusText}`);
            this.streamConnection.disconnect();
          } else {
            console.warn(`Refresh attempt #${numberOfAttempts} failed: ${res.status} ${res.statusText}`);
          }
        }
      } catch(e) {
        console.warn(`Refresh attempt #${numberOfAttempts} threw an exception: ${e}`);
      }
    }

    console.error("Retries exhausted");
    this.streamConnection.disconnect();
  }