tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.56k stars 211 forks source link

Auto reconnect rejoins parted channels #121

Closed mccxiv closed 8 years ago

mccxiv commented 8 years ago

Test

  1. Start with:
var client = new tmi.client({
    options: {debug: false},
    connection: {cluster: 'aws', timeout: 2000, reconnect: true},
    channels: ['yamuda', 'sqmp']
});
  1. Part from 'yamuda'
  2. Join 'k3nt0456'
  3. Trigger a disconnection and reconnection

Actual behaviour: Active channels after reconnecting: [ '#yamuda', '#sqmp', '#k3nt0456' ]

Expected behaviour: Channels after reconnecting should be: [ '#sqmp', '#k3nt0456' ]

Server configuration

Full test I used, pardon the awful code

var tmi = require('../src/node_modules/tmi.js');

var client = new tmi.client({
    options: {debug: false},
    connection: {cluster: 'aws', timeout: 2000, reconnect: true},
    channels: ['yamuda', 'sqmp']
});

client.connect();

client.once('connected', function() {
    console.log('Connected, now joining a new channel.');
    setTimeout(function() {
        console.log('channels right now:', client.channels);
        console.log('leaving #yamuda, joining #k3nt0456');
        client.part('yamuda');
        client.join('k3nt0456');
        setTimeout(function() {
            console.log('channels right now:', client.channels);
            console.log('Please trigger a network failure...');
            client.once('connected', function() {
                console.log('reconnected');
                setTimeout(function() {
                    console.log('channels right now:', client.channels);
                }, 2000);
                setTimeout(function() {
                    console.log('channels right now:', client.channels);
                }, 4000);
                setTimeout(function() {
                    console.log('channels right now:', client.channels);
                }, 6000);
                setTimeout(function() {
                    console.log('channels right now:', client.channels);
                }, 8000);
            });
        }, 2000);
    }, 3000);

});

client.on('connecting', l('connecting'));
client.on('connected', l('connected'));
client.on('disconnected', l('disconnected'));
client.on('chat', l('chat'));

function l(event) {
    return function() {
        console.log('EVENT: ' + event, arguments);
    }
}

Log

EVENT: connecting { '0': 'irc-ws.chat.twitch.tv', '1': '80' }
Connected, now joining a new channel.
EVENT: connected { '0': 'irc-ws.chat.twitch.tv', '1': '80' }
channels right now: [ '#yamuda', '#sqmp' ]
leaving #yamuda
channels right now: [ '#sqmp', '#k3nt0456' ]
Please trigger a network failure...
[05:38pm] error: Ping timeout.
EVENT: disconnected { '0': '' }
[05:39pm] error: Could not connect to server. Trying to reconnect in 0 seconds..
EVENT: disconnected { '0': 'Sorry, we were unable to connect to chat.' }
[05:39pm] error: Could not connect to server. Trying to reconnect in 10 seconds..
EVENT: connecting { '0': 'irc-ws.chat.twitch.tv', '1': '80' }
EVENT: connected { '0': 'irc-ws.chat.twitch.tv', '1': '80' }
reconnected
channels right now: [ '#yamuda' ]
channels right now: [ '#yamuda', '#sqmp' ]
channels right now: [ '#yamuda', '#sqmp', '#k3nt0456' ]
channels right now: [ '#yamuda', '#sqmp', '#k3nt0456' ]
Schmoopiie commented 8 years ago

Thanks, fixed in 1.0.0 - No ETA for the release date though :smile: