Content-Length: 336674 | pFad | http://github.com/blockcoders/nestjs-websocket/tree/bbfef6987934bc0125da213cdf72b53c5d1f2053

CB GitHub - blockcoders/nestjs-websocket at bbfef6987934bc0125da213cdf72b53c5d1f2053
Skip to content

blockcoders/nestjs-websocket

Repository files navigation

NestJS-Websocket

npm CircleCI Coverage Status vulnerabilities supported platforms

Websocket utility for NestJS based on WS

Install

npm i nestjs-websocket

Register module

Configuration params

The url param that websocket module expects should be a string, for example:

{
  url: 'ws://localhost:3000',
}

Synchronous configuration

Use WebSocketModule.forRoot method with String param:

import { WebSocketModule } from 'nestjs-websocket'

@Module({
  imports: [
    WebSocketModule.forRoot({
      url: 'ws://localhost:3000',
    }),
  ],
  ...
})
class MyModule {}

Asynchronous configuration

WebSocketModule.forRootAsync allows you, for example, inject ConfigService to use it in Nest useFactory method.

useFactory should return an object with String param.

import { WebSocketModule } from 'nestjs-websocket'

@Injectable()
@Module({
  imports: [
    WebSocketModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => {
        return {
          url: 'ws://localhost:3000'
        }
      },
    }),
  ],
  ...
})
class MyModule {}

Testing a class that uses @InjectWebSocketProvider

This package exposes a getWebSocketToken() function that returns a prepared injection token based on the provided context. Using this token, you can easily provide a mock implementation of the WS using any of the standard custom provider techniques, including useClass, useValue, and useFactory.

const module: TestingModule = await Test.createTestingModule({
  providers: [
    MyService,
    {
      provide: getWebSocketToken(),
      useValue: mockProvider,
    },
  ],
}).compile();

Change Log

See Changelog for more information.

Contributing

Contributions welcome! See Contributing.

Authors

License

Licensed under the Apache 2.0 - see the LICENSE file for details.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/blockcoders/nestjs-websocket/tree/bbfef6987934bc0125da213cdf72b53c5d1f2053

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy