Websockets & Connection Upgrade on Next server
So i've been trying to bind a websocket connection from client to server on next, and i've done my usual server flow for this kind of shit:
and connected to it like so, with a context:
This only results in a pending handshake or a client error where it says i'm not in a context (the latter of which only happens when i leave out the useEffect and undefined check on the client)
https://i-work-at-the.cocaine.institute/Lizzy6373b0daKzIbzcbyX5xU.png
I've done the same deal with socket.io before with no problem and this seems to be the recommended way of doing this according to the google
wtf is going on lol
4 Replies
well, we've got websockets working by themselves
but i'd like to be able to broadcast a message to all or some clients via trpc, i.e. when a message is created.
the project is on github if anyone wants to take a look at our current source: https://github.com/SynapseTech/iridium-chat
GitHub
GitHub - SynapseTech/iridium-chat: Iridium Chat helps teams and pro...
Iridium Chat helps teams and professionals connect and do what matters most: get sh*t done. - GitHub - SynapseTech/iridium-chat: Iridium Chat helps teams and professionals connect and do what matte...
for some reason clients is still an empty set even with websocket clients actively connected https://i-work-at-the.cocaine.institute/Lizzy637ce353BtfU4j3x0UhV.png
for more context, in a trpc mutation i'm calling socketState.broadcastMessage() and in this instance the value of
this.clients
is Set{0}
i solved it, weirdly enough by putting the client list on the global object