diff --git a/src/app.js b/src/app.js index 406508d..9d83c28 100644 --- a/src/app.js +++ b/src/app.js @@ -260,10 +260,16 @@ function handleError(error, socket, domain, data) { } } -async function connect(wsCreds, sessionCookie, bot, games) { +async function connect(bot, games) { const socket = { ws: { readyState: 0 } }; - socket.connect = () => { + socket.connect = async () => { + const { user, httpSession, sessionCookie } = await auth(); + const wsCreds = await getWsId(httpSession); + + bot.user = user; + bot.httpSession = httpSession; + logger.info(`Attempting to connect to ${config.socket}`); socket.ws = new WebSocket(`${config.socket}?${new URLSearchParams({ v: wsCreds.wsId, t: wsCreds.timestamp }).toString()}`, [], { @@ -310,19 +316,14 @@ async function connect(wsCreds, sessionCookie, bot, games) { } async function init() { - const { user, httpSession, sessionCookie } = await auth(); - const wsCreds = await getWsId(httpSession); - const bot = { - user, - httpSession, rooms: [], users: [], }; const games = getGames(bot); - bot.socket = await connect(wsCreds, sessionCookie, bot, games); + bot.socket = await connect(bot, games); await initPoints(); }