create connection socket io
This commit is contained in:
parent
d8bd400c57
commit
3384fdcc6c
7 changed files with 10529 additions and 31 deletions
|
@ -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
10515
server/package-lock.json
generated
File diff suppressed because it is too large
Load diff
17
server/src/api-v1/communication/communication.gateway.ts
Normal file
17
server/src/api-v1/communication/communication.gateway.ts
Normal 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}`,
|
||||
);
|
||||
}
|
||||
}
|
8
server/src/api-v1/communication/communication.module.ts
Normal file
8
server/src/api-v1/communication/communication.module.ts
Normal 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 {}
|
4
server/src/api-v1/communication/communication.service.ts
Normal file
4
server/src/api-v1/communication/communication.service.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class CommunicationService {}
|
|
@ -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!';
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue