npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-google-nearby-connection

v0.0.9

Published

Select single or multiple images, with cropping option

Downloads

19

Readme

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

import NearbyConnection, {CommonStatusCodes, ConnectionsStatusCodes, Strategy, Payload, PayloadTransferUpdate} from 'react-native-google-nearby-connection';

Starting the discovery service

NearbyConnection.startDiscovering(
    serviceId                // A unique identifier for the service
);

Stopping the discovery service

NearbyConnection.stopDiscovering(serviceId);

Whether a service is currently discovering

NearbyConnection.isDiscovering();

Connect to a discovered endpoint

NearbyConnection.connectToEndpoint(
    serviceId,              // A unique identifier for the service
    endpointId              // ID of the endpoint to connect to
);

Disconnect from an endpoint

NearbyConnection.disconnectFromEndpoint(
    serviceId,              // A unique identifier for the service
    endpointId              // ID of the endpoint we wish to disconnect from
);

Starting the advertising service

NearbyConnection.startAdvertising(
    endpointName,           // This nodes endpoint name
    serviceId,              // A unique identifier for the service
    strategy                // The Strategy to be used when discovering or advertising to Nearby devices [See Strategy](https://developers.google.com/android/reference/com/google/android/gms/nearby/connection/Strategy)
);

Stopping the advertising service

NearbyConnection.stopAdvertising(
    serviceId                // A unique identifier for the service
);

Whether a service is currently advertising

NearbyConnection.isAdvertising();

Accepting a connection from an endpoint

NearbyConnection.acceptConnection(
    serviceId,               // A unique identifier for the service
    endpointId               // ID of the endpoint wishing to accept the connection from
);

Rejecting a connection from an endpoint

NearbyConnection.rejectConnection(
    serviceId,               // A unique identifier for the service
    endpointId               // ID of the endpoint wishing to reject the connection from
);

Removes a payload (free memory)

NearbyConnection.removePayload(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
    payloadId                // Unique identifier of the payload
);

Open the microphone and broadcast audio to an endpoint

```javascript
NearbyConnection.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.closeMicrophone(
    serviceId,               // A unique identifier for the service
    endpointId               // ID of the endpoint wishing to stop sending audio to
);

Start playing an audio stream from a received payload (Payload.STREAM)

NearbyConnection.startPlayingAudioStream(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to start playing audio from
    payloadId                // Unique identifier of the payload
);

Stop playing an audio stream from a received payload (Payload.STREAM)

NearbyConnection.stopPlayingAudioStream(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
    payloadId                // Unique identifier of the payload
);

Send a file to a service endpoint (Payload.FILE)

NearbyConnection.sendFile(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
    uri,                     // Location of the file to send
    metadata                 // String of metadata you wish to pass along with the file
);

Save a file from a payload (Payload.FILE) to storage

NearbyConnection.saveFile(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
    payloadId,               // Unique identifier of the payload
).then({
    path,                    // Path where the file was saved on local filesystem
    originalFilename,        // The original name of the sent file
    metadata,                // Any metadata that was sent along with sendFile
}) => {
});

Send a bytes payload (Payload.BYTES)

NearbyConnection.sendBytes(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
);

Read payload [Payload.Type.BYTES] or out of band file [Payload.Type.FILE] or stream [Payload.Type.STREAM] information

NearbyConnection.readBytes(
    serviceId,               // A unique identifier for the service
    endpointId,              // ID of the endpoint wishing to stop playing audio from
    payloadId                // Unique identifier of the payload
).then(({
    type,                    // The Payload.Type represented by this payload
    bytes,                   // \[Payload\.Type\.BYTES\] The bytes string that was sent
    payloadId,               // \[Payload\.Type\.FILE\ or Payload\.Type\.STREAM\] The payloadId of the payload this payload is describing
    filename,                // \[Payload\.Type\.FILE\] The name of the file being sent
    metadata,                // \[Payload\.Type\.FILE\] The metadata sent along with the file
    streamType,              // \[Payload\.Type\.STREAM\] The type of stream this is \[audio or video\]
}) => {
});

Callbacks

Endpoint Discovery

NearbyConnection.onDiscoveryStarting(({
    serviceId               // A unique identifier for the service
}) => {
    // Discovery services is starting
});

NearbyConnection.onDiscoveryStarted(({
    serviceId               // A unique identifier for the service
}) => {
    // Discovery services has started
});

NearbyConnection.onDiscoveryStartFailed(({
    serviceId               // A unique identifier for the service
    statusCode              // The status of the response [See CommonStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes)
}) => {
    // Failed to start discovery service
});

// Note - Can take up to 3 min to time out
NearbyConnection.onEndpointLost(({
    endpointId,             // ID of the endpoint we lost
    endpointName,           // The name of the remote device we lost
    serviceId               // A unique identifier for the service
}) => {
    // Endpoint moved out of range or disconnected
});

NearbyConnection.onEndpointDiscovered(({
    endpointId,             // ID of the endpoint wishing to connect
    endpointName,           // The name of the remote device we're connecting to.
    serviceId               // A unique identifier for the service
}) => {
    // An endpoint has been discovered we can connect to
});

Endpoint Advertisement

NearbyConnection.onAdvertisingStarting(({
    endpointName,            // The name of the service thats starting to advertise
    serviceId,               // A unique identifier for the service
}) => {
    // Advertising service is starting
});

NearbyConnection.onAdvertisingStarted(({
    endpointName,            // The name of the service thats started to advertise
    serviceId,               // A unique identifier for the service
}) => {
    // Advertising service has started
});

NearbyConnection.onAdvertisingStartFailed(({
    endpointName,            // The name of the service thats failed to start to advertising
    serviceId,               // A unique identifier for the service
    statusCode,              // The status of the response [See CommonStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes)
}) => {
    // Failed to start advertising service
});

Connection negotiation

NearbyConnection.onConnectionInitiatedToEndpoint(({
    endpointId,             // ID of the endpoint wishing to connect
    endpointName,           // The name of the remote device we're connecting to.
    authenticationToken,    // A small symmetrical token that has been given to both devices.
    serviceId,              // A unique identifier for the service
    incomingConnection      // True if the connection request was initated from a remote device.
}) => {
    // Connection has been initated
});

NearbyConnection.onConnectedToEndpoint(({
    endpointId,             // ID of the endpoint we connected to
    endpointName,           // The name of the service
    serviceId,              // A unique identifier for the service
}) => {
    // Succesful connection to an endpoint established
});

NearbyConnection.onEndpointConnectionFailed(({
    endpointId,             // ID of the endpoint we failed to connect to
    endpointName,           // The name of the service
    serviceId,              // A unique identifier for the service
    statusCode              // The status of the response [See CommonStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes)
}) => {
    // Failed to connect to an endpoint
});

NearbyConnection.onDisconnectedFromEndpoint(({
    endpointId,             // ID of the endpoint we disconnected from
    endpointName,           // The name of the service
    serviceId,              // A unique identifier for the service
}) => {
    // Disconnected from an endpoint
});

Payload Status

Nearby.onReceivePayload(({
    serviceId,              // A unique identifier for the service
    endpointId,             // ID of the endpoint we got the payload from
    payloadType,            // The type of this payload (File or a Stream) [See Payload](https://developers.google.com/android/reference/com/google/android/gms/nearby/connection/Payload)
    payloadId               // Unique identifier of the payload
}) => {
    // Payload has been received
});

Nearby.onPayloadUpdate(({
    serviceId,              // A unique identifier for the service
    endpointId,             // ID of the endpoint we got the payload from
    bytesTransferred,       // Bytes transfered so far
    totalBytes,             // Total bytes to transfer
    payloadId,              // Unique identifier of the payload
    payloadStatus,          // [See PayloadTransferUpdate.Status](https://developers.google.com/android/reference/com/google/android/gms/nearby/connection/PayloadTransferUpdate.Status)
    payloadHashCode,        // ???
}) => {
    // Update on a previously received payload
});

Nearby.onSendPayloadFailed(({
    serviceId,              // A unique identifier for the service
    endpointId,             // ID of the endpoint wishing to connect
    statusCode              // The status of the response [See CommonStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes)
}) => {
    // Failed to send a payload
});