Skip to content

Commit 2681c59

Browse files
authored
Merge pull request #10 from Myrkie/main
Source generators, example update
2 parents 077d645 + 2355d88 commit 2681c59

6 files changed

Lines changed: 24 additions & 25 deletions

File tree

OscQueryExample/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static async Task Main(string[] args)
6868

6969
oscQueryServers.Add(localHostServer);
7070

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

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

94-
_gameConnection = new OscDuplex(
95-
new IPEndPoint(ipEndPoint.Address, oscQueryServer.OscReceivePort),
96-
ipEndPoint);
94+
_gameConnection = new OscDuplex(new IPEndPoint(ipEndPoint.Address, oscQueryServer.OscReceivePort), ipEndPoint);
9795
_currentOscQueryServer = oscQueryServer;
9896
ErrorHandledTask.Run(ReceiverLoopAsync);
9997
return Task.CompletedTask;

OscQueryLibrary/Models/JsonSourceGenerationContext.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace OscQueryLibrary.Models;
4+
5+
[JsonSerializable(typeof(HostInfo))]
6+
[JsonSerializable(typeof(HostInfo.ExtensionsNode))]
7+
[JsonSerializable(typeof(HostInfo.OscTransportType))]
8+
[JsonSerializable(typeof(RootNode))]
9+
[JsonSerializable(typeof(AvatarContents))]
10+
[JsonSerializable(typeof(OscParameterNode))]
11+
[JsonSerializable(typeof(OscParameterNodeEnd<>))]
12+
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, WriteIndented = true, AllowTrailingCommas = true)]
13+
internal partial class ModelsSourceGenerationContext : JsonSerializerContext;

OscQueryLibrary/OscQueryLibrary.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
<PackageProjectUrl>https://github.com/Natsumi-sama/OscQueryLibrary</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/Natsumi-sama/OscQueryLibrary</RepositoryUrl>
1515
<PackageTags>osc async oscquery open-sound-control</PackageTags>
16-
<AssemblyVersion>1.0.0.0</AssemblyVersion>
17-
<FileVersion>1.0.0.0</FileVersion>
16+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
17+
<FileVersion>1.1.0.0</FileVersion>
1818
<NeutralLanguage>en</NeutralLanguage>
19-
<Version>1.0.0</Version>
19+
<Version>1.1.0</Version>
2020
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageReadmeFile>README.md</PackageReadmeFile>

OscQueryLibrary/OscQueryServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public OscQueryServer(string serviceName, IPAddress ipAddress)
6363
.WithModule(new ActionModule("/", HttpVerbs.Get,
6464
ctx => ctx.SendStringAsync(
6565
ctx.Request.RawUrl.Contains("HOST_INFO")
66-
? JsonSerializer.Serialize(_hostInfo, JsonSourceGenerationContext.Default.HostInfo)
67-
: JsonSerializer.Serialize(_queryData, JsonSourceGenerationContext.Default.RootNode), MediaTypeNames.Application.Json, Encoding.UTF8)));
66+
? JsonSerializer.Serialize(_hostInfo, ModelsSourceGenerationContext.Default.HostInfo!)
67+
: JsonSerializer.Serialize(_queryData, ModelsSourceGenerationContext.Default.RootNode!), MediaTypeNames.Application.Json, Encoding.UTF8)));
6868

6969
// mDNS
7070
_multicastService = new MulticastService
@@ -169,7 +169,7 @@ private async Task FoundNewVrcClient(IPAddress ipAddress, int port)
169169
try
170170
{
171171
response = await Client.GetStringAsync(url);
172-
var rootNode = JsonSerializer.Deserialize(response, JsonSourceGenerationContext.Default.HostInfo);
172+
var rootNode = JsonSerializer.Deserialize(response, ModelsSourceGenerationContext.Default.HostInfo);
173173
if (rootNode?.OscPort == null)
174174
{
175175
Logger.Error("OSCQueryHttpClient: Error no OSC port found");
@@ -204,7 +204,7 @@ private async Task FetchJsonFromVrc(IPAddress ipAddress, int port)
204204
{
205205
response = await Client.GetStringAsync(url);
206206

207-
var rootNode = JsonSerializer.Deserialize(response, JsonSourceGenerationContext.Default.RootNode);
207+
var rootNode = JsonSerializer.Deserialize(response, ModelsSourceGenerationContext.Default.RootNode);
208208
if (rootNode?.Contents?.Avatar?.Contents?.Parameters?.Contents == null)
209209
{
210210
Logger.Debug("OSCQueryHttpClient: Error no parameters found");

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var localHostServer = new OscQueryServer(
2525
);
2626
localHostServer.FoundVrcClient += FoundVrcClient; // event on vrc discovery
2727
localHostServer.ParameterUpdate += UpdateAvailableParameters; // event on parameter list update
28+
localHostServer.Start(); // this is required to start the service, no events will fire without this.
2829
2930
// listen for VRC on every network interface (Quest only)
3031
var host = await Dns.GetHostEntryAsync(Dns.GetHostName());
@@ -40,7 +41,7 @@ foreach (var ip in host.AddressList)
4041

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

4647
private static Task FoundVrcClient(OscQueryServer oscQueryServer, IPEndPoint ipEndPoint)

0 commit comments

Comments
 (0)