-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#129]feat: 경매 API socket 추가
- Loading branch information
Showing
13 changed files
with
198 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IoAdapter } from '@nestjs/platform-socket.io'; | ||
|
||
export class SocketIoAdapter extends IoAdapter { | ||
createIOServer(port: number, options?: any): any { | ||
const server = super.createIOServer(port, options); | ||
|
||
return server; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
WebSocketGateway, | ||
WebSocketServer, | ||
OnGatewayConnection, | ||
OnGatewayDisconnect, | ||
} from '@nestjs/websockets'; | ||
import { Server, Socket } from 'socket.io'; | ||
|
||
@WebSocketGateway({ | ||
cors: { | ||
origin: ['http://localhost:3000', 'https://mybackend.arios67.shop'], | ||
}, | ||
namespace: /./, | ||
}) | ||
export class EventGateway implements OnGatewayConnection, OnGatewayDisconnect { | ||
constructor() {} | ||
@WebSocketServer() | ||
server: Server; | ||
|
||
//소켓 연결시 유저목록에 추가 | ||
public handleConnection(client: Socket): void { | ||
console.log('connected', client.id); | ||
client.leave(client.id); | ||
client.data.roomId = `room:lobby`; | ||
client.join('room:lobby'); | ||
} | ||
|
||
//소켓 연결 해제시 유저목록에서 제거 | ||
public handleDisconnect(client: Socket): void { | ||
console.log('disonnected', client.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { EventGateway } from './event.gateway'; | ||
|
||
@Module({ | ||
providers: [EventGateway], | ||
exports: [EventGateway], | ||
}) | ||
export class EventModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import * as cors from 'cors'; | ||
import { graphqlUploadExpress } from 'graphql-upload'; | ||
import { SocketIoAdapter } from './adapters/socket-io.adapters'; | ||
import { NestExpressApplication } from '@nestjs/platform-express'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const app = await NestFactory.create<NestExpressApplication>(AppModule); | ||
app.enableCors({ | ||
origin: 'http://localhost:3000', | ||
credentials: true, | ||
}); | ||
app.use(graphqlUploadExpress()); | ||
app.useWebSocketAdapter(new SocketIoAdapter(app)); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |
Oops, something went wrong.