Add MagpieClient::send_json_message()

This commit is contained in:
mars 2022-10-30 19:12:16 -06:00
parent ea1631d24d
commit 8c8d89b34d
2 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,8 @@ pub use magpie_types;
use std::os::unix::net::UnixStream;
use std::path::Path;
use magpie_types::ClientMessenger;
use magpie_types::{serde::Serialize, serde_json};
use magpie_types::{ClientMessenger, MagpieServerMsg, PanelId, SendMessage};
/// The name of the Magpie server socket.
pub const MAGPIE_SOCK: &str = "magpie.sock";
@ -23,4 +24,10 @@ impl MagpieClient {
messenger: ClientMessenger::new(socket),
})
}
pub fn send_json_message<T: Serialize>(&mut self, id: PanelId, msg: &T) {
let msg = serde_json::to_vec(msg).unwrap();
let msg = SendMessage { id, msg };
let _ = self.messenger.send(&MagpieServerMsg::SendMessage(msg));
}
}

View File

@ -5,6 +5,9 @@ use std::path::PathBuf;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
pub use serde;
pub use serde_json;
/// An identifier for a Magpie panel.
///
/// Only valid on a connection between a single client and its server. Clients