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
close(reason: String?)

Closes the connection, cleaning up any resources allocated for it.

ListenableFuture<Void?>
closeFuture(reason: String?)

Java-compatible version of close.

open ListenableFuture<Void?>

Java-compatible version of close.

Unit

Registers the given connection receiver with this channel.

suspend Result<Unit>
send(bytes: ByteArray)

Enqueues bytes to be sent across the channel.

ListenableFuture<Void?>

Java-compatible version of send.

Unit

Unregisters a given receiver from the remote device.

Public properties

ConnectionType

The type of the connection.

Boolean

true if this connection is closed.

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.

closeFuture

fun closeFuture(reason: String?): ListenableFuture<Void?>

Java-compatible version of close.

closeFuture

open fun closeFuture(): 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>

Result.success if the message was sent successfully, or a failed result with ConnectionsException if the connection is already closed.

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.

Public properties

connectionType

val connectionTypeConnectionType

The type of the connection.

isClosed

val isClosedBoolean

true if this connection is closed.

participant

val participantParticipant

The participant this remote connection is connected to.