react-native-google-nearby-connection
React Native wrapper for Googles Nearby Connection API
Install
Install package
npm i react-native-google-nearby-connection --save
Android
- Make sure you are using Gradle
2.2.x
(project build.gradle) - Add google-services
buildscript { ... dependencies { ... classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.google.gms:google-services:3.1.2' ... } ...}
- Add the following to your
build.gradle
's repositories section. (project build.gradle)
allprojects { repositories { ... maven { url "https://maven.google.com" } ... }}
app:build.gradle
Add project under dependencies
android {
...
compileSdkVersion 26
buildToolsVersion "26.0.1"
...
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 26
...
multiDexEnabled true
...
}
...
dependencies {
...
compile 'com.google.android.gms:play-services-nearby:11.8.0'
compile project(':react-native-google-nearby-connection')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:multidex:1.0.1'
...
}
settings.gradle
Include project, so gradle knows where to find the project
include ':react-native-google-nearby-connection'
project(':react-native-google-nearby-connection').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-nearby-connection/android')
MainApplication.java
We need to register our package
Add import com.butchmarshall.reactnative.google.nearby.connection.NearbyConnectionPackage;
as an import statement and
new NearbyConnectionPackage()
in getPackages()
Usage
Import library
;
Starting the discovery service
NearbyConnection;
Stopping the discovery service
NearbyConnection;
Whether a service is currently discovering
NearbyConnection;
Connect to a discovered endpoint
NearbyConnection;
Disconnect from an endpoint
NearbyConnection;
Starting the advertising service
NearbyConnection;
Stopping the advertising service
NearbyConnection;
Whether a service is currently advertising
NearbyConnection;
Accepting a connection from an endpoint
NearbyConnection;
Rejecting a connection from an endpoint
NearbyConnection;
Removes a payload (free memory)
NearbyConnection; Open the microphone and broadcast audio to an endpoint ```javascriptNearbyConnection.openMicrophone( serviceId, // A unique identifier for the service endpointId, // ID of the endpoint wishing to send the audio to metadata // String of metadata you wish to pass along with the stream);
Stop broadcasting audio to an endpoint
NearbyConnection;
Start playing an audio stream from a received payload (Payload.STREAM)
NearbyConnection;
Stop playing an audio stream from a received payload (Payload.STREAM)
NearbyConnection;
Send a file to a service endpoint (Payload.FILE)
NearbyConnection;
Save a file from a payload (Payload.FILE) to storage
NearbyConnection );
Send a bytes payload (Payload.BYTES)
NearbyConnection;
Read payload [Payload.Type.BYTES] or out of band file [Payload.Type.FILE] or stream [Payload.Type.STREAM] information
NearbyConnection;
Callbacks
Endpoint Discovery
NearbyConnection; NearbyConnection; NearbyConnection; // Note - Can take up to 3 min to time outNearbyConnection; NearbyConnection;
Endpoint Advertisement
NearbyConnection; NearbyConnection; NearbyConnection;
Connection negotiation
NearbyConnection; NearbyConnection; NearbyConnection; NearbyConnection;
Payload Status
Nearby; Nearby; Nearby;