// TODO: Maybe keep the time of the last received message so if there hasn't been a message in
// a while send a ping of our own.
Maybe keep the time of the last received message so if there hasn't been a message in
a while send a ping of our own.
Maybe keep the time of the last received message so if there hasn ' t been a message in a while send a ping of our own .
async fn handle_read(
        read: tokio::io::ReadHalf<TlsStream<TcpStream>>,
        send_msg: async_channel::Sender<Message>,
        shutdown: async_channel::Sender<()>,
        reconnect: Arc<Mutex<Reconnect>>,
        internal_send: async_channel::Sender<String>,
    ) {
        let mut read = FramedRead::new(read, LinesCodec::new());
        while let Some(result) = read.next().await {
            match result {
                Ok(line) => {
                    if line.contains("Login authentication failed") {
                        println!("Authentication failed");
                        reconnect.lock().await.should_reconnect = false;
                    }
                    let message = Message::parse(&line);
                    match message {
                        Ok(parsed) => {
                            //println!("RAW {}", line);
                            match parsed.command.as_deref() {
                                // Some("PRIVMSG") => {
                                //     if parsed.params.to_owned().unwrap()[1] == "quit" {
                                //         shutdown.close();
                                //         break;
                                //     }
                                // }
                                Some("PING") => {
                                    let _ =
                                        internal_send.send("PONG :tmi.twitch.tv".to_owned()).await;
                                    //println!("Sending PONG!");
                                }
                                _ => (),
                            }
                            let _ = send_msg.send(parsed).await;
                        }
                        Err(e) => println!("Got an error parsing: {}", e),
                    }
                }
                Err(e) => println!("Reading line error: {}", e),
            }
        }
        // TODO: Since shutdown sender is dropped, it automatically shutsdown the writer and
        // keepalive so do i need this?
        shutdown.close();
    }
async fn handle_read ( read : tokio :: io :: ReadHalf < TlsStream < TcpStream > > , send_msg : async_channel :: Sender < Message > , shutdown : async_channel :: Sender < ( ) > , reconnect : Arc < Mutex < Reconnect > > , internal_send : async_channel :: Sender < String > , ) { let mut read = FramedRead :: new ( read , LinesCodec :: new ( ) ) ; while let Some ( result ) = read . next ( ) . await { match result { Ok ( line ) => { if line . contains ( " " ) { println ! ( " " ) ; reconnect . lock ( ) . await . should_reconnect = false ; } let message = Message :: parse ( & line ) ; match message { Ok ( parsed ) => { //println!("RAW {}", line); match parsed . command . as_deref ( ) { // Some("PRIVMSG") => { //     if parsed.params.to_owned().unwrap()[1] == "quit" { //         shutdown.close(); //         break; //     } // } Some ( " " ) => { let _ = internal_send . send ( " " . to_owned ( ) ) . await ; //println!("Sending PONG!"); } _ => ( ) , } let _ = send_msg . send ( parsed ) . await ; } Err ( e ) => println ! ( " " e ) , } } Err ( e ) => println ! ( " " e ) , } } // TODO: Since shutdown sender is dropped, it automatically shutsdown the writer and // keepalive so do i need this? shutdown . close ( ) ; }
TODO: Maybe keep the time of the last received message so if there hasn't been a message in
a while send a ping of our own.
TODO : Maybe keep the time of the last received message so if there hasn ' t been a message in a while send a ping of our own .
read
tokio::io::ReadHalf<TlsStream<TcpStream>>
send_msg
async_channel::Sender<Message>
shutdown
async_channel::Sender<()>
reconnect
Arc<Mutex<Reconnect>>
internal_send
async_channel::Sender<String>