-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.rs
More file actions
69 lines (65 loc) · 1.82 KB
/
Copy pathprotocol.rs
File metadata and controls
69 lines (65 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use serde::{Deserialize, Serialize};
/// Frames the CLIENT sends us. The JSON `type` field selects the variant;
/// per-variant camelCase matches the Go wire format (roomId, clientId, …).
#[derive(Debug, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Inbound {
#[serde(rename_all = "camelCase")]
Join { room_id: String },
#[serde(rename_all = "camelCase")]
Leave { room_id: String },
#[serde(rename_all = "camelCase")]
Send {
room_id: String,
body: String,
client_id: String,
#[serde(default)]
token: Option<String>,
},
#[serde(rename_all = "camelCase")]
TypingStart { room_id: String },
#[serde(rename_all = "camelCase")]
TypingStop { room_id: String },
Ping {
#[serde(default)]
token: Option<String>,
},
}
/// Frames WE send the client.
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Outbound {
#[serde(rename_all = "camelCase")]
Hello {
server: String,
version: String,
},
Pong,
#[serde(rename_all = "camelCase")]
PresenceUpdate {
room_id: String,
users: Vec<String>,
},
#[serde(rename_all = "camelCase")]
TypingUpdate {
room_id: String,
user_id: String,
typing: bool,
},
#[serde(rename_all = "camelCase")]
Ack {
room_id: String,
message_id: String,
client_id: String,
created_at: f64,
},
#[serde(rename_all = "camelCase")]
Error {
#[serde(skip_serializing_if = "Option::is_none")]
room_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
client_id: Option<String>,
reason: String,
},
// Ack / PresenceUpdate / TypingUpdate land in M2–M4.
}