Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-find-local-devices

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-find-local-devices

It can be helpful when you try to get a list of your local devices over WiFi with websocket connection.

  • 1.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
45
decreased by-2.17%
Maintainers
1
Weekly downloads
 
Created
Source

🚀 react-native-find-local-devices

npm version platform license

example

It can be helpful when you try to get a list of your local devices over WiFi when the devices includes at least one websocket connection.

This package allows you detect all devices over your local network with websocket connection.

You've to add a timeout and an array of ports as parameters. The package will try to create a connection with those ports and return the ip adresses which have successful connection.

See the example: https://github.com/RichardRNStudio/react-native-find-local-devices/tree/main/example

NOTICE: It doesn't work with IOS yet. If you can help me in this case please contact me on the following email: info@rnstudio.hu

This package has been written for the PC Controller react-native application as a submodule.

Visit the PC Controller website

Installation

npm install react-native-find-local-devices --save

Running the example project

NOTICE: It requires a real device with Wi-Fi connection

npm run example:android

Usage

import FindLocalDevices from 'react-native-find-local-devices';
import { DeviceEventEmitter } from 'react-native';

// Don't forget to call DeviceEventEmitter.removeAllListeners() when discovering isn't running.
// WARNING: DeviceEventEmitter.removeAllListeners will remove all of your listeners. 
// See the example folder. There is an advanced example how you can create 
// and remove listeners independent of any other listeners.
// MAIN BEHAVIOUR: 
// ...
  DeviceEventEmitter.addListener('NEW_DEVICE_FOUND', (device) => {
    console.log(`NEW DEVICE FOUND: ${device.ipAddress}:${device.port}`);
    // This listener will be activated at the moment when the device has been found.
    // FORMAT: {ipAddress: "192.168.1.66", port: 70}
  });

  DeviceEventEmitter.addListener('RESULTS', (devices) => {
    // ALL OF RESULTS when discovering has been finished.
    // FORMAT: [{ipAddress: "192.168.1.66", port: 70}, {ipAddress: "192.168.1.69", port: 85}]
  });

  DeviceEventEmitter.addListener('CHECK', (device) => {
    // This listener will be activated in that moment when package checking a device.
    // FORMAT: {ipAddress: "192.168.1.65", port: 70}
  });

  DeviceEventEmitter.addListener('NO_DEVICES', () => {
    // This listener will be activated at the end of discovering.
  });

  DeviceEventEmitter.addListener('NO_PORTS', () => {
    // This listener will be activated if you don't pass any ports to the package.
  });

  DeviceEventEmitter.addListener('CONNECTION_ERROR', (error) => {
    // Handle error messages for each socket connection
    // console.log(error.message);
  });

  // Getting local devices which have active socket server on the following ports:
  FindLocalDevices.getLocalDevices({
    ports: [70, 85, 1200],
    timeout: 40
  });

  // When the discovering is running, you can cancel that with the following function:
  FindLocalDevices.cancelDiscovering();
// ...

Create a listener and remove it

  // ...
  const newDeviceFoundSubscription = DeviceEventEmitter.addListener(
    NEW_DEVICE_FOUND,
    (device) => {
      if (device.ipAddress && device.port) {
        console.log(device);
      }
    }
  );
  // ...
  if(newDeviceFoundSubscription) newDeviceFoundSubscription.remove();
  // ...

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Keywords

FAQs

Package last updated on 03 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc