Implement ProcessLogService and hook it up to existing log features

This commit is contained in:
Kristóf Tóth
2018-05-29 16:48:45 +02:00
parent 1b8a36331c
commit cfdb69987d
6 changed files with 59 additions and 15 deletions

View 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
});
}
}
}