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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mkay4real/react-native-nearby-api

v1.0.1

Published

React Native wrapper around Google's Nearby API SDK

Downloads

7

Readme

react-native-nearby-api npm version

This is a React Native wrapper for the Google Nearby Messages API. It is a fork of this repository by badfeatures.

Noteable changes to the original respository

  • Rewritten in Typescript
  • Autolinking support for React Native 0.60 and above.
  • Android X support
  • Upgraded to [email protected] on Android
  • Upgraded to Gradle 3.5.2

Getting started

$ yarn add @adrianso/react-native-nearby-api

Installation

iOS

  • cd ios/
    pod install
  • Build and run project

Android

There are no additional steps required for Android

Usage

See the example app for more detail and code examples.

  • Retrieve your API Keys from the Google Console iOS | Android

  • Add the correct permissions to the AndroidManifest.

    <!-- Include if wish to use BLE -->
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <!-- Include if wish to use audio -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
  • Add the Android API Key in the AndroidManifest .

    <meta-data
      android:name="com.google.android.nearby.messages.API_KEY"
      android:value="MY_API_KEY" />
  • The iOS API key will be supplied through the connect() method.

  • Add NSBluetoothPeripheralUsageDescription to the Info.plist

  • Add NSMicrophoneUsageDescription to the iOS project's Info.plist if using audio

import NearbyApi from 'react-native-nearby-api';

const nearbyAPI = new NearbyAPI(true); // Use BLE only, no audio.

nearbyAPI.onConnected((message) => {
  console.log(message);
});

nearbyAPI.onDisconnected((message) => {
  console.log(message);
});

nearbyAPI.onFound((message) => {
  console.log('Message Found!');
  console.log(message);
});

nearbyAPI.onLost((message) => {
  console.log('Message Lost!');
  console.log(message);
});

// Android Only
nearbyAPI.onDistanceChanged((message, value) => {
  console.log('Distance Changed!');
  console.log(message, value);
});

// Android Only
nearbyAPI.onBLESignalChanged((message, value) => {
  console.log('BLE Signal Changed!');
  console.log(message, value);
});

nearbyAPI.onPublishSuccess((message) => {
  console.log(message);
});

nearbyAPI.onPublishFailed((message) => {
  console.log(message);
});

nearbyAPI.onSubscribeSuccess(() => {});

nearbyAPI.onSubscribeFailed(() => {});

// To connect from Google API Client
nearbyAPI.connect(API_KEY);

// To check if the nearby API is connected.
nearbyAPI.isConnected((connected, error) => {
  console.log(connected);
});

// To disconnect later
nearbyAPI.disconnect();

// To publish to nearby devices
nearbyAPI.publish('Hello World!');

// To check if the nearby API is publishing.
nearbyAPI.isPublishing((publishing, error) => {
  console.log(publishing);
});

// To subscribe to nearby devices broadcasting
nearbyAPI.subscribe();

// To check if the nearby API is subscribing.
nearbyAPI.isSubscribing((subscribing, error) => {
  console.log(subscribing);
});

// To unpublish
nearbyAPI.unpublish();

// To unsubscribe
nearbyAPI.unsubscribe();

Running the Example

  • Install the dependencies in the root folder

    yarn

Generate an API Key from the Google Developer Console

  1. Go to the Google Developers Console.
  2. Create or select a project to register your application with.
  3. Click Continue to Enable the API.
  4. On the Credentials page, create a new API Key. (No key restrictions are needed for this example)
  5. Copy/Paste your key in example/index.js and in the example AndroidManifest.xml

Android

  • To run the example app, the packager must have the projectRoots reordered for the example/ directory. In another terminal window:

yarn start --projectRoots <FULL-PATH-TO-REPO>/react-native-nearby-api/example,<FULL-PATH-TO-REPO>/react-native-nearby-api

yarn run:android

adb reverse tcp:8081 tcp:8081

iOS

  • cd example ios/
  • bundle exec pod install
  • Open example.xcworkspace
  • Add your IP to AppDelegate.m
  jsCodeLocation = [NSURL URLWithString:@"http://<IP-ADDRESS>:8081/index.bundle?platform=ios&dev=true"];
  • In another terminal window: yarn start
  • Run on device

Common issues

iOS compilation error: duplicate symbols for architecture

Cause

This is caused by a conflict of the AddLogSink and RemoveLogSink functions in the glog and NearbyMessages library.

Workaround

Add the following to your Podfile.

post_install do |installer|
  puts "Renaming logging functions"

  root = File.dirname(installer.pods_project.path)
  Dir.chdir(root);
  Dir.glob("**/*.{h,cc,cpp,in}") {|filename|
    filepath = root + "/" + filename
    text = File.read(filepath)
    addText = text.gsub!(/(?<!React)AddLogSink/, "ReactAddLogSink")
    if addText
      File.chmod(0644, filepath)
      f = File.open(filepath, "w")
      f.write(addText)
      f.close
    end

    text2 = addText ? addText : text
    removeText = text2.gsub!(/(?<!React)RemoveLogSink/, "ReactRemoveLogSink")
    if removeText
      File.chmod(0644, filepath)
      f = File.open(filepath, "w")
      f.write(removeText)
      f.close
    end
  }
end

iOS compilation error: Multiple commands produce Assets.car.

Details

This is casued by an issue in the NearbyMessage podspec. This only affects bulids using the "New Build System" in Xcode.

Work around

Add the following to your Podfile

  post_install do |installer|
    project_path = 'example.xcodeproj'
    project = Xcodeproj::Project.open(project_path)
    project.targets.each do |target|
        build_phase = target.build_phases.find { |bp| bp.display_name == '[CP] Copy Pods Resources' }
        assets_path = '${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Assets.car'
        if build_phase.present? && build_phase.output_paths.include?(assets_path) == true
            build_phase.output_paths.delete(assets_path)
        end
    end
    project.save(project_path)
  end