public interface NearbyBridge
Internal service-provider interface implemented by each platform port to
carry the com.codename1.nearby API onto the native short-range stacks:
Apple’s Nearby Interaction, MultipeerConnectivity and AccessorySetupKit,
Android’s Jetpack UWB, Nearby Connections and CompanionDeviceManager.
Application code never touches this interface. It is obtained by the
com.codename1.nearby packages from
com.codename1.ui.Display#getNearbyBridge(), and the base
implementation returns null – which is why the public API degrades to
a well-behaved NOT_SUPPORTED on ports that implement nothing, and why
application code needs no platform if statements.
Everything here is primitives, strings and byte arrays
A port may be Objective-C reached through ParparVM, where constructing a
Java object is expensive and easy to get wrong. So no method on this
interface takes or returns a framework type: enums cross as their
ordinals, capability sets cross as bit masks, and structured records
cross as tab-delimited strings built by
com.codename1.impl.nearby.NearbyWire.
Asynchrony is by request id, and every operation must answer
Operations that can fail take a requestId allocated by the caller and
answer exactly once by calling the matching deliver... entry point on
the public class. An operation that never answers is worse than one
that fails: the caller holds an AsyncResource that will never settle
and has no way to find out. A port that cannot start something must
still report the failure.
Unsolicited events – ranging updates, endpoint discoveries, presence changes – carry the handle or endpoint id they belong to instead of a request id. Every entry point may be called from any thread; they marshal to the EDT themselves.
Fields
Methods
Field details
CAPABILITY_DISTANCE
public static final int CAPABILITY_DISTANCE = 1getRangingCapabilities() bit: precise distance is measurable.CAPABILITY_DIRECTION
public static final int CAPABILITY_DIRECTION = 2getRangingCapabilities() bit: horizontal direction is measurable.CAPABILITY_ELEVATION
public static final int CAPABILITY_ELEVATION = 4getRangingCapabilities() bit: vertical direction is measurable.CAPABILITY_CAMERA_ASSISTANCE
public static final int CAPABILITY_CAMERA_ASSISTANCE = 8getRangingCapabilities() bit: camera assistance is available.CAPABILITY_ACCESSORY
public static final int CAPABILITY_ACCESSORY = 16getRangingCapabilities() bit: third-party UWB accessories can be
ranged.CAPABILITY_BACKGROUND
public static final int CAPABILITY_BACKGROUND = 32getRangingCapabilities() bit: ranging continues in the background.PERMISSION_RANGING
public static final int PERMISSION_RANGING = 1requestPermissions bit for NearbyPermission.RANGING.PERMISSION_DISCOVERY
public static final int PERMISSION_DISCOVERY = 2requestPermissions bit for NearbyPermission.DISCOVERY.PERMISSION_ADVERTISE
public static final int PERMISSION_ADVERTISE = 4requestPermissions bit for NearbyPermission.ADVERTISE.PERMISSION_CONNECT
public static final int PERMISSION_CONNECT = 8requestPermissions bit for NearbyPermission.CONNECT.PAYLOAD_BYTES
public static final int PAYLOAD_BYTES = 0sendPayload type: the payload is the bytes argument.PAYLOAD_FILE
public static final int PAYLOAD_FILE = 1sendPayload type: the payload is the file at path.Method details
isRangingSupported
public abstract boolean isRangingSupported()Returns
com.codename1.nearby.ranging has a real implementationisCompanionSupported
public abstract boolean isCompanionSupported()Returns
com.codename1.nearby.companion has a real implementationisTransportSupported
public abstract boolean isTransportSupported()Returns
com.codename1.nearby.transport has a real implementationgetRangingAvailability
public abstract int getRangingAvailability()NearbyAvailability ordinal.
A port backed by a simulation must answer LOCAL_ONLY rather than
AVAILABLE, so an app can tell the developer their peers are not
real.Returns
com.codename1.nearby.NearbyAvailability constantgetCompanionAvailability
public abstract int getCompanionAvailability()NearbyAvailability ordinal.Returns
com.codename1.nearby.NearbyAvailability constantgetTransportAvailability
public abstract int getTransportAvailability()NearbyAvailability
ordinal.Returns
com.codename1.nearby.NearbyAvailability constantrequestPermissions
public abstract void requestPermissions(int requestId, int permissionBits)Requests the platform permissions behind the given
NearbyPermission bits, answering with
com.codename1.nearby.ranging.Ranging#deliverPermissionResult.
A port that needs no permission for the bits it was given must still answer, reporting them granted.
Parameters
requestIdint- the id to answer with
permissionBitsint- an OR of the
PERMISSION_constants
getRangingCapabilities
public abstract int getRangingCapabilities()CAPABILITY_ constants.Returns
prepareRangingSession
public abstract void prepareRangingSession(int requestId, int sessionHandle, boolean controller)Allocates a platform ranging session and publishes its local token.
The port answers with
com.codename1.nearby.ranging.Ranging#deliverSessionPrepared on
success, passing back the same sessionHandle it was given, or with
Ranging#deliverRequestFailed on failure. The session is not ranging
yet – startRanging or startAccessoryRanging does that.
Parameters
requestIdint- the id to answer with
sessionHandleint- the handle every later call and event uses to name this session
controllerboolean- true for
RangingRole.CONTROLLER. Ports whose platform negotiates roles by itself ignore this.
startRanging
public abstract void startRanging(int requestId, int sessionHandle, byte[] peerToken)Starts ranging a peer whose token arrived out of band.
The token is the full encoded form from
com.codename1.nearby.ranging.RangingToken#toByteArray(); the port
validates that it was minted by this platform and fails the request
with NearbyError.INVALID_TOKEN when it was not.
Parameters
requestIdint- the id to answer with, via
Ranging#deliverSessionStarted sessionHandleint- the prepared session
peerTokenbyte[]- the peer’s encoded token
startAccessoryRanging
public abstract void startAccessoryRanging(int requestId, int sessionHandle, byte[] accessoryData)Starts ranging a third-party UWB accessory.
The port answers with
com.codename1.nearby.ranging.Ranging#deliverAccessoryConfiguration,
passing the bytes the app must send back to the accessory to make it
start ranging (Apple’s Nearby Interaction Accessory Protocol
requires this handshake). A platform with no such handshake answers
with an empty array rather than failing.
Parameters
requestIdint- the id to answer with
sessionHandleint- the prepared session
accessoryDatabyte[]- the configuration data the accessory published
stopRangingSession
public abstract void stopRangingSession(int sessionHandle)Parameters
sessionHandleint- the session to stop
associate
public abstract void associate(int requestId, int profile, boolean singleDevice, String[] filters)com.codename1.nearby.companion.CompanionDevices#deliverAssociated.Parameters
requestIdint- the id to answer with
profileint- the ordinal of a
com.codename1.nearby.companion.CompanionProfileconstant singleDeviceboolean- whether to associate without showing a list when exactly one device matches
filtersString[]- the encoded filters from
com.codename1.impl.nearby.NearbyWire, never null and possibly empty
getAssociations
public abstract String[] getAssociations()com.codename1.impl.nearby.NearbyWire.Returns
disassociate
public abstract void disassociate(int requestId, String associationId)com.codename1.nearby.companion.CompanionDevices#deliverRequestFailed
only on failure and
CompanionDevices#deliverDisassociated on success.Parameters
requestIdint- the id to answer with
associationIdString- the association to drop
startObservingPresence
public abstract boolean startObservingPresence(String associationId)Parameters
associationIdString- the association to watch
Returns
stopObservingPresence
public abstract void stopObservingPresence(String associationId)Parameters
associationIdString- the association to stop watching
getMaxPayloadSize
public abstract int getMaxPayloadSize()sendPayload accepts in one call.Returns
startAdvertising
public abstract void startAdvertising(int requestId, String serviceId, String localName, int strategy)com.codename1.nearby.transport.NearbyTransport#deliverRequestOk.Parameters
requestIdint- the id to answer with
serviceIdString- the service both ends agreed on
localNameString- the name to show peers
strategyint- the ordinal of a
com.codename1.nearby.transport.TransportStrategyconstant
stopAdvertising
public abstract void stopAdvertising()startDiscovery
public abstract void startDiscovery(int requestId, String serviceId, int strategy)NearbyTransport#deliverRequestOk. Sightings arrive
unsolicited through NearbyTransport#deliverEndpointFound.Parameters
requestIdint- the id to answer with
serviceIdString- the service both ends agreed on
strategyint- the ordinal of a
com.codename1.nearby.transport.TransportStrategyconstant
stopDiscovery
public abstract void stopDiscovery()requestConnection
public abstract void requestConnection(int requestId, String endpointId, String localName)NearbyTransport#deliverConnectionResult.Parameters
requestIdint- the id to answer with
endpointIdString- the endpoint to ask
localNameString- the name to show them
acceptConnection
public abstract void acceptConnection(int requestId, String endpointId)Parameters
requestIdint- the id to answer with
endpointIdString- the endpoint that asked
rejectConnection
public abstract void rejectConnection(String endpointId)Parameters
endpointIdString- the endpoint that asked
sendPayload
public abstract void sendPayload(int requestId, String[] endpointIds, int payloadId, int payloadType, byte[] bytes, String path)NearbyTransport#deliverPayloadProgress.Parameters
requestIdint- the id to answer with once the payload is handed to the platform
endpointIdsString[]- the recipients
payloadIdint- the id progress and cancellation use
payloadTypeintPAYLOAD_BYTESorPAYLOAD_FILEbytesbyte[]- the payload for
PAYLOAD_BYTES, otherwise null pathString- the file for
PAYLOAD_FILE, otherwise null
cancelPayload
public abstract void cancelPayload(int payloadId)Parameters
payloadIdint- the payload to cancel
disconnect
public abstract void disconnect(String endpointId)Parameters
endpointIdString- the endpoint to drop
stopAllTransport
public abstract void stopAllTransport()