create connection socket io

This commit is contained in:
Alex Tran 2022-02-13 21:35:07 -06:00
parent d8bd400c57
commit 3384fdcc6c
7 changed files with 10529 additions and 31 deletions

View file

@ -12,6 +12,7 @@ services:
command: npm run start:dev
ports:
- "3000:3000"
- "3001:3001"
volumes:
- .:/usr/src/app
- ${UPLOAD_LOCATION}:/usr/src/app/upload

10515
server/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,17 @@
import { OnGatewayConnection, WebSocketGateway, WebSocketServer } from '@nestjs/websockets';
import { CommunicationService } from './communication.service';
import { Socket, Server } from 'socket.io';
@WebSocketGateway()
export class CommunicationGateway implements OnGatewayConnection {
constructor(private readonly communicationService: CommunicationService) {}
@WebSocketServer() server: Server;
handleConnection(client: Socket, ...args: any[]) {
console.log('Socket IO - New connetrion ', client.id);
this.server.emit(
'on_connected',
`Connection Success - hi ${client.id} - you are connecting to chat room ${client.nsp.name}`,
);
}
}

View file

@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { CommunicationService } from './communication.service';
import { CommunicationGateway } from './communication.gateway';
@Module({
providers: [CommunicationGateway, CommunicationService]
})
export class CommunicationModule {}

View file

@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class CommunicationService {}

View file

@ -1,9 +0,0 @@
import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
@WebSocketGateway()
export class NotificationGateway {
@SubscribeMessage('message')
handleMessage(client: any, payload: any): string {
return 'Hello world!';
}
}

View file

@ -14,7 +14,7 @@ import { BullModule } from '@nestjs/bull';
import { ImageOptimizeModule } from './modules/image-optimize/image-optimize.module';
import { ServerInfoModule } from './api-v1/server-info/server-info.module';
import { BackgroundTaskModule } from './modules/background-task/background-task.module';
import { NotificationGateway } from './api-v1/notification/notification.gateway';
import { CommunicationModule } from './api-v1/communication/communication.module';
@Module({
imports: [
@ -41,9 +41,11 @@ import { NotificationGateway } from './api-v1/notification/notification.gateway'
ServerInfoModule,
BackgroundTaskModule,
CommunicationModule,
],
controllers: [],
providers: [NotificationGateway],
providers: [],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {