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

inversify-socket-io-utils - new project submission #369

Open
mattwills8 opened this issue Feb 11, 2020 · 1 comment
Open

inversify-socket-io-utils - new project submission #369

mattwills8 opened this issue Feb 11, 2020 · 1 comment

Comments

@mattwills8
Copy link

Hey guys, wasn't sure how else to get in contact.

I've put together a package for defining controllers and handlers using inversify for a socket.io server (https://socket.io/) based heavily on the inversify-express-utils package you have.

Setup looks like

const ioServer = new InversifySocketIOServer(
    inversifyContainer,
    httpServer,
    socketConfig
)

ioServer.build()

with an example controller looking like

@controller('/')
export class OnlineStatusController {
  constructor(
    @inject(SERVICE_TYPES.UserService) private userService: UserService
  ) {}

  @handler(CONNECT_USER)
  private async handleConnect(@socketId() socketId: string, @body() body: ConnectUserBody) {
    const {userId} = body

    // save socketId and userId somewhere

    this.userService.setUserOnline(userId)
  }

  @handler([SOCKET_IO_EVENT.DISCONNECT, DISCONNECT_USER])
  private async handleDisconnect(@socketId() socketId: string) {

    // retrieve userId given socketId
    
    this.userService.setUserOffline(userId)
  }
}

It currently supports:

  • auto discovery and binding of controllers using @controller(namespace?: string) class decorator
  • auto registration of event handlers using the @handler(events: string | string[]) method decorator
  • @socketId(): string @socket(): SocketIO.Socket @body(): any param decorators.
  • optional debug and logging feature
  • optional redis adapter feature

If this is a repo you guys would be interested in bringing in to your org, then I'd be happy to write up a proper readme and maintain it for you. I can zip up and send over the code for you to check out.

Let me know!

@PodaruDragos PodaruDragos transferred this issue from inversify/InversifyJS Jan 28, 2022
@PodaruDragos
Copy link
Member

@mattwills8 hello, apologies for the late response, this is the first time i am seeing this issue, since i am triaging a bit.

That would be really cool. Is is posible to not limit it to socket-io. A lot of people also use ws and then if someone does a new package for ws then there would be at least 2 more packages.

Let me know if you are interested in that, and we will gladly add it here.

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

No branches or pull requests

2 participants