Ditto 4.8.0
Loading...
Searching...
No Matches
DittoSDK.DittoPresence Class Reference

The entrypoint for all actions that relate presence of other peers known by the current peer, either directly or through other peers. More...

Inherits Drop.

Public Member Functions

DittoPresenceObserver Observe (Action< DittoPresenceGraph > callback)
 Request information about Ditto peers in range of this device. This method returns an observer which should be held as long as updates are required. A newly registered observer will have a peers update delivered to it immediately. From then on it will be invoked repeatedly when Ditto devices come and go, or the active connections to them change.
 
DittoPresenceGraph Exec ()
 Request information about Ditto peers in range of this device.
 
void SetPeerMetadata (Dictionary< string, object > peerMetadata)
 Set arbitrary metadata to be associated with the current peer.
 
void SetPeerMetadataJsonString (string jsonString)
 Set arbitrary metadata formatted as JSON to be associated with the current peer.
 

Protected Member Functions

override void Dispose (bool disposing)
 

Properties

Dictionary< string, object > PeerMetadata [get]
 Metadata associated with the current peer.
 
string PeerMetadataJsonString [get]
 Metadata associated with the current peer as a JSON string.
 
Func< DittoConnectionRequest, Task< DittoConnectionRequestAuthorization > > ConnectionRequestHandler [get, set]
 Set this handler to control which peers in a Ditto mesh can connect to the current peer.
 
DittoPresenceGraph Graph [get]
 Returns the current presence graph capturing all known peers and connections between them.
 

Detailed Description

The entrypoint for all actions that relate presence of other peers known by the current peer, either directly or through other peers.

You don't create one directly but can access it from a particular Ditto instance via its Presence property.

Member Function Documentation

◆ Exec()

DittoPresenceGraph DittoSDK.DittoPresence.Exec ( )
inline

Request information about Ditto peers in range of this device.

Returns
A DittoPresenceGraph instance.

◆ Observe()

DittoPresenceObserver DittoSDK.DittoPresence.Observe ( Action< DittoPresenceGraph > callback)
inline

Request information about Ditto peers in range of this device. This method returns an observer which should be held as long as updates are required. A newly registered observer will have a peers update delivered to it immediately. From then on it will be invoked repeatedly when Ditto devices come and go, or the active connections to them change.

Parameters
callbackThe Action that will be invoked when there is a presence update.
Returns
A DittoPeersObserver instance, which must be retained to continue receiving callback updates.

◆ SetPeerMetadata()

void DittoSDK.DittoPresence.SetPeerMetadata ( Dictionary< string, object > peerMetadata)
inline

Set arbitrary metadata to be associated with the current peer.

The metadata must not exceed 4 KB in size when JSON-encoded.

This is a convenience method that wraps SetPeerMetadataJsonString(string)(byte[])

Parameters
peerMetadataA dictionary containing metadata.Keys must be strings and values must be JSON-compatible.
Exceptions
DittoNotJsonCompatibleExceptionIf dictionary contains a value that is not JSON-compatible.
DittoSizeLimitExceededValidationExceptionIf dictionary encoded as JSON exceeds the maximum size as given by 4 KB.
See also
PeerMetadata

◆ SetPeerMetadataJsonString()

void DittoSDK.DittoPresence.SetPeerMetadataJsonString ( string jsonString)
inline

Set arbitrary metadata formatted as JSON to be associated with the current peer.

The metadata must not exceed 4 KB in size.

Parameters
jsonStringJSON metadata.
Exceptions
DittoNotADictionaryValidationExceptionIf jsonData decodes to an object that is not a dictionary.
DittoSizeLimitExceededValidationExceptionIf dictionary encoded as JSON exceeds the maximum size as given by 4 KB.
DittoInvalidJsonExceptionIf jsonString is not valid JSON.
See also
PeerMetadata

Property Documentation

◆ ConnectionRequestHandler

Func<DittoConnectionRequest, Task<DittoConnectionRequestAuthorization> > DittoSDK.DittoPresence.ConnectionRequestHandler
getset

Set this handler to control which peers in a Ditto mesh can connect to the current peer.

Each peer in a Ditto mesh will attempt to connect to other peers that it can reach. By default, the mesh will try and establish connections that optimize for the best overall connectivity between peers. However, you can set this handler to assert some control over which peers you connect to.

If set, this handler is called for every incoming connection request from a remote peer and is passed the other peer's PeerKey, PeerMetadata, and IdentityServiceMetadata. The handler can then accept or reject the request by returning an according DittoConnectionRequestAuthorization value. When the connection request is rejected, the remote peer may retry the connection request after a short delay.

Connection request handlers must reliably respond to requests within a short time. If a handler takes too long to respond or throws an exception, the connection request will be denied. The response currently times out after 10 seconds, but this exact value may be subject to change in future releases.

Note
The handler is called from a different thread.
See also
PeerMetadata

◆ PeerMetadata

Dictionary<string, object> DittoSDK.DittoPresence.PeerMetadata
get

Metadata associated with the current peer.

Other peers in the same mesh can access this user-provided dictionary of metadata via the presence graph at DittoPresence.Graph and when evaluating connection requests using DittoPresence.ConnectionRequestHandler. Use SetPeerMetadata(Dictionary<string, object>) or SetPeerMetadataJsonString(string) to set this value.

This is a convenience property that wraps PeerMetadataJsonString

◆ PeerMetadataJsonString

string DittoSDK.DittoPresence.PeerMetadataJsonString
get

Metadata associated with the current peer as a JSON string.

Other peers in the same mesh can access this user-provided dictionary of metadata via the presence graph at DittoPresence.Graph and when evaluating connection requests using DittoPresence.ConnectionRequestHandler. Use SetPeerMetadata(Dictionary<string, object>) or SetPeerMetadataJsonString(string) to set this value.

See also
PeerMetadata