Skip to content

Commit

Permalink
Merge pull request #29 from vrchat-community/feature/refactor-to-flue…
Browse files Browse the repository at this point in the history
…nt-interface

Feature/refactor to fluent interface
  • Loading branch information
momo-the-monster authored Dec 2, 2022
2 parents 4866973 + 2d01e5a commit 1166c57
Show file tree
Hide file tree
Showing 15 changed files with 902 additions and 433 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ PublishScripts/
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
Expand Down
4 changes: 2 additions & 2 deletions Examples/DataReceiver/FindServiceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FindServiceDialog : Dialog

public FindServiceDialog(ILogger<OSCQueryService> logger)
{
_service = new OSCQueryService( OSCQueryService.DefaultServerName + "1", OSCQueryService.DefaultPortHttp + 10, OSCQueryService.DefaultPortOsc + 10, logger);
_service = new OSCQueryService( OSCQueryService.DefaultServerName + "1", Extensions.GetAvailableTcpPort(), OSCQueryService.DefaultPortOsc, logger);

Width = 45;
Height = 10;
Expand Down Expand Up @@ -47,7 +47,7 @@ public FindServiceDialog(ILogger<OSCQueryService> logger)
};
Add(_listView);

_service.OnProfileAdded += _ =>
_service.OnOscQueryServiceAdded += _ =>
{
RefreshListings();
};
Expand Down
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,30 @@ private void StartService()
var serverName = $"{w.IngVerb().UpperCaseFirstChar()}-{w2.Word().UpperCaseFirstChar()}-{w.Abbreviation()}";

// Create OSC Server on available port
var port = VRC.OSCQuery.Extensions.GetAvailableTcpPort();
_receiver = OscServer.GetOrCreate(port);
var port = Extensions.GetAvailableTcpPort();
var udpPort = Extensions.GetAvailableUdpPort();
_receiver = OscServer.GetOrCreate(udpPort);

// Listen to all incoming messages
_receiver.AddMonitorCallback(OnMessageReceived);
_oscQuery = new OSCQueryService(
serverName,
port,
port,
new UnityMSLogger()
);

var logger = new UnityMSLogger();

_oscQuery = new OSCQueryServiceBuilder()
.WithServiceName(serverName)
.WithTcpPort(port)
.WithOscPort(udpPort)
.WithLogger(logger)
.WithDiscovery(new MeaModDiscovery(logger))
.StartHttpServer()
.AdvertiseOSC()
.AdvertiseOSCQuery()
.Build();

_oscQuery.RefreshServices();

// Show server name and chosen port
HeaderText.text = $"{serverName} listening on {port}";
HeaderText.text = $"{serverName} running at tcp:{port} osc: {udpPort}";
}

// Process incoming messages, add to message queue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Net.Sockets;
using OscCore;

namespace VRC.OSCQuery.Samples.Shared
{
public class OscClientPlus : OscClient
{
/// <summary>Send a message with a string and a bool</summary>
public void Send(string address, string message, bool value)
{
string boolTag = value ? "T" : "F";
m_Writer.Reset();
m_Writer.Write(address);
string typeTags = $",s{boolTag}";
m_Writer.Write(typeTags);
m_Writer.Write(message);
m_Socket.Send(m_Writer.Buffer, m_Writer.Length, SocketFlags.None);
}

public OscClientPlus(string ipAddress, int port) : base(ipAddress, port)
{
}
}
}
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This library does not yet return limited attributes based on query strings, like
## ⚡️ Basic Use

1. Build vrc-oscquery-lib into vrc-oscquery-lib.dll and add it to your project (will make this a NuGet package once it's ready for wider use).
2. Construct a new OSCQuery service with `new OSCQueryService()`, optionally passing in the name, TCP port to use for serving HTTP, UDP port that you're using for OSC, and an ILogger if you want logs.
2. Construct a new OSCQuery service with `new OSCQueryServiceBuilder().WithDefaults().Build()`. T optionally passing in the name, TCP port to use for serving HTTP, UDP port that you're using for OSC, and an ILogger if you want logs.
3. You should now be able to visit `http://localhost:tcpPort` in a browser and see raw JSON describing an empty root node.
- You can also visit `http://localhost:tcpPort?explorer` to see an OSCQuery Explorer UI for the OSCQuery service, which should be easier to navigate than the raw JSON.
4. You can also visit `http://localhost:tcpPort?HOST_INFO` to get information about the supported attributes of this OSCQuery Server.
Expand Down
Loading

0 comments on commit 1166c57

Please sign in to comment.