Random a channel

You’re only loading one channel at a time. You need to use /streams?channel= to load them all at the same time, so that you can choose one.

function getRandomStream(channels) {
    return $.getJSON("https://api.twitch.tv/kraken/streams?channel=" + channels.join(",") + "&callback=?").then(function (data) {
        return data.streams.length ? data.streams[Math.floor(Math.random() * data.streams.length)] : null;
    });
}

getRandomStream(['maddenamy','lvpes2','lulosguat','gamerstudiotv','yosoyyazz','esl_spain']).then(function (stream) {
    $('#name').text(stream ? stream.channel.display_name : "No streams live");
});
1 Like