|
|
|
@ -9,6 +9,7 @@ import { Server, Socket } from 'socket.io'
@@ -9,6 +9,7 @@ import { Server, Socket } from 'socket.io'
|
|
|
|
|
import { JwtWsGuard } from '../guards' |
|
|
|
|
import { WsServerService, WsUsersService } from '../services' |
|
|
|
|
import { WsThrottlerGuard } from '../guards/ws-throtler.guard' |
|
|
|
|
import { JwtService } from 'src/libs' |
|
|
|
|
|
|
|
|
|
@WebSocketGateway({ |
|
|
|
|
transports: ['websocket', 'polling'], |
|
|
|
@ -22,6 +23,7 @@ export class MainGateway {
@@ -22,6 +23,7 @@ export class MainGateway {
|
|
|
|
|
constructor( |
|
|
|
|
private readonly wsServerService: WsServerService, |
|
|
|
|
private readonly wsUsersService: WsUsersService, |
|
|
|
|
private readonly jwtCoreService: JwtService, |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
public afterInit(server: Server) { |
|
|
|
@ -39,6 +41,12 @@ export class MainGateway {
@@ -39,6 +41,12 @@ export class MainGateway {
|
|
|
|
|
|
|
|
|
|
handleConnection(@ConnectedSocket() client: Socket) { |
|
|
|
|
console.log(client.handshake.auth) |
|
|
|
|
const accessToken = client.handshake.auth.accessToken |
|
|
|
|
if (accessToken) { |
|
|
|
|
const user = this.jwtCoreService.decodeToken(accessToken) |
|
|
|
|
console.log('user', user) |
|
|
|
|
this.wsUsersService.joinUser(client, { user }) |
|
|
|
|
} |
|
|
|
|
this.logger.log('Connect new user to server') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|