|
@@ -1,10 +1,11 @@
|
|
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
|
import { ClientProxy } from '@nestjs/microservices';
|
|
|
import { ConnectedSocket, MessageBody, OnGatewayConnection, OnGatewayDisconnect, SubscribeMessage, WebSocketGateway, WebSocketServer, WsResponse, } from '@nestjs/websockets';
|
|
|
-import { from, Observable } from 'rxjs';
|
|
|
+import { from, Observable, Subject } from 'rxjs';
|
|
|
import { map } from 'rxjs/operators';
|
|
|
import { Server, Socket } from 'socket.io';
|
|
|
import { SampleAppService } from './sample-app.service';
|
|
|
+import { FisMessage } from 'libs';
|
|
|
|
|
|
@WebSocketGateway({
|
|
|
cors: {
|
|
@@ -17,8 +18,12 @@ export class SampleEventsGateway implements OnGatewayConnection, OnGatewayDiscon
|
|
|
server!: Server;
|
|
|
logger: Logger = new Logger(`SampleEventGateway`)
|
|
|
|
|
|
+ private messageResponseSubject: Subject<FisMessage> = new Subject()
|
|
|
+
|
|
|
constructor(private readonly service: SampleAppService) {
|
|
|
// logic here
|
|
|
+ this.service.getFingerprintMessages().subscribe(message => this.messageResponseSubject.next(message));
|
|
|
+ this.service.getFingerprintMessages().subscribe(message => console.log(message));
|
|
|
}
|
|
|
|
|
|
@SubscribeMessage('test')
|
|
@@ -27,10 +32,14 @@ export class SampleEventsGateway implements OnGatewayConnection, OnGatewayDiscon
|
|
|
}
|
|
|
|
|
|
@SubscribeMessage('message')
|
|
|
- handleMesage(@MessageBody() data: string, @ConnectedSocket() client: Socket): void {
|
|
|
+ handleMesage(@MessageBody() data: string, @ConnectedSocket() client: Socket): Observable<WsResponse<FisMessage>> {
|
|
|
// console.log(data)
|
|
|
this.logger.log(`Received data from ${client.id}`)
|
|
|
this.service.emit(data)
|
|
|
+
|
|
|
+ return this.messageResponseSubject.asObservable().pipe(
|
|
|
+ map(data => ({ event: `message`, data: data }))
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
// this two methods are non essential. as they are used to keep track of the local ui port 3000, not keeping track of the actual clients
|