diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index d216b9745..3a567e7f7 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -81,19 +81,13 @@ export class ApiService { private readonly login: LoginService, ) { // show recording archives when recordings available - this.login - .getSessionState() - .pipe( - concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.doGet('recordings') : EMPTY)), - ) - .subscribe({ - next: () => { - this.archiveEnabled.next(true); - }, - error: () => { - this.archiveEnabled.next(false); - }, - }); + this.doGet('recordings').pipe( + tap(() => this.archiveEnabled.next(true)), + catchError(() => { + this.archiveEnabled.next(false); + return EMPTY; + }) + ).subscribe(); const getDatasourceURL: Observable = fromFetch( `${this.login.authority}/api/v1/grafana_datasource_url`, diff --git a/src/app/Shared/Services/Login.service.tsx b/src/app/Shared/Services/Login.service.tsx index f338e0191..23fd5bf4c 100644 --- a/src/app/Shared/Services/Login.service.tsx +++ b/src/app/Shared/Services/Login.service.tsx @@ -22,11 +22,12 @@ import type { SettingsService } from './Settings.service'; export class LoginService { private readonly logout = new ReplaySubject(1); private readonly username = new ReplaySubject(1); - private readonly sessionState = new ReplaySubject(SessionState.CREATING_USER_SESSION); + private readonly sessionState = new ReplaySubject(1); readonly authority: string; constructor(private readonly settings: SettingsService) { this.authority = process.env.CRYOSTAT_AUTHORITY || '.'; + this.sessionState.next(SessionState.CREATING_USER_SESSION); fromFetch(`${this.authority}/api/v2.1/auth`, { credentials: 'include', @@ -46,7 +47,6 @@ export class LoginService { ) .subscribe((v) => { this.username.next(v?.data?.result?.username ?? ''); - this.sessionState.next(SessionState.USER_SESSION); }); } diff --git a/src/app/Shared/Services/NotificationChannel.service.tsx b/src/app/Shared/Services/NotificationChannel.service.tsx index 3bc395ca0..ffcd71785 100644 --- a/src/app/Shared/Services/NotificationChannel.service.tsx +++ b/src/app/Shared/Services/NotificationChannel.service.tsx @@ -65,11 +65,13 @@ export class NotificationChannel { }); }); - combineLatest([this.login.getSessionState(), this._ready, timer(0, 5000)]) + combineLatest([this.login.getSessionState(), timer(0, 5000)]) .pipe(distinctUntilChanged(_.isEqual)) .subscribe({ - next: ([sessionState, readyState]) => { - if (sessionState === SessionState.NO_USER_SESSION || readyState.ready) { + next: (parts: string[]) => { + const sessionState = parseInt(parts[0]); + + if (sessionState !== SessionState.CREATING_USER_SESSION) { return; } @@ -84,7 +86,10 @@ export class NotificationChannel { url: url.toString(), protocol: '', openObserver: { - next: () => this._ready.next({ ready: true }), + next: () => { + this._ready.next({ ready: true }); + this.login.setSessionState(SessionState.USER_SESSION); + }, }, closeObserver: { next: (evt) => { diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index e5134319d..45eb5f76f 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -33,12 +33,9 @@ export class TargetsService { login: LoginService, notificationChannel: NotificationChannel, ) { - login - .getSessionState() - .pipe(concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.queryForTargets() : EMPTY))) - .subscribe(() => { - // just trigger a startup query - }); + // just trigger a startup query + this.queryForTargets().subscribe(); + notificationChannel.messages(NotificationCategory.TargetJvmDiscovery).subscribe((v) => { const evt: TargetDiscoveryEvent = v.message.event; switch (evt.kind) {