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
For a small app hosting on Vercel with SSE subscriptions removes a lot of complexity involved with setting up NextJS + a WS server
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
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
@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."
Yeah it works, see what your dev console say and the network tab
yeah.. fixed it in the meantime, apparently 'edge' runtime does not support it well, 'nodejs' runtime works well tho. thanks for the fast reply!
Oh, weird thought the edge runtime supported streaming
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.
Does state it in their docs
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...
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.
yeah, i guess it's not working well when returning the same sort of readablestream via trpc subscription procedure