-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(socket.io): implements parser for socket.io
The SocketioInterceptorParser has two hardcoded values, one for method and one for protocol. It also only has the concept of pass (200) and fail (500), though there could be a case for checking if the error is an `HttpException` and if so getting the status from there like is done in the HttpParsers. fix #22
- Loading branch information
Showing
14 changed files
with
6,624 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@ogma/platform-socket-io-integration", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "nest build", | ||
"start": "nest start" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@nestjs/common": "^7.0.0", | ||
"@nestjs/core": "^7.0.0", | ||
"@nestjs/platform-express": "^7.0.0", | ||
"@nestjs/platform-socket.io": "^7.0.0", | ||
"@nestjs/websockets": "^7.0.6" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^7.1.1", | ||
"@nestjs/testing": "^7.0.0", | ||
"@types/socket.io": "1.4.33", | ||
"jest": "^25.2.3", | ||
"reflect-metadata": "0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "6.5.4", | ||
"socket.io": "^2.3.0", | ||
"ts-jest": "^25.2.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets'; | ||
import { AppService } from './app.service'; | ||
import { BadRequestException, UseInterceptors } from '@nestjs/common'; | ||
import { OgmaInterceptor, OgmaSkip } from '@ogma/nestjs-module'; | ||
|
||
@UseInterceptors(OgmaInterceptor) | ||
@WebSocketGateway() | ||
export class AppGateway { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@SubscribeMessage('message') | ||
getMessage(): string { | ||
return this.appService.getHello(); | ||
} | ||
|
||
@SubscribeMessage('throw') | ||
getThrow(): never { | ||
throw new BadRequestException('Borked'); | ||
} | ||
|
||
@SubscribeMessage('skip') | ||
@OgmaSkip() | ||
getSkip(): string { | ||
return this.appService.getHello(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OgmaModule } from '@ogma/nestjs-module'; | ||
import { SocketioInterceptorParser } from '@ogma/platform-socket.io'; | ||
import { AppGateway } from './app.gateway'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
OgmaModule.forRoot({ | ||
interceptor: { | ||
ws: SocketioInterceptorParser, | ||
}, | ||
}), | ||
], | ||
providers: [AppGateway, AppService], | ||
}) | ||
export class AppModule {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
getHello(): string { | ||
return 'Hello World!'; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { OgmaService } from '@ogma/nestjs-module'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const logger = app.get(OgmaService); | ||
await app.listen(process.env.PORT || 3000); | ||
logger.log(`Socket.io test running at ${await app.getUrl()}`); | ||
} | ||
|
||
bootstrap(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const socket = require('socket.io-client')('http://[::1]:3000'); | ||
|
||
function cb(...args) { | ||
args.forEach((arg) => console.log(arg)); | ||
} | ||
|
||
function socketCall(message) { | ||
socket.emit(message, '', cb); | ||
} | ||
|
||
socketCall('message'); | ||
socketCall('throw'); | ||
socketCall('skip'); | ||
|
||
setTimeout(() => socket.disconnect(), 500); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./tsconfig.json" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": false, | ||
"rootDir": "./src", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["./src"] | ||
} |
Oops, something went wrong.