Give tungstenite types distinct names
This commit is contained in:
parent
50b86d4472
commit
9372e32edb
|
@ -11,16 +11,17 @@ use super::GatewayMessage;
|
||||||
use crate::errors::GatewayError;
|
use crate::errors::GatewayError;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct WebSocketBackend;
|
pub struct TungsteniteBackend;
|
||||||
|
|
||||||
// These could be made into inherent associated types when that's stabilized
|
// These could be made into inherent associated types when that's stabilized
|
||||||
pub type WsSink = SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, tungstenite::Message>;
|
pub type TungsteniteSink =
|
||||||
pub type WsStream = SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>;
|
SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, tungstenite::Message>;
|
||||||
|
pub type TungsteniteStream = SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>;
|
||||||
|
|
||||||
impl WebSocketBackend {
|
impl TungsteniteBackend {
|
||||||
pub async fn connect(
|
pub async fn connect(
|
||||||
websocket_url: &str,
|
websocket_url: &str,
|
||||||
) -> Result<(WsSink, WsStream), crate::errors::GatewayError> {
|
) -> Result<(TungsteniteSink, TungsteniteStream), crate::errors::GatewayError> {
|
||||||
let mut roots = rustls::RootCertStore::empty();
|
let mut roots = rustls::RootCertStore::empty();
|
||||||
for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs")
|
for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs")
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@ use tokio::task;
|
||||||
|
|
||||||
use self::event::Events;
|
use self::event::Events;
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::{WsSink, WsStream};
|
use super::{Sink, Stream};
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
self, AutoModerationRule, AutoModerationRuleUpdate, Channel, ChannelCreate, ChannelDelete,
|
self, AutoModerationRule, AutoModerationRuleUpdate, Channel, ChannelCreate, ChannelDelete,
|
||||||
ChannelUpdate, Guild, GuildRoleCreate, GuildRoleUpdate, JsonField, RoleObject, SourceUrlField,
|
ChannelUpdate, Guild, GuildRoleCreate, GuildRoleUpdate, JsonField, RoleObject, SourceUrlField,
|
||||||
|
@ -17,8 +17,8 @@ use crate::types::{
|
||||||
pub struct Gateway {
|
pub struct Gateway {
|
||||||
events: Arc<Mutex<Events>>,
|
events: Arc<Mutex<Events>>,
|
||||||
heartbeat_handler: HeartbeatHandler,
|
heartbeat_handler: HeartbeatHandler,
|
||||||
websocket_send: Arc<Mutex<WsSink>>,
|
websocket_send: Arc<Mutex<Sink>>,
|
||||||
websocket_receive: WsStream,
|
websocket_receive: Stream,
|
||||||
kill_send: tokio::sync::broadcast::Sender<()>,
|
kill_send: tokio::sync::broadcast::Sender<()>,
|
||||||
store: Arc<Mutex<HashMap<Snowflake, Arc<RwLock<ObservableObject>>>>>,
|
store: Arc<Mutex<HashMap<Snowflake, Arc<RwLock<ObservableObject>>>>>,
|
||||||
url: String,
|
url: String,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::types::{self, Composite};
|
||||||
pub struct GatewayHandle {
|
pub struct GatewayHandle {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub events: Arc<Mutex<Events>>,
|
pub events: Arc<Mutex<Events>>,
|
||||||
pub websocket_send: Arc<Mutex<WsSink>>,
|
pub websocket_send: Arc<Mutex<Sink>>,
|
||||||
/// Tells gateway tasks to close
|
/// Tells gateway tasks to close
|
||||||
pub(super) kill_send: tokio::sync::broadcast::Sender<()>,
|
pub(super) kill_send: tokio::sync::broadcast::Sender<()>,
|
||||||
pub(crate) store: Arc<Mutex<HashMap<Snowflake, Arc<RwLock<ObservableObject>>>>>,
|
pub(crate) store: Arc<Mutex<HashMap<Snowflake, Arc<RwLock<ObservableObject>>>>>,
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub(super) struct HeartbeatHandler {
|
||||||
impl HeartbeatHandler {
|
impl HeartbeatHandler {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
heartbeat_interval: Duration,
|
heartbeat_interval: Duration,
|
||||||
websocket_tx: Arc<Mutex<WsSink>>,
|
websocket_tx: Arc<Mutex<Sink>>,
|
||||||
kill_rc: tokio::sync::broadcast::Receiver<()>,
|
kill_rc: tokio::sync::broadcast::Receiver<()>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (send, receive) = tokio::sync::mpsc::channel(32);
|
let (send, receive) = tokio::sync::mpsc::channel(32);
|
||||||
|
@ -49,7 +49,7 @@ impl HeartbeatHandler {
|
||||||
/// Can be killed by the kill broadcast;
|
/// Can be killed by the kill broadcast;
|
||||||
/// If the websocket is closed, will die out next time it tries to send a heartbeat;
|
/// If the websocket is closed, will die out next time it tries to send a heartbeat;
|
||||||
pub async fn heartbeat_task(
|
pub async fn heartbeat_task(
|
||||||
websocket_tx: Arc<Mutex<WsSink>>,
|
websocket_tx: Arc<Mutex<Sink>>,
|
||||||
heartbeat_interval: Duration,
|
heartbeat_interval: Duration,
|
||||||
mut receive: Receiver<HeartbeatThreadCommunication>,
|
mut receive: Receiver<HeartbeatThreadCommunication>,
|
||||||
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
||||||
|
|
|
@ -23,11 +23,11 @@ use std::sync::{Arc, RwLock};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub type WsSink = backend_tungstenite::WsSink;
|
pub type Sink = backend_tungstenite::TungsteniteSink;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub type WsStream = backend_tungstenite::WsStream;
|
pub type Stream = backend_tungstenite::TungsteniteStream;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub type WebSocketBackend = backend_tungstenite::WebSocketBackend;
|
pub type WebSocketBackend = backend_tungstenite::TungsteniteBackend;
|
||||||
|
|
||||||
// Gateway opcodes
|
// Gateway opcodes
|
||||||
/// Opcode received when the server dispatches a [crate::types::WebSocketEvent]
|
/// Opcode received when the server dispatches a [crate::types::WebSocketEvent]
|
||||||
|
|
Loading…
Reference in New Issue