Struct mumble_link::SharedLink

source ·
pub struct SharedLink { /* private fields */ }
Expand description

A weak Mumble link connection.

Constructing a SharedLink always succeeds, even if Mumble is not running or another application is writing to the link. If this happens, update() will retry opening the link on a regular basis, succeeding if Mumble is started or the other application stops using the link.

Implementations§

source

pub fn new(name: &str, description: &str) -> SharedLink

Open the Mumble link, providing the specified application name and description.

Examples found in repository?
examples/simple.rs (line 15)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}
source

pub fn set_context(&mut self, context: &[u8])

Update the context string, used to determine which users on a Mumble server should hear each other positionally.

If context between two Mumble users does not match, the positional audio data is stripped server-side and voice will be received as non-positional. Accordingly, the context should only match for players on the same game, server, and map, depending on the game itself. When in doubt, err on the side of including less; this allows for more flexibility in the future.

The context should be changed infrequently, at most a few times per second.

The context has a maximum length of 256 bytes.

Examples found in repository?
examples/simple.rs (line 39)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}
source

pub fn set_identity(&mut self, identity: &str)

Update the identity, uniquely identifying the player in the given context. This is usually the in-game name or ID.

The identity may also contain any additional information about the player which might be useful for the Mumble server, for example to move teammates to the same channel or give squad leaders additional powers. It is recommended that a parseable format like JSON or CSV is used for this.

The identity should be changed infrequently, at most a few times per second.

The identity has a maximum length of 255 UTF-16 code units.

Examples found in repository?
examples/simple.rs (line 17)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}
source

pub fn update(&mut self, avatar: Position, camera: Position)

Update the link with the latest position information. Should be called once per frame.

avatar should be the position of the player. If it is all zero, positional audio will be disabled. camera should be the position of the camera, which may be the same as avatar.

Examples found in repository?
examples/simple.rs (line 27)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}
source

pub fn status(&self) -> Status<'_>

Get the status of the shared link. See Status for details.

Examples found in repository?
examples/simple.rs (line 31)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}
source

pub fn deactivate(&mut self)

Deactivate the shared link.

Should be called when update() will not be called again for a while, such as if the player is no longer in-game.

Examples found in repository?
examples/simple.rs (line 41)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
fn main() {
    println!("Attempting to open Link...");
    let mut link = SharedLink::new("Test", "test.");
    println!("Enter an identity:");
    link.set_identity(&read_line());

    let (tx, rx) = mpsc::channel();
    std::thread::spawn(move || {
        let mut timer = Timer::new(1000 / 50);
        let mut position = Position::default();
        let mut i = 0;
        position.position[0] = 0.005;
        loop {
            timer.sleep_until_tick();
            link.update(position, position);
            i += 1;
            if i == 200 {
                i = 0;
                println!("Status: {:?}", link.status());
            }
            loop {
                match rx.try_recv() {
                    Ok(Command::Left) => position.position = [-2., 0., 0.],
                    Ok(Command::Right) => position.position = [2., 0., 0.],
                    Ok(Command::Middle) => position.position = [0.005, 0., 0.],
                    Ok(Command::Distant) => position.position = [1000., 0., 0.],
                    Ok(Command::Red) => link.set_context(b"red"),
                    Ok(Command::Blue) => link.set_context(b"blue"),
                    Ok(Command::Free) => link.deactivate(),
                    Err(mpsc::TryRecvError::Disconnected) => return,
                    Err(mpsc::TryRecvError::Empty) => break,
                }
            }
        }
    });

    let help = "Commands are: left, right, middle, distant, red, blue, free, exit";
    println!("{}", help);
    loop {
        let m = match read_line().trim() {
            "left" => Command::Left,
            "right" => Command::Right,
            "middle" => Command::Middle,
            "distant" => Command::Distant,
            "red" => Command::Red,
            "blue" => Command::Blue,
            "free" => Command::Free,
            "exit" => { drop(tx); break }
            _ => { println!("{}", help); continue }
        };
        tx.send(m).unwrap();
    }
    println!("Exiting");
}

Trait Implementations§

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.