Table of Contents

Class NearbyPresence

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

What a device shows to every other device in range before any connection exists: a display name and up to MaxInfoBytes bytes of application-defined information.

public sealed record NearbyPresence : IEquatable<NearbyPresence>
Inheritance
NearbyPresence
Implements
Inherited Members

Examples

// Outbound: application-defined bytes, at most MaxInfoBytes.
options.Presence = new() { Info = "table:T3"u8.ToArray() };

// Inbound: the same bytes, unparsed and unverified.
var table = Encoding.UTF8.GetString(device.Presence.Info.Span);

Remarks

Public. Both members are broadcast in the clear to every device in range that knows the ServiceId, before encryption or consent apply. Never put a secret, a token, or personal data in either one.

Unauthenticated. Anyone can claim anything. A remote presence is a label to filter and display by, never a credential. See docs/security.md for the membership-tag recipe and its limits.

As sent. The plugin bounds the length of both members and rewrites neither, so a remote DisplayName may contain bidi controls, separators, or nothing at all, and a remote Info is untrusted input to size-check and validate before parsing.

Constructors

NearbyPresence()

Initializes a new presence with this device's own name and no info.

public NearbyPresence()

Fields

MaxDisplayNameBytes

The UTF-8 byte cap on DisplayName, local or remote.

public const int MaxDisplayNameBytes = 63

Field Value

int

Remarks

What the plugin's connect request frame reserves for a name. The same cap applies on every platform, so a name that advertises on one advertises on all.

MaxInfoBytes

The cap on Info, in bytes.

public const int MaxInfoBytes = 57

Field Value

int

Remarks

What is left of the plugin's connect request frame once its header, the offer window, and a maximum-length name are accounted for. Stated as a constant so an application that serializes a schema into Info can assert against it.

Properties

DisplayName

Gets the name nearby devices see for this device.

public string DisplayName { get; init; }

Property Value

string

1 to MaxDisplayNameBytes UTF-8 bytes. The default is this device's own name, cut to the cap.

Exceptions

ArgumentException

The value is null, empty, or over MaxDisplayNameBytes UTF-8 bytes. Never silently shortened: a name you cannot see the library change is one you would have to discover from someone else's screen.

Info

Gets the application-defined information nearby devices see for this device.

public ReadOnlyMemory<byte> Info { get; init; }

Property Value

ReadOnlyMemory<byte>

At most MaxInfoBytes bytes, opaque to the plugin. The default is empty.

Remarks

The bytes are copied on assignment, so an array mutated afterwards cannot change what is advertised. The application owns the encoding: "…"u8.ToArray() in and Encoding.UTF8.GetString(span) out for text, or any serializer that fits the budget.

Exceptions

ArgumentException

The value is longer than MaxInfoBytes bytes.

Methods

Equals(NearbyPresence?)

Determines whether the specified presence has the same name and the same info bytes.

public bool Equals(NearbyPresence? other)

Parameters

other NearbyPresence

The presence to compare with this one.

Returns

bool

true when the names are ordinally equal and the info bytes are the same sequence.

Remarks

Written out because the generated version would compare Info by reference, so two presences built from equal but distinct arrays would not be equal.

GetHashCode()

Returns the hash code for this presence.

public override int GetHashCode()

Returns

int

A hash code derived from the name and the info bytes.

See Also