api/ws/tickets/
ws_handlers.rs1use serde_json::json;
2use util::ws::handler_trait::WsHandler;
3use util::ws::runtime::WsContext;
4use util::ws::handler_trait::async_trait;
5use super::common::TicketIncoming;
6
7pub struct TicketWsHandler;
8
9#[async_trait]
10impl WsHandler for TicketWsHandler {
11 type In = TicketIncoming;
12
13 async fn on_open(&self, _ctx: &WsContext) {
14 }
17
18 async fn on_message(&self, ctx: &WsContext, msg: Self::In) {
19 match msg {
20 TicketIncoming::Typing { sender } => {
21 ctx.emit("typing", &json!({ "sender": sender })).await;
23 }
24 TicketIncoming::Ping => {
25 let _ = ctx.reply_text(json!({
27 "event": "pong",
28 "topic": ctx.topic,
29 "payload": {},
30 "ts": chrono::Utc::now().to_rfc3339(),
31 }).to_string()).await;
32 }
33 }
34 }
35
36 async fn on_close(&self, _ctx: &WsContext) {
37 }
39}