Next.js Discord

Discord Forum

Server Actions: Open a Websocket?

Unanswered
Knopper gall posted this in #help-forum
Open in Discord
Knopper gallOP
Is it possible to open a websocket after a server action is called?
The reason I'm asking is I'd like my app to do the following

Page Load:
- Query Discord Bot Logs -> Show in Textarea (useEffect, server action)
- Open a WebSocket connection for any new log entries

Bot:
- Send any new stdout messages over the websocket to the website (client)

Or is there an easier way to do this?
I don't really want to be querying all the logs every five seconds

7 Replies

Knopper gallOP
anyone? please? 😢
Southern rough shrimp
Not related to websockets, but why are you not using a suspense boundary here for the first point? Remove the use of useEffect and a secondary client side call
Query Discord Bot Logs -> Show in Textarea (useEffect, server action)
You should have an async server component here which is streamed into a suspense boundary
@Southern rough shrimp Not related to websockets, but why are you not using a suspense boundary here for the first point? Remove the use of useEffect and a secondary client side call
Knopper gallOP
I'm not that experienced with react tbh.
JS and TS I'm great with, still learning React.

I'll read up on suspense boundaries, thanks
Just need to figure out how to stream the logs to the client live now 😦
Southern rough shrimp
You could follow the same idea as OpenAI's npm package? Maybe this will help (I have never done this so I don't know) https://stackoverflow.com/questions/76273091/how-to-send-openai-stream-response-from-nextjs-api-to-client