You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.2 KiB

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
use tokio::net::UdpSocket;
use std::{net::SocketAddrV4, str::FromStr};
use rosc::{encoder, OscMessage, OscPacket, OscType};
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![
send_osc_message,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
async fn send_osc_message(
key: &str,
message: &str,
host: &str,
target: &str,
) -> Result<(), String> {
// print
println!("Sending OSC message: {}", message);
let sock = UdpSocket::bind(host).await.unwrap();
let remote = SocketAddrV4::from_str(target).unwrap();
let msg_buf = encoder::encode(&OscPacket::Message(OscMessage {
addr: key.to_string(),
args: vec![OscType::String(message.parse().unwrap())],
}))
.unwrap();
sock.send_to(&msg_buf, remote).await.unwrap();
Ok(())
}