Readonly
dittoThe Ditto instance this object belongs to.
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 ConnectionRequestAuthorization
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 timeout is currently 10 seconds but may be subject to change in future releases.
TypeError: if the given handler is not a function.
Returns the current presence graph capturing all known peers and connections between them.
This is a convenience property that wraps peerMetadataJSONString().
peerMetadataJSONString() for details.
Metadata associated with the current peer. Other peers in the same mesh can access this user-provided object of metadata via the presence graph and when evaluating connection requests using connectionRequestHandler().
Uses UTF-8 encoding.
peerMetadata() for a convenience property that provides access to parsed metadata.
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.
This is a convenience method that wraps setPeerMetadataJSONString().
DittoError validation/not-an-object
: if peerMetadata
is
not an object.
DittoError validation/not-json-compatible
: if
peerMetadata
is not JSON serializable.
DittoError validation/size-limit-exceeded
: if the size
limit for peerMetadata
has been exceeded.
setPeerMetadataJSONString() for details.
Set arbitrary metadata to be associated with the current peer.
The metadata must not exceed 4 KB in size when JSON-encoded.
JSON-encoded metadata.
DittoError validation/invalid-json
: if jsonString
does
not contain valid JSON.
DittoError validation/not-an-object
: if jsonString
does
not contain an object.
DittoError validation/size-limit-exceeded
: if the size
limit for jsonString
has been exceeded.
peerMetadataJSONString() for details on usage of metadata.
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 itspresence
property.