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 functions |
|
---|---|
suspend Unit |
Closes the connection, cleaning up any resources allocated for it. |
ListenableFuture<Void?> |
closeFuture(reason: String?) Java-compatible version of |
open ListenableFuture<Void?> |
Java-compatible version of |
Unit |
registerReceiver(receiver: ConnectionReceiver) Registers the given connection receiver with this channel. |
suspend Result<Unit> |
Enqueues bytes to be sent across the channel. |
ListenableFuture<Void?> |
sendFuture(bytes: ByteArray) Java-compatible version of |
Unit |
unregisterReceiver(receiver: ConnectionReceiver) Unregisters a given receiver from the remote device. |
Public properties |
|
---|---|
ConnectionType |
The type of the connection. |
Boolean |
|
Participant |
The participant this remote connection is connected to. |
Public functions
close
suspend fun close(reason: String? = null): Unit
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 | |
---|---|
reason: String? = null |
An optional reason field telling the remote participant why the connection is closed. |
See also | |
---|---|
onConnectionClosed |
closeFuture
fun closeFuture(reason: String?): ListenableFuture<Void?>
Java-compatible version of close
.
registerReceiver
fun registerReceiver(receiver: ConnectionReceiver): Unit
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
suspend fun send(bytes: ByteArray): Result<Unit>
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 | |
---|---|
Result<Unit> |
|
sendFuture
fun sendFuture(bytes: ByteArray): ListenableFuture<Void?>
Java-compatible version of send
.
unregisterReceiver
fun unregisterReceiver(receiver: ConnectionReceiver): Unit
Unregisters a given receiver from the remote device.