DoctorMcKay / node-tf2

Simple module to interact with the TF2 game coordinator
https://www.npmjs.com/package/tf2
MIT License
54 stars 26 forks source link

Auto-reconnect method? #12

Closed lewisgibson closed 8 years ago

lewisgibson commented 8 years ago

Way to auto reconnect to TF2 GC? Will it auto reconnect, or is there a method to reconnect? (Assuming it will auto reconnect although I want to make sure)

Some code that isnt 100%, got lazy =P; but you should still understand the concept!

var Steam = require('steam'),
    TeamFortress2 = require('tf2'),
    SteamUser = require('steam-user');

var client = new SteamUser(),
    tf2 = new TeamFortress2(client),
    reconnectInterval;

client.gamesPlayed([440]);

tf2.on('connectedToGC', function(){
    console.log("Connected to TF2 Game Co-ordinator!");
    if(["undefined", null].indexOf(reconnectInterval) !== -1) clearInterval(reconnectInterval);
});

tf2.on('disconnectedFromGC', function(){
    console.log("Disconnected from TF2 Game Co-ordinator, retrying in 10 seconds.");

   reconnectInterval = setInterval(function(){
       tf2.connect();    
   }, 10000);
});
lewisgibson commented 8 years ago
if(self._isInTF2) {
    if(!self.haveGCSession) {
        self._connect();
    }
}