mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-15 23:41:55 +00:00
Implement first version of ProcessManagerService
This commit is contained in:
parent
a2e5dc39a9
commit
fefed5b84e
3
src/app/services/processcommand.ts
Normal file
3
src/app/services/processcommand.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export class ProcessCommand {
|
||||
command: string;
|
||||
}
|
41
src/app/services/processmanager.service.ts
Normal file
41
src/app/services/processmanager.service.ts
Normal file
@ -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<ProcessCommand>(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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user