pub async fn connect_client(ws: warp::ws::WebSocket) {
    let (tx, mut rx) = ws.split();
    let id = ID_CTR.fetch_add(1, Ordering::SeqCst);
    STATUS
        .lock()
        .await
        .connections
        .push(Client { id, socket: tx });
    while let Some(msg) = rx.next().await {
        log::debug!(target: "scr::sharing_service", "Received message: {:?} from user {}", msg, id);
        let msg = msg.unwrap();
        if msg.is_close() {
            break;
        } else if let Ok(msg_text) = msg.to_str() {
            let payload: serde_json::Value = serde_json::from_str(msg_text).unwrap();
            let comic = payload.get("comic").unwrap().as_str().unwrap();
            if let Some(page) = payload.get("page").and_then(|val| val.as_str()) {
                // broadcast page to other clients and update current page
                STATUS
                    .lock()
                    .await
                    .current_pages
                    .insert(comic.to_string(), page.to_string());
                broadcast_page(id, comic, page).await;
            } else {
                // respond to same client with the current page, if there is one
                let current_page = STATUS.lock().await.current_pages.get(comic).cloned();
                reply_current_page(id, comic, current_page).await;
            }
        }
    }
}
// Initializes the connection to a client and runs the main loop that listens
// for websocket messages from them.
Initializes the connection to a client and runs the main loop that listens
for websocket messages from them.
Initializes the connection to a client and runs the main loop that listens for websocket messages from them .
pub async fn connect_client(ws: warp::ws::WebSocket) {
    let (tx, mut rx) = ws.split();
    let id = ID_CTR.fetch_add(1, Ordering::SeqCst);
    STATUS
        .lock()
        .await
        .connections
        .push(Client { id, socket: tx });
    while let Some(msg) = rx.next().await {
        log::debug!(target: "scr::sharing_service", "Received message: {:?} from user {}", msg, id);
        let msg = msg.unwrap();
        if msg.is_close() {
            break;
        } else if let Ok(msg_text) = msg.to_str() {
            let payload: serde_json::Value = serde_json::from_str(msg_text).unwrap();
            let comic = payload.get("comic").unwrap().as_str().unwrap();
            if let Some(page) = payload.get("page").and_then(|val| val.as_str()) {
                // broadcast page to other clients and update current page
                STATUS
                    .lock()
                    .await
                    .current_pages
                    .insert(comic.to_string(), page.to_string());
                broadcast_page(id, comic, page).await;
            } else {
                // respond to same client with the current page, if there is one
                let current_page = STATUS.lock().await.current_pages.get(comic).cloned();
                reply_current_page(id, comic, current_page).await;
            }
        }
    }
}
pub async fn connect_client ( ws : warp :: ws :: WebSocket ) { let ( tx , mut rx ) = ws . split ( ) ; let id = ID_CTR . fetch_add ( 1 , Ordering :: SeqCst ) ; STATUS . lock ( ) . await . connections . push ( Client { id , socket : tx } ) ; while let Some ( msg ) = rx . next ( ) . await { log :: debug ! ( target " " " " msg id ) ; let msg = msg . unwrap ( ) ; if msg . is_close ( ) { break ; } else if let Ok ( msg_text ) = msg . to_str ( ) { let payload : serde_json :: Value = serde_json :: from_str ( msg_text ) . unwrap ( ) ; let comic = payload . get ( " " ) . unwrap ( ) . as_str ( ) . unwrap ( ) ; if let Some ( page ) = payload . get ( " " ) . and_then ( | val | val . as_str ( ) ) { // broadcast page to other clients and update current page STATUS . lock ( ) . await . current_pages . insert ( comic . to_string ( ) , page . to_string ( ) ) ; broadcast_page ( id , comic , page ) . await ; } else { // respond to same client with the current page, if there is one let current_page = STATUS . lock ( ) . await . current_pages . get ( comic ) . cloned ( ) ; reply_current_page ( id , comic , current_page ) . await ; } } } }
Initializes the connection to a client and runs the main loop that listens
for websocket messages from them.
Initializes the connection to a client and runs the main loop that listens for websocket messages from them .
ws
warp::ws::WebSocket
ws
warp::ws::WebSocket