-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
event.service.ts
56 lines (48 loc) · 1.52 KB
/
event.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Injectable, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { ConfigService } from './config/config.service';
import { PrinterEvent } from './model/event.model';
import { SocketService } from './services/socket/socket.service';
@Injectable()
export class EventService implements OnDestroy {
private subscriptions: Subscription = new Subscription();
private printing = false;
public constructor(
private socketService: SocketService,
private configService: ConfigService,
private router: Router,
) {
this.subscriptions.add(
this.socketService.getEventSubscribable().subscribe((event: PrinterEvent) => this.handlePrinterEvent(event)),
);
}
private handlePrinterEvent(event: PrinterEvent): void {
if (event === PrinterEvent.PRINTING || event === PrinterEvent.PAUSED) {
setTimeout(() => {
this.printing = true;
}, 500);
} else {
setTimeout(() => {
this.printing = false;
}, 1000);
}
if (event === PrinterEvent.CLOSED) {
this.router.navigate(['/standby']);
} else if (event === PrinterEvent.CONNECTED) {
setTimeout(() => {
if (this.configService.isTouchscreen()) {
this.router.navigate(['/main-screen']);
} else {
this.router.navigate(['/main-screen-no-touch']);
}
}, 500);
}
}
ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}
public isPrinting(): boolean {
return this.printing;
}
}