Skip to content

Commit 464a6fd

Browse files
authored
Merge pull request #64 from shun20010921/fix/issue-40-withdefaults-usage
2 parents bc2d69d + 4b61c37 commit 464a6fd

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Readme.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ This library does not yet return limited attributes based on query strings, like
2222
## ⚡️ Basic Use
2323

2424
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).
25-
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.
25+
2. Construct a new OSCQuery service.
26+
- **Important**: If you want to customize settings (name, ports, etc.), configure them **before** calling `WithDefaults()`, as `WithDefaults()` immediately starts the HTTP server and advertising.
27+
```csharp
28+
var service = new OSCQueryServiceBuilder()
29+
.WithTcpPort(Extensions.GetAvailableTcpPort())
30+
.WithUdpPort(Extensions.GetAvailableUdpPort())
31+
.WithServiceName("MyService")
32+
.WithDefaults()
33+
.Build();
34+
```
35+
2636
3. You should now be able to visit `http://localhost:tcpPort` in a browser and see raw JSON describing an empty root node.
2737
- 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.
2838
4. You can also visit `http://localhost:tcpPort?HOST_INFO` to get information about the supported attributes of this OSCQuery Server.

getting-started.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The format is always `new OSCQueryServiceBuilder()`, followed by all the things
2727
There's a lot of options you _can_ configure if you want more control over what happens. The additional methods are listed below. Note that if you do not add any fluent options, then `WithDefaults()` is called for you automatically.
2828

2929
* WithDefaults()
30+
* **Important**: This immediately starts the HTTP server and advertising. Configure all settings (ports, names, etc.) **before** calling this method.
3031
* Sets up Discovery, Advertising and HTTP serving using default names and ports.
3132
* WithTcpPort(int port)
3233
* Set the TCP port you want to use for serving the HTTP endpoints. Defaults to any available open TCP port.
@@ -53,15 +54,16 @@ There's a lot of options you _can_ configure if you want more control over what
5354
* AddListenerForServiceType(Action\<OSCQueryServiceProfile\> listener, OSCQueryServiceProfile.ServiceType type)
5455
* Adds a listener which will be sent OSCQueryServiceProfiles for newly-discovered OSC or OSCQuery services.
5556

56-
You can can add these onto `.WithDefaults()` if you want _almost_ all the defaults. For example, this code will have all the defaults, but find the first available TCP port instead of 8060, and uses the name "MyService" instead of "OSCQueryService".
57+
**Important**: You must configure settings **before** calling `.WithDefaults()`, as `WithDefaults()` immediately starts the HTTP server and advertising. Settings configured after `WithDefaults()` will not be applied.
5758

5859
```csharp
5960
var oscQuery = new OSCQueryServiceBuilder()
60-
.WithDefaults()
6161
.WithTcpPort(Extensions.GetAvailableTcpPort())
6262
.WithServiceName("MyService")
63+
.WithDefaults()
6364
.Build();
6465
```
66+
6567
## A Simple Example
6668

6769
A minimal example for a working OSCQuery Service could look like this:
@@ -71,10 +73,10 @@ var tcpPort = Extensions.GetAvailableTcpPort();
7173
var udpPort = Extensions.GetAvailableUdpPort();
7274

7375
var oscQuery = new OSCQueryServiceBuilder()
74-
.WithDefaults()
7576
.WithTcpPort(tcpPort)
7677
.WithUdpPort(udpPort)
7778
.WithServiceName("MyService")
79+
.WithDefaults() // Configure settings BEFORE calling WithDefaults()
7880
.Build();
7981

8082
// Manually logging the ports to see them without a logger

0 commit comments

Comments
 (0)