|
@@ -0,0 +1,44 @@
|
|
|
+import { Injectable } from '@nestjs/common';
|
|
|
+import { EventEmitter } from 'events';
|
|
|
+import { fromEvent, Observable } from 'rxjs';
|
|
|
+
|
|
|
+@Injectable()
|
|
|
+export class EventsService {
|
|
|
+ private readonly emitter: EventEmitter;
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ this.emitter = new EventEmitter();
|
|
|
+ }
|
|
|
+
|
|
|
+ private subscribe(event: string): Observable<unknown> {
|
|
|
+ return fromEvent(this.emitter, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ private emit(event: string, data: any): void {
|
|
|
+ this.emitter.emit(event, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ subscribeUserPrivilegeUpdate(vatsimId: string): Observable<unknown> {
|
|
|
+ return this.subscribe(`/users/${vatsimId}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ emitUserPrivilegeUpdate(vatsimId: string): void {
|
|
|
+ this.emit(`/users/${vatsimId}`, {});
|
|
|
+ }
|
|
|
+
|
|
|
+ subscribeAirportRenew(): Observable<unknown> {
|
|
|
+ return this.subscribe('/airports/renew');
|
|
|
+ }
|
|
|
+
|
|
|
+ emitAirportRenew(): void {
|
|
|
+ this.emit('/airports/renew', {});
|
|
|
+ }
|
|
|
+
|
|
|
+ subscribeArrivalSequenceUpdate(icao: string): Observable<unknown> {
|
|
|
+ return this.subscribe(`/airports/arrival/${icao}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ emitArrivalSequenceUpdate(icao: string): void {
|
|
|
+ this.emit(`/airports/arrival/${icao}`, {});
|
|
|
+ }
|
|
|
+}
|