update to support user expire, timeout, and disconnect
This commit is contained in:
parent
fe65835f4a
commit
5fcd49e847
16 changed files with 744 additions and 238 deletions
|
|
@ -273,3 +273,27 @@ pub async fn set_afk<'e>(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the last_moved_at timestamp to keep the member alive.
|
||||
///
|
||||
/// Called when a ping is received from the client to prevent
|
||||
/// the member from being reaped by the stale member cleanup.
|
||||
pub async fn touch_member<'e>(
|
||||
executor: impl PgExecutor<'e>,
|
||||
channel_id: Uuid,
|
||||
user_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
sqlx::query(
|
||||
r#"
|
||||
UPDATE scene.instance_members
|
||||
SET last_moved_at = now()
|
||||
WHERE instance_id = $1 AND user_id = $2
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
.bind(user_id)
|
||||
.execute(executor)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,25 @@ use uuid::Uuid;
|
|||
|
||||
use crate::models::{AvatarRenderData, ChannelMemberInfo, ChannelMemberWithAvatar, LooseProp};
|
||||
|
||||
/// WebSocket configuration sent to client on connect.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WsConfig {
|
||||
/// Interval for client to send ping to keep connection alive (seconds).
|
||||
pub ping_interval_secs: u64,
|
||||
}
|
||||
|
||||
/// Reason for member disconnect.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DisconnectReason {
|
||||
/// Graceful disconnect (browser close, normal WebSocket close).
|
||||
Graceful,
|
||||
/// Scene navigation (custom close code 4000).
|
||||
SceneChange,
|
||||
/// Timeout (connection lost, no ping response).
|
||||
Timeout,
|
||||
}
|
||||
|
||||
/// Client-to-server WebSocket messages.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
|
|
@ -60,6 +79,8 @@ pub enum ServerMessage {
|
|||
member: ChannelMemberInfo,
|
||||
/// All current members with avatars.
|
||||
members: Vec<ChannelMemberWithAvatar>,
|
||||
/// WebSocket configuration for the client.
|
||||
config: WsConfig,
|
||||
},
|
||||
|
||||
/// A member joined the channel.
|
||||
|
|
@ -74,6 +95,8 @@ pub enum ServerMessage {
|
|||
user_id: Option<Uuid>,
|
||||
/// Guest session ID (if guest).
|
||||
guest_session_id: Option<Uuid>,
|
||||
/// Reason for disconnect.
|
||||
reason: DisconnectReason,
|
||||
},
|
||||
|
||||
/// A member updated their position.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue