Skip to content

Instantly share code, notes, and snippets.

@bbangert
Created September 4, 2020 00:21
Show Gist options
  • Save bbangert/7c7361e5776251713aef1dd2c47a6d6a to your computer and use it in GitHub Desktop.
Save bbangert/7c7361e5776251713aef1dd2c47a6d6a to your computer and use it in GitHub Desktop.
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