-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.cs
More file actions
57 lines (46 loc) · 1.3 KB
/
Message.cs
File metadata and controls
57 lines (46 loc) · 1.3 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
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Json;
namespace WebSocketServer
{
public class Message
{
public string eventName { get; set; }
//public abstract object data { get; set; }
public string ToJson()
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(GetType());
MemoryStream stream = new MemoryStream();
serializer.WriteObject(stream, this);
stream.Position = 0;
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
public class JoinRoom
{
public string eventName { get; set; }
public object data { get; set; }
}
public class NewPeerConnected : Message
{
public NewPeerConnected()
{
eventName = "new_peer_connected";
}
public Dictionary<string, List<string>> data { get; set; }
}
public class GetPeers : Message
{
public class InnerData
{
public List<string> connections { get; set; }
public string you { get; set; }
}
public GetPeers()
{
eventName = "get_peers";
}
public InnerData data { get; set; }
}
}