Skip to content

hopinc/leap_client_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leap_edge_rs

Utility library for connecting and receiving events from Leap Edge. Used for Channels and Pipe.

Installation

Add this to your Cargo.toml:

[dependencies]
leap_edge_rs = "0.1"

or if you want to add features:

[dependencies.leap_edge_rs]
version = "0.1"
default-features = false
features = ["rustls-tls-webpki-roots", "zlib"]

Usage

Subscribe to a channel

use leap_edge_rs::{LeapEdge, LeapOptions, leap::types::Event};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let leap = LeapEdge::new(LeapOptions {
        project: "my-project",
        ..Default::default()
    }).await?;

    leap.channel_subscribe("my-channel").await?;

    while let Some(event) = leap.listen().await {
        println!("{:?}", event);
    }
}

Get all events:

use leap_edge_rs::{LeapEdge, LeapOptions};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let leap = LeapEdge::new(LeapOptions {
        project: "my-project",
        ..Default::default()
    }).await?;

    while let Some(event) = leap.listen().await {
        println!("{:?}", event);
    }
}

Get only messages or direct messages:

use leap_edge_rs::{LeapEdge, LeapOptions, leap::types::Event};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let leap = LeapEdge::new(LeapOptions {
        project: "my-project",
        ..Default::default()
    }).await?;

    while let Some(event) = leap.listen().await {
        match event {
            Event::Message(message) | Event::DirectMessage(message) => println!("{:?}", message),

            _ => {}
        }
    }
}