Guest User

Untitled

a guest
Jan 23rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. let timer = 5;
  2. io.on("connection", socket => {
  3. const timerT = setInterval(
  4. () => timerRun(socket),
  5. 10
  6. );
  7.  
  8.  
  9. socket.on("disconnect", () => console.log("Client disconnected"));
  10. });
  11. const timerGo = async socket => {
  12. try {
  13. if (timer === 0 || timer < 0) {
  14. socket.emit("FromAPI", "Stop")
  15. setTimeout(function () {
  16. socket.emit("FromAPI", "Go")
  17. /*
  18. * Do Something Else
  19. * */
  20.  
  21. },5000)
  22. setTimeout(function () {
  23. timer=5
  24. },2500)
  25.  
  26. } else {
  27. timer = timer - 0.01;
  28. console.log(timer.toFixed(2))
  29. socket.emit("FromAPI", timer.toFixed(2));
  30. }
  31. } catch (error) {
  32. console.error(`Error: ${error.code}`);
  33. }
  34. };
Add Comment
Please, Sign In to add comment