made websockets able to run functions
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user