Socket
Socket
Sign inDemoInstall

react-native-find-local-devices

Package Overview
Dependencies
514
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

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.


Version published
Maintainers
1
Created

Readme

Source

react-native-find-local-devices

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 under 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

Inside the example folder run the following command: (it requires a real device with Wi-Fi connection)

npm run 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. 
// See the example folder for an advanced example.
// ...
  DeviceEventEmitter.addListener('NEW_DEVICE_FOUND', (device) => {
    console.log(`NEW DEVICE FOUND: ${device.ipAddress}:${device.port}`);
    // This listener will be activated in that moment when the device has been found.
    // FORMAT: {ipAddress: "192.168.1.12", port: 70}
  });

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

  DeviceEventEmitter.addListener('CHECK', (device) => {
    // This listener will be activated in that moment when package checking a device.
    // FORMAT: {ipAddress: "192.168.1.2", 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.
  });

  // 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();
// ...

Contributing

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

License

MIT

Keywords

FAQs

Last updated on 27 Dec 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc