Giter Club home page Giter Club logo

ripewire's Introduction

RipeWire

PipeWire client library in idiomatic Rust

WIP...

Simple proof of concept (definitely not final API):

#[derive(Default)]
struct State {
    globals: GlobalList,
}

impl State {
    pub fn core_event(
        &mut self,
        context: &mut Context<Self>,
        core: PwCore,
        event: pw_core::Event,
    ) {
        match event {
            pw_core::Event::Done(done) => {
                if done.id == 0 && done.seq == 0 {
                    // Let's print globals advertised by the registry
                    dbg!(&self.globals)
                }
            }
            _ => {}
        }
    }

    pub fn registry_event(
        &mut self,
        context: &mut Context<Self>,
        registry: PwRegistry,
        event: pw_registry::Event,
    ) {
        self.globals.handle_event(&event);
    }
}

let mut ctx = Context::connect("/run/user/1000/pipewire-0").unwrap();
let core = ctx.core();
let client = ctx.client();

core.hello(&mut ctx);

client.update_properties(
    &mut ctx,
    Dictionary::from([
        ("application.name", "RipeWire"),
        ("application.process.binary", "ripewire"),
    ]),
);

let registry = core.get_registry(&mut ctx);

core.sync(&mut ctx, 0, 0);

ctx.set_object_callback(&core, State::core_event);
ctx.set_object_callback(&registry, State::registry_event);

ctx.set_object_callback(&client, |state, client, event| {
    println!("You can use closures as well: {:?}", event);
});

let mut state = State::default();

loop { // any event loop or async runtime of your choice
    let (messages, fds) = ctx.rcv_msg();

    for msg in messages {
        ctx.dispatch_event(&mut state, msg, &fds);
    }
}

ripewire's People

Contributors

polymeilex avatar

Stargazers

Andrew Prentice avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.