rust 桌面 sip 软电话(基于tauri 、pjsip库)

本文尝试下rust 的tauri 桌面运用 原因在于体积小

1、pjsip 提供了rust 接口官方的 rust demo 没编译出来 在git找了个sip-phone-rs-master

https://github.com/Charles-Schleich/sip-phone-rs

可以自己编译下pjsip lib库替换该项目的lib

2、创建一个tauri demo 引用

dependencies

tauri = { version = "1", features = ["shell-open"] }

serde = { version = "1", features = ["derive"] }

serde_json = "1"

te-telephony-rs = {path="../../sip-phone-rs-master"}

3.稍微修改下sip-phone-rs项目加了消息回调用到以下

pj_str_t 转CString 找了很久,r

let c_str = unsafe {

CString::from_vec_unchecked(std::slice::from_raw_parts(ci.state_text .ptr as *const u8, ci.state_text .slen as usize)

.to_vec())

};

引用lazy_static 然后做方法消息回调

#[derive(Debug)]

pub struct MyChannel{

pub sr:mpsc::Sender<String>,

pub rr:mpsc::Receiver<String>

}

impl MyChannel {

pub fn new( sr:mpsc::Sender<String>, rr:mpsc::Receiver<String>)->MyChannel{

MyChannel{ sr,rr }

}

}

unsafe impl Sync for MyChannel {

}

lazy_static! {

pub static ref GLOBAL_MYCHANNEL: Arc<MyChannel > = {

let ( sr,rr) = mpsc::channel();

Arc::new( MyChannel::new(sr, rr) )

};

用法

GLOBAL_MYCHANNEL.sr.send( format!("reg={}={}",renew,code) );

最后显示到页面

pub fn xunmsg(app: AppHandle<Wry>) {

let main_window = app.get_window("main").unwrap();

let main_window_clone = main_window.clone();

thread::spawn(move || {

let cloneChannel= GLOBAL_MYCHANNEL.clone();

loop{

let z=cloneChannel.rr.try_recv().unwrap_or_default();

if z.len()>1{

println!("get:{:?}",z);

main_window_clone.emit("msg_callstate", Payload { message: z }).unwrap();

}

sleep(Duration::from_secs(1));

}

});

}

最后效果7.54M 好小 比包括一个google 内核小的多

sip客户端和freeswitch 需求可到https://item.taobao.com/item.htm?id=653611115230

相关推荐
codealy1 天前
Rust 核心理论与内存安全(一)
后端·安全·rust
土豆.exe1 天前
IfAI v0.5.0 深度技术解析:120,000 行 Rust 打造的 AI-Native 编辑器
rust·编辑器·ai-native
咸甜适中1 天前
rust语言学习笔记Trait之 AsRef 和 AsMut(引用转换)
笔记·学习·rust
XD7429716361 天前
科技早报晚报|2026年5月18日:Agent 原生语言、代码语义图谱与 Rust 数据层,今天更值得跟进的 3 个技术机会
开发语言·科技·rust·科技新闻·开发者工具·ai工程
yezipi耶不耶1 天前
讲讲 RTMate (WebSocket as A Service)中的消息的发布订阅机制
websocket·网络协议·rust
五月君_2 天前
Bun v1.3.14 发布,Rust 版即将进 Claude Code 内测,下一版可能就告别 Zig
开发语言·后端·rust
techdashen2 天前
深入 Rust enum 的内存世界
开发语言·后端·rust
techdashen2 天前
Rust 模块和文件不是一回事:一次讲清 `mod`、`use`、`pub use`
开发语言·后端·rust
Arman_2 天前
02 rusty-cat 实战:MeowClient 配置、任务参数、进度回调与暂停恢复
http·https·rust·tokio·文件分片上传·文件分片下载
wzhao1012 天前
Relink 0.15.1:一个 no_std 的 ELF 加载器/链接器
linux·rust·gnu