Skip to content

Commit

Permalink
feat: Add DocFX
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenak committed May 28, 2021
1 parent 4a0e433 commit fc85545
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 100 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Example documentation

on:
push:
branches:
- master

jobs:
# Build the documentation
build:
runs-on: windows-latest # Required by DocFX
steps:
- name: Checkout
uses: actions/checkout@v2
# with:
# submodules: true

- name: Install DocFX
run: choco install -y docfx

- name: Use README.md as index.md
run: cp README.md Documentation/index.md

- name: Build
run: docfx Documentation/docfx.json

# Upload the generated documentation
- name: Upload site artifact
uses: actions/upload-artifact@v1
with:
name: _site
path: _site # Must equals the 'build.dest' value on your docfx.json

# Deploy the generated documentation to the gh-pages branch
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# with:
# submodules: true

# Download the generated documentation
- name: Download site artifact
uses: actions/download-artifact@v1
with:
name: _site

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: _site
56 changes: 37 additions & 19 deletions Assets/Adrenak.AirPeer/Runtime/APNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@ namespace Adrenak.AirPeer {
/// An AirPeer Node. Can serve as a server and a client.
/// </summary>
public class APNode {
/// <summary>
/// Describes the different modes that an <see cref="APNode"/> can be on
/// </summary>
public enum Mode {
/// <summary>
/// State when the node is neither a server (i.e. hosting a network with or
/// without clients) or a client (connected to a server and part of a network).
/// </summary>
Idle,

/// <summary>
/// State when the node is hosting a network at an address. May or may not
/// have clients.
/// </summary>
Server,

/// <summary>
/// State when the node is connected to a server node and part of a network.
/// </summary>
Client
}

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

/// <summary>
/// The name of the server the node is hosting/connected to
/// The address of the network the node is i) hosting as a server or ii) connected to
/// a as a client
/// </summary>
public string Address { get; private set; }

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

/// <summary>
/// The IDs of the peers of this node
/// The IDs of other nodes on this network (not including own ID)
/// </summary>
public List<short> Peers = new List<short>();
public List<short> Peers { get; private set; } = new List<short>();

// Common
/// <summary>
/// Fired when another client joins the network
/// Fired when a new client joins the network
/// </summary>
public event Action<short> OnClientJoined;

/// <summary>
/// Fired when another client leaves the network
/// Fired when a client leaves the network
/// </summary>
public event Action<short> OnClientLeft;

/// <summary>
/// Fired when the node is assigned an ID
/// Fired when this node is assigned an ID
/// </summary>
public event Action<short> OnReceiveID;

Expand Down Expand Up @@ -98,10 +117,9 @@ public enum Mode {
ConnectionId serverCID = ConnectionId.INVALID;

/// <summary>
/// Constructs a peer with the given the signalling server and with a default list of ICE servers
/// Constructs a <see cref="APNode"/> with the given the signaling server URL and with a default list of ICE servers.
/// </summary>
/// <param name="signalingServer">The URL of the signalling server</param>
/// <param name="iceServer">List of URLs of ICE servers</param>
public APNode(string signalingServer) : this(signalingServer, new[] {
"stun.l.google.com:19302",
"stun1.l.google.com:19302",
Expand All @@ -113,7 +131,7 @@ public enum Mode {
}) { }

/// <summary>
/// Constructs a peer with the given the signalling server and a list of ICE servers
/// Constructs a node with the given the signaling server and a list of ICE servers
/// </summary>
/// <param name="signalingServer">The URL of the signalling server</param>
/// <param name="iceServer">List of URLs of ICE servers</param>
Expand All @@ -136,7 +154,7 @@ public enum Mode {
// API
// ================================================
/// <summary>
/// Starts the server with a name
/// Starts the server using the given address.
/// </summary>
public void StartServer(string address) {
if (CurrentMode == Mode.Idle) {
Expand Down Expand Up @@ -172,36 +190,36 @@ public enum Mode {
}

/// <summary>
/// Sends a packet message to a single recipient
/// Sends a packet message to a recipient peer
/// </summary>
/// <param name="recipient">Recipient ID</param>
/// <param name="recipient">Recipient peer ID</param>
/// <param name="packet">The packet containing the message</param>
/// <param name="reliable">Whether the message is reliable or not</param>
public void SendPacket(short recipient, Packet packet, bool reliable = false) =>
SendPacket(new List<short> { recipient }, packet, reliable);

/// <summary>
/// Sends a packet message to several recipients
/// Sends a packet message to several recipient peers
/// </summary>
/// <param name="recipients">Recipient IDs</param>
/// <param name="recipients">Recipient peer IDs</param>
/// <param name="packet">The packet containing the message</param>
/// <param name="reliable">Whether the message is reliable or not</param>
public void SendPacket(List<short> recipients, Packet packet, bool reliable = false) =>
SendRaw(recipients, packet.Serialize(), reliable);

/// <summary>
/// Sends a byte array to a single recipient
/// Sends a byte array to a single recipient peer
/// </summary>
/// <param name="recipient">The recipient ID</param>
/// <param name="recipient">The recipient peer ID</param>
/// <param name="bytes">The byte array to send</param>
/// <param name="reliable">Whether the message is reliable or not</param>
public void SendRaw(short recipient, byte[] bytes, bool reliable = false) =>
SendRaw(new List<short> { recipient }, bytes, reliable);

/// <summary>
/// Sends a byte array to several recipients
/// Sends a byte array to several recipient peers
/// </summary>
/// <param name="recipients">A list of the recipient IDs</param>
/// <param name="recipients">A list of the recipient peer IDs</param>
/// <param name="bytes">The byte array to send</param>
/// <param name="reliable">Whether the message is reliable or not</param>
public void SendRaw(List<short> recipients, byte[] bytes, bool reliable = false) {
Expand Down
14 changes: 12 additions & 2 deletions Assets/Adrenak.AirPeer/Runtime/EndianUtility.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
using System;

namespace Adrenak.AirPeer {
public class EndianUtility {
const bool UseLittleEndian = true;
/// <summary>
/// The utility used by <see cref="BytesReader"/> and
/// <see cref="BytesWriter"/> for reading and writing bytes.
/// </summary>
public static class EndianUtility {
/// <summary>
/// Whether the big or the little Endian is used.
/// Default is Little Endian
/// There is little reason to change this.
/// Don't do so unless you're sure what you're doing.
/// </summary>
static bool UseLittleEndian = true;

public static bool RequiresEndianCorrection {
get { return UseLittleEndian ^ BitConverter.IsLittleEndian; }
Expand Down
30 changes: 29 additions & 1 deletion Assets/Adrenak.AirPeer/Runtime/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@
using System.Text;

namespace Adrenak.AirPeer {
/// <summary>
/// Data structure representing how messages are send in AirPeer.
/// </summary>
public class Message {
/// <summary>
/// ID of the sender of the message
/// </summary>
public short sender;

/// <summary>
/// IDs of the intended recipients of the message
/// </summary>
public short[] recipients;

/// <summary>
/// Byte array representing the data the message object contains
/// </summary>
public byte[] bytes;

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

Expand All @@ -29,6 +48,10 @@ public class Message {
return message;
}

/// <summary>
/// Serializes <see cref="Message"/> instance into a byte array
/// </summary>
/// <returns>Returns byte array if successful else throws exception</returns>
public byte[] Serialize() {
BytesWriter writer = new BytesWriter();
try {
Expand All @@ -44,12 +67,17 @@ public class Message {
}
}

/// <summary>
/// Returns string representation of the instance
/// </summary>
/// <returns>The string representation</returns>
public override string ToString() {
StringBuilder sb = new StringBuilder("Packet:");
sb.Append("\n");
sb.Append("sender=").Append(sender).Append("\n");
sb.Append("recipients={").Append(string.Join(", ", recipients)).Append("}").Append("\n");
sb.Append("bytesLen=").Append(bytes.Length.ToString());
sb.Append("bytesLen=").Append(bytes.Length.ToString()).Append("\n");
sb.Append("bytes=").Append(bytes);
return sb.ToString();
}
}
Expand Down

0 comments on commit fc85545

Please sign in to comment.