|
|
@ -6,26 +6,39 @@ import { |
|
|
|
WebSocketServer, |
|
|
|
WebSocketServer, |
|
|
|
} from '@nestjs/websockets'; |
|
|
|
} from '@nestjs/websockets'; |
|
|
|
import { Server, Socket } from 'socket.io'; |
|
|
|
import { Server, Socket } from 'socket.io'; |
|
|
|
import { Injectable, UseGuards } from '@nestjs/common'; |
|
|
|
import { Injectable } from '@nestjs/common'; |
|
|
|
import { GlobalGuard } from 'src/guards/global/global.guard'; |
|
|
|
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; |
|
|
|
import { ExtractProjectIdMiddleware } from 'src/middlewares/extract-project-id/extract-project-id.middleware'; |
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
|
|
|
import { JobsService } from './jobs.service'; |
|
|
|
import { JobsService } from './jobs.service'; |
|
|
|
|
|
|
|
import type { OnModuleInit } from '@nestjs/common'; |
|
|
|
|
|
|
|
|
|
|
|
@WebSocketGateway(8081, { |
|
|
|
@WebSocketGateway({ |
|
|
|
cors: { |
|
|
|
cors: { |
|
|
|
origin: '*', |
|
|
|
origin: '*', |
|
|
|
|
|
|
|
allowedHeaders: ['xc-auth'], |
|
|
|
|
|
|
|
credentials: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
allowedHeaders: ['xc-auth'], |
|
|
|
|
|
|
|
credentials: true, |
|
|
|
|
|
|
|
namespace: 'jobs', |
|
|
|
namespace: 'jobs', |
|
|
|
}) |
|
|
|
}) |
|
|
|
@Injectable() |
|
|
|
@Injectable() |
|
|
|
export class JobsGateway { |
|
|
|
export class JobsGateway implements OnModuleInit { |
|
|
|
constructor(private readonly jobsService: JobsService) {} |
|
|
|
constructor(private readonly jobsService: JobsService) {} |
|
|
|
|
|
|
|
|
|
|
|
@WebSocketServer() |
|
|
|
@WebSocketServer() |
|
|
|
server: Server; |
|
|
|
server: Server; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async onModuleInit() { |
|
|
|
|
|
|
|
this.server.use(async (socket, next) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const context = new ExecutionContextHost([socket.handshake as any]); |
|
|
|
|
|
|
|
const guard = new (AuthGuard('jwt'))(context); |
|
|
|
|
|
|
|
await guard.canActivate(context); |
|
|
|
|
|
|
|
} catch {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SubscribeMessage('subscribe') |
|
|
|
@SubscribeMessage('subscribe') |
|
|
|
async subscribe( |
|
|
|
async subscribe( |
|
|
|
@MessageBody() data: { type: string; id: string }, |
|
|
|
@MessageBody() data: { type: string; id: string }, |
|
|
|