diff --git a/src/app/services/processcommand.ts b/src/app/services/processcommand.ts new file mode 100644 index 0000000..9b6d711 --- /dev/null +++ b/src/app/services/processcommand.ts @@ -0,0 +1,3 @@ +export class ProcessCommand { + command: string; +} diff --git a/src/app/services/processmanager.service.ts b/src/app/services/processmanager.service.ts new file mode 100644 index 0000000..092a7ac --- /dev/null +++ b/src/app/services/processmanager.service.ts @@ -0,0 +1,41 @@ +import { Injectable } from '@angular/core'; + +import { WebSocketService } from './websocket.service'; +import { ProcessCommand } from './processcommand'; + + +@Injectable() +export class ProcessManagerService { + anchor = 'anchor_processmanager'; + process_name: string; + + constructor(private webSocketService: WebSocketService) {} + + init(process_name: string) { + this.process_name = process_name; + this.webSocketService.connect(); + } + + subscribeCallback(callback: (event: any) => void) { + this.webSocketService.observeAnchor(this.anchor).subscribe(callback); + } + + sendCommand(command: string, callback?: (event: any) => void) { + if (callback) { + this.subscribeCallback(callback); + } + this.webSocketService.send(this.anchor, {'command': command}); + } + + startProcess(callback?: (event: any) => void) { + this.sendCommand('start', callback); + } + + stopProcess(callback?: (event: any) => void) { + this.sendCommand('stop', callback); + } + + restartProcess(callback?: (event: any) => void) { + this.sendCommand('restart', callback); + } +}