aboutsummaryrefslogtreecommitdiff
path: root/src/voice
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-27 08:10:41 +0200
committeracdenisSK <[email protected]>2017-07-27 08:10:41 +0200
commit70b5097aaac85f970c32ceb988dbb5f5d575ee0f (patch)
treed2f391d3b552cfae58b74748a2a2aa5ae80c7986 /src/voice
parentrustfmt (diff)
downloadserenity-70b5097aaac85f970c32ceb988dbb5f5d575ee0f.tar.xz
serenity-70b5097aaac85f970c32ceb988dbb5f5d575ee0f.zip
Change the config a bit, and a few nitpicks
Diffstat (limited to 'src/voice')
-rw-r--r--src/voice/connection.rs86
-rw-r--r--src/voice/handler.rs12
-rw-r--r--src/voice/manager.rs4
-rw-r--r--src/voice/streamer.rs8
-rw-r--r--src/voice/threading.rs6
5 files changed, 60 insertions, 56 deletions
diff --git a/src/voice/connection.rs b/src/voice/connection.rs
index 6f8343c..7cc8b3a 100644
--- a/src/voice/connection.rs
+++ b/src/voice/connection.rs
@@ -145,23 +145,23 @@ impl Connection {
let encoder = OpusEncoder::new(SAMPLE_RATE, Channels::Mono, CodingMode::Audio)?;
Ok(Connection {
- audio_timer: Timer::new(1000 * 60 * 4),
- client: mutexed_client,
- decoder_map: HashMap::new(),
- destination: destination,
- encoder: encoder,
- encoder_stereo: false,
- key: key,
- keepalive_timer: Timer::new(hello.heartbeat_interval),
- udp: udp,
- sequence: 0,
- silence_frames: 0,
- speaking: false,
- ssrc: hello.ssrc,
- thread_items: thread_items,
- timestamp: 0,
- user_id: info.user_id,
- })
+ audio_timer: Timer::new(1000 * 60 * 4),
+ client: mutexed_client,
+ decoder_map: HashMap::new(),
+ destination: destination,
+ encoder: encoder,
+ encoder_stereo: false,
+ key: key,
+ keepalive_timer: Timer::new(hello.heartbeat_interval),
+ udp: udp,
+ sequence: 0,
+ silence_frames: 0,
+ speaking: false,
+ ssrc: hello.ssrc,
+ thread_items: thread_items,
+ timestamp: 0,
+ user_id: info.user_id,
+ })
}
#[allow(unused_variables)]
@@ -183,7 +183,8 @@ impl Connection {
let timestamp = handle.read_u32::<BigEndian>()?;
let ssrc = handle.read_u32::<BigEndian>()?;
- nonce.0[..HEADER_LEN].clone_from_slice(&packet[..HEADER_LEN]);
+ nonce.0[..HEADER_LEN]
+ .clone_from_slice(&packet[..HEADER_LEN]);
if let Ok(decrypted) =
secretbox::open(&packet[HEADER_LEN..], &nonce, &self.key) {
@@ -200,7 +201,8 @@ impl Connection {
let b = if is_stereo { len * 2 } else { len };
- receiver.voice_packet(ssrc, seq, timestamp, is_stereo, &buffer[..b]);
+ receiver
+ .voice_packet(ssrc, seq, timestamp, is_stereo, &buffer[..b]);
}
},
ReceiverStatus::Websocket(VoiceEvent::Speaking(ev)) => {
@@ -282,7 +284,8 @@ impl Connection {
cursor.write_u32::<BigEndian>(self.ssrc)?;
}
- nonce.0[..HEADER_LEN].clone_from_slice(&packet[..HEADER_LEN]);
+ nonce.0[..HEADER_LEN]
+ .clone_from_slice(&packet[..HEADER_LEN]);
let sl_index = packet.len() - 16;
let buffer_len = if self.encoder_stereo { 960 * 2 } else { 960 };
@@ -386,12 +389,15 @@ fn encryption_key(client: &mut Client) -> Result<Key> {
return Err(Error::Voice(VoiceError::VoiceModeInvalid));
}
- return Key::from_slice(&ready.secret_key).ok_or(Error::Voice(VoiceError::KeyGen));
+ return Key::from_slice(&ready.secret_key)
+ .ok_or(Error::Voice(VoiceError::KeyGen));
},
VoiceEvent::Unknown(op, value) => {
- debug!("[Voice] Expected ready for key; got: op{}/v{:?}",
- op.num(),
- value);
+ debug!(
+ "[Voice] Expected ready for key; got: op{}/v{:?}",
+ op.num(),
+ value
+ );
},
_ => {},
}
@@ -437,24 +443,24 @@ fn start_threads(client: Arc<Mutex<Client>>, udp: &UdpSocket) -> Result<ThreadIt
let ws_thread = ThreadBuilder::new()
.name(format!("{} WS", thread_name))
.spawn(move || loop {
- while let Ok(msg) = client.lock().unwrap().recv_json(VoiceEvent::decode) {
- if tx_clone.send(ReceiverStatus::Websocket(msg)).is_ok() {
- return;
- }
- }
+ while let Ok(msg) = client.lock().unwrap().recv_json(VoiceEvent::decode) {
+ if tx_clone.send(ReceiverStatus::Websocket(msg)).is_ok() {
+ return;
+ }
+ }
- if ws_close_reader.try_recv().is_ok() {
- return;
- }
+ if ws_close_reader.try_recv().is_ok() {
+ return;
+ }
- thread::sleep(Duration::from_millis(25));
- })?;
+ thread::sleep(Duration::from_millis(25));
+ })?;
Ok(ThreadItems {
- rx: rx,
- udp_close_sender: udp_close_sender,
- udp_thread: udp_thread,
- ws_close_sender: ws_close_sender,
- ws_thread: ws_thread,
- })
+ rx: rx,
+ udp_close_sender: udp_close_sender,
+ udp_thread: udp_thread,
+ ws_close_sender: ws_close_sender,
+ ws_thread: ws_thread,
+ })
}
diff --git a/src/voice/handler.rs b/src/voice/handler.rs
index fb1bf28..24b3cd9 100644
--- a/src/voice/handler.rs
+++ b/src/voice/handler.rs
@@ -153,12 +153,12 @@ impl Handler {
// Safe as all of these being present was already checked.
self.send(VoiceStatus::Connect(ConnectionInfo {
- endpoint: endpoint,
- guild_id: guild_id,
- session_id: session_id,
- token: token,
- user_id: user_id,
- }));
+ endpoint: endpoint,
+ guild_id: guild_id,
+ session_id: session_id,
+ token: token,
+ user_id: user_id,
+ }));
true
}
diff --git a/src/voice/manager.rs b/src/voice/manager.rs
index 785aef8..34d2a40 100644
--- a/src/voice/manager.rs
+++ b/src/voice/manager.rs
@@ -64,9 +64,7 @@ impl Manager {
/// [`get`]: #method.get
#[allow(map_entry)]
pub fn join<C, G>(&mut self, guild_id: G, channel_id: C) -> &mut Handler
- where
- C: Into<ChannelId>,
- G: Into<GuildId>, {
+ where C: Into<ChannelId>, G: Into<GuildId> {
let channel_id = channel_id.into();
let guild_id = guild_id.into();
diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs
index c755da2..c8400f0 100644
--- a/src/voice/streamer.rs
+++ b/src/voice/streamer.rs
@@ -101,11 +101,9 @@ pub fn ytdl(uri: &str) -> Result<Box<AudioSource>> {
};
let uri = match obj.remove("url") {
- Some(v) => {
- match v {
- Value::String(uri) => uri,
- other => return Err(Error::Voice(VoiceError::YouTubeDLUrl(other))),
- }
+ Some(v) => match v {
+ Value::String(uri) => uri,
+ other => return Err(Error::Voice(VoiceError::YouTubeDLUrl(other))),
},
None => return Err(Error::Voice(VoiceError::YouTubeDLUrl(Value::Object(obj)))),
};
diff --git a/src/voice/threading.rs b/src/voice/threading.rs
index f272282..fc3a947 100644
--- a/src/voice/threading.rs
+++ b/src/voice/threading.rs
@@ -67,8 +67,10 @@ fn runner(rx: &MpscReceiver<Status>) {
match cycle {
Ok(()) => false,
Err(why) => {
- error!("(╯°□°)╯︵ ┻━┻ Error updating connection: {:?}",
- why);
+ error!(
+ "(╯°□°)╯︵ ┻━┻ Error updating connection: {:?}",
+ why
+ );
true
},