Created
September 4, 2020 00:21
-
-
Save bbangert/7c7361e5776251713aef1dd2c47a6d6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { OnApplicationBootstrap, UseGuards } from '@nestjs/common'; | |
import { | |
SubscribeMessage, | |
WebSocketGateway, | |
WebSocketServer, | |
} from '@nestjs/websockets'; | |
import { Server } from 'ws'; | |
import { JwtWsAuthGuard } from '../auth/jwt-auth-ws.guard'; | |
@UseGuards(JwtWsAuthGuard) | |
@WebSocketGateway({ path: '/v1' }) | |
export class SampleGateway implements OnApplicationBootstrap { | |
@WebSocketServer() | |
server: Server; | |
onApplicationBootstrap() { | |
this.server.on('connection', (ws, request) => { | |
(ws as any).request = request; | |
}); | |
} | |
@SubscribeMessage('message') | |
handleMessage(client: any, payload: any): string { | |
console.log('got mesg: ' + JSON.stringify(payload)); | |
return 'Hello world!'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment