mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-07-12 14:56:24 +00:00
Implement ProcessLogService and hook it up to existing log features
This commit is contained in:
31
src/app/services/processlog.service.ts
Normal file
31
src/app/services/processlog.service.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { WebSocketService } from './websocket.service';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { ProcessLogCommand } from './processlog-command';
|
||||
import { config } from '../config';
|
||||
|
||||
@Injectable()
|
||||
export class ProcessLogService {
|
||||
newLog = new Subject<any>();
|
||||
showLiveLogs = config.console.showLiveLogs;
|
||||
|
||||
command_handlers = {
|
||||
'new_log': this.newLogHandler.bind(this)
|
||||
};
|
||||
|
||||
constructor(private webSocketService: WebSocketService) {
|
||||
this.webSocketService.connect();
|
||||
this.webSocketService.observeKey<ProcessLogCommand>('processlog').subscribe(
|
||||
(event) => this.command_handlers[event.data.command](event.data)
|
||||
);
|
||||
}
|
||||
|
||||
newLogHandler(data: ProcessLogCommand) {
|
||||
if (this.showLiveLogs) {
|
||||
this.newLog.next({
|
||||
stdout: data.stdout,
|
||||
stderr: data.stderr
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user