eventemitter not having any listeners on websocket
Hi,
I have a app router project with TRPC but I created a websocket server alongside and a websocket client with the approuter and usecontext modified to work,
the problem is that first of all (i don't know if this is normal) it says there are two connections when i load a page
the next problem is that nothing gets emitted back from if i access a query diretly on my browser which is supposed to (as a test) send data back to the client.
the problem in the WS is that there are two weird responses which i don't understand
This is my code
and this is what i have in the client
6 Replies
@Albastru were you able to fix this? going through the same right now.
i just completely gave up on that and started to use Pusher
i managed to get it working using redis but in production it kept crashing after a while
WS really needs to be rethought in the next release it would bring a lot of new opportunities to apps using tRPC
Mmm okay thank you
the problem you're seeing is likely because the websocket server and the rest of the api runs in two different processes locally
you should likely use redis or something so they can share state
try swapping all communication to use websockets in the client to verify
hmmm that makes sense. is there a way to share context between the two without 100% switching over to WS Links and without using Redis? Redis feels a bit overkill for my needs and I'd love to simply be able to share an event emitter instance between the two routes i have (one mutation and one subscription)
Yes you can run them as the same server