const { startAuthServer } = require("./twitch/authServer");
const { connect } = require("./twitch/websocket");

const auth = startAuthServer();

// wait for login before starting Twitch connection
const wait = setInterval(() => {
  const token = auth.getToken();

  if (token) {
    clearInterval(wait);

    // inject token into runtime config
    const config = require("./config");
    config.token = token;

    console.log("🚀 Starting Twitch connection...");
    connect();
  }
}, 1000);