Improved structure
This commit is contained in:
+28
-1
@@ -1,5 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use voxa_server::{Server, export_plugin, logger, plugin::Plugin};
|
||||
use voxa_server::{Server, export_plugin, logger, utils::plugin::Plugin};
|
||||
|
||||
logger! {
|
||||
const LOGGER "My Plugin"
|
||||
@@ -12,6 +12,33 @@ impl Plugin for MyPlugin {
|
||||
fn init(&mut self, _server: &Arc<Server>) {
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user