nestjs-socket.io-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

nestjs-socket.io-client

A simple wrapper around socket.io-client for the nestjs framework.

Instalation

Package has to be installed with the socket.io-client version you want.

Via npm npm install nestjs-socket.io-client socket.io-client

Via yarn yarn add nestjs-socket.io-client socket.io-client

Usage

In your AppModule file:

import { Module } from "@nestjs/common";
import { SocketIoClientModule } from "nestjs-socket.io-client";

@Module({
  imports: [
    SocketIoClientModule.forRoot({
      // ... options for the client
      // https://socket.io/docs/v4/client-api/#new-Manager-url-options
    }),
  ],
})
export class AppModule {}

And in your service:

import { Injectable, Inject, Logger } from "@nestjs/common";
import { SocketIoClientModule, OnSocketEvent, SOCKET_IO_CLIENT } from "nestjs-socket.io-client";
import { Socket } from "socket.io-client"

@Injectable()
export class Service {
  private logger = new Logger("Service");

  /**
   * Inject the socket instance and use it's methods this way:
   */ 
  constructor(@Inject(SOCKET_IO_CLIENT) private readonly socket: Socket) {}

  @OnSocketEvent("connect")
  onConnect() {
    this.logger.log("Successfully connected the socket.io server!");
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-socket.io-client

Weekly Downloads

90

Version

1.0.6

License

MIT

Unpacked Size

259 kB

Total Files

34

Last publish

Collaborators

  • danocmx