mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 12:33:40 +00:00
31 lines
864 B
TypeScript
31 lines
864 B
TypeScript
import { StaticClassProvider } from '@angular/core'
|
|
import { defer, Observable, switchMap } from 'rxjs'
|
|
import { WebSocketSubjectConfig } from 'rxjs/webSocket'
|
|
import { Log } from '../types/api'
|
|
import { Constructor } from '../types/constructor'
|
|
|
|
interface Api {
|
|
followLogs: () => Promise<string>
|
|
openLogsWebsocket$: (config: WebSocketSubjectConfig<Log>) => Observable<Log>
|
|
}
|
|
|
|
export function provideSetupLogsService(
|
|
api: Constructor<Api>,
|
|
): StaticClassProvider {
|
|
return {
|
|
provide: SetupLogsService,
|
|
deps: [api],
|
|
useClass: SetupLogsService,
|
|
}
|
|
}
|
|
|
|
export class SetupLogsService extends Observable<Log> {
|
|
private readonly log$ = defer(() => this.api.followLogs()).pipe(
|
|
switchMap(url => this.api.openLogsWebsocket$({ url })),
|
|
)
|
|
|
|
constructor(private readonly api: Api) {
|
|
super(subscriber => this.log$.subscribe(subscriber))
|
|
}
|
|
}
|