This commit is contained in:
Brandon Thomas committed 2022-01-10 04:39:02 -05:00
1 parent 22cf399f5c
commit fd9cfc159b
4 files changed
+35 -5

No files matched your search

@@ -16,6 +16,8 @@ use tokio::runtime::Handle;
use twitch_api2::pubsub::Topic;
use twitch_api2::pubsub;
use crate::twitch::pubsub::build_pubsub_topics_for_user::build_pubsub_topics_for_user;
use crate::twitch::oauth::oauth_token_refresher::OauthTokenRefresher;
use crate::twitch::websocket_client::TwitchWebsocketClient;
/// Endpoint
pub async fn obs_gateway_websocket_handler(
@@ -28,7 +30,9 @@ pub async fn obs_gateway_websocket_handler(
let user_id = server_state.twitch_oauth_temp.temp_oauth_user_id.parse::<u32>().unwrap();
let auth_token = server_state.twitch_oauth_temp.temp_oauth_access_token.clone();
let mut client = PollingTwitchWebsocketClient::new().unwrap();
let mut client = TwitchWebsocketClient::new().unwrap();
let token_refresher = OauthTokenRefresher::new(user_id, &auth_token, None);
info!("Connecting to Twitch PubSub...");
client.connect().await.unwrap();
@@ -66,7 +70,7 @@ struct ObsGatewayWebSocket {
impl ObsGatewayWebSocket {
fn new(twitch_user_id: u32, twitch_client: PollingTwitchWebsocketClient) -> Self {
fn new(twitch_user_id: u32, twitch_client: TwitchWebsocketClient) -> Self {
let twitch_thread = ObsTwitchThread::new(twitch_user_id, twitch_client);
Self {
twitch_user_id,
@@ -1,4 +1,5 @@
use crate::twitch::polling_websocket_client::PollingTwitchWebsocketClient;
use crate::twitch::websocket_client::TwitchWebsocketClient;
use log::error;
use log::info;
use std::sync::atomic::AtomicBool;
@@ -19,12 +20,12 @@ use tokio::runtime::Handle;
pub struct ObsTwitchThread {
twitch_user_id: u32,
twitch_client: Arc<RwLock<PollingTwitchWebsocketClient>>,
twitch_client: Arc<RwLock<TwitchWebsocketClient>>,
last_requested: Arc<RwLock<Instant>>,
}
impl ObsTwitchThread {
pub fn new(twitch_user_id: u32, twitch_client: PollingTwitchWebsocketClient) -> Self {
pub fn new(twitch_user_id: u32, twitch_client: TwitchWebsocketClient) -> Self {
let now = Instant::now();
Self {
twitch_user_id,
@@ -1 +1,2 @@
pub mod oauth_token_builder;
pub mod oauth_token_builder;
pub mod oauth_token_refresher;
@@ -0,0 +1,24 @@
// TODO: I know this is something we'll need, but I haven't built it yet.
// We'll probably want to write back to the database.
#[derive(Clone)]
pub struct OauthTokenRefresher {
user_id: u32,
auth_token: String,
refresh_token: Option<String>,
}
impl OauthTokenRefresher {
pub fn new(user_id: u32, auth_token: &str, refresh_token: Option<&str>) -> Self {
Self {
user_id,
auth_token: auth_token.to_string(),
refresh_token: refresh_token.map(|str| str.to_string()),
}
}
pub fn get_auth_token(&self) -> String {
self.auth_token.clone()
}
}