RemoteConnection
@RequiresApi(value = 26) interface RemoteConnection
A connection to a remote device, used for sending and receiving payloads. Multiple connections can exist between the same pair of devices, and they will share the underlying physical connection. Developers can use this connection to send and receive payloads between devices.
Implementations are not required to be thread safe.
Summary
Public fields |
|
---|---|
abstract @NonNull ConnectionType |
The type of the connection. |
abstract boolean |
|
abstract @NonNull Participant |
The participant this remote connection is connected to. |
Public methods |
|
---|---|
abstract void |
Closes the connection, cleaning up any resources allocated for it. |
abstract @NonNull ListenableFuture<Void> |
closeFuture(String reason) Java-compatible version of |
default @NonNull ListenableFuture<Void> |
Java-compatible version of |
abstract void |
registerReceiver(@NonNull ConnectionReceiver receiver) Registers the given connection receiver with this channel. |
abstract @NonNull Result<Unit> |
Enqueues bytes to be sent across the channel. |
abstract @NonNull ListenableFuture<Void> |
sendFuture(@NonNull byte[] bytes) Java-compatible version of |
abstract void |
unregisterReceiver(@NonNull ConnectionReceiver receiver) Unregisters a given receiver from the remote device. |
Public fields
participant
abstract @NonNull Participant participant
The participant this remote connection is connected to.
Public methods
close
abstract void close(String reason)
Closes the connection, cleaning up any resources allocated for it.
If called when the connection is already closed, this method will be a no-op.
Parameters | |
---|---|
String reason |
An optional reason field telling the remote participant why the connection is closed. |
See also | |
---|---|
onConnectionClosed |
closeFuture
abstract @NonNull ListenableFuture<Void> closeFuture(String reason)
Java-compatible version of close
.
registerReceiver
abstract void registerReceiver(@NonNull ConnectionReceiver receiver)
Registers the given connection receiver with this channel.
Throws | |
---|---|
com.google.ambient.crossdevice.connections.ConnectionsException com.google.ambient.crossdevice.connections.ConnectionsException |
if the connection is closed. |
send
abstract @NonNull Result<Unit> send(@NonNull byte[] bytes)
Enqueues bytes to be sent across the channel.
Bytes are sent in the order they are enqueued, and this function completes when the payload is successfully enqueued. Note that completion of this method does not mean the remote device has received or processed the payload message.
Returns | |
---|---|
@NonNull Result<Unit> |
|
sendFuture
abstract @NonNull ListenableFuture<Void> sendFuture(@NonNull byte[] bytes)
Java-compatible version of send
.
unregisterReceiver
abstract void unregisterReceiver(@NonNull ConnectionReceiver receiver)
Unregisters a given receiver from the remote device.