aboutsummaryrefslogtreecommitdiff
path: root/src/gateway
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-01-18 08:33:27 -0800
committerZeyla Hellyer <[email protected]>2018-01-18 08:33:27 -0800
commit9232b8f065deb4637a74e7f85ab617bb527c51be (patch)
tree9c2cc2bd6b6238a1bd039e9ad4900e8705197af2 /src/gateway
parentFix travis' cache by chmoding $HOME/.cargo (#252) (diff)
downloadserenity-9232b8f065deb4637a74e7f85ab617bb527c51be.tar.xz
serenity-9232b8f065deb4637a74e7f85ab617bb527c51be.zip
Use an InterMessage to communicate over gateway
Instead of communicating over the gateway in a split form of a `serde_json::Value` or a `client::bridge::gateway::ShardClientMessage`, wrap them both into a single enum for better interaction between the client, gateway, and voice modules.
Diffstat (limited to 'src/gateway')
-rw-r--r--src/gateway/mod.rs16
-rw-r--r--src/gateway/shard.rs8
2 files changed, 22 insertions, 2 deletions
diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs
index 8445b29..c4748a0 100644
--- a/src/gateway/mod.rs
+++ b/src/gateway/mod.rs
@@ -59,10 +59,14 @@ pub use self::ws_client_ext::WebSocketGatewayClientExt;
use model::gateway::Game;
use model::user::OnlineStatus;
+use serde_json::Value;
use std::fmt::{Display, Formatter, Result as FmtResult};
use websocket::sync::client::Client;
use websocket::sync::stream::{TcpStream, TlsStream};
+#[cfg(feature = "client")]
+use client::bridge::gateway::ShardClientMessage;
+
pub type CurrentPresence = (Option<Game>, OnlineStatus);
pub type WsClient = Client<TlsStream<TcpStream>>;
@@ -163,6 +167,18 @@ impl Display for ConnectionStage {
}
}
+/// A message to be passed around within the library.
+///
+/// As a user you usually don't need to worry about this, but when working with
+/// the lower-level internals of the `client`, `gateway, and `voice` modules it
+/// may be necessary.
+#[derive(Clone, Debug)]
+pub enum InterMessage {
+ #[cfg(feature = "client")]
+ Client(ShardClientMessage),
+ Json(Value),
+}
+
pub enum ShardAction {
Heartbeat,
Identify,
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs
index a890029..af7b76b 100644
--- a/src/gateway/shard.rs
+++ b/src/gateway/shard.rs
@@ -26,6 +26,8 @@ use serde_json::Value;
#[cfg(feature = "voice")]
use std::sync::mpsc::{self, Receiver as MpscReceiver};
#[cfg(feature = "voice")]
+use super::InterMessage;
+#[cfg(feature = "voice")]
use voice::Manager as VoiceManager;
#[cfg(feature = "voice")]
use http;
@@ -94,7 +96,8 @@ pub struct Shard {
/// update the voice connections' states.
#[cfg(feature = "voice")]
pub manager: VoiceManager,
- #[cfg(feature = "voice")] manager_rx: MpscReceiver<Value>,
+ #[cfg(feature = "voice")]
+ manager_rx: MpscReceiver<InterMessage>,
}
impl Shard {
@@ -684,9 +687,10 @@ impl Shard {
pub(crate) fn cycle_voice_recv(&mut self) -> Vec<Value> {
let mut messages = vec![];
- while let Ok(v) = self.manager_rx.try_recv() {
+ while let Ok(InterMessage::Json(v)) = self.manager_rx.try_recv() {
messages.push(v);
}
+
self.shutdown = true;
debug!("[Shard {:?}] Cleanly shutdown shard", self.shard_info);