feat: add publisher and browser client SDK (#9)
quality-gate / quality (push) Successful in 1m6s
quality-gate / quality (push) Successful in 1m6s
Closes #9
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# FinalFactory.Rendezvous.Client
|
||||
|
||||
Godot-independent .NET publisher and session-browser SDK for Rendezvous v1.
|
||||
The package targets `netstandard2.1` and uses a caller-owned `HttpClient`.
|
||||
|
||||
```csharp
|
||||
using FinalFactory.Rendezvous.Client;
|
||||
using FinalFactory.Rendezvous.Contracts;
|
||||
|
||||
using HttpClient http = new()
|
||||
{
|
||||
BaseAddress = new Uri("https://rendezvous.example/"),
|
||||
};
|
||||
|
||||
string publisherCredential = Environment.GetEnvironmentVariable(
|
||||
"RENDEZVOUS_PUBLISHER_CREDENTIAL")
|
||||
?? throw new InvalidOperationException("Publisher credential is not configured.");
|
||||
CancellationToken cancellationToken = default;
|
||||
RendezvousPublisherClient publisher = new(http);
|
||||
RendezvousClientResult<PublishedSession> registered = await publisher.RegisterAsync(
|
||||
new RegisterSessionRequest
|
||||
{
|
||||
IdempotencyKey = Guid.NewGuid().ToString("N"),
|
||||
GameId = new("space-game"),
|
||||
EnvironmentId = new("production"),
|
||||
RegionId = new("eu-central"),
|
||||
ProtocolVersion = 7,
|
||||
BuildVersion = "1.0.0",
|
||||
DisplayName = "My server",
|
||||
Visibility = ListingVisibility.Public,
|
||||
Capacity = new() { CurrentPlayers = 1, MaximumPlayers = 8 },
|
||||
},
|
||||
publisherCredential,
|
||||
cancellationToken);
|
||||
if (!registered.IsSuccess || registered.Value is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Registration failed: {registered.Error} ({registered.Message})");
|
||||
}
|
||||
```
|
||||
|
||||
Load `publisherCredential` from the game's deployment secret boundary; never
|
||||
embed it in a client build or source control. A successful registration returns a
|
||||
`PublishedSession` containing the lease and host-presence capabilities.
|
||||
|
||||
Lease renewal is explicit and caller-controlled:
|
||||
|
||||
```csharp
|
||||
PublishedSession session = registered.Value;
|
||||
await using SessionLeaseMaintainer maintainer = publisher.CreateLeaseMaintainer(
|
||||
session,
|
||||
publisherCredential);
|
||||
LeaseMaintenanceResult stopped = await maintainer.RunAsync(cancellationToken);
|
||||
```
|
||||
|
||||
Creating the maintainer does not start background work. Await its run and dispose
|
||||
it when hosting stops. Use `IRendezvousPublisherClient` and
|
||||
`IRendezvousSessionBrowserClient` as injection seams in game tests. The SDK disposes
|
||||
the requests and responses it creates but never disposes the supplied `HttpClient`.
|
||||
|
||||
See the repository's ADR 0007 for retry, paging, ownership, and failure semantics.
|
||||
Reference in New Issue
Block a user