Skip to content

Commit fc85545

Browse files
committed
feat: Add DocFX
1 parent 4a0e433 commit fc85545

13 files changed

Lines changed: 364 additions & 100 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Example documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
# Build the documentation
10+
build:
11+
runs-on: windows-latest # Required by DocFX
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
# with:
16+
# submodules: true
17+
18+
- name: Install DocFX
19+
run: choco install -y docfx
20+
21+
- name: Use README.md as index.md
22+
run: cp README.md Documentation/index.md
23+
24+
- name: Build
25+
run: docfx Documentation/docfx.json
26+
27+
# Upload the generated documentation
28+
- name: Upload site artifact
29+
uses: actions/upload-artifact@v1
30+
with:
31+
name: _site
32+
path: _site # Must equals the 'build.dest' value on your docfx.json
33+
34+
# Deploy the generated documentation to the gh-pages branch
35+
deploy:
36+
needs: build
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
# with:
42+
# submodules: true
43+
44+
# Download the generated documentation
45+
- name: Download site artifact
46+
uses: actions/download-artifact@v1
47+
with:
48+
name: _site
49+
50+
- name: Deploy
51+
uses: peaceiris/actions-gh-pages@v3
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
publish_branch: gh-pages
55+
publish_dir: _site

Assets/Adrenak.AirPeer/Runtime/APNode.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,38 @@ namespace Adrenak.AirPeer {
99
/// An AirPeer Node. Can serve as a server and a client.
1010
/// </summary>
1111
public class APNode {
12+
/// <summary>
13+
/// Describes the different modes that an <see cref="APNode"/> can be on
14+
/// </summary>
1215
public enum Mode {
16+
/// <summary>
17+
/// State when the node is neither a server (i.e. hosting a network with or
18+
/// without clients) or a client (connected to a server and part of a network).
19+
/// </summary>
1320
Idle,
21+
22+
/// <summary>
23+
/// State when the node is hosting a network at an address. May or may not
24+
/// have clients.
25+
/// </summary>
1426
Server,
27+
28+
/// <summary>
29+
/// State when the node is connected to a server node and part of a network.
30+
/// </summary>
1531
Client
1632
}
1733

1834
/// <summary>
19-
/// the current mode of the node
35+
/// The current mode of the node. The <see cref="Mode"/> changes to <see cref="Mode.Idle"/>
36+
/// in error scenarios too such as when the node fails to become a server, fails to connect
37+
/// to a server. Or when the server is stopped or the client is disconnected.
2038
/// </summary>
2139
public Mode CurrentMode { get; private set; }
2240

2341
/// <summary>
24-
/// The name of the server the node is hosting/connected to
42+
/// The address of the network the node is i) hosting as a server or ii) connected to
43+
/// a as a client
2544
/// </summary>
2645
public string Address { get; private set; }
2746

@@ -31,23 +50,23 @@ public enum Mode {
3150
public short ID { get; private set; } = -1;
3251

3352
/// <summary>
34-
/// The IDs of the peers of this node
53+
/// The IDs of other nodes on this network (not including own ID)
3554
/// </summary>
36-
public List<short> Peers = new List<short>();
55+
public List<short> Peers { get; private set; } = new List<short>();
3756

3857
// Common
3958
/// <summary>
40-
/// Fired when another client joins the network
59+
/// Fired when a new client joins the network
4160
/// </summary>
4261
public event Action<short> OnClientJoined;
4362

4463
/// <summary>
45-
/// Fired when another client leaves the network
64+
/// Fired when a client leaves the network
4665
/// </summary>
4766
public event Action<short> OnClientLeft;
4867

4968
/// <summary>
50-
/// Fired when the node is assigned an ID
69+
/// Fired when this node is assigned an ID
5170
/// </summary>
5271
public event Action<short> OnReceiveID;
5372

@@ -98,10 +117,9 @@ public enum Mode {
98117
ConnectionId serverCID = ConnectionId.INVALID;
99118

100119
/// <summary>
101-
/// Constructs a peer with the given the signalling server and with a default list of ICE servers
120+
/// Constructs a <see cref="APNode"/> with the given the signaling server URL and with a default list of ICE servers.
102121
/// </summary>
103122
/// <param name="signalingServer">The URL of the signalling server</param>
104-
/// <param name="iceServer">List of URLs of ICE servers</param>
105123
public APNode(string signalingServer) : this(signalingServer, new[] {
106124
"stun.l.google.com:19302",
107125
"stun1.l.google.com:19302",
@@ -113,7 +131,7 @@ public APNode(string signalingServer) : this(signalingServer, new[] {
113131
}) { }
114132

115133
/// <summary>
116-
/// Constructs a peer with the given the signalling server and a list of ICE servers
134+
/// Constructs a node with the given the signaling server and a list of ICE servers
117135
/// </summary>
118136
/// <param name="signalingServer">The URL of the signalling server</param>
119137
/// <param name="iceServer">List of URLs of ICE servers</param>
@@ -136,7 +154,7 @@ public APNode(string signalingServer, string[] iceServer) {
136154
// API
137155
// ================================================
138156
/// <summary>
139-
/// Starts the server with a name
157+
/// Starts the server using the given address.
140158
/// </summary>
141159
public void StartServer(string address) {
142160
if (CurrentMode == Mode.Idle) {
@@ -172,36 +190,36 @@ public void Disconnect() {
172190
}
173191

174192
/// <summary>
175-
/// Sends a packet message to a single recipient
193+
/// Sends a packet message to a recipient peer
176194
/// </summary>
177-
/// <param name="recipient">Recipient ID</param>
195+
/// <param name="recipient">Recipient peer ID</param>
178196
/// <param name="packet">The packet containing the message</param>
179197
/// <param name="reliable">Whether the message is reliable or not</param>
180198
public void SendPacket(short recipient, Packet packet, bool reliable = false) =>
181199
SendPacket(new List<short> { recipient }, packet, reliable);
182200

183201
/// <summary>
184-
/// Sends a packet message to several recipients
202+
/// Sends a packet message to several recipient peers
185203
/// </summary>
186-
/// <param name="recipients">Recipient IDs</param>
204+
/// <param name="recipients">Recipient peer IDs</param>
187205
/// <param name="packet">The packet containing the message</param>
188206
/// <param name="reliable">Whether the message is reliable or not</param>
189207
public void SendPacket(List<short> recipients, Packet packet, bool reliable = false) =>
190208
SendRaw(recipients, packet.Serialize(), reliable);
191209

192210
/// <summary>
193-
/// Sends a byte array to a single recipient
211+
/// Sends a byte array to a single recipient peer
194212
/// </summary>
195-
/// <param name="recipient">The recipient ID</param>
213+
/// <param name="recipient">The recipient peer ID</param>
196214
/// <param name="bytes">The byte array to send</param>
197215
/// <param name="reliable">Whether the message is reliable or not</param>
198216
public void SendRaw(short recipient, byte[] bytes, bool reliable = false) =>
199217
SendRaw(new List<short> { recipient }, bytes, reliable);
200218

201219
/// <summary>
202-
/// Sends a byte array to several recipients
220+
/// Sends a byte array to several recipient peers
203221
/// </summary>
204-
/// <param name="recipients">A list of the recipient IDs</param>
222+
/// <param name="recipients">A list of the recipient peer IDs</param>
205223
/// <param name="bytes">The byte array to send</param>
206224
/// <param name="reliable">Whether the message is reliable or not</param>
207225
public void SendRaw(List<short> recipients, byte[] bytes, bool reliable = false) {

Assets/Adrenak.AirPeer/Runtime/EndianUtility.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
using System;
22

33
namespace Adrenak.AirPeer {
4-
public class EndianUtility {
5-
const bool UseLittleEndian = true;
4+
/// <summary>
5+
/// The utility used by <see cref="BytesReader"/> and
6+
/// <see cref="BytesWriter"/> for reading and writing bytes.
7+
/// </summary>
8+
public static class EndianUtility {
9+
/// <summary>
10+
/// Whether the big or the little Endian is used.
11+
/// Default is Little Endian
12+
/// There is little reason to change this.
13+
/// Don't do so unless you're sure what you're doing.
14+
/// </summary>
15+
static bool UseLittleEndian = true;
616

717
public static bool RequiresEndianCorrection {
818
get { return UseLittleEndian ^ BitConverter.IsLittleEndian; }

Assets/Adrenak.AirPeer/Runtime/Message.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22
using System.Text;
33

44
namespace Adrenak.AirPeer {
5+
/// <summary>
6+
/// Data structure representing how messages are send in AirPeer.
7+
/// </summary>
58
public class Message {
9+
/// <summary>
10+
/// ID of the sender of the message
11+
/// </summary>
612
public short sender;
13+
14+
/// <summary>
15+
/// IDs of the intended recipients of the message
16+
/// </summary>
717
public short[] recipients;
18+
19+
/// <summary>
20+
/// Byte array representing the data the message object contains
21+
/// </summary>
822
public byte[] bytes;
923

24+
/// <summary>
25+
/// Constructs a <see cref="Message"/> from a byte array
26+
/// </summary>
27+
/// <param name="bytes">The byte array representing the <see cref="Message"/></param>
28+
/// <returns><see cref="Message"/> instance if deserialization was successful or null</returns>
1029
public static Message Deserialize(byte[] bytes) {
1130
BytesReader reader = new BytesReader(bytes);
1231

@@ -29,6 +48,10 @@ public static Message Deserialize(byte[] bytes) {
2948
return message;
3049
}
3150

51+
/// <summary>
52+
/// Serializes <see cref="Message"/> instance into a byte array
53+
/// </summary>
54+
/// <returns>Returns byte array if successful else throws exception</returns>
3255
public byte[] Serialize() {
3356
BytesWriter writer = new BytesWriter();
3457
try {
@@ -44,12 +67,17 @@ public byte[] Serialize() {
4467
}
4568
}
4669

70+
/// <summary>
71+
/// Returns string representation of the instance
72+
/// </summary>
73+
/// <returns>The string representation</returns>
4774
public override string ToString() {
4875
StringBuilder sb = new StringBuilder("Packet:");
4976
sb.Append("\n");
5077
sb.Append("sender=").Append(sender).Append("\n");
5178
sb.Append("recipients={").Append(string.Join(", ", recipients)).Append("}").Append("\n");
52-
sb.Append("bytesLen=").Append(bytes.Length.ToString());
79+
sb.Append("bytesLen=").Append(bytes.Length.ToString()).Append("\n");
80+
sb.Append("bytes=").Append(bytes);
5381
return sb.ToString();
5482
}
5583
}

0 commit comments

Comments
 (0)