Add UserId newtype and WebSocket ping keep-alive
All checks were successful
CI / ci (push) Successful in 5m57s
All checks were successful
CI / ci (push) Successful in 5m57s
Replace raw String user IDs with a UserId newtype in domain for type safety, and add 30s ping/pong to prevent idle WebSocket disconnects.
This commit is contained in:
@@ -8,6 +8,6 @@ pub use canvas::Canvas;
|
||||
pub use errors::DomainError;
|
||||
pub use events::BroadcastEvent;
|
||||
pub use ports::BroadcastSubscription;
|
||||
pub use value_objects::{Color, PixelUpdate, Position};
|
||||
pub use value_objects::{Color, PixelUpdate, Position, UserId};
|
||||
|
||||
pub const COOLDOWN_MESSAGE: &str = "You can only place one pixel per minute";
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UserId(String);
|
||||
|
||||
impl UserId {
|
||||
pub fn new(id: String) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for UserId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
pub struct Color(u32);
|
||||
|
||||
Reference in New Issue
Block a user