made websockets able to run functions

This commit is contained in:
2025-02-08 20:18:00 +01:00
parent bf2e1e347f
commit b816c12a6c
9 changed files with 99 additions and 59 deletions
+17
View File
@@ -4,6 +4,7 @@ use tokio::net::TcpListener;
use tokio_tungstenite::{accept_async, tungstenite};
use futures::StreamExt;
use std::sync::Arc;
use serde_json::Value;
use crate::rs_println;
use crate::Args;
@@ -33,6 +34,22 @@ pub async fn send_msg(msg: &str) {
}
pub async fn send_cmd_json(func_name: &str, func_args: Value) {
unsafe {
if let Some(sender) = &GLOBAL_SENDER {
let mut sender = sender.lock().await;
if let Some(s) = sender.as_mut() {
let json_str: String = format!(
"json:{{\"type\": \"function\", \"value\":\"{}\", \"args\": {}}}",
func_name, func_args
);
s.send(tungstenite::Message::Text(json_str.into())).await.unwrap();
}
}
}
}
pub async fn start(args: Args) {
rs_println!("Starting local websocket...");
let ip = format!("127.0.0.1:{}", args.port);