Improved structure

This commit is contained in:
2025-09-14 14:20:36 +02:00
parent 59e96fe05e
commit a4ce0c0589
17 changed files with 357 additions and 321 deletions
-1
View File
@@ -13,7 +13,6 @@ rusqlite = "0.37.0"
serde = { version = "1.0.219", features = ["serde_derive"] } serde = { version = "1.0.219", features = ["serde_derive"] }
serde_json = "1.0.143" serde_json = "1.0.143"
sha1 = "0.10.6" sha1 = "0.10.6"
tungstenite = "0.27.0"
[features] [features]
default = [] default = []
-170
View File
@@ -50,12 +50,6 @@ version = "3.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "bytes"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.37" version = "1.2.37"
@@ -117,12 +111,6 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "data-encoding"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.7" version = "0.10.7"
@@ -151,12 +139,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d" checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "foldhash" name = "foldhash"
version = "0.1.5" version = "0.1.5"
@@ -173,18 +155,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "getrandom"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.15.5" version = "0.15.5"
@@ -203,23 +173,6 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "http"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]]
name = "httparse"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.64" version = "0.1.64"
@@ -319,15 +272,6 @@ version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.101" version = "1.0.101"
@@ -346,41 +290,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "rusqlite" name = "rusqlite"
version = "0.37.0" version = "0.37.0"
@@ -473,43 +382,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "thiserror"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tungstenite"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eadc29d668c91fcc564941132e17b28a7ceb2f3ebf0b9dae3e03fd7a6748eb0d"
dependencies = [
"bytes",
"data-encoding",
"http",
"httparse",
"log",
"rand",
"sha1",
"thiserror",
"utf-8",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.18.0" version = "1.18.0"
@@ -522,12 +394,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
@@ -553,16 +419,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"sha1", "sha1",
"tungstenite",
]
[[package]]
name = "wasi"
version = "0.14.3+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95"
dependencies = [
"wit-bindgen",
] ]
[[package]] [[package]]
@@ -753,29 +609,3 @@ name = "windows_x86_64_msvc"
version = "0.53.0" version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "wit-bindgen"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"
[[package]]
name = "zerocopy"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
+1 -1
View File
@@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use voxa_server::{ServerConfig, vfs}; use voxa_server::{ServerConfig, utils::vfs};
fn main() -> voxa_server::Result<()> { fn main() -> voxa_server::Result<()> {
let root = PathBuf::from(""); let root = PathBuf::from("");
+1 -1
View File
@@ -19,7 +19,7 @@ ws.onmessage = (event) => {
function sendMessage(message) { function sendMessage(message) {
ws.send(JSON.stringify({ type: 'send_message', params: { ws.send(JSON.stringify({ type: 'send_message', params: {
channel_id: 'Hello', channel_id: 'general',
contents: message contents: message
}})); }}));
} }
+17 -15
View File
@@ -5,23 +5,16 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
pub mod client;
pub mod database;
#[cfg(feature = "loader")]
pub mod loader;
pub mod logger;
pub mod macros; pub mod macros;
pub mod plugin;
pub mod types; pub mod types;
pub mod vfs; pub mod utils;
pub use anyhow::Result; pub use anyhow::Result;
pub use tungstenite;
use crate::{ use crate::{
client::Client,
plugin::DynPlugin,
types::{ClientMessage, WsMessage}, types::{ClientMessage, WsMessage},
utils::client::Client,
utils::plugin::DynPlugin,
}; };
pub use once_cell; pub use once_cell;
@@ -37,7 +30,7 @@ pub struct Server {
config: ServerConfig, config: ServerConfig,
plugins: Mutex<Vec<DynPlugin>>, plugins: Mutex<Vec<DynPlugin>>,
clients: Mutex<HashSet<Client>>, clients: Mutex<HashSet<Client>>,
pub db: database::Database, pub db: utils::database::Database,
} }
impl Default for ServerConfig { impl Default for ServerConfig {
@@ -64,7 +57,7 @@ impl Server {
pub fn new_config(root: &Path, config: ServerConfig) -> Arc<Self> { pub fn new_config(root: &Path, config: ServerConfig) -> Arc<Self> {
Arc::new(Self { Arc::new(Self {
db: database::Database::new(&config).unwrap(), db: utils::database::Database::new(&config).unwrap(),
plugins: Mutex::new(Vec::new()), plugins: Mutex::new(Vec::new()),
root: root.to_path_buf(), root: root.to_path_buf(),
config, config,
@@ -75,7 +68,7 @@ impl Server {
pub fn run(self: &Arc<Self>) -> Result<()> { pub fn run(self: &Arc<Self>) -> Result<()> {
// Load plugins // Load plugins
#[cfg(feature = "loader")] #[cfg(feature = "loader")]
loader::load_plugins( utils::loader::load_plugins(
&mut *self.plugins.lock().unwrap(), &mut *self.plugins.lock().unwrap(),
&self.root.join("./plugins"), &self.root.join("./plugins"),
)?; )?;
@@ -122,8 +115,17 @@ impl Server {
self.clients.lock().unwrap().insert(client.clone()); self.clients.lock().unwrap().insert(client.clone());
// The main req/res loop // The main req/res loop
loop { 'outer: loop {
match client.read()? { let req = client.read()?;
if let Some(r) = &req {
for p in self.plugins.lock().unwrap().iter_mut() {
if p.on_request(r, &client, self) {
continue 'outer;
}
}
}
match req {
Some(WsMessage::Message(req)) => match req { Some(WsMessage::Message(req)) => match req {
ClientMessage::SendMessage { ClientMessage::SendMessage {
channel_id, channel_id,
+7 -7
View File
@@ -2,7 +2,7 @@
macro_rules! export_plugin { macro_rules! export_plugin {
($p:expr) => { ($p:expr) => {
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
pub extern "C" fn load_plugin() -> $crate::plugin::DynPlugin { pub extern "C" fn load_plugin() -> $crate::utils::plugin::DynPlugin {
$p $p
} }
}; };
@@ -11,20 +11,20 @@ macro_rules! export_plugin {
#[macro_export] #[macro_export]
macro_rules! logger { macro_rules! logger {
(const $i:ident $name:expr) => { (const $i:ident $name:expr) => {
const $i: $crate::once_cell::sync::Lazy<$crate::logger::Logger> = pub const $i: $crate::once_cell::sync::Lazy<$crate::utils::logger::Logger> =
$crate::once_cell::sync::Lazy::new(|| $crate::logger::Logger::new($name)); $crate::once_cell::sync::Lazy::new(|| $crate::utils::logger::Logger::new($name));
}; };
($i:ident $name:expr) => { ($i:ident $name:expr) => {
const $i: $crate::once_cell::sync::Lazy<$crate::logger::Logger> = pub const $i: $crate::once_cell::sync::Lazy<$crate::utils::logger::Logger> =
$crate::once_cell::sync::Lazy::new(|| $crate::logger::Logger::new($name)); $crate::once_cell::sync::Lazy::new(|| $crate::utils::logger::Logger::new($name));
}; };
(const $name:expr) => { (const $name:expr) => {
$crate::once_cell::sync::Lazy::new(|| $crate::logger::Logger::new($name)) $crate::once_cell::sync::Lazy::new(|| $crate::utils::logger::Logger::new($name))
}; };
($name:expr) => { ($name:expr) => {
$crate::logger::Logger::new($name) $crate::logger::utils::Logger::new($name)
}; };
} }
+15 -3
View File
@@ -29,11 +29,17 @@ pub enum ClientMessage {
#[serde(tag = "type", content = "params", rename_all = "snake_case")] #[serde(tag = "type", content = "params", rename_all = "snake_case")]
pub enum ServerMessage { pub enum ServerMessage {
/// Successful authentication /// Successful authentication
Authenticated { user_id: String }, Authenticated {
user_id: String,
},
/// Error responses /// Error responses
Error(), Error(),
TempMessage {
message: String,
},
/// A new message in a channel /// A new message in a channel
MessageCreate(data::Message), MessageCreate(data::Message),
@@ -47,10 +53,16 @@ pub enum ServerMessage {
}, },
/// Presence updates /// Presence updates
PresenceUpdate { user_id: String, status: String }, PresenceUpdate {
user_id: String,
status: String,
},
/// Typing indicator /// Typing indicator
Typing { user_id: String, channel_id: String }, Typing {
user_id: String,
channel_id: String,
},
} }
/// WebSocket wrapper /// WebSocket wrapper
+1 -1
View File
@@ -2,7 +2,7 @@ use std::path::Path;
use libloading::{Library, Symbol}; use libloading::{Library, Symbol};
use crate::{logger, plugin::DynPlugin, vfs}; use crate::{logger, utils::plugin::DynPlugin, utils::vfs};
logger! { logger! {
const LOGGER "Loader" const LOGGER "Loader"
+7
View File
@@ -0,0 +1,7 @@
pub mod client;
pub mod database;
#[cfg(feature = "loader")]
pub mod loader;
pub mod logger;
pub mod plugin;
pub mod vfs;
+7 -1
View File
@@ -3,6 +3,7 @@ use std::sync::Arc;
use crate::{ use crate::{
Server, Server,
types::{ClientMessage, WsMessage}, types::{ClientMessage, WsMessage},
utils::client::Client,
}; };
pub type DynPlugin = Box<dyn Plugin + Send + Sync>; pub type DynPlugin = Box<dyn Plugin + Send + Sync>;
@@ -10,7 +11,12 @@ pub type DynPlugin = Box<dyn Plugin + Send + Sync>;
pub trait Plugin { pub trait Plugin {
fn init(&mut self, server: &Arc<Server>); fn init(&mut self, server: &Arc<Server>);
#[allow(unused_variables)] #[allow(unused_variables)]
fn on_request(&mut self, msg: &WsMessage<ClientMessage>, server: &Arc<Server>) -> bool { fn on_request(
&mut self,
req: &WsMessage<ClientMessage>,
client: &Client,
server: &Arc<Server>,
) -> bool {
false false
} }
} }
View File
+272 -119
View File
@@ -2,12 +2,39 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.99" version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
[[package]]
name = "autocfg"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bitflags"
version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@@ -18,10 +45,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "bytes" name = "bumpalo"
version = "1.10.1" version = "3.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "cc"
version = "1.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@@ -29,6 +66,25 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "chrono"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.17" version = "0.2.17"
@@ -48,12 +104,6 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "data-encoding"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.7" version = "0.10.7"
@@ -65,10 +115,28 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fnv" name = "fallible-iterator"
version = "1.0.7" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
[[package]]
name = "fallible-streaming-iterator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "find-msvc-tools"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]] [[package]]
name = "generic-array" name = "generic-array"
@@ -81,33 +149,46 @@ dependencies = [
] ]
[[package]] [[package]]
name = "getrandom" name = "hashbrown"
version = "0.3.3" version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [ dependencies = [
"cfg-if", "foldhash",
"libc",
"r-efi",
"wasi",
] ]
[[package]] [[package]]
name = "http" name = "hashlink"
version = "1.3.1" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
dependencies = [ dependencies = [
"bytes", "hashbrown",
"fnv",
"itoa",
] ]
[[package]] [[package]]
name = "httparse" name = "iana-time-zone"
version = "1.10.1" version = "0.1.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
@@ -115,12 +196,32 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "js-sys"
version = "0.3.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.175" version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
[[package]]
name = "libsqlite3-sys"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
dependencies = [
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.27" version = "0.4.27"
@@ -133,6 +234,15 @@ version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.3" version = "1.21.3"
@@ -140,13 +250,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "ppv-lite86" name = "pkg-config"
version = "0.2.21" version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
@@ -167,39 +274,24 @@ dependencies = [
] ]
[[package]] [[package]]
name = "r-efi" name = "rusqlite"
version = "5.3.0" version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [ dependencies = [
"rand_chacha", "bitflags",
"rand_core", "fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
"libsqlite3-sys",
"smallvec",
] ]
[[package]] [[package]]
name = "rand_chacha" name = "rustversion"
version = "0.9.0" version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
@@ -250,6 +342,18 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.106" version = "2.0.106"
@@ -268,43 +372,6 @@ dependencies = [
"voxa-server", "voxa-server",
] ]
[[package]]
name = "thiserror"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tungstenite"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eadc29d668c91fcc564941132e17b28a7ceb2f3ebf0b9dae3e03fd7a6748eb0d"
dependencies = [
"bytes",
"data-encoding",
"http",
"httparse",
"log",
"rand",
"sha1",
"thiserror",
"utf-8",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.18.0" version = "1.18.0"
@@ -318,10 +385,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]] [[package]]
name = "utf-8" name = "vcpkg"
version = "0.7.6" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "version_check" name = "version_check"
@@ -334,43 +401,129 @@ name = "voxa-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64",
"chrono",
"once_cell", "once_cell",
"rusqlite",
"serde", "serde",
"serde_json", "serde_json",
"tungstenite", "sha1",
] ]
[[package]] [[package]]
name = "wasi" name = "wasm-bindgen"
version = "0.14.3+wasi-0.2.4" version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b"
dependencies = [ dependencies = [
"wit-bindgen", "cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wit-bindgen" name = "wasm-bindgen-backend"
version = "0.45.0" version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb"
[[package]]
name = "zerocopy"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
dependencies = [ dependencies = [
"zerocopy-derive", "bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "wasm-bindgen-macro"
version = "0.8.26" version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-core"
version = "0.62.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57fe7168f7de578d2d8a05b07fd61870d2e73b4020e9f49aa00da8471723497c"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-implement"
version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
] ]
[[package]]
name = "windows-interface"
version = "0.59.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
[[package]]
name = "windows-result"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda"
dependencies = [
"windows-link",
]
+28 -1
View File
@@ -1,5 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use voxa_server::{Server, export_plugin, logger, plugin::Plugin}; use voxa_server::{Server, export_plugin, logger, utils::plugin::Plugin};
logger! { logger! {
const LOGGER "My Plugin" const LOGGER "My Plugin"
@@ -12,6 +12,33 @@ impl Plugin for MyPlugin {
fn init(&mut self, _server: &Arc<Server>) { fn init(&mut self, _server: &Arc<Server>) {
LOGGER.info("MyPlugin initialized!"); LOGGER.info("MyPlugin initialized!");
} }
fn on_request(
&mut self,
msg: &voxa_server::types::WsMessage<voxa_server::types::ClientMessage>,
client: &voxa_server::utils::client::Client,
_server: &Arc<Server>,
) -> bool {
LOGGER.info(&format!("Received message: {:?}", msg));
match msg {
voxa_server::types::WsMessage::Message(
voxa_server::types::ClientMessage::SendMessage { contents, .. },
) => {
if contents == "ping" {
LOGGER.info("Pong!");
client
.send(voxa_server::types::ServerMessage::TempMessage {
message: "pong".to_string(),
})
.unwrap();
true
} else {
false
}
}
_ => false,
}
}
} }
export_plugin!(Box::new(MyPlugin)); export_plugin!(Box::new(MyPlugin));
+1 -1
View File
@@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use voxa_server::{ServerConfig, vfs}; use voxa_server::{ServerConfig, utils::vfs};
fn main() -> voxa_server::Result<()> { fn main() -> voxa_server::Result<()> {
let root = PathBuf::from("./"); let root = PathBuf::from("./");