-
-
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ To build your the project and link the dependencies together you can run `lerna | |
|
||
When running the integration specific applications in a non--testing context (i.e. starting them locally), make sure to `cd` into the directory, `yarn install` the dependencies, and then run `yarn build && yarn start` to compile and start the server. From there, in a separate terminal, you can use [curl](https://curl.haxx.se/) or [Postman](https://www.postman.com/), or just use the browser directly. For websocket testing, you can use the node REPL (i.e. use `node` from the terminal) and make websocket calls from there. | ||
|
||
## Commits | ||
|
||
We are using [Conventional Commit]() to help keep commit messages aligned as development continues. The easiest way to get acquainted with what the commit should look like is to run `yarn commit` which will use the `git-cz` cli and walk you through the steps of committing. When asked about the scope, you can checkout the [commitlint.config](./commitlint.config.js) file and look at the `scope-enum` property. Once you've made your commit, prettier and eslint will run and ensure that the new code is up to the standards we have in place. | ||
|
||
## Issues | ||
|
||
Please raise an issue, or discuss with me [via email](mailto:[email protected]) or [Discord](https://discordapp.com) (PerfectOrphan31#6003) before opening a Pull Request so we can see if they align with the goals of the project. |
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.