aboutsummaryrefslogtreecommitdiff
path: root/src/ext
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-16 21:26:54 -0800
committerAustin Hellyer <[email protected]>2016-12-16 21:26:54 -0800
commit7b45f16f063a47dc8a302dce5b016cf43a3edcc1 (patch)
tree42586d38945cdbe1583dee4ea59d47060e86e61f /src/ext
parentSimplify gateway identify compression (diff)
downloadserenity-7b45f16f063a47dc8a302dce5b016cf43a3edcc1.tar.xz
serenity-7b45f16f063a47dc8a302dce5b016cf43a3edcc1.zip
Make 'voice' feature not require 'cache'
The voice module required the cache feature in order to access the current user's Id. Instead, just copy the Id into the VoiceManager and distribute it from there -- the memory impact will be very minimal in comparison to the benefits of not needing to constantly unlock the Cache and not needing the user to be forced to use the Cache.
Diffstat (limited to 'src/ext')
-rw-r--r--src/ext/voice/connection.rs3
-rw-r--r--src/ext/voice/connection_info.rs3
-rw-r--r--src/ext/voice/handler.rs9
-rw-r--r--src/ext/voice/manager.rs6
-rw-r--r--src/ext/voice/payload.rs4
5 files changed, 18 insertions, 7 deletions
diff --git a/src/ext/voice/connection.rs b/src/ext/voice/connection.rs
index 373f4ef..3f40d85 100644
--- a/src/ext/voice/connection.rs
+++ b/src/ext/voice/connection.rs
@@ -27,6 +27,7 @@ use ::internal::prelude::*;
use ::internal::ws_impl::{ReceiverExt, SenderExt};
use ::internal::Timer;
use ::model::event::VoiceEvent;
+use ::model::UserId;
enum ReceiverStatus {
Udp(Vec<u8>),
@@ -59,6 +60,7 @@ pub struct Connection {
thread_items: ThreadItems,
timestamp: u32,
udp: UdpSocket,
+ user_id: UserId,
}
impl Connection {
@@ -159,6 +161,7 @@ impl Connection {
ssrc: hello.ssrc,
thread_items: thread_items,
timestamp: 0,
+ user_id: info.user_id,
})
}
diff --git a/src/ext/voice/connection_info.rs b/src/ext/voice/connection_info.rs
index c257e4a..282b5f1 100644
--- a/src/ext/voice/connection_info.rs
+++ b/src/ext/voice/connection_info.rs
@@ -1,7 +1,10 @@
+use ::model::UserId;
+
#[derive(Clone, Debug)]
pub struct ConnectionInfo {
pub endpoint: String,
pub session_id: String,
pub target_id: u64,
pub token: String,
+ pub user_id: UserId,
}
diff --git a/src/ext/voice/handler.rs b/src/ext/voice/handler.rs
index 16f700a..e9e5cd6 100644
--- a/src/ext/voice/handler.rs
+++ b/src/ext/voice/handler.rs
@@ -5,7 +5,7 @@ use super::connection_info::ConnectionInfo;
use super::{Status as VoiceStatus, Target};
use ::client::gateway::GatewayStatus;
use ::constants::VoiceOpCode;
-use ::model::{ChannelId, GuildId, VoiceState};
+use ::model::{ChannelId, GuildId, UserId, VoiceState};
use super::threading;
/// The handler is responsible for "handling" a single voice connection, acting
@@ -39,7 +39,7 @@ pub struct Handler {
self_mute: bool,
sender: MpscSender<VoiceStatus>,
session_id: Option<String>,
- user_id: u64,
+ user_id: UserId,
ws: MpscSender<GatewayStatus>,
}
@@ -53,7 +53,7 @@ impl Handler {
///
/// [`Manager::join`]: struct.Manager.html#method.join
#[doc(hidden)]
- pub fn new(target: Target, ws: MpscSender<GatewayStatus>, user_id: u64)
+ pub fn new(target: Target, ws: MpscSender<GatewayStatus>, user_id: UserId)
-> Self {
let (tx, rx) = mpsc::channel();
@@ -266,11 +266,14 @@ impl Handler {
return;
};
+ let user_id = self.user_id;
+
self.send(VoiceStatus::Connect(ConnectionInfo {
endpoint: endpoint,
session_id: session_id,
target_id: target_id,
token: token,
+ user_id: user_id,
}))
}
diff --git a/src/ext/voice/manager.rs b/src/ext/voice/manager.rs
index b4f3501..4e71195 100644
--- a/src/ext/voice/manager.rs
+++ b/src/ext/voice/manager.rs
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::mpsc::Sender as MpscSender;
use super::{Handler, Target};
use ::client::gateway::GatewayStatus;
-use ::model::{ChannelId, GuildId};
+use ::model::{ChannelId, GuildId, UserId};
/// A manager is a struct responsible for managing [`Handler`]s which belong to
/// a single [WebSocket connection]. This is a fairly complex key-value store,
@@ -22,13 +22,13 @@ use ::model::{ChannelId, GuildId};
/// [WebSocket connection]: ../../client/struct.Connection.html
pub struct Manager {
handlers: HashMap<Target, Handler>,
- user_id: u64,
+ user_id: UserId,
ws: MpscSender<GatewayStatus>,
}
impl Manager {
#[doc(hidden)]
- pub fn new(ws: MpscSender<GatewayStatus>, user_id: u64) -> Manager {
+ pub fn new(ws: MpscSender<GatewayStatus>, user_id: UserId) -> Manager {
Manager {
handlers: HashMap::new(),
user_id: user_id,
diff --git a/src/ext/voice/payload.rs b/src/ext/voice/payload.rs
index c9ceeeb..45ccf4d 100644
--- a/src/ext/voice/payload.rs
+++ b/src/ext/voice/payload.rs
@@ -2,6 +2,8 @@ use serde_json::builder::ObjectBuilder;
use serde_json::Value;
use super::connection_info::ConnectionInfo;
use ::constants::VoiceOpCode;
+
+#[cfg(feature="cache")]
use ::client::CACHE;
#[inline]
@@ -12,7 +14,7 @@ pub fn build_identify(info: &ConnectionInfo) -> Value {
.insert("server_id", info.target_id)
.insert("session_id", &info.session_id)
.insert("token", &info.token)
- .insert("user_id", CACHE.read().unwrap().user.id.0))
+ .insert("user_id", info.user_id.0))
.build()
}