r/node • u/UtopianCorps • Nov 10 '20
Real time synced counter built with Socket.io, NodeJS and Express! The counter will be integrated in a live-quizzing platform I'm currently working on, to control the current question.
8
5
u/xehbit Nov 11 '20 edited Nov 11 '20
Sorry, couldn't resist messing around with your app, the counter is a bit high heheh :)
Also, it seems that you're request "what num" quite a lot! The awesome thing about WebSockets it that you can push the state to all connected WebSockets when the value changes without the client asking the current state over and over again (The good old polling XHR way).
EDIT: In my opinion socket.io is a bit heavy, i prefer to use ws :-)
1
u/UtopianCorps Nov 11 '20
"A bit high"?! ππ (Great hack btw xP )
Thanks a lot for the advice!
Since everyone in the comments has mentioned about sockets.io being heavy, I would love to try the websockets implementation now. =)
2
u/kevinzaki Nov 10 '20
Currently building something similar but for trivia games using same stack plus react on the front end.
Basic concept is a host screen displays the question with users answering the questions using their phones
1
u/UtopianCorps Nov 11 '20
Exactly the thing I'm trying to build...
Won't be using react though cause I think vanilla HTML, CSS would be enought
Or bootstrap at most2
u/kevinzaki Nov 11 '20
React is not necessary but I am using this as a portfolio project and want to improve React skills. Good luck! I should be done in a few days then i'll post it up here.
1
0
Nov 11 '20
[deleted]
1
u/kevinzaki Nov 11 '20
That's cool. I'm just building this as a side project with minimum functionality and trying to make it super easy to use. A lot of the functionality is complete. Still need to style it up. I'll post it up here and share the code when it is complete.
2
u/wise_introvert Nov 11 '20
Just out of curiosity, if this is a seperate application, how do you plan on integrating it in another application? Or is this is just a POC and you'll simply redoing it in the main application?
1
2
u/Miridius Nov 11 '20
Feathersjs could be a good fit for your project, I'd suggest checking it out
2
2
u/PiggiePlank Nov 11 '20
If you like real-time and sockets you should take a look at SocketCluster it's like socket.io ok steroids. It's awesome.
1
2
u/alex_agc Nov 11 '20
Do you thing about the using of a mqtt server just after the websocket server?? that's perfect if you are thinking in doing a native app too.
1
u/UtopianCorps Nov 11 '20
That's nice! I recently started with backend so still learning this stuff!
2
u/dankobgd Nov 11 '20
why is this upvoted 500 times? what am i missing?
you update a number via websocket, and you are even using socket io which is not meant for this anyway compared to faster and pure websocket libraries like ws.
1
u/UtopianCorps Nov 11 '20
With all due respect I've just started learning back end and in case you want to give constructive feedback, you are welcome.
31
Nov 10 '20
You should make voting machines for the US
10
u/BigGingerJake Nov 10 '20
And make both colours blue.
1
-1
u/UniversalJS Nov 11 '20
To replicate the massive fraud that happened in the real election? :p
0
6
3
4
Nov 10 '20
Socket.io is quite resource hungry. My experience of optimizing it wasn't good nd i don't prefer using it at all for big projects.
2
u/LinkifyBot Nov 10 '20
I found links in your comment that were not hyperlinked:
I did the honors for you.
delete | information | <3
1
u/applejak Nov 10 '20
What do you prefer?
4
u/johnyma22 Nov 11 '20
ws or uws.
op is right. if you are building anything serious, migrate away from socketio early.
2
Nov 10 '20
Tbh i don't know myself. I prefer pusher if you need real-time factor for just a small part of your application.
2
2
u/TheNicklesPickles Nov 11 '20
Slightly different stack, but Iβm working on a multi-user quiz app too!
-2
0
Nov 10 '20
[deleted]
11
u/rockefeller22 Nov 11 '20
My brain: Italy? No sideways. Hungary? No red is on top. Iran? Maybe.
2
1
0
Nov 10 '20
[deleted]
8
u/UtopianCorps Nov 10 '20
https://socket.io/get-started/chat/
I referred to this post from the official site. It's a great way to get started.
0
Nov 11 '20
[deleted]
1
u/UtopianCorps Nov 11 '20
Recently started with node and backend, so it's more like project-based learning than an actual app. Anyways, it's also a POC for a live quizzing platform I'm currently working on.
2
Nov 11 '20
[removed] β view removed comment
2
u/UtopianCorps Nov 11 '20
Here you go!
https://github.com/aapatre/Socket.io-Controllable-and-Synced-CounterLive demo: https://socketio-synced-counter.herokuapp.com/
Forgot to add it, so thanks for reminding!
5
Nov 10 '20 edited Nov 10 '20
[removed] β view removed comment
14
4
3
3
u/s_trader Nov 10 '20
I assume you're using redis's pub-sub for that right?
Probably you set the IDs in the fashion of putting the user ID then period then whatever notification / alert / update you want to push to the client (for example user_id.new_message_id) then when a user connects to socketIO you subscribe that server to the user's Pub using * (like that user_id.*) this way your server receives all the notification that user should receive and then you can tells socketIO to emit whatever data it needs to the proper clients even if there are multiple clients connecting to multiple different servers and are in the same chat room for example...
72
u/gorsesoup Nov 10 '20
You can stop the double tap zooming with a meta tag, but very good otherwise