listen wip

This commit is contained in:
Brandon Thomas committed 2021-09-26 20:33:51 -04:00
1 parent fc19a1430b
commit c2eb31cbb2
2 files changed
+32 -13

No files matched your search

+23 -3
View File
@@ -113,12 +113,32 @@ async fn run() -> AnyhowResult<()> {
println!("Starting polling thread...");
client.start_ping_thread().await;
// We want to subscribe to moderator actions on channel with id 1234
// as if we were a user with id 4321 that is moderator on the channel.
let chat_mod_actions = pubsub::moderation::ChatModeratorActions {
user_id: 4321,
channel_id: 1234,
}.into_topic();
// Listen to follows as well
let follows = pubsub::following::Following { channel_id: 1234 }.into_topic();
println!("Begin LISTEN...");
client.listen("auth_token", &[chat_mod_actions, follows]).await;
println!("Try read next...");
client.try_next().await?;
let r = client.try_next().await?;
println!("Result: {:?}", r);
println!("Try read next...");
client.try_next().await?;
let r = client.try_next().await?;
println!("Result: {:?}", r);
println!("Try read next...");
client.try_next().await?;
let r = client.try_next().await?;
println!("Result: {:?}", r);
println!("Sleep...");
std::thread::sleep(Duration::from_millis(30000));
+9 -10
View File
@@ -52,6 +52,15 @@ impl PollingTwitchWebsocketClient {
}
}
pub async fn listen<'t>(&mut self, auth_token: &str, topics: &'t [Topics]) -> AnyhowResult<()> {
match self.client.lock() {
Err(e) => Err(anyhow!("unlock client err: {:?}", e)),
Ok(mut client) => {
client.listen(auth_token, topics).await
}
}
}
/// Start a pinging background thread.
/// Per Twitch PubSub docs,
/// To keep the server from closing the connection, clients must send a PING command
@@ -181,16 +190,6 @@ impl TwitchWebsocketClient {
}
pub async fn listen<'t>(&mut self, auth_token: &str, topics: &'t [Topics]) -> AnyhowResult<()> {
//// We want to subscribe to moderator actions on channel with id 1234
//// as if we were a user with id 4321 that is moderator on the channel.
//let chat_mod_actions = pubsub::moderation::ChatModeratorActions {
// user_id: 4321,
// channel_id: 1234,
//}.into_topic();
//// Listen to follows as well
//let follows = pubsub::following::Following { channel_id: 1234 }.into_topic();
let mut socket = match self.socket {
None => return Err(anyhow!("not connected")),
Some(ref mut socket) => socket,