tsclientlib icon indicating copy to clipboard operation
tsclientlib copied to clipboard

Listing available files in channels?

Open vablings opened this issue 3 years ago • 1 comments

When calling channel.file_list("","") It returns OutFileListRequestedPart.

I'm wanting to list all available files to download inside of the respective channel and this doesn't seem to be the right function.

vablings avatar Aug 25 '22 22:08 vablings

It is the right function. You’re right, it only returns a packet and that packet then needs to be sent to a connection. (It’s a two-step process otherwise all these structs would have to borrow the connection mutably and that doesn’t really work out in Rust.) For example the set_subscribed here is creating a packet that is then sent: https://github.com/ReSpeak/tsclientlib/blob/77b065421ec9066c6209bc2e183cc900a02c4e33/tsclientlib/examples/channeltree.rs#L88

For file_list that would be roughly like this:

con.get_state().unwrap().channels[ChannelId(0)].file_list("", "/").send(&mut con)?;

// Get file list packets
let mut events = con.events();
loop {
    if let Some(event) = events.next().await {
        if let StreamItem::MessageEvent(InMessage::FileList(file_list)) = event? {
            for part in &file_list {
                // part is an InFileListPart, do whatever needs to be done
            }
        }
        // Should also check for FileListFinished and exit the loop
    }
}
drop(events);

Flakebi avatar Sep 09 '22 06:09 Flakebi