10.3.0 • Published 4 months ago

@anotherpit/nestjs-ws-routable-adapter v10.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

WsRoutableAdapter for NestJS

Extended version of NestJs' WsAdapter that supports route parameters, similar to those of HTTP controllers.

Usage

gateway.ts

// Regular gateway definition
@WebSocketGateway({ path: '/' })
export class TestGateway {
  // Route-aware analog of @SubscribeMessage(...)
  @WsRouteSubscribe('ping/:param')
  onPing(
    @MessageBody() data,
    // New decorator to get the full route
    @WsRoute() route,
    // Route-aware analog of @Param(...)
    @WsRouteParam('param') param,
    @WsRouteParam('missingParam') missingParam,
  ) {
    return {
      event: 'pong',
      data: {
        data,
        route,
        param
      },
    };
  }
}

main.ts

async function bootstrap(): Promise<void> {
  // ...
  const app = await NestFactory.create(AppModule);
  app.useWebSocketAdapter(new WsRoutableAdapter(app));
  // ...
}

Now if you send

{ 
  "event": "ping/42", 
  "data": "data"
}

gateway will responde with

{
  "event": "pong",
  "data": {
    "data": "data",
    "route": "ping/42",
    "param": "42"
  }
}

Versioning

Since this library extends the build-in WsAdapter from the @nestjs/platform-ws package, versioning of this library will follow versioning of NestJs (patch versions might differ).

10.2.8

4 months ago

10.2.9

4 months ago

10.2.10

4 months ago

10.3.0

4 months ago

10.2.7

7 months ago

10.2.6

7 months ago

10.2.5

7 months ago

10.2.4

7 months ago

10.2.3

7 months ago

10.2.2

8 months ago

10.2.0

9 months ago

10.1.3

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago