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

相关推荐
unconditional4 小时前
我拆了 sdkm 的回滚设计:每个写操作,都提前写好了翻车预案
rust·开源
数字幽灵4 小时前
开源!我用 Rust 手搓了一个 Agent 原生的鸿蒙逆向分析平台
rust
Kapaseker1 天前
Rust 不用写 for 循环?看我怎么写!
rust
奶油话梅糖1 天前
打开项目 0.9 秒、内存只有 IDEA 的 1/12:OpenIDEA 用 Rust 把 IntelliJ IDEA 重造了一遍
java·rust·github·intellij-idea
Vex2une2 天前
Google Picasa 精神续作:Rust 重写的离线本地相册工具‌
rust·图片管理·picasa·马良·本地照片管理·重复图片检测·maliang
unconditional3 天前
我拆了 sdkm 的自定义 SDK 机制:所谓“内置”,就是官方提前帮你填好的表
rust·开源
Ramble_Naylor4 天前
Rust深度解读:Send 与 Sync 的本质与线程安全边界
python·算法·rust
Ramble_Naylor4 天前
Rust深度解读:异步流(Async Streams)与生成器的处理艺术
开发语言·后端·rust
RobinDevNotes4 天前
Memvid 把 Agent 长期记忆塞进一个文件
人工智能·rust·openresty
miofly4 天前
GitHub 今日推荐|agent-desktop:通过无障碍树让 AI 代理直接操作桌面应用
rust·开源·github