1use crate::events::EventWrapper;
6use crate::server_communications::GameServerCommunications;
7use actix::{Actor, Addr, Handler, StreamHandler};
8use actix_web_actors::ws;
9use std::time::Duration;
10
11pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
14pub const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
16pub const SOCKET_SELF_ID: &str = "self";
18
19pub trait Socket<G, S, R>
21where
22 Self: Actor,
23 Self: StreamHandler<Result<ws::Message, ws::ProtocolError>>,
24 Self: Handler<EventWrapper<S>>,
25 Self: GameServerCommunications<G, S>,
26 G: Actor,
27{
28 fn new(gs: Addr<G>) -> Self;
30 fn hb(&self, ctx: &mut <Self as Actor>::Context)
32 where
33 Self: actix::Actor;
34 fn self_emit(ctx: &mut <Self as Actor>::Context, event: S)
39 where
40 Self: actix::Actor;
41 fn emit(ctx: &mut <Self as Actor>::Context, wrapped: &EventWrapper<S>)
43 where
44 Self: actix::Actor;
45 fn handle_receiveable(&mut self, ctx: &mut <Self as Actor>::Context, event: R)
47 where
48 Self: actix::Actor;
49 fn handle_sendable(&mut self, ctx: &mut <Self as Actor>::Context, wrapped: EventWrapper<S>)
51 where
52 Self: actix::Actor;
53}