Skip to content

Commit

Permalink
Merge pull request #10 from Myrkie/main
Browse files Browse the repository at this point in the history
Source generators, example update
  • Loading branch information
LucHeart authored Sep 16, 2024
2 parents 077d645 + 2355d88 commit 2681c59
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
6 changes: 2 additions & 4 deletions OscQueryExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static async Task Main(string[] args)

oscQueryServers.Add(localHostServer);

localHostServer.Start();
localHostServer.Start(); // this is required to start the service, no events will fire without this.

while (true)
{
Expand All @@ -91,9 +91,7 @@ private static Task FoundVrcClient(OscQueryServer oscQueryServer, IPEndPoint ipE
_logger.Information("Found VRC client at {EndPoint}", ipEndPoint);
_logger.Information("Starting listening for VRC client at {Port}", oscQueryServer.OscReceivePort);

_gameConnection = new OscDuplex(
new IPEndPoint(ipEndPoint.Address, oscQueryServer.OscReceivePort),
ipEndPoint);
_gameConnection = new OscDuplex(new IPEndPoint(ipEndPoint.Address, oscQueryServer.OscReceivePort), ipEndPoint);
_currentOscQueryServer = oscQueryServer;
ErrorHandledTask.Run(ReceiverLoopAsync);
return Task.CompletedTask;
Expand Down
13 changes: 0 additions & 13 deletions OscQueryLibrary/Models/JsonSourceGenerationContext.cs

This file was deleted.

13 changes: 13 additions & 0 deletions OscQueryLibrary/Models/JsonSourceGenerators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;

namespace OscQueryLibrary.Models;

[JsonSerializable(typeof(HostInfo))]
[JsonSerializable(typeof(HostInfo.ExtensionsNode))]
[JsonSerializable(typeof(HostInfo.OscTransportType))]
[JsonSerializable(typeof(RootNode))]
[JsonSerializable(typeof(AvatarContents))]
[JsonSerializable(typeof(OscParameterNode))]
[JsonSerializable(typeof(OscParameterNodeEnd<>))]

Check warning on line 11 in OscQueryLibrary/Models/JsonSourceGenerators.cs

View workflow job for this annotation

GitHub Actions / build

Did not generate serialization metadata for type 'OscQueryLibrary.Models.OscParameterNodeEnd<>'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030)

Check warning on line 11 in OscQueryLibrary/Models/JsonSourceGenerators.cs

View workflow job for this annotation

GitHub Actions / build

Did not generate serialization metadata for type 'OscQueryLibrary.Models.OscParameterNodeEnd<>'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030)

Check warning on line 11 in OscQueryLibrary/Models/JsonSourceGenerators.cs

View workflow job for this annotation

GitHub Actions / build

Did not generate serialization metadata for type 'OscQueryLibrary.Models.OscParameterNodeEnd<>'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030)

Check warning on line 11 in OscQueryLibrary/Models/JsonSourceGenerators.cs

View workflow job for this annotation

GitHub Actions / build

Did not generate serialization metadata for type 'OscQueryLibrary.Models.OscParameterNodeEnd<>'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030)
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, WriteIndented = true, AllowTrailingCommas = true)]
internal partial class ModelsSourceGenerationContext : JsonSerializerContext;
6 changes: 3 additions & 3 deletions OscQueryLibrary/OscQueryLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageProjectUrl>https://github.com/Natsumi-sama/OscQueryLibrary</PackageProjectUrl>
<RepositoryUrl>https://github.com/Natsumi-sama/OscQueryLibrary</RepositoryUrl>
<PackageTags>osc async oscquery open-sound-control</PackageTags>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
8 changes: 4 additions & 4 deletions OscQueryLibrary/OscQueryServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public OscQueryServer(string serviceName, IPAddress ipAddress)
.WithModule(new ActionModule("/", HttpVerbs.Get,
ctx => ctx.SendStringAsync(
ctx.Request.RawUrl.Contains("HOST_INFO")
? JsonSerializer.Serialize(_hostInfo, JsonSourceGenerationContext.Default.HostInfo)
: JsonSerializer.Serialize(_queryData, JsonSourceGenerationContext.Default.RootNode), MediaTypeNames.Application.Json, Encoding.UTF8)));
? JsonSerializer.Serialize(_hostInfo, ModelsSourceGenerationContext.Default.HostInfo!)
: JsonSerializer.Serialize(_queryData, ModelsSourceGenerationContext.Default.RootNode!), MediaTypeNames.Application.Json, Encoding.UTF8)));

// mDNS
_multicastService = new MulticastService
Expand Down Expand Up @@ -169,7 +169,7 @@ private async Task FoundNewVrcClient(IPAddress ipAddress, int port)
try
{
response = await Client.GetStringAsync(url);
var rootNode = JsonSerializer.Deserialize(response, JsonSourceGenerationContext.Default.HostInfo);
var rootNode = JsonSerializer.Deserialize(response, ModelsSourceGenerationContext.Default.HostInfo);
if (rootNode?.OscPort == null)
{
Logger.Error("OSCQueryHttpClient: Error no OSC port found");
Expand Down Expand Up @@ -204,7 +204,7 @@ private async Task FetchJsonFromVrc(IPAddress ipAddress, int port)
{
response = await Client.GetStringAsync(url);

var rootNode = JsonSerializer.Deserialize(response, JsonSourceGenerationContext.Default.RootNode);
var rootNode = JsonSerializer.Deserialize(response, ModelsSourceGenerationContext.Default.RootNode);
if (rootNode?.Contents?.Avatar?.Contents?.Parameters?.Contents == null)
{
Logger.Debug("OSCQueryHttpClient: Error no parameters found");
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var localHostServer = new OscQueryServer(
);
localHostServer.FoundVrcClient += FoundVrcClient; // event on vrc discovery
localHostServer.ParameterUpdate += UpdateAvailableParameters; // event on parameter list update
localHostServer.Start(); // this is required to start the service, no events will fire without this.
// listen for VRC on every network interface (Quest only)
var host = await Dns.GetHostEntryAsync(Dns.GetHostName());
Expand All @@ -40,7 +41,7 @@ foreach (var ip in host.AddressList)

server.FoundVrcClient += FoundVrcClient; // event on vrc discovery
server.ParameterUpdate += UpdateAvailableParameters; // event on parameter list update
server.Start();
server.Start(); // this is required to start the service, no events will fire without this.
}

private static Task FoundVrcClient(OscQueryServer oscQueryServer, IPEndPoint ipEndPoint)
Expand Down

0 comments on commit 2681c59

Please sign in to comment.