#socket.io and payload 3.0

7 messages · Page 1 of 1 (latest)

violet rose
#

HI, anyone knows, or is willing to try and figure out with me, how to initialize socket.io in 3.0 (blank template)?
here is their example that should work for "regular" next.js applications:
https://socket.io/how-to/use-with-nextjs

Note that I am very new to node.js in general, but have strong react and c# background.
From my understanding all this needs to happen before withPayload in next.config.mjs is called, but i do not have idea how to make both of them happen on load.

This guide shows how to use Socket.IO within a Next.js application.

analog wigeonBOT
violet rose
#

i think i got it working, will post all steps here if true, testing now

violet rose
#

after some hair pulling (mainly because its all new to me, not too much changes really), i got socket io to boot up, but i can only emit events from the file that initialized it.
when i import io object from that file into file where my handler is that should emit a useful event, like collection item updated, i am getting build error
Module not found: Can't resolve 'fs'

#

so if someone has experience setting up socket io to be used to emit events from file other than the one that initializes it, i would be grateful for some guidelines

#

ok, figured out why i was getting above error... i was trying to import it into client side file by mistake, because in my infinite wisdom i called custom endpoint file the same name as client side file that calls it...
new issue: io (exported from file that creates server) is undefined when i import it in my custom endpoint file...

violet rose
#

managed to get it working, but not sure its optimal way. basically using socket.io-client to send events from api to server.ts than server.ts re-emits them for frontend.
Will post all files tomorrow in case someone ends up here via search