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
70
use actix::{Message, Recipient};
use jamsocket::{ClientId, MessageRecipient};
#[derive(Debug, Clone)]
pub enum MessageFromClient {
Connect(ClientId, Recipient<MessageFromServer>),
Disconnect(ClientId),
Message {
from_client: ClientId,
data: MessageData,
},
}
impl Message for MessageFromClient {
type Result = ();
}
#[derive(Debug, Clone)]
pub enum MessageData {
String(String),
Binary(Vec<u8>),
}
#[derive(Debug, Clone)]
pub struct MessageFromServer {
pub to_client: MessageRecipient,
pub data: MessageData,
}
impl Message for MessageFromServer {
type Result = ();
}
impl MessageFromServer {
#[must_use]
pub fn new(to_client: MessageRecipient, data: String) -> Self {
MessageFromServer {
to_client,
data: MessageData::String(data),
}
}
#[must_use]
pub fn new_binary(to_client: MessageRecipient, data: Vec<u8>) -> Self {
MessageFromServer {
to_client,
data: MessageData::Binary(data),
}
}
}
pub struct AssignClientId;
impl Message for AssignClientId {
type Result = ClientId;
}