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

true if this connection is closed.

abstract @NonNull Participant

The participant this remote connection is connected to.

Public methods

abstract void
close(String reason)

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

abstract @NonNull ListenableFuture<Void>

Java-compatible version of close.

default @NonNull ListenableFuture<Void>

Java-compatible version of close.

abstract void

Registers the given connection receiver with this channel.

abstract @NonNull Result<Unit>
send(@NonNull byte[] bytes)

Enqueues bytes to be sent across the channel.

abstract @NonNull ListenableFuture<Void>
sendFuture(@NonNull byte[] bytes)

Java-compatible version of send.

abstract void

Unregisters a given receiver from the remote device.

Public fields

connectionType

abstract @NonNull ConnectionType connectionType

The type of the connection.

isClosed

abstract boolean isClosed

true if this connection is closed.

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.

closeFuture

abstract @NonNull ListenableFuture<VoidcloseFuture(String reason)

Java-compatible version of close.

closeFuture

default @NonNull ListenableFuture<VoidcloseFuture()

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<Unitsend(@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>

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

sendFuture

abstract @NonNull ListenableFuture<VoidsendFuture(@NonNull byte[] bytes)

Java-compatible version of send.

unregisterReceiver

abstract void unregisterReceiver(@NonNull ConnectionReceiver receiver)

Unregisters a given receiver from the remote device.