diff options
| author | acdenisSK <[email protected]> | 2018-11-21 18:21:20 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2018-11-21 18:21:20 +0100 |
| commit | f148326056c39faf2601c47c8fa88f6081171b08 (patch) | |
| tree | 0643f6c62ba7e06ce791c9701235ab07561d7b38 /src | |
| parent | Replace `hyper` with `reqwest` (#440) (diff) | |
| download | serenity-f148326056c39faf2601c47c8fa88f6081171b08.tar.xz serenity-f148326056c39faf2601c47c8fa88f6081171b08.zip | |
Switch to tungstenite from rust-websocket (#341)
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/bridge/gateway/shard_messenger.rs | 4 | ||||
| -rw-r--r-- | src/client/bridge/gateway/shard_runner.rs | 50 | ||||
| -rw-r--r-- | src/client/bridge/gateway/shard_runner_message.rs | 4 | ||||
| -rw-r--r-- | src/constants.rs | 1 | ||||
| -rw-r--r-- | src/error.rs | 24 | ||||
| -rw-r--r-- | src/gateway/error.rs | 4 | ||||
| -rw-r--r-- | src/gateway/mod.rs | 8 | ||||
| -rw-r--r-- | src/gateway/shard.rs | 36 | ||||
| -rw-r--r-- | src/internal/ws_impl.rs | 48 | ||||
| -rw-r--r-- | src/lib.rs | 6 | ||||
| -rw-r--r-- | src/model/event.rs | 57 | ||||
| -rw-r--r-- | src/voice/connection.rs | 36 |
12 files changed, 132 insertions, 146 deletions
diff --git a/src/client/bridge/gateway/shard_messenger.rs b/src/client/bridge/gateway/shard_messenger.rs index 21e586a..c2236ed 100644 --- a/src/client/bridge/gateway/shard_messenger.rs +++ b/src/client/bridge/gateway/shard_messenger.rs @@ -2,7 +2,7 @@ use gateway::InterMessage; use model::prelude::*; use super::{ShardClientMessage, ShardRunnerMessage}; use std::sync::mpsc::{SendError, Sender}; -use websocket::message::OwnedMessage; +use tungstenite::Message; /// A lightweight wrapper around an mpsc sender. /// @@ -264,7 +264,7 @@ impl ShardMessenger { /// the [`set_presence`] method. /// /// [`set_presence`]: #method.set_presence - pub fn websocket_message(&self, message: OwnedMessage) { + pub fn websocket_message(&self, message: Message) { let _ = self.send(ShardRunnerMessage::Message(message)); } diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs index 0f244bd..c462937 100644 --- a/src/client/bridge/gateway/shard_runner.rs +++ b/src/client/bridge/gateway/shard_runner.rs @@ -4,25 +4,28 @@ use internal::ws_impl::{ReceiverExt, SenderExt}; use model::event::{Event, GatewayEvent}; use parking_lot::Mutex; use serde::Deserialize; -use std::sync::{ - mpsc::{ - self, - Receiver, - Sender, - TryRecvError +use std::{ + borrow::Cow, + sync::{ + mpsc::{ + self, + Receiver, + Sender, + TryRecvError + }, + Arc, }, - Arc }; use super::super::super::dispatch::{DispatchEvent, dispatch}; use super::super::super::EventHandler; use super::event::{ClientEvent, ShardStageUpdateEvent}; use super::{ShardClientMessage, ShardId, ShardManagerMessage, ShardRunnerMessage}; use threadpool::ThreadPool; -use typemap::ShareMap; -use websocket::{ - message::{CloseData, OwnedMessage}, - WebSocketError +use tungstenite::{ + error::Error as TungsteniteError, + protocol::frame::CloseFrame, }; +use typemap::ShareMap; #[cfg(feature = "framework")] use framework::Framework; @@ -190,9 +193,10 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { return true; } - let close_data = CloseData::new(1000, String::new()); - let msg = OwnedMessage::Close(Some(close_data)); - let _ = self.shard.client.send_message(&msg); + let _ = self.shard.client.close(Some(CloseFrame { + code: 1000.into(), + reason: Cow::from(""), + })); false } @@ -250,13 +254,14 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { }, ShardRunnerMessage::Close(code, reason) => { let reason = reason.unwrap_or_else(String::new); - let data = CloseData::new(code, reason); - let msg = OwnedMessage::Close(Some(data)); - - self.shard.client.send_message(&msg).is_ok() + let close = CloseFrame { + code: code.into(), + reason: Cow::from(reason), + }; + self.shard.client.close(Some(close)).is_ok() }, ShardRunnerMessage::Message(msg) => { - self.shard.client.send_message(&msg).is_ok() + self.shard.client.write_message(msg).is_ok() }, ShardRunnerMessage::SetActivity(activity) => { // To avoid a clone of `activity`, we do a little bit of @@ -371,7 +376,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { GatewayEvent::deserialize(value).map(Some).map_err(From::from) }, Ok(None) => Ok(None), - Err(Error::WebSocket(WebSocketError::IoError(_))) => { + Err(Error::Tungstenite(TungsteniteError::Io(_))) => { // Check that an amount of time at least double the // heartbeat_interval has passed. // @@ -409,11 +414,6 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { return (None, None, true); }, - Err(Error::WebSocket(WebSocketError::NoDataAvailable)) => { - // This is hit when the websocket client dies this will be - // hit every iteration. - return (None, None, false); - }, Err(why) => Err(why), }; diff --git a/src/client/bridge/gateway/shard_runner_message.rs b/src/client/bridge/gateway/shard_runner_message.rs index 0fac329..76fb1fe 100644 --- a/src/client/bridge/gateway/shard_runner_message.rs +++ b/src/client/bridge/gateway/shard_runner_message.rs @@ -3,7 +3,7 @@ use model::{ id::GuildId, user::OnlineStatus, }; -use websocket::message::OwnedMessage; +use tungstenite::Message; /// A message to send from a shard over a WebSocket. #[derive(Clone, Debug)] @@ -37,7 +37,7 @@ pub enum ShardRunnerMessage { /// [`ShardManager`]: struct.ShardManager.html Close(u16, Option<String>), /// Indicates that the client is to send a custom WebSocket message. - Message(OwnedMessage), + Message(Message), /// Indicates that the client is to update the shard's presence's activity. SetActivity(Option<Activity>), /// Indicates that the client is to update the shard's presence in its diff --git a/src/constants.rs b/src/constants.rs index 58a8ea0..ca6e137 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -128,7 +128,6 @@ impl OpCode { } } - /// Enum to map voice opcodes. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum VoiceOpCode { diff --git a/src/error.rs b/src/error.rs index ef9ea1a..3c9e61a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -16,8 +16,8 @@ use std::{ use reqwest::{Error as ReqwestError, header::InvalidHeaderValue}; #[cfg(feature = "voice")] use opus::Error as OpusError; -#[cfg(feature = "websocket")] -use websocket::result::WebSocketError; +#[cfg(feature = "tungstenite")] +use tungstenite::error::Error as TungsteniteError; #[cfg(feature = "client")] use client::ClientError; #[cfg(feature = "gateway")] @@ -92,9 +92,9 @@ pub enum Error { /// [`http`]: http/index.html #[cfg(feature = "http")] Http(HttpError), - /// An error from the `rust-websocket` crate. - #[cfg(feature = "gateway")] - WebSocket(WebSocketError), + /// An error from the `tungstenite` crate. + #[cfg(feature = "tungstenite")] + Tungstenite(TungsteniteError), /// An error from the `opus` crate. #[cfg(feature = "voice")] Opus(OpusError), @@ -135,9 +135,9 @@ impl From<OpusError> for Error { fn from(e: OpusError) -> Error { Error::Opus(e) } } -#[cfg(feature = "gateway")] -impl From<WebSocketError> for Error { - fn from(e: WebSocketError) -> Error { Error::WebSocket(e) } +#[cfg(feature = "tungstenite")] +impl From<TungsteniteError> for Error { + fn from(e: TungsteniteError) -> Error { Error::Tungstenite(e) } } #[cfg(feature = "http")] @@ -180,10 +180,10 @@ impl StdError for Error { Error::Http(ref inner) => inner.description(), #[cfg(feature = "voice")] Error::Opus(ref inner) => inner.description(), + #[cfg(feature = "tungstenite")] + Error::Tungstenite(ref inner) => inner.description(), #[cfg(feature = "voice")] Error::Voice(_) => "Voice error", - #[cfg(feature = "gateway")] - Error::WebSocket(ref inner) => inner.description(), } } @@ -191,8 +191,8 @@ impl StdError for Error { match *self { Error::Json(ref inner) => Some(inner), Error::Io(ref inner) => Some(inner), - #[cfg(feature = "gateway")] - Error::WebSocket(ref inner) => Some(inner), + #[cfg(feature = "tungstenite")] + Error::Tungstenite(ref inner) => Some(inner), _ => None, } } diff --git a/src/gateway/error.rs b/src/gateway/error.rs index 49cf10c..d4cfdc8 100644 --- a/src/gateway/error.rs +++ b/src/gateway/error.rs @@ -6,7 +6,7 @@ use std::{ Result as FmtResult } }; -use websocket::message::CloseData; +use tungstenite::protocol::CloseFrame; /// An error that occurred while attempting to deal with the gateway. /// @@ -17,7 +17,7 @@ pub enum Error { /// There was an error building a URL. BuildingUrl, /// The connection closed, potentially uncleanly. - Closed(Option<CloseData>), + Closed(Option<CloseFrame<'static>>), /// Expected a Hello during a handshake ExpectedHello, /// When there was an error sending a heartbeat. diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index a5f3a5e..75f083d 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -62,16 +62,16 @@ use model::{ }; use serde_json::Value; use std::fmt::{Display, Formatter, Result as FmtResult}; -use websocket::sync::{ - client::Client, - stream::{TcpStream, TlsStream} +use tungstenite::{ + client::AutoStream, + protocol::WebSocket, }; #[cfg(feature = "client")] use client::bridge::gateway::ShardClientMessage; pub type CurrentPresence = (Option<Activity>, OnlineStatus); -pub type WsClient = Client<TlsStream<TcpStream>>; +pub type WsClient = WebSocket<AutoStream>; /// Indicates the current connection stage of a [`Shard`]. /// diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index b629361..bdcb4ac 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -20,12 +20,12 @@ use super::{ WsClient, WebSocketGatewayClientExt, }; -use websocket::{ - client::Url, - stream::sync::AsTcpStream, - sync::client::ClientBuilder, - WebSocketError +use tungstenite::{ + self, + error::Error as TungsteniteError, + handshake::client::Request, }; +use url::Url; /// A Shard is a higher-level handler for a websocket connection to Discord's /// gateway. The shard allows for sending and receiving messages over the @@ -224,7 +224,7 @@ impl Shard { }, Err(why) => { match why { - Error::WebSocket(WebSocketError::IoError(err)) => if err.raw_os_error() != Some(32) { + Error::Tungstenite(TungsteniteError::Io(err)) => if err.raw_os_error() != Some(32) { debug!("[Shard {:?}] Err heartbeating: {:?}", self.shard_info, err); @@ -465,7 +465,7 @@ impl Shard { Ok(Some(ShardAction::Reconnect(ReconnectType::Reidentify))) }, Err(Error::Gateway(GatewayError::Closed(ref data))) => { - let num = data.as_ref().map(|d| d.status_code); + let num = data.as_ref().map(|d| d.code.into()); let clean = num == Some(1000); match num { @@ -542,13 +542,7 @@ impl Shard { ShardAction::Reconnect(ReconnectType::Reidentify) })) }, - Err(Error::WebSocket(ref why)) => { - if let WebSocketError::NoDataAvailable = *why { - if self.heartbeat_instants.1.is_none() { - return Ok(None); - } - } - + Err(Error::Tungstenite(ref why)) => { warn!("[Shard {:?}] Websocket error: {:?}", self.shard_info, why); @@ -837,15 +831,19 @@ impl Shard { fn connect(base_url: &str) -> Result<WsClient> { let url = build_gateway_url(base_url)?; - let client = ClientBuilder::from_url(&url).connect_secure(None)?; + let client = tungstenite::connect(Request::from(url))?; - Ok(client) + Ok(client.0) } fn set_client_timeout(client: &mut WsClient) -> Result<()> { - let stream = client.stream_ref().as_tcp(); - stream.set_read_timeout(Some(StdDuration::from_millis(100)))?; - stream.set_write_timeout(Some(StdDuration::from_secs(5)))?; + let stream = match client.get_mut() { + tungstenite::stream::Stream::Plain(stream) => stream, + tungstenite::stream::Stream::Tls(stream) => stream.get_mut(), + }; + + stream.set_read_timeout(Some(StdDuration::from_millis(500)))?; + stream.set_write_timeout(Some(StdDuration::from_secs(50)))?; Ok(()) } diff --git a/src/internal/ws_impl.rs b/src/internal/ws_impl.rs index 8c10264..c8c74bb 100644 --- a/src/internal/ws_impl.rs +++ b/src/internal/ws_impl.rs @@ -1,12 +1,8 @@ use flate2::read::ZlibDecoder; -use gateway::GatewayError; +use gateway::WsClient; use internal::prelude::*; use serde_json; -use websocket::{ - message::OwnedMessage, - sync::stream::{TcpStream, TlsStream}, - sync::Client as WsClient -}; +use tungstenite::Message; pub trait ReceiverExt { fn recv_json(&mut self) -> Result<Option<Value>>; @@ -16,32 +12,44 @@ pub trait SenderExt { fn send_json(&mut self, value: &Value) -> Result<()>; } -impl ReceiverExt for WsClient<TlsStream<TcpStream>> { +impl ReceiverExt for WsClient { fn recv_json(&mut self) -> Result<Option<Value>> { - Ok(match self.recv_message()? { - OwnedMessage::Binary(bytes) => { - serde_json::from_reader(ZlibDecoder::new(&bytes[..])).map(Some)? + Ok(match self.read_message()? { + Message::Binary(bytes) => { + serde_json::from_reader(ZlibDecoder::new(&bytes[..])) + .map(Some) + .map_err(|why| { + warn!("Err deserializing bytes: {:?}; bytes: {:?}", why, bytes); + + why + })? }, - OwnedMessage::Close(data) => return Err(Error::Gateway(GatewayError::Closed(data))), - OwnedMessage::Text(payload) => { - serde_json::from_str(&payload).map(Some)? + Message::Text(payload) => { + serde_json::from_str(&payload).map(Some).map_err(|why| { + warn!( + "Err deserializing text: {:?}; text: {}", + why, + payload, + ); + + why + })? }, - OwnedMessage::Ping(x) => { - self.send_message(&OwnedMessage::Pong(x)) - .map_err(Error::from)?; + Message::Ping(x) => { + self.write_message(Message::Pong(x)).map_err(Error::from)?; None }, - OwnedMessage::Pong(_) => None, + Message::Pong(_) => None, }) } } -impl SenderExt for WsClient<TlsStream<TcpStream>> { +impl SenderExt for WsClient { fn send_json(&mut self, value: &Value) -> Result<()> { serde_json::to_string(value) - .map(OwnedMessage::Text) + .map(Message::Text) .map_err(Error::from) - .and_then(|m| self.send_message(&m).map_err(Error::from)) + .and_then(|m| self.write_message(m).map_err(Error::from)) } } @@ -145,10 +145,12 @@ extern crate rand; extern crate sodiumoxide; #[cfg(feature = "threadpool")] extern crate threadpool; +#[cfg(feature = "tungstenite")] +extern crate tungstenite; #[cfg(feature = "typemap")] extern crate typemap; -#[cfg(feature = "evzht9h3nznqzwl")] -extern crate evzht9h3nznqzwl as websocket; +#[cfg(feature = "url")] +extern crate url; #[allow(unused_imports)] #[cfg(test)] diff --git a/src/model/event.rs b/src/model/event.rs index 9b8bb36..779f244 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -728,7 +728,7 @@ impl CacheUpdate for GuildUpdateEvent { type Output = (); fn update(&mut self, cache: &mut Cache) -> Option<()> { - if let Some(guild) = cache.guilds.get_mut(&self.guild.id) { + cache.guilds.get_mut(&self.guild.id).map(|guild| { let mut guild = guild.write(); guild.afk_timeout = self.guild.afk_timeout; @@ -739,7 +739,7 @@ impl CacheUpdate for GuildUpdateEvent { guild.region.clone_from(&self.guild.region); guild.roles.clone_from(&self.guild.roles); guild.verification_level = self.guild.verification_level; - } + }); None } @@ -842,7 +842,7 @@ pub struct MessageUpdateEvent { pub mentions: Option<Vec<User>>, pub mention_roles: Option<Vec<RoleId>>, pub attachments: Option<Vec<Attachment>>, - pub embeds: Option<Vec<Embed>>, + pub embeds: Option<Vec<Value>>, } #[cfg(feature = "cache")] @@ -1346,35 +1346,32 @@ pub enum Event { ChannelDelete(ChannelDeleteEvent), /// The pins for a [`Channel`] have been updated. /// - /// Fires the [`Client::channel_pins_update`] event. + /// Fires the [`Client::on_channel_pins_update`] event. /// - /// [`Channel`]: ../channel/enum.Channel.html - /// [`Client::channel_pins_update`]: ../../client/struct.Client.html#channel_pins_update + /// [`Channel`]: ../enum.Channel.html + /// [`Client::channel_pins_update`]: + /// ../../client/struct.Client.html#channel_pins_update ChannelPinsUpdate(ChannelPinsUpdateEvent), /// A [`User`] has been added to a [`Group`]. /// - /// Fires the [`Client::recipient_add`] event. + /// Fires the [`Client::on_recipient_add`] event. /// - /// [`Client::recipient_add`]: ../../client/struct.Client.html#recipient_add - /// [`User`]: ../user/struct.User.html - /// [`Group`]: ../channel/struct.Group.html + /// [`Client::on_recipient_add`]: ../../client/struct.Client.html#on_recipient_add + /// [`User`]: ../struct.User.html ChannelRecipientAdd(ChannelRecipientAddEvent), /// A [`User`] has been removed from a [`Group`]. /// - /// Fires the [`Client::recipient_remove`] event. + /// Fires the [`Client::on_recipient_remove`] event. /// - /// [`Channel`]: ../channel/enum.Channel.html - /// [`Client::recipient_remove`]: ../../client/struct.Client.html#recipient_remove - /// [`User`]: ../user/struct.User.html - /// [`Group`]: ../channel/struct.Group.html + /// [`Client::on_recipient_remove`]: ../../client/struct.Client.html#on_recipient_remove + /// [`User`]: ../struct.User.html ChannelRecipientRemove(ChannelRecipientRemoveEvent), /// A [`Channel`] has been updated. /// - /// Fires the [`Client::channel_update`] event. + /// Fires the [`Client::on_channel_update`] event. /// - /// [`Channel`]: ../channel/enum.Channel.html - /// [`Client::channel_update`]: ../../client/struct.Client.html#channel_update - /// [`User`]: ../user/struct.User.html + /// [`Client::on_channel_update`]: ../../client/struct.Client.html#on_channel_update + /// [`User`]: ../struct.User.html ChannelUpdate(ChannelUpdateEvent), GuildBanAdd(GuildBanAddEvent), GuildBanRemove(GuildBanRemoveEvent), @@ -1404,23 +1401,24 @@ pub enum Event { PresencesReplace(PresencesReplaceEvent), /// A reaction was added to a message. /// - /// Fires the [`reaction_add`] event handler. + /// Fires the [`message_reaction_add`] event handler. /// - /// [`reaction_add`]: ../../prelude/trait.EventHandler.html#method.reaction_add + /// [`message_reaction_add`]: ../client/struct.Client.html#method.message_reaction_add ReactionAdd(ReactionAddEvent), /// A reaction was removed to a message. /// - /// Fires the [`reaction_remove`] event handler. + /// Fires the [`message_reaction_remove`] event handler. /// - /// [`reaction_remove`]: ../../prelude/trait.EventHandler.html#method.reaction_remove + /// [`message_reaction_remove`]: + /// ../client/struct.Client.html#method.message_reaction_remove ReactionRemove(ReactionRemoveEvent), /// A request was issued to remove all [`Reaction`]s from a [`Message`]. /// /// Fires the [`reaction_remove_all`] event handler. /// - /// [`Message`]: ../channel/struct.Message.html - /// [`Reaction`]: ../channel/struct.Reaction.html - /// [`reaction_remove_all`]: ../../prelude/trait.EventHandler.html#method.reaction_remove_all + /// [`Message`]: struct.Message.html + /// [`Reaction`]: struct.Reaction.html + /// [`reaction_remove_all`]: ../client/struct.Clint.html#method.reaction_remove_all ReactionRemoveAll(ReactionRemoveAllEvent), /// The first event in a connection, containing the initial ready cache. /// @@ -1436,11 +1434,10 @@ pub enum Event { VoiceStateUpdate(VoiceStateUpdateEvent), /// Voice server information is available VoiceServerUpdate(VoiceServerUpdateEvent), - /// A webhook for a [`Channel`]-variant [`GuildChannel`] was updated in a [`Guild`]. + /// A webhook for a [channel][`GuildChannel`] was updated in a [`Guild`]. /// - /// [`Channel`]: ../channel/enum.Channel.html - /// [`GuildChannel`]: ../channel/enum.Channel.html#variant.Guild - /// [`Guild`]: ../guild/struct.Guild.html + /// [`Guild`]: struct.Guild.html + /// [`GuildChannel`]: struct.GuildChannel.html WebhookUpdate(WebhookUpdateEvent), /// An event type not covered by the above Unknown(UnknownEvent), diff --git a/src/voice/connection.rs b/src/voice/connection.rs index 772ef5f..841216c 100644 --- a/src/voice/connection.rs +++ b/src/voice/connection.rs @@ -6,6 +6,7 @@ use byteorder::{ WriteBytesExt }; use constants::VOICE_GATEWAY_VERSION; +use gateway::WsClient; use internal::prelude::*; use internal::{ ws_impl::{ReceiverExt, SenderExt}, @@ -50,20 +51,8 @@ use std::{ use super::audio::{AudioReceiver, AudioType, HEADER_LEN, SAMPLE_RATE, DEFAULT_BITRATE, LockedAudio}; use super::connection_info::ConnectionInfo; use super::{payload, VoiceError, CRYPTO_MODE}; -use websocket::{ - client::Url as WebsocketUrl, - sync::{ - client::ClientBuilder, - stream::{ - AsTcpStream, - TcpStream, - TlsStream - }, - }, - sync::Client as WsClient -}; - -type Client = WsClient<TlsStream<TcpStream>>; +use tungstenite::{self, handshake::client::Request}; +use url::Url; enum ReceiverStatus { Udp(Vec<u8>), @@ -82,7 +71,7 @@ struct ThreadItems { #[allow(dead_code)] pub struct Connection { audio_timer: Timer, - client: Arc<Mutex<Client>>, + client: Arc<Mutex<WsClient>>, decoder_map: HashMap<(u32, Channels), OpusDecoder>, destination: SocketAddr, encoder: OpusEncoder, @@ -105,7 +94,7 @@ impl Connection { pub fn new(mut info: ConnectionInfo) -> Result<Connection> { let url = generate_url(&mut info.endpoint)?; - let mut client = ClientBuilder::from_url(&url).connect_secure(None)?; + let mut client = tungstenite::connect(Request::from(url))?.0; let mut hello = None; let mut ready = None; client.send_json(&payload::build_identify(&info))?; @@ -187,11 +176,6 @@ impl Connection { let key = encryption_key(&mut client)?; - let _ = client - .stream_ref() - .as_tcp() - .set_read_timeout(Some(Duration::from_millis(25))); - let mutexed_client = Arc::new(Mutex::new(client)); let thread_items = start_threads(Arc::clone(&mutexed_client), &udp)?; @@ -202,8 +186,6 @@ impl Connection { encoder.set_bitrate(Bitrate::Bits(DEFAULT_BITRATE))?; let soft_clip = SoftClip::new(Channels::Stereo); - let soft_clip = SoftClip::new(Channels::Stereo); - // Per discord dev team's current recommendations: // (https://discordapp.com/developers/docs/topics/voice-connections#heartbeating) let temp_heartbeat = (hello.heartbeat_interval as f64 * 0.75) as u64; @@ -544,19 +526,19 @@ fn combine_audio( } } -fn generate_url(endpoint: &mut String) -> Result<WebsocketUrl> { +fn generate_url(endpoint: &mut String) -> Result<Url> { if endpoint.ends_with(":80") { let len = endpoint.len(); endpoint.truncate(len - 3); } - WebsocketUrl::parse(&format!("wss://{}/?v={}", endpoint, VOICE_GATEWAY_VERSION)) + Url::parse(&format!("wss://{}/?v={}", endpoint, VOICE_GATEWAY_VERSION)) .or(Err(Error::Voice(VoiceError::EndpointUrl))) } #[inline] -fn encryption_key(client: &mut Client) -> Result<Key> { +fn encryption_key(client: &mut WsClient) -> Result<Key> { loop { let value = match client.recv_json()? { Some(value) => value, @@ -593,7 +575,7 @@ where T: for<'a> PartialEq<&'a str>, } #[inline] -fn start_threads(client: Arc<Mutex<Client>>, udp: &UdpSocket) -> Result<ThreadItems> { +fn start_threads(client: Arc<Mutex<WsClient>>, udp: &UdpSocket) -> Result<ThreadItems> { let (udp_close_sender, udp_close_reader) = mpsc::channel(); let (ws_close_sender, ws_close_reader) = mpsc::channel(); |