record-daemon: add record raw events, subscribe lp change events
record-daemon / Build, check and test (push) Successful in 2m0s
record-daemon / Build, check and test (push) Successful in 2m0s
This commit is contained in:
@@ -14,7 +14,7 @@ use super::endpoints;
|
||||
use super::events::GameEvent;
|
||||
use super::state::{ClientState, GameflowPhase};
|
||||
use super::tls::create_insecure_tls_config;
|
||||
use super::websocket::parse_websocket_message;
|
||||
use super::websocket::{parse_websocket_message, ParsedEvent};
|
||||
use crate::error::{LqpError, Result};
|
||||
|
||||
/// LQP Client for League Client communication.
|
||||
@@ -24,7 +24,7 @@ pub struct LqpClient {
|
||||
/// Current client state.
|
||||
state: Arc<RwLock<ClientState>>,
|
||||
/// Event broadcaster.
|
||||
event_sender: broadcast::Sender<GameEvent>,
|
||||
event_sender: broadcast::Sender<ParsedEvent>,
|
||||
/// HTTP client for REST API.
|
||||
http_client: reqwest::Client,
|
||||
/// Shutdown signal.
|
||||
@@ -54,7 +54,7 @@ impl LqpClient {
|
||||
}
|
||||
|
||||
/// Get a subscriber for game events.
|
||||
pub fn subscribe(&self) -> broadcast::Receiver<GameEvent> {
|
||||
pub fn subscribe(&self) -> broadcast::Receiver<ParsedEvent> {
|
||||
self.event_sender.subscribe()
|
||||
}
|
||||
|
||||
@@ -184,12 +184,12 @@ impl LqpClient {
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if let Some(event) = parse_websocket_message(&text) {
|
||||
if let Some(parsed) = parse_websocket_message(&text) {
|
||||
// Update state based on event
|
||||
Self::update_state_from_event(&state, &event).await;
|
||||
Self::update_state_from_event(&state, &parsed.event).await;
|
||||
|
||||
// Check for duplicate GameStart events
|
||||
if let GameEvent::GameStart(ref info) = event {
|
||||
if let GameEvent::GameStart(ref info) = parsed.event {
|
||||
let mut last_game_id = last_emitted_game_id.write().await;
|
||||
if *last_game_id == Some(info.game_id) {
|
||||
info!(
|
||||
@@ -202,12 +202,12 @@ impl LqpClient {
|
||||
}
|
||||
|
||||
// Reset last_emitted_game_id on GameEnd to allow new game starts
|
||||
if let GameEvent::GameEnd(_) = &event {
|
||||
if let GameEvent::GameEnd(_) = &parsed.event {
|
||||
*last_emitted_game_id.write().await = None;
|
||||
}
|
||||
|
||||
// Broadcast event
|
||||
if event_sender.send(event.clone()).is_err() {
|
||||
if event_sender.send(parsed).is_err() {
|
||||
trace!("No event subscribers");
|
||||
}
|
||||
}
|
||||
@@ -217,12 +217,12 @@ impl LqpClient {
|
||||
// Try to parse as UTF-8
|
||||
if let Ok(text) = String::from_utf8(data) {
|
||||
if !text.is_empty() {
|
||||
if let Some(event) = parse_websocket_message(&text) {
|
||||
if let Some(parsed) = parse_websocket_message(&text) {
|
||||
// Update state based on event
|
||||
Self::update_state_from_event(&state, &event).await;
|
||||
Self::update_state_from_event(&state, &parsed.event).await;
|
||||
|
||||
// Check for duplicate GameStart events
|
||||
if let GameEvent::GameStart(ref info) = event {
|
||||
if let GameEvent::GameStart(ref info) = parsed.event {
|
||||
let mut last_game_id = last_emitted_game_id.write().await;
|
||||
if *last_game_id == Some(info.game_id) {
|
||||
info!(
|
||||
@@ -235,12 +235,12 @@ impl LqpClient {
|
||||
}
|
||||
|
||||
// Reset last_emitted_game_id on GameEnd to allow new game starts
|
||||
if let GameEvent::GameEnd(_) = &event {
|
||||
if let GameEvent::GameEnd(_) = &parsed.event {
|
||||
*last_emitted_game_id.write().await = None;
|
||||
}
|
||||
|
||||
// Broadcast event
|
||||
if event_sender.send(event.clone()).is_err() {
|
||||
if event_sender.send(parsed).is_err() {
|
||||
trace!("No event subscribers");
|
||||
}
|
||||
}
|
||||
@@ -448,6 +448,16 @@ impl LqpClient {
|
||||
pub async fn fetch_raw_end_game_stats(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::GAME_STATS).await
|
||||
}
|
||||
|
||||
/// Fetch ranked stats as JSON (for LP tracking).
|
||||
pub async fn fetch_ranked_stats(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::RANKED_STATS).await
|
||||
}
|
||||
|
||||
/// Fetch current ranked stats as JSON.
|
||||
pub async fn fetch_current_ranked_stats(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::CURRENT_RANKED_STATS).await
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LqpClient {
|
||||
|
||||
Reference in New Issue
Block a user