client server counication with webSockets
Hi, I would like to be able to send data via ws api from my frontend. Still, I don't seem to be able to send any data from the frontend to the trpc backend, I tried to do it in a way that I make mutation and I open ws connection in this procedure. Still, it reconnects me on every request and I need this connection to stay open and just send the data, is there a way to send data from trpc client - frontend to the subscription precedure?
On the client, apart from onData there are only onComplete, onError, onSarted, and onStopped.
ws API offers ws.send() and it seems that I can only receive data from the server, is trpc client lacking this functionality or am i missing something?
Many Thanks
4 Replies
The wsLink supports mutations, it should stay open. There is an option for the ws client to be lazy, but I believe that's not enabled by default.
Hi @BeBoRE what do you mean by that wsLink supports mutations? and what does it mean that is is lazy? you can evable it in config but the doc says that
how does it realte to sending messages via ws to my subscription procedure?
You can only listen to subscriptions, but the wsLink does allow for you to call mutations over WebSocket
could you please give me some code example how thiscould look like? i don't understand how it should be done 🙂
and many thanks for replying this i important to me
if i understand correectly you say that i could configure in my trpc client that if i use certain procedure (i want this ws link to work only on placeOrder mutation procedure) than instead od http link ws link would be used and the connection to my procedure would stau open and the data would be transmitted super fast?
this does not work i get waring in the console saying that
hmmm no it was because od lazy flag was on now its working and im gettingconsole logs 😄
thank you!