'Having multiple 'states' in a game using Socketio and Nodejs

I'm trying to make a casino game called crash. In this game users must simply crash out before the a counter reaches a random multiplier. A game looks like this; first of all users will be able place bets in a ten second period, then have a counter go on in which users can "crash out" and finally have it crash at a random value and repeat the process.

I'm trying to to this with socket.io. However, I'm struggling at two things. First of all how can I make several states (betState, countState and crashedState) and make these specific to a task. Therefore in the betstate the placeBet function should be active, in the countState users won't be able to place a bet and be able to crashOut and ultimately in the crashedState it just shows a message that it's crashed. How can I make these 'tasks' easily run on the server, and is there an example I can look into?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source