Participant
@RequiresApi(value = 26) interface Participant
An opaque handle that represents a participant in a cross device experience. This participant is expected to be passed back to other Cross device SDK components to identify the desired participant.
Participants are not stable across experiences. If the user starts another experience by selecting the same receiving device, the resulting Participant
instance will still be different.
This class is not thread safe.
Summary
Public fields |
|
---|---|
abstract @NonNull List<@NonNull RemoteConnection> |
The list of connections connected to this participant. |
abstract @NonNull CharSequence |
A user-friendly name of the selected device. |
Public methods |
|
---|---|
default @NonNull Result<@NonNull RemoteConnection> |
acceptConnection(@NonNull String channelName) Accepts an incoming connection from a remote device. |
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> |
acceptConnectionFuture(@NonNull String channelName) Java-compatible version of |
abstract void |
close() Closes this participant and all the associated |
abstract @NonNull ListenableFuture<Void> |
Java-compatible version of |
default @NonNull Result<@NonNull RemoteConnection> |
openConnection(@NonNull String channelName) Returns a remote channel to send and receive messages. |
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> |
openConnectionFuture(@NonNull String channelName) Java-compatible version of |
Public fields
connections
abstract @NonNull List<@NonNull RemoteConnection> connections
The list of connections connected to this participant. This list includes both connections opened and accepted.
displayName
abstract @NonNull CharSequence displayName
A user-friendly name of the selected device. This is the same name that the user saw in the device picker, for example, "Ryan's Pixel 6".
Public methods
acceptConnection
default @NonNull Result<@NonNull RemoteConnection> acceptConnection(@NonNull String channelName)
Accepts an incoming connection from a remote device.
This function completes as soon as the connection channel is created, even if there are no listeners registered for this connection on the receiving device yet. Messages can be sent as soon as the connection is created, but they may be queued until a listener is registered.
It is expected that this call will fail for a fraction of cases due to circumstances outside of the application and system's control, such as poor signal strength or wireless interference. Therefore, this method returns a Result
and callers should always check and handle the failure cases.
If the connection is not created successfully within an implementation-defined timeout (typically on the order of tens of seconds), the result will fail with the code ConnectionsException.TIMEOUT
.
Callers should close the connection after using it by calling either RemoteConnection.close
or Participant.close
.
Parameters | |
---|---|
@NonNull String channelName |
A string identifying the channel. This string must be the same on this device and the remote device indicated by |
acceptConnectionFuture
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> acceptConnectionFuture(@NonNull String channelName)
Java-compatible version of acceptConnection
.
close
abstract void close()
Closes this participant and all the associated RemoteConnection
s. This participant should not be used after calling this method.
closeFuture
abstract @NonNull ListenableFuture<Void> closeFuture()
Java-compatible version of close
.
openConnection
default @NonNull Result<@NonNull RemoteConnection> openConnection(@NonNull String channelName)
Returns a remote channel to send and receive messages.
This function completes as soon as the connection channel is created, even if there are no listeners registered for this connection on the receiving device yet. Messages can be sent as soon as the connection is created, but they may be queued until a listener is registered.
It is expected that this call will fail for a fraction of cases due to circumstances outside of the application and system's control, such as poor signal strength or wireless interference. Therefore, this method returns a Result
and callers should always check and handle the failure cases.
If the connection is not created successfully within an implementation-defined timeout (typically on the order of tens of seconds), the result will fail with the code ConnectionsException.TIMEOUT
.
Callers should close the connection after using it by calling either RemoteConnection.close
or Participant.close
.
Parameters | |
---|---|
@NonNull String channelName |
A string identifying the channel. This string must be the same on this device and the remote device from which this |
openConnectionFuture
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> openConnectionFuture(@NonNull String channelName)
Java-compatible version of openConnection
.