@blackgersain/capacitor-nearby
v1.6.0
Published
Nearby connections capabilities
Readme
@blackgersain/capacitor-nearby
Nearby connections capabilities
Install
npm install @blackgersain/capacitor-nearby
npx cap syncAPI
initialize(...)startAdvertising(...)stopAdvertising()startDiscovery(...)stopDiscovery()requestConnection(...)acceptConnection(...)rejectConnection(...)sendPayload(...)disconnectFromEndpoint(...)disconnectFromAllEndpoints()setStrategy(...)addListener('onConnectionInitiated', ...)addListener('onConnectionResult', ...)addListener('onDisconnected', ...)addListener('onEndpointFound', ...)addListener('onEndpointLost', ...)addListener('onJsonReceived', ...)addListener('onFileReceived', ...)addListener('onStreamReceived', ...)addListener('onPayloadTransferUpdate', ...)removeAllListeners()- Interfaces
initialize(...)
initialize(options: { serviceId: string; }) => Promise<void>Initialize the plugin with service ID
| Param | Type |
| ------------- | ----------------------------------- |
| options | { serviceId: string; } |
startAdvertising(...)
startAdvertising(options: { endpointName: string; serviceId: string; }) => Promise<void>Start advertising with endpoint name
| Param | Type |
| ------------- | --------------------------------------------------------- |
| options | { endpointName: string; serviceId: string; } |
stopAdvertising()
stopAdvertising() => Promise<void>Stop advertising
startDiscovery(...)
startDiscovery(options: { serviceId: string; }) => Promise<void>Start discovering nearby endpoints
| Param | Type |
| ------------- | ----------------------------------- |
| options | { serviceId: string; } |
stopDiscovery()
stopDiscovery() => Promise<void>Stop discovering
requestConnection(...)
requestConnection(options: { endpointName: string; endpointId: string; }) => Promise<void>Request connection to an endpoint
| Param | Type |
| ------------- | ---------------------------------------------------------- |
| options | { endpointName: string; endpointId: string; } |
acceptConnection(...)
acceptConnection(options: { endpointId: string; }) => Promise<void>Accept connection from an endpoint
| Param | Type |
| ------------- | ------------------------------------ |
| options | { endpointId: string; } |
rejectConnection(...)
rejectConnection(options: { endpointId: string; }) => Promise<void>Reject connection from an endpoint
| Param | Type |
| ------------- | ------------------------------------ |
| options | { endpointId: string; } |
sendPayload(...)
sendPayload(options: { endpointId: string; bytes: number[]; }) => Promise<void>Send bytes payload to endpoint
| Param | Type |
| ------------- | ----------------------------------------------------- |
| options | { endpointId: string; bytes: number[]; } |
disconnectFromEndpoint(...)
disconnectFromEndpoint(options: { endpointId: string; }) => Promise<void>Disconnect from endpoint
| Param | Type |
| ------------- | ------------------------------------ |
| options | { endpointId: string; } |
disconnectFromAllEndpoints()
disconnectFromAllEndpoints() => Promise<void>Disconnect from all endpoints
setStrategy(...)
setStrategy(options: { strategy: 'P2P_CLUSTER' | 'P2P_STAR' | 'P2P_POINT_TO_POINT'; }) => Promise<void>Set advertising strategy
| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| options | { strategy: 'P2P_CLUSTER' | 'P2P_STAR' | 'P2P_POINT_TO_POINT'; } |
addListener('onConnectionInitiated', ...)
addListener(eventName: 'onConnectionInitiated', listenerFunc: (event: ConnectionInitiatedEvent) => void) => Promise<PluginListenerHandle>Add listener for connection lifecycle events
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------- |
| eventName | 'onConnectionInitiated' |
| listenerFunc | (event: ConnectionInitiatedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onConnectionResult', ...)
addListener(eventName: 'onConnectionResult', listenerFunc: (event: ConnectionResultEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------- |
| eventName | 'onConnectionResult' |
| listenerFunc | (event: ConnectionResultEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onDisconnected', ...)
addListener(eventName: 'onDisconnected', listenerFunc: (event: DisconnectedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------- |
| eventName | 'onDisconnected' |
| listenerFunc | (event: DisconnectedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onEndpointFound', ...)
addListener(eventName: 'onEndpointFound', listenerFunc: (event: EndpointFoundEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------- |
| eventName | 'onEndpointFound' |
| listenerFunc | (event: EndpointFoundEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onEndpointLost', ...)
addListener(eventName: 'onEndpointLost', listenerFunc: (event: EndpointLostEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------- |
| eventName | 'onEndpointLost' |
| listenerFunc | (event: EndpointLostEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onJsonReceived', ...)
addListener(eventName: 'onJsonReceived', listenerFunc: (event: PayloadReceivedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'onJsonReceived' |
| listenerFunc | (event: PayloadReceivedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onFileReceived', ...)
addListener(eventName: 'onFileReceived', listenerFunc: (event: PayloadReceivedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'onFileReceived' |
| listenerFunc | (event: PayloadReceivedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onStreamReceived', ...)
addListener(eventName: 'onStreamReceived', listenerFunc: (event: PayloadReceivedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'onStreamReceived' |
| listenerFunc | (event: PayloadReceivedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('onPayloadTransferUpdate', ...)
addListener(eventName: 'onPayloadTransferUpdate', listenerFunc: (event: PayloadTransferUpdateEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------------------- |
| eventName | 'onPayloadTransferUpdate' |
| listenerFunc | (event: PayloadTransferUpdateEvent) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Remove all listeners
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
ConnectionInitiatedEvent
| Prop | Type |
| -------------------------- | -------------------- |
| endpointId | string |
| endpointName | string |
| authenticationDigits | string |
| isIncomingConnection | boolean |
ConnectionResultEvent
| Prop | Type |
| ---------------- | ------------------- |
| endpointId | string |
| statusCode | number |
DisconnectedEvent
| Prop | Type |
| ---------------- | ------------------- |
| endpointId | string |
EndpointFoundEvent
| Prop | Type |
| ------------------ | ------------------- |
| endpointId | string |
| endpointName | string |
| serviceId | string |
EndpointLostEvent
| Prop | Type |
| ---------------- | ------------------- |
| endpointId | string |
PayloadReceivedEvent
| Prop | Type |
| --------------- | ------------------------------------------ |
| type | 'BYTES' | 'FILE' | 'STREAM' |
| bytes | number[] |
| fileUri | string |
| streamUri | string |
PayloadTransferUpdateEvent
| Prop | Type |
| ---------------------- | ------------------------------------------------------------------ |
| endpointId | string |
| payloadId | number |
| status | 'SUCCESS' | 'FAILURE' | 'IN_PROGRESS' | 'CANCELED' |
| bytesTransferred | number |
| totalBytes | number |
