Skip to content

Commit

Permalink
refactor!: update namespace to drop Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
viglucci committed Apr 4, 2022
1 parent 6dc148f commit 228532c
Show file tree
Hide file tree
Showing 64 changed files with 172 additions and 158 deletions.
179 changes: 91 additions & 88 deletions UnityRSocket/Assets/Viglucci/UnityRSocket/Example/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,126 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Viglucci.UnityRSocket.Runtime;
using Viglucci.UnityRSocket.Runtime.Metadata;
using Viglucci.UnityRSocket.Runtime.Scheduling;
using Viglucci.UnityRSocket.Metadata;
using Viglucci.UnityRSocket.Scheduling;
using Viglucci.UnityRSocket.Transport;

public class ClientManager : MonoBehaviour
namespace Viglucci.UnityRSocket.Example
{
private static ClientManager _instance;
public class ClientManager : MonoBehaviour
{
private static ClientManager _instance;

/**
/**
* How often to send KeepAlive frames.
*/
public int keepAliveInterval = 10_000;
public int keepAliveInterval = 10_000;

/**
/**
* The max delay between a keep alive frame and a server ACK. Client will disconnect if server does not
* respond to a KeepAlive frame within this time period.
*/
public int keepAliveTimeout = 60_000;

private IRSocket _rSocket;
private IClientTransport _transport;
public int keepAliveTimeout = 60_000;

private void Awake()
{
Debug.Log("Awake");
private IRSocket _rSocket;
private IClientTransport _transport;

if (_instance == null)
{
_instance = this;
}
else if (_instance != this)
private void Awake()
{
Debug.LogWarning(
$"Instance of {GetType().Name} already exists. Newly created instance will be destroyed.");
Destroy(this);
Debug.Log("Awake");

if (_instance == null)
{
_instance = this;
}
else if (_instance != this)
{
Debug.LogWarning(
$"Instance of {GetType().Name} already exists. Newly created instance will be destroyed.");
Destroy(this);
}
}
}

private void Start()
{
Debug.Log("Start");
private void Start()
{
Debug.Log("Start");

_transport = new TcpClientTransport("localhost", 9090);
_transport = new TcpClientTransport("localhost", 9090);

SetupOptions setupOptions = new SetupOptions(
keepAliveInterval,
keepAliveTimeout,
data: new List<byte>(),
metadata: new List<byte>(),
dataMimeType:
Metadata.WellKnownMimeTypeToString(
SetupOptions setupOptions = new SetupOptions(
keepAliveInterval,
keepAliveTimeout,
data: new List<byte>(),
metadata: new List<byte>(),
dataMimeType:
Metadata.Metadata.WellKnownMimeTypeToString(
WellKnownMimeType.APPLICATION_JSON),
metadataMimeType:
Metadata.WellKnownMimeTypeToString(
metadataMimeType:
Metadata.Metadata.WellKnownMimeTypeToString(
WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA)
);
);

RSocketConnector connector = new RSocketConnector(
_transport,
setupOptions,
new MonoBehaviorScheduler());
RSocketConnector connector = new RSocketConnector(
_transport,
setupOptions,
new MonoBehaviorScheduler());

IRSocket rSocket = connector.Bind();
IRSocket rSocket = connector.Bind();

try
{
Debug.Log("Binding connector");
_rSocket = connector.Bind();
try
{
Debug.Log("Binding connector");
_rSocket = connector.Bind();
}
catch (Exception e)
{
Debug.LogError(e);
return;
}

OnRSocketConnected();
}
catch (Exception e)

private void Update()
{
Debug.LogError(e);
return;
_transport.ProcessMessages();
}

OnRSocketConnected();
}

private void Update()
{
_transport.ProcessMessages();
}

private void OnRSocketConnected()
{
_rSocket.OnClose((ex) =>
private void OnRSocketConnected()
{
Debug.Log("RSocket connection closed.");
if (ex != null)
Debug.LogError(ex);
});
_rSocket.OnClose((ex) =>
{
Debug.Log("RSocket connection closed.");
if (ex != null)
Debug.LogError(ex);
});

List<byte> data = new List<byte>(Encoding.UTF8.GetBytes("{ \"key\": \"value\"}"));
List<byte> metadata = new List<byte>();
List<byte> data = new List<byte>(Encoding.UTF8.GetBytes("{ \"key\": \"value\"}"));
List<byte> metadata = new List<byte>();

ICancellable cancellable = _rSocket.RequestResponse(new RSocketPayload
{
Data = data,
Metadata = metadata
},
new Subscriber(
(payload, isComplete) =>
ICancellable cancellable = _rSocket.RequestResponse(new RSocketPayload
{
string decodedData = Encoding.UTF8.GetString(payload.Data.ToArray());
string decodedMetadata = Encoding.UTF8.GetString(payload.Metadata.ToArray());

Debug.Log($"data: {decodedData}");
Debug.Log($"metadata: {decodedMetadata}");
Debug.Log($"isComplete: {isComplete}");

if (isComplete)
{
Debug.Log("RequestResponse done");
}
Data = data,
Metadata = metadata
},
() => Debug.Log("RequestResponse done"),
Debug.LogError
));
new Subscriber(
(payload, isComplete) =>
{
string decodedData = Encoding.UTF8.GetString(payload.Data.ToArray());
string decodedMetadata = Encoding.UTF8.GetString(payload.Metadata.ToArray());

Debug.Log($"data: {decodedData}");
Debug.Log($"metadata: {decodedMetadata}");
Debug.Log($"isComplete: {isComplete}");

if (isComplete)
{
Debug.Log("RequestResponse done");
}
},
() => Debug.Log("RequestResponse done"),
Debug.LogError
));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public static class BufferUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public class CancellableRequestableWrapper : ICancellableRequestable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public class CancellableWrapper : ICancellable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Viglucci.UnityRSocket.Runtime.Frame;
using Viglucci.UnityRSocket.Frame;

namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public abstract class ClientServerInputMultiplexerDemultiplexer : Deferred, IMultiplexer, IStream
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Viglucci.UnityRSocket.Runtime.Frame;
using Viglucci.UnityRSocket.Runtime.KeepAlive;
using Viglucci.UnityRSocket.Frame;
using Viglucci.UnityRSocket.KeepAlive;

namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public class DefaultConnectionFrameHandler : IConnectionFrameHandler
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;

namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public class Deferred : ICloseable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime
namespace Viglucci.UnityRSocket
{
public class EpochUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static class FrameDeserializer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public enum FrameType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static class FrameUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public interface ISerializableFrame<out T>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Viglucci.UnityRSocket.Runtime.Frame
namespace Viglucci.UnityRSocket.Frame
{
public static partial class RSocketFrame
{
Expand Down
Loading

0 comments on commit 228532c

Please sign in to comment.