Compare commits
No commits in common. "96b9eac4f7c9f388865fffea1a4aa2a05a5ddb0d" and "768882cacc59b4cc114cb3d29aebef0dba7eb8ef" have entirely different histories.
96b9eac4f7
...
768882cacc
|
@ -6,18 +6,15 @@ import {
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
OnGatewayConnection,
|
OnGatewayConnection,
|
||||||
OnGatewayDisconnect,
|
|
||||||
OnGatewayInit,
|
|
||||||
SubscribeMessage,
|
SubscribeMessage,
|
||||||
WebSocketGateway,
|
WebSocketGateway,
|
||||||
WebSocketServer,
|
WebSocketServer,
|
||||||
} from '@nestjs/websockets';
|
} from '@nestjs/websockets';
|
||||||
|
import { Server } from 'http';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { Server, Socket } from 'socket.io';
|
|
||||||
|
|
||||||
@WebSocketGateway(4001)
|
@WebSocketGateway(4001)
|
||||||
export class AppGateway
|
export class AppGateway implements OnGatewayConnection {
|
||||||
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
|
|
||||||
@WebSocketServer()
|
@WebSocketServer()
|
||||||
wss: Server;
|
wss: Server;
|
||||||
|
|
||||||
|
@ -25,21 +22,12 @@ export class AppGateway
|
||||||
|
|
||||||
constructor(private appService: AppService) {}
|
constructor(private appService: AppService) {}
|
||||||
|
|
||||||
afterInit(server: Server) {
|
handleConnection(client: any, ...args: any[]) {
|
||||||
this.logger.log('Initialized...');
|
|
||||||
}
|
|
||||||
|
|
||||||
handleConnection(client: Socket, ...args: any[]) {
|
|
||||||
this.logger.log(`Client connected: ${client.id}`);
|
|
||||||
client.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
|
client.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDisconnect(client: Socket) {
|
|
||||||
this.logger.log(`Client disconnected: ${client.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeMessage(MESSAGE_TO_SERVER)
|
@SubscribeMessage(MESSAGE_TO_SERVER)
|
||||||
handleMessage(client: Socket, payload: Message): void {
|
handleMessage(client: any, payload: Message): void {
|
||||||
this.logger.log(payload);
|
this.logger.log(payload);
|
||||||
this.appService.addMessage(payload);
|
this.appService.addMessage(payload);
|
||||||
this.wss.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
|
this.wss.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
|
||||||
|
|
Loading…
Reference in New Issue