qinstagram 0.1.1

Enterprise-grade IG Private API Architecture & Protocol Engineering toolkit with 100% Async-GraphQL & Websocket integration.
Documentation
use crate::error::{InstagramError, Result};
#[cfg(feature = "websocket")]
use crate::ws::InstagramWsEvent;
#[cfg(feature = "websocket")]
use tokio::sync::broadcast;

pub struct RealtimeClient {
    #[cfg(feature = "websocket")]
    pub broadcaster: Option<broadcast::Sender<InstagramWsEvent>>,
}

impl Default for RealtimeClient {
    fn default() -> Self {
        Self::new()
    }
}

impl RealtimeClient {
    pub fn new() -> Self {
        Self {
            #[cfg(feature = "websocket")]
            broadcaster: None,
        }
    }

    #[cfg(feature = "websocket")]
    pub fn with_broadcaster(mut self, tx: broadcast::Sender<InstagramWsEvent>) -> Self {
        self.broadcaster = Some(tx);
        self
    }
    
    pub async fn connect(&mut self) -> Result<()> {
        // Architecture Placeholder for rumqttc loop.
        // let mut eventloop = ...
        // while let Ok(notification) = eventloop.poll().await {
        //     match notification {
        //         Event::Incoming(Incoming::Publish(p)) => {
        //             let event = parse_skywalker_binary(&p.payload)?;
        //             if let Some(ref tx) = self.broadcaster {
        //                  let _ = tx.send(event);
        //             }
        //         }
        //         _ => {}
        //     }
        // }
        Err(InstagramError::NotImplemented("MQTT Connect / Thrift Binary Parsing missing".into()))
    }
}

#[cfg(feature = "websocket")]
pub fn parse_skywalker_binary(_bytes: &[u8]) -> Result<InstagramWsEvent> {
    // Advanced Thrift decoding maps here corresponding to IG protobufs.
    Err(InstagramError::NotImplemented("Thrift Decode".into()))
}