Replies: 2 comments 11 replies
-
Here is example of working with websockets # Import HappyX
import
happyx
import
templates/index
serve("0.0.0.0", 5000):
get "/{title:string}":
{.gcsafe.}:
return mainPage(title)
# websockets
wsConnect:
echo "Connected"
echo wsClient # you also can get WebSocket connection
ws "/":
echo wsData # This is connection data
# You should just answer to wsClient
# For every ws connection wsClient is different WebSocket Connection
await wsClient.send("<div id=\"idMessage\" hx-swap-oob=\"true\">" & $parseJson(wsData)["text"] & "</div>")
wsError:
echo "This will be printed on websocket connection error"
echo wsClient # you also can get WebSocket connection
wsClosed:
echo "This will be printed on websocket connection closed"
echo wsClient # you also can get WebSocket connection |
Beta Was this translation helpful? Give feedback.
10 replies
-
btw, If I want to implement a chat app, where multiple user can chat in a group or 1 to 1 message, do I need to change wsClient.send logic? for example A send a message to B, then wsClient for A and B are different connections, how should I use wsClient.send ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I have been trying to implement a chat app using HTMX with WebSockets, I have looked at the htmx websocket extensions doc and the example code from happyx here
htmx has provided a nodejs server code example, So I have modified it in happyx, but I did not get any results, could you help me take a look at my code? thank you.
main.nim
index.nim
Beta Was this translation helpful? Give feedback.
All reactions