Nest: WebSocket adapters

Created on 5 May 2017  路  10Comments  路  Source: nestjs/nest

It would be great to extract the websocket functionality to use a proper adapter pattern.

Right now there's a stub of an adapter which just returns a socket.io instance.

Ideally:

  • Wrap any websocket functionality in an adapter
  • Call that in nest side code

This lets socket.io be potentially swapped out for alternatives, without breaking changes.

type

Most helpful comment

Socket.io is familiar to most of the Angular community of which Nest has it's roots. I don't disagree that uWebSockets outperforms socket.io at scale but imo Nest shouldn't make choices like that for consumers.

As @ProbablePrime said above, make it pluggable, support what makes sense & allow consumers to make their own tooling choices.

All 10 comments

uWebSockets should be better than socket.io, IMO

Socket.io is familiar to most of the Angular community of which Nest has it's roots. I don't disagree that uWebSockets outperforms socket.io at scale but imo Nest shouldn't make choices like that for consumers.

As @ProbablePrime said above, make it pluggable, support what makes sense & allow consumers to make their own tooling choices.

Hi @ProbablePrime,
Since latest update you should be able to use custom socket.io adapter. Example:

import { SocketIoAdapter } from '@nestjs/common';

class CustomAdapter implements SocketIoAdapter {
    create(port: number) {
        return {};
    }
    createWithNamespace(port: number, namespace: string) {
        return {};
    }
}

const app = NestFactory.create(ApplicationModule, instance);
app.setIoAdapter(new CustomAdapter());

@kamilmysliwiec I don't think this addresses the issue.

The issue is asking for a way to replace Socket.io completely. Right now this appears to just require an adapter to return Socket.io instances. It would still require the whole Socket.io interface on the object returned from createWithNamespace

@kamilmysliwiec will be this #80 pr merged in a few days?

@cojack, yes :smiley:

This looks a lot better \o/ thanks! doing a more indepth read of your changes but i will close it most likely

Hi @ProbablePrime,

Since 3.0.0 you can create adapter for any ws library. Read more

Yep PERFECT. thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KamGor picture KamGor  路  3Comments

artaommahe picture artaommahe  路  3Comments

mishelashala picture mishelashala  路  3Comments

yanshuf0 picture yanshuf0  路  3Comments

marshall007 picture marshall007  路  3Comments