#include common.js
#include utility.js

const UmiServers = (function() {
    let servers = undefined,
        index = Number.MAX_SAFE_INTEGER - 1;

    return {
        getServer: function(callback) {
            // FutamiCommon is delayed load
            if(servers === undefined) {
                const futamiServers = futami.get('servers');
                $as(futamiServers);
                servers = futamiServers;
            }

            if(++index >= servers.length)
                index = 0;

            let server = servers[index];
            if(server.includes('//'))
                server = location.protocol.replace('http', 'ws') + server;

            callback(server);
        },
    };
})();
