diff --git a/src/backend/chatClient/index.ts b/src/backend/chatClient/index.ts index a6560d2..95e2877 100644 --- a/src/backend/chatClient/index.ts +++ b/src/backend/chatClient/index.ts @@ -1,6 +1,6 @@ -import { AuthProvider } from "twitch-auth"; +import { getApiClient, getAuthProvider } from "../helpers/twitch"; + import { ChatClient } from "twitch-chat-client"; -import { getApiClient } from "../helpers/twitch"; import { sockets } from "../webServer"; import { start } from "../helpers/scheduledActions"; @@ -14,7 +14,10 @@ export { say }; -async function connect(authProvider: AuthProvider, channels: Array) { +async function connect(channels: Array) { + const authProvider = await getAuthProvider( + + ); if ( chatClient && ( diff --git a/src/backend/index.ts b/src/backend/index.ts index 94e4f48..3ab8df6 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -1,5 +1,3 @@ -import { getApiClient, getAuthProvider } from "./helpers/twitch"; - import { connect } from "./chatClient"; import { listen } from "./webServer"; import { registerUserListener } from "./pubSubClient"; @@ -7,12 +5,10 @@ import { registerUserListener } from "./pubSubClient"; const channel = "alexbcberio"; export async function bootstrap() { - - const apiClient = await getApiClient(); - await registerUserListener(apiClient, channel); - - const authProvider = await getAuthProvider(); - await connect(authProvider, [channel]); + await Promise.all([ + registerUserListener(channel), + connect([channel]), + ]); listen(); } \ No newline at end of file diff --git a/src/backend/pubSubClient/index.ts b/src/backend/pubSubClient/index.ts index b7e9745..27d1b29 100644 --- a/src/backend/pubSubClient/index.ts +++ b/src/backend/pubSubClient/index.ts @@ -1,15 +1,17 @@ -import { ApiClient, UserIdResolvable } from "twitch"; import { PubSubClient, PubSubRedemptionMessage } from "twitch-pubsub-client"; import { broadcast, chatClient, say } from "../chatClient"; +import { getApiClient, getUsernameFromId } from "../helpers/twitch"; import { saveScheduledActions, scheduledActions } from "../helpers/scheduledActions"; -import { getUsernameFromId } from "../helpers/twitch"; +import { UserIdResolvable } from "twitch"; export { registerUserListener } -async function registerUserListener(apiClient: ApiClient, user?: UserIdResolvable) { +async function registerUserListener(user: UserIdResolvable) { + const apiClient = await getApiClient(); + const pubSubClient = new PubSubClient(); const userId = await pubSubClient.registerUserListener(apiClient, user); /*const listener = */ await pubSubClient.onRedemption(userId, onRedemption);