From 7aa33d19b0bdb2cab4d5d38b9672d5edcaa8ad57 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 10 Jan 2022 03:33:23 -0500 Subject: [PATCH] refactor --- .../obs_gateway_websocket_handler.rs | 5 ++++- crates/service/obs_gateway/src/twitch/mod.rs | 1 + .../pubsub/build_pubsub_topics_for_user.rs | 19 +++++++++++++++++++ .../obs_gateway/src/twitch/pubsub/mod.rs | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 crates/service/obs_gateway/src/twitch/pubsub/build_pubsub_topics_for_user.rs create mode 100644 crates/service/obs_gateway/src/twitch/pubsub/mod.rs diff --git a/crates/service/obs_gateway/src/endpoints_ws/obs_gateway_websocket_handler.rs b/crates/service/obs_gateway/src/endpoints_ws/obs_gateway_websocket_handler.rs index e8f35bc70b..05e97a412d 100644 --- a/crates/service/obs_gateway/src/endpoints_ws/obs_gateway_websocket_handler.rs +++ b/crates/service/obs_gateway/src/endpoints_ws/obs_gateway_websocket_handler.rs @@ -15,6 +15,7 @@ use std::time::Duration; 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; /// Endpoint pub async fn obs_gateway_websocket_handler( @@ -63,7 +64,9 @@ pub async fn obs_gateway_websocket_handler( channel_id: user_id, }.into_topic(); - let topics = [bit_topic, points_topic, cheer_topic, sub_topic]; + //let topics = [bit_topic, points_topic, cheer_topic, sub_topic]; + + let topics = build_pubsub_topics_for_user(user_id); let auth_token = server_state.twitch_oauth_temp.temp_oauth_access_token.clone(); diff --git a/crates/service/obs_gateway/src/twitch/mod.rs b/crates/service/obs_gateway/src/twitch/mod.rs index cb82754d94..7743cc2916 100644 --- a/crates/service/obs_gateway/src/twitch/mod.rs +++ b/crates/service/obs_gateway/src/twitch/mod.rs @@ -1,5 +1,6 @@ pub mod oauth_token_builder; pub mod polling_websocket_client; +pub mod pubsub; pub mod twitch_client_wrapper; pub mod twitch_secrets; pub mod websocket_client; \ No newline at end of file diff --git a/crates/service/obs_gateway/src/twitch/pubsub/build_pubsub_topics_for_user.rs b/crates/service/obs_gateway/src/twitch/pubsub/build_pubsub_topics_for_user.rs new file mode 100644 index 0000000000..b61ae41e70 --- /dev/null +++ b/crates/service/obs_gateway/src/twitch/pubsub/build_pubsub_topics_for_user.rs @@ -0,0 +1,19 @@ +use twitch_api2::pubsub::{Topics, Topic}; +use twitch_api2::pubsub; + +pub fn build_pubsub_topics_for_user(user_id: u32) -> Vec { + vec![ + pubsub::channel_bits::ChannelBitsEventsV2 { + channel_id: user_id, + }.into_topic(), + pubsub::channel_points::ChannelPointsChannelV1 { + channel_id: user_id, + }.into_topic(), + pubsub::channel_cheer::ChannelCheerEventsPublicV1 { + channel_id: user_id, + }.into_topic(), + pubsub::channel_subscriptions::ChannelSubscribeEventsV1 { + channel_id: user_id, + }.into_topic(), + ] +} diff --git a/crates/service/obs_gateway/src/twitch/pubsub/mod.rs b/crates/service/obs_gateway/src/twitch/pubsub/mod.rs new file mode 100644 index 0000000000..e771e309d2 --- /dev/null +++ b/crates/service/obs_gateway/src/twitch/pubsub/mod.rs @@ -0,0 +1 @@ +pub mod build_pubsub_topics_for_user; \ No newline at end of file