franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 171 forks source link

Any schedule for migrating to socket.io 4.x? #139

Closed lantica closed 1 year ago

lantica commented 3 years ago

The socket.io using now is v 2.x, which means client using v3.x / 4.x will not be able to connect. I would like to know is there any plan for updating it?

franciscop commented 3 years ago

Sorry no plans at the moment for that, do versions 3.x and 4.x totally break backwards compatibility?

Edit: it seems that we can upgrade at least safely to 3.x on the server side:

Update: As of Socket.IO 3.1.0, the v3 server is now able to communicate with v2 clients. More information below. A v3 client is still not be able to connect to a v2 server though.

lantica commented 3 years ago

Yes, there is backward compatibility for both v3.x and v4.x server to v2.x client. However, an option (allowEIO3: true) will be required in order for the backward compatibility.

I have tried just updating the socket-io to v4.1.3 with that option, it seems to be work fine with v2.x client.

franciscop commented 3 years ago

The sockets is the main part of the codebase without tests (I'm not even sure how to approach testing here) so migration is not going to be easy at all to ensure compatibility, specially with how large socket.io API is.

I created a small example for socket.io, and I'll be adding more and more bits (or maybe other examples) to check whether it works as intended both with 2.x and 4.x. Unfortunately I'm limited on time, so the earliest I feel comfortable shipping this is September

If you need it right now, you could do it in a not-too-difficult way:

  1. Disable the official socket plugin with the option { socket: false }
  2. Copy plugins/socket/index.js into your codebase e.g. into ./mycodebase/socket.js
  3. Change the name to newsocket or something different, and update accordingly
  4. Install socket.io 4.x or whichever version you use locally npm i socket.io@4
  5. Update your codebase to use this new plugin. It has the basic config, but also a small router callback, so this should work:
const server = require('server');
const newsocket = require('./mycodebase/socket');

server.plugins.push(newsocket);
server.router.socket = newsocket.router;

server({ router: false }, ...);

I haven't tried this, but AFAIK this should be it so please feel free to report any issue trying to follow these steps.

kinostl commented 1 year ago

144 updated this to 4.5

franciscop commented 1 year ago

Thanks! I guess we can close this now :)

franciscop commented 1 year ago

Note: not released yet, will be released within a couple of days