got cheer !!!
This commit is contained in:
parent
52785debf7
commit
d83fbb993e
|
|
@ -35,17 +35,17 @@ pub async fn listen_for_active_obs_session_thread(
|
|||
//}
|
||||
|
||||
loop {
|
||||
info!("[PubSub]");
|
||||
//info!("[PubSub]");
|
||||
|
||||
// TODO: ERROR HANDLING
|
||||
let message = pubsub.get_message().unwrap();
|
||||
let payload : String = message.get_payload().unwrap();
|
||||
|
||||
info!("Message: {}", payload);
|
||||
//info!("Message: {}", payload);
|
||||
|
||||
let payload = ObsActivePayload::from_json_str(&payload).unwrap();
|
||||
|
||||
info!("Message decoded: {:?}", payload);
|
||||
//info!("Message decoded: {:?}", payload);
|
||||
|
||||
let lease_key = RedisKeys::twitch_pubsub_lease(&payload.twitch_user_id);
|
||||
|
||||
|
|
@ -54,15 +54,15 @@ pub async fn listen_for_active_obs_session_thread(
|
|||
let lease_value : Option<String> = redis.get(&lease_key).unwrap();
|
||||
|
||||
if let Some(value) = lease_value.as_deref() {
|
||||
info!("Already has lease.");
|
||||
//info!("Already has lease.");
|
||||
let lease = LeasePayload::deserialize(value).unwrap();
|
||||
|
||||
info!("Lease value: {:?}", &lease);
|
||||
//info!("Lease value: {:?}", &lease);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
info!("No existing lease...");
|
||||
info!("No existing lease for {:?}...", &lease_key);
|
||||
|
||||
let lease = LeasePayload::new("foo", "bar");
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use sqlx::MySql;
|
|||
use std::sync::Arc;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use twitch_api2::pubsub::Response;
|
||||
|
||||
pub async fn twitch_pubsub_user_subscriber_thread(
|
||||
twitch_user_id: String,
|
||||
|
|
@ -62,6 +63,7 @@ pub async fn twitch_pubsub_user_subscriber_thread(
|
|||
warn!("Connecting to Twitch PubSub for user {}...", &record.twitch_username);
|
||||
client.connect().await.unwrap();
|
||||
|
||||
// TODO: BACKGROUND PINGS UGH!
|
||||
warn!("Sending ping...");
|
||||
client.send_ping().await.unwrap();
|
||||
|
||||
|
|
@ -70,7 +72,20 @@ pub async fn twitch_pubsub_user_subscriber_thread(
|
|||
|
||||
client.listen(&record.access_token, &topics).await.unwrap();
|
||||
|
||||
loop {
|
||||
warn!("client.next()");
|
||||
let event = client.next().await.unwrap();
|
||||
|
||||
sleep(Duration::from_secs(30));
|
||||
warn!("event: {:?}", event);
|
||||
|
||||
match event {
|
||||
Response::Response(_) => {}
|
||||
Response::Message { .. } => {}
|
||||
Response::Pong => {}
|
||||
Response::Reconnect => {}
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>Websocket Test</h1>
|
||||
<h2 id="username"></h2>
|
||||
<p>Use the URL hash to set the username, eg. #testytest</p>
|
||||
<script src="./websocket_test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
|
||||
const WS_URL = 'ws://localhost:54321/obs';
|
||||
|
||||
const DEFAULT_USERNAME = 'testytest512';
|
||||
|
||||
(function() {
|
||||
console.log('installing script');
|
||||
|
||||
const username = 'testytest512';
|
||||
const maybeUsername = window.location.hash.replace('#', '').trim();
|
||||
|
||||
const username = (!!maybeUsername) ? maybeUsername : DEFAULT_USERNAME;
|
||||
|
||||
console.log('username', username);
|
||||
document.getElementById('username').innerHTML = username;
|
||||
|
||||
const url = `${WS_URL}/${username}`;
|
||||
|
||||
let sock = new WebSocket(url);
|
||||
|
|
|
|||
Loading…
Reference in New Issue