GithubHelp home page GithubHelp logo

zhunings / react-native-wifi-hotspot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yeomanye/react-native-wifi-hotspot

0.0 1.0 0.0 1.89 MB

A react-native implementation for handling hotspot requests and make it easier to communicate with peers!

License: ISC License

JavaScript 0.18% Java 99.82%

react-native-wifi-hotspot's Introduction


React Native Hotspot [Android]

NPM Version NPM Version PRs Welcome

Introduce

Since there's not a strict API from React Native to allow us to handle operations on Hotspot. So, today I would like to share my small kit with you guys to help most of rn developers to be able to use wifi-hotspot and enjoy its powerful.

The kit is designed to be helpful and to provide an easy API that can suit your needs so let me tell you how this kit can help you a long away with:

  • Talk to your ROBOT!
  • Communicating without an Internet
  • Build yourown SHAREit (Share any types of files locally)
  • Build a tiny network with your friends

Setup

Fetch it using npm or yarn

npm i --save react-naive-wifi-hotspot
OR
yarn add react-native-wifi-hotspot

Then run this command to link it

react-native link react-naive-wifi-hotspot

Almost done just put this lines into Settings.gradle

include ':hotspotmanager'
project(':hotspotmanager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-hotspot/android/hotspotmanager')

๐Ÿ’ฅ Just run it!

Example

๐Ÿ”ฅ Full Example

Features

  • Enable Hotspot
  • Disable Hotspot
  • Create Hotspot's Settings (SSID, Password, ..)
  • Fetch Hotspot's Settings
  • Get List of Connected Peers

Demo

example app

Get Started

  • Check WIFI is on/off then turn hotspot on and automatically check if hotspot already opened
Hotspot.enable(() => {
      ToastAndroid.show("Hotspot Enabled",ToastAndroid.SHORT);
    }, (err) => {
      ToastAndroid.show(err.toString(),ToastAndroid.SHORT);
    })
  • Check hotspot is on then turn it off and automatically check if hotspot already closed
Hotspot.disable(() => {
      ToastAndroid.show("Hotspot Disabled",ToastAndroid.SHORT);
    }, (err) => {
      ToastAndroid.show(err.toString(),ToastAndroid.SHORT);
    })
  • You can set your own configuration to your hotspot using this function. supported configuration:
    • SSID
    • Password
    • Protocols
    • authAlgorithms
    • Security type
Parameters Required Types Default
SSID * none none
password * none password should be provided if you will use our settings
protocols - Hotspot.protocols.RSN
Hotspot.protocols.WPA
Hotspot.protocols.BOTH
Hotspot.protocols.BOTH
securityType - Hotspot.security.WPA_PSK
Hotspot.security.WPA_EAP
Hotspot.security.IEEE8021X
Hotspot.security.WPA2_PSK
Hotspot.security.WPA2_PSK
authAlgorithms - Hotspot.auth.OPEN
Hotspot.auth.SHARED
Hotspot.auth.LEAP
Hotspot.auth.SHARED
const hotspot = {SSID: 'ASSEM', password: 'helloworld', authAlgorithms: Hotspot.auth.OPEN, protocols: Hotspot.protocols.WPA }
    Hotspot.create(hotspot, () => {
      ToastAndroid.show("Hotspot enstablished", ToastAndroid.SHORT);
    }, (err) => {
      ToastAndroid.show(err.toString(), ToastAndroid.SHORT);
    })

You can also use your own old settings without the need of creating new one

  • You can fetch your hotsot's configuration. Supported returning config:
    • ssid
    • password
    • status ( network is enabled or disabled )
    • networkId
config: {
  ssid: string,
  password: string,
  status: boolean ( true means enable, false means disable )
  networkId: Int
}
Hotspot.getConfig((config) => {
      ToastAndroid.show("Hotspot SSID: " + config.ssid, ToastAndroid.SHORT);
    }, (err) => {
      ToastAndroid.show(err.toString(), ToastAndroid.SHORT);
    })
  • Fethcing connected devices to your wifi network. Returned an object for every device contains:
    • ip
    • mac
    • device number
data: [
  results: {
    ip: 192.168.x.x,
    mac: A3:76:E1:33:79:F3,
    device: number
  }
]
Hotspot.peersList((data) => {
      const peers = JSON.parse(data);
    }, (err) => {
      ToastAndroid.show(err.toString(), ToastAndroid.SHORT);
    })

react-native-wifi-hotspot's People

Contributors

yeomanye avatar aboozaid avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.