Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/websockets #82

Merged
merged 16 commits into from
Mar 7, 2024
Merged

Feat/websockets #82

merged 16 commits into from
Mar 7, 2024

Conversation

Sorikairox
Copy link
Collaborator

@Sorikairox Sorikairox commented Mar 4, 2024

Description

Websocket are a must for real-time application such as chats or video-games.

This PR introduces a new router and associated decorators, the WebsocketRouter.

It has the same features as the OG HttpRouter :

  • Guards
  • ErrorFitlers
  • Middlewares
  • Body and Param decorators
  • Pattern matching for topics

Example:

@UseGuard(ExampleAuthGuard)
@WebSocketController('ws')
class ExampleController {
	constructor(private service: ExampleService) {
	}

	@UseGuard(ControllerGuard)
	@OnWebSocketMessage('hello')
	sayHello() {
		return { topic: 'hello', data: this.service.sayHello() };
	}
	
	@OnWebSocketMessage('goodbye')
	saygoodbye(@Body() whateverIsSent: any) {
		return { topic: 'goodbye', data: whateverIsSent };
	}

	@OnWebSocketMessage('hello/:name')
	sayHelloWithName(@Param('name') name: string) {
		return { topic: 'hello', data: name };
	}
}

Issue Ticket Number

Fixes #(issue_number)


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update

Checklist:

  • I have run deno lint AND deno fmt AND deno task test and got no
    errors.
  • I have followed the contributing guidelines of this project as mentioned
    in CONTRIBUTING.md
  • I have checked to ensure there aren't other open
    Pull Requests for the same
    update/change?
  • I have performed a self-review of my own code
  • I have made corresponding changes needed to the documentation

@Sorikairox Sorikairox self-assigned this Mar 4, 2024
Copy link
Contributor

@marco-souza marco-souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
I found the implementation ws router implementation SUPER COOOL! 🙌🏼

src/exception/filter/executor.ts Outdated Show resolved Hide resolved
src/router/websocket/router.ts Outdated Show resolved Hide resolved
src/router/websocket/router.ts Outdated Show resolved Hide resolved
spec/websocket/exception-filter.test.ts Outdated Show resolved Hide resolved
spec/websocket/auth-guard.test.ts Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 91.57895% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 88.96%. Comparing base (887c762) to head (3702bba).

❗ Current head 3702bba differs from pull request most recent head 012f2d0. Consider uploading reports for the commit 012f2d0 to get more accurate results

Files Patch % Lines
src/router/controller/params/decorators.ts 69.81% 16 Missing ⚠️
src/router/websocket/router.ts 95.03% 8 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
+ Coverage   88.39%   88.96%   +0.57%     
==========================================
  Files          63       66       +3     
  Lines        1904     2103     +199     
  Branches      196      212      +16     
==========================================
+ Hits         1683     1871     +188     
- Misses        218      229      +11     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Sorikairox Sorikairox merged commit c5cb35e into main Mar 7, 2024
1 check passed
@Sorikairox Sorikairox deleted the feat/websockets branch March 7, 2024 13:01
Copy link
Contributor

@marco-souza marco-souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! 🚀

I found one minor, but we can fix it in the upcoming PRs 👍

@@ -27,7 +28,7 @@ export class FilterExecutor {
exceptionFilter: ExceptionFilter,
context: HttpContext,
error: unknown,
): Response | undefined {
): Response | undefined | { topic: string; data: unknown } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, we can fix it later

Suggested change
): Response | undefined | { topic: string; data: unknown } {
): Response | undefined | WebSocketPayload {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants