0

I'm new in nodejs and socket.io.

I'm trying to start a timer (with seconds and milliseconds) for all users at the same time after I (admin) click a 'start' button. The timer should end for all users at the same time too. If a user enters timer page after clicking the button, timer shouldn't start from the start for him/her.

I already know how to implement a timer in js.

Also I have a redux state for timer's status, though I'm not sure if I'm going to need it.

I'm using react, redux, redux-persist, nodejs, expressjs, socket.io, mongodb for my app.

I don't have any proper code for it, since I'm still unsure of how I should implement it.

1 Answers1

0

You can start your timer code on receival of request socket.io event say 'global_timer_request' from your react client. I don't know if there is any react client though. just a thought.

In your timer code you will just have to broadcast chain of regular 'global_timer_broadcast'(again an imaginary name) events with timer object payload with socket.io.

socket.io emit/ broadcast cheatsheet

When your user opens up the timer page your client will just has to catch the broadcast event and put it on display. you can also augment this timer with rooms and namespaces.

socket.io rooms and namespaces

I don't know if I am comprehensible enough.

What's the difference between io.sockets.emit and broadcast? Update all clients using Socket.io?

Debu
  • 21
  • 1
  • 5