Browse Source

CHANGE | Socket connnect

pull/1/head
Vitalik 1 year ago
parent
commit
7a773e7ebb
  1. 8
      src/domain/real-time/gateways/main.gateway.ts

8
src/domain/real-time/gateways/main.gateway.ts

@ -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')
}

Loading…
Cancel
Save