Vaibhav
Vaibhav7mo ago

websocket or sse

So, im implementing real time transcription using google api , so should i use sockets or sse in trpc for this? im using nextjs btw , also tried integrate sockets in my app , its pretty complex for a noob coder like me
12 Replies
BeBoRE
BeBoRE7mo ago
For a small app hosting on Vercel with SSE subscriptions removes a lot of complexity involved with setting up NextJS + a WS server
Vaibhav
VaibhavOP7mo ago
yes you right , but sse only supports server to client comm not vice versa right? im implementing a live transcription , where the user will get the transcript live while he speaks
BeBoRE
BeBoRE7mo ago
Subscription are one way only aswell One problem with using HTTP mutations here are the amount of mutations you’d have to send to the server, WebSockets would probably be better for latency
Cristian
Cristian4w ago
@BeBoRE do you know, would the SSE Subscriptions on vercel work out of the box? I am trying to implement them with trpc (which locally work) but deployed on vercel don't "TypeError: This ReadableStream did not return bytes."
BeBoRE
BeBoRE4w ago
Yeah it works, see what your dev console say and the network tab
Cristian
Cristian4w ago
yeah.. fixed it in the meantime, apparently 'edge' runtime does not support it well, 'nodejs' runtime works well tho. thanks for the fast reply!
BeBoRE
BeBoRE4w ago
Oh, weird thought the edge runtime supported streaming
BeBoRE
BeBoRE4w ago
Vercel
An Introduction to Streaming on the Web - Vercel
Learn how web streams work, their advantages, streaming on Vercel, and tools built around web streams.
BeBoRE
BeBoRE4w ago
Does state it in their docs
Cristian
Cristian4w ago
streaming yes, but SSE required a continuing open connection, got the solution from here: https://github.com/vercel/next.js/discussions/48427#discussioncomment-5624604
GitHub
Server-Sent Events don't work in Next API routes · vercel next.js ·...
Bug report Describe the bug When using Next's API routes, chunks that are written with res.write aren't sent until after res.end() is called. To Reproduce Steps to reproduce the behavior, p...
BeBoRE
BeBoRE4w ago
Should be the same concept, they also use an EventSource etc. https://vercel.com/blog/an-introduction-to-streaming-on-the-web Maybe subscriptions are too long running
Vercel
An Introduction to Streaming on the Web - Vercel
Learn how web streams work, their advantages, streaming on Vercel, and tools built around web streams.
Cristian
Cristian4w ago
yeah, i guess it's not working well when returning the same sort of readablestream via trpc subscription procedure

Did you find this page helpful?