Connecting to Twitch API with NodeJS and socket io

You should ping/pong rather that disconnect/reconnect

As during the disconnect/reconnect you could miss a message/event.

To keep the server from closing the connection, clients must send a PING command at least once every 5 minutes. If a client does not receive a PONG message within 10 seconds of issuing a PING command, it should reconnect to the server. See details in Handling Connection Failures.

You need multiple timers.

One to handle sending ping and one to handle recieving a pong and doing stuff if a Pong isn’t receieved in time.

Thats why I have some things split out. So it’s less tangled and the seperate timer controller is held away from the main pubsub loop.