fix: implement gateway Reconnect and InvalidSession
This commit is contained in:
parent
a3ea5c0975
commit
46dc18dd4c
|
@ -46,6 +46,8 @@ pub struct Session {
|
||||||
pub ready: GatewayEvent<types::GatewayReady>,
|
pub ready: GatewayEvent<types::GatewayReady>,
|
||||||
pub ready_supplemental: GatewayEvent<types::GatewayReadySupplemental>,
|
pub ready_supplemental: GatewayEvent<types::GatewayReadySupplemental>,
|
||||||
pub replace: GatewayEvent<types::SessionsReplace>,
|
pub replace: GatewayEvent<types::SessionsReplace>,
|
||||||
|
pub reconnect: GatewayEvent<types::GatewayReconnect>,
|
||||||
|
pub invalid: GatewayEvent<types::GatewayInvalidSession>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
|
@ -14,8 +14,9 @@ use super::*;
|
||||||
use super::{Sink, Stream};
|
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, GatewayInvalidSession, GatewayReconnect, Guild, GuildRoleCreate,
|
||||||
ThreadUpdate, UpdateMessage, WebSocketEvent,
|
GuildRoleUpdate, JsonField, RoleObject, SourceUrlField, ThreadUpdate, UpdateMessage,
|
||||||
|
WebSocketEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -338,10 +339,42 @@ impl Gateway {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
GATEWAY_RECONNECT => {
|
GATEWAY_RECONNECT => {
|
||||||
todo!()
|
trace!("GW: Received Reconnect");
|
||||||
|
|
||||||
|
let reconnect = GatewayReconnect {};
|
||||||
|
|
||||||
|
self.events
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.session
|
||||||
|
.reconnect
|
||||||
|
.notify(reconnect)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
GATEWAY_INVALID_SESSION => {
|
GATEWAY_INVALID_SESSION => {
|
||||||
todo!()
|
trace!("GW: Received Invalid Session");
|
||||||
|
|
||||||
|
let mut resumable: bool = false;
|
||||||
|
|
||||||
|
if let Some(raw_value) = gateway_payload.event_data {
|
||||||
|
if let Ok(deserialized) = serde_json::from_str(raw_value.get()) {
|
||||||
|
resumable = deserialized;
|
||||||
|
} else {
|
||||||
|
warn!("Failed to parse part of INVALID_SESSION ('{}' as bool), assuming non-resumable", raw_value.get());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Failed to parse part of INVALID_SESSION ('d' missing), assuming non-resumable");
|
||||||
|
}
|
||||||
|
|
||||||
|
let invalid_session = GatewayInvalidSession { resumable };
|
||||||
|
|
||||||
|
self.events
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.session
|
||||||
|
.invalid
|
||||||
|
.notify(invalid_session)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
// Starts our heartbeat
|
// Starts our heartbeat
|
||||||
// We should have already handled this in gateway init
|
// We should have already handled this in gateway init
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::WebSocketEvent;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||||
|
/// Your session is now invalid.
|
||||||
|
///
|
||||||
|
/// Either reauthenticate and reidentify or resume if possible.
|
||||||
|
///
|
||||||
|
/// # Reference
|
||||||
|
/// See <https://docs.discord.sex/topics/gateway-events#invalid-session>
|
||||||
|
pub struct GatewayInvalidSession {
|
||||||
|
#[serde(rename = "d")]
|
||||||
|
pub resumable: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WebSocketEvent for GatewayInvalidSession {}
|
|
@ -14,12 +14,14 @@ pub use hello::*;
|
||||||
pub use identify::*;
|
pub use identify::*;
|
||||||
pub use integration::*;
|
pub use integration::*;
|
||||||
pub use interaction::*;
|
pub use interaction::*;
|
||||||
|
pub use invalid_session::*;
|
||||||
pub use invite::*;
|
pub use invite::*;
|
||||||
pub use lazy_request::*;
|
pub use lazy_request::*;
|
||||||
pub use message::*;
|
pub use message::*;
|
||||||
pub use passive_update::*;
|
pub use passive_update::*;
|
||||||
pub use presence::*;
|
pub use presence::*;
|
||||||
pub use ready::*;
|
pub use ready::*;
|
||||||
|
pub use reconnect::*;
|
||||||
pub use relationship::*;
|
pub use relationship::*;
|
||||||
pub use request_members::*;
|
pub use request_members::*;
|
||||||
pub use resume::*;
|
pub use resume::*;
|
||||||
|
@ -60,12 +62,14 @@ mod hello;
|
||||||
mod identify;
|
mod identify;
|
||||||
mod integration;
|
mod integration;
|
||||||
mod interaction;
|
mod interaction;
|
||||||
|
mod invalid_session;
|
||||||
mod invite;
|
mod invite;
|
||||||
mod lazy_request;
|
mod lazy_request;
|
||||||
mod message;
|
mod message;
|
||||||
mod passive_update;
|
mod passive_update;
|
||||||
mod presence;
|
mod presence;
|
||||||
mod ready;
|
mod ready;
|
||||||
|
mod reconnect;
|
||||||
mod relationship;
|
mod relationship;
|
||||||
mod request_members;
|
mod request_members;
|
||||||
mod resume;
|
mod resume;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::WebSocketEvent;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||||
|
/// "The reconnect event is dispatched when a client should reconnect to the Gateway (and resume their existing session, if they have one). This event usually occurs during deploys to migrate sessions gracefully off old hosts"
|
||||||
|
///
|
||||||
|
/// # Reference
|
||||||
|
/// See <https://docs.discord.sex/topics/gateway-events#reconnect>
|
||||||
|
pub struct GatewayReconnect {}
|
||||||
|
|
||||||
|
impl WebSocketEvent for GatewayReconnect {}
|
Loading…
Reference in New Issue