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

const auth = startAuthServer();

// wait until token exists before starting twitch
const waitForToken = setInterval(() => {
  const token = auth.getToken();

  if (token) {
    clearInterval(waitForToken);

    process.env.APP_ACCESS_TOKEN = token;

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