Table of Contents

Class NearbyOptions

Namespace
Plugin.Maui.NearbyConnectivity
Assembly
Plugin.Maui.NearbyConnectivity.dll

Configures nearby connectivity: display identity, service discovery, timeouts, and platform-specific behavior.

public sealed class NearbyOptions
Inheritance
NearbyOptions
Inherited Members

Examples

builder.Services.AddNearbyConnectivity(options =>
{
    options.ServiceId = "cardtable";                // required, identical on every device
    options.OfferWindow = TimeSpan.FromSeconds(30);
});

Remarks

Configure this type in the delegate passed to AddNearbyConnectivity(IServiceCollection, Action<NearbyOptions>). The plugin validates the options and captures an immutable copy before that call returns. Changing a property afterward has no effect on the session.

Properties

Android

Gets the Android-specific settings.

public NearbyAndroidOptions Android { get; }

Property Value

NearbyAndroidOptions

The Android options. Never null.

Remarks

Get-only, so the returned instance is configured in place and never replaced. See NearbyAndroidOptions for why it exists on every target framework.

DiscoveryRefreshInterval

Gets or sets how often discovery is restarted to drop devices that have gone away without the platform reporting it.

public TimeSpan? DiscoveryRefreshInterval { get; set; }

Property Value

TimeSpan?

The interval between discovery passes, or null to never restart. The default is null.

Remarks

After each restart, devices the new pass does not re-report are removed. A device that is connected, or mid-handshake, is never removed no matter how long it has been quiet.

The default is null: discovery never restarts on its own. Set an interval to opt in, where lower values detect departures sooner at the cost of more frequent radio work.

FileTransferInactivityTimeout

Gets or sets how long a file transfer may report no progress before it is considered stalled and is abandoned.

public TimeSpan? FileTransferInactivityTimeout { get; set; }

Property Value

TimeSpan?

The interval to wait between progress updates. The default is 10 seconds. Set this to null to disable the check.

Remarks

When this interval elapses, the pending SendFileAsync call throws NearbyTransferTimeoutException.

This value covers outbound transfers only. An inbound transfer that stops making progress has no time limit. To bound one, watch InboundTransfersAsync(CancellationToken) and call CancelInboundTransferAsync(long).

An inbound file is copied out of the platform's own storage before it reaches the application, and disposal waits for a copy that is still running. That wait has a fixed internal bound of a few seconds, so disposing a session during a large inbound transfer can take that much longer to return.

OfferWindow

Gets or sets how long a connection offer made by ConnectAsync(CancellationToken) lives, on both ends.

public TimeSpan OfferWindow { get; set; }

Property Value

TimeSpan

The offer's lifetime, measured from the call. The default is 2 minutes, and the longest permitted value is 30 minutes, the same bound a remote device applies to the window it is handed. There is no unbounded setting: InfiniteTimeSpan, and anything above the bound, is rejected when the options are validated. Waiting past the point the remote device has already discarded the offer could only end in a wait nothing will answer.

Remarks

The offer's one deadline, not a local patience setting, which is why this is a window rather than a timeout. The value is declared to the remote device with the request itself, so the remote prompt (ExpiresAt) and an accepted handshake expire at the same moment. A small value also gives the remote user a small decision window.

A request answered by a consent policy rather than by a person is bounded separately: the handshake gets 30 seconds, because a policy that answers on the application's behalf removes the deciding from what the window covers. See SetConsent(NearbyConsentPolicy, Func<NearbyDevice, CancellationToken, ValueTask<bool?>>?).

The window covers the request reaching the remote device, the remote user deciding, and the handshake completing. NearbyConnectException with TimedOut is thrown when the window elapses, and the device returns to Visible.

The plugin enforces this itself on both platforms, and there is no unbounded setting. Because the value is declared on the wire, a remote advertiser learns it. It carries no identity data, but a distinctive value is mildly fingerprintable.

See Also

Presence

Gets or sets what nearby devices see for this device before any connection exists.

public NearbyPresence Presence { get; set; }

Property Value

NearbyPresence

The presence to advertise and to send with every connection request. The default is this device's own name with empty info. Never null.

Remarks

Broadcast in the clear and unauthenticated — see NearbyPresence. Change it after startup with SetPresence(NearbyPresence).

ServiceId

Gets or sets the service identifier that devices use to find one another.

public string ServiceId { get; set; }

Property Value

string

The service identifier. This property has no default and must be set explicitly, on every platform: a derived default would make every application built on this plugin discoverable to every other one.

Remarks

Only devices configured with the same service identifier discover one another.

The identifier must be 1 to 15 characters of ASCII lowercase letters, digits, and hyphens, containing at least one letter, with no leading, trailing, or adjacent hyphens: for example, "nearbychat". Registration fails with a descriptive error if the value does not meet those rules, on every platform, so a configuration that works in development cannot fail on a user's device.

This is not a Bonjour _name._tcp service type. An iOS application also declares the longer Bonjour form in its Info.plist under NSBonjourServices; both are required and they take different forms. See NSBonjourServices.

See Also