rust-socketio icon indicating copy to clipboard operation
rust-socketio copied to clipboard

Receiving a message from the server that requires an ack

Open mendess opened this issue 1 year ago • 0 comments

I want to send from the socket io server an emit_with_ack event. But I don't see how I can ack from the client

async fn handler(payload: Payload, socket: Client) {
    let values = match payload {
        Payload::Text(values) => values,
        Payload::Binary(_) => panic!("unexpected bytes"),
        #[allow(deprecated)]
        Payload::String(_) => panic!("Payload::String panicked"),
    };

    tracing::info!("got values: {values:?}");
    // how do I ack here?
}

async fn run(config: &Config, hostname: &Hostname) -> anyhow::Result<()> {
    let socket = ClientBuilder::new(format!("{}?h={}", config.backend_domain, hostname))
        .namespace(ws::NS)
        .on(ws::COMMAND, |payload, socket| {
            handler(payload, socket).boxed()
        })
        .on("error", |err, _| {
            async move { tracing::error!(error = ?err, "socket io error") }.boxed()
        })
        .connect()
        .await?;

    std::future::pending::<()>().await;
    socket.disconnect().await?;
    drop(socket);
    Ok(())
}

I've tested and I do get a value in here but I can't ack. Is this just not implemented yet or am I missing something?

mendess avatar Sep 15 '24 19:09 mendess