Socket
Socket
Sign inDemoInstall

global-input-react

Package Overview
Dependencies
37
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    global-input-react

global input react component


Version published
Weekly downloads
22
increased by450%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

This React JS library allows you to introduce interoperability between your mobile app and your React applications. With this library, you will be able to receive mobile events from within your React applications, implementing interoperability logic in your device application instead of separating it across the two interacting applications. This mechanism offers a range of features that include Mobile Encryption, Mobile Authentication, Mobile Input & Control, Second Screen Experience, Mobile Personal Storage, Mobile Encryption & Signing, Mobile Content Transfer.

Setup

npm i global-input-react

Usage

The custom React hook useGlobalInputApp allows a React component specify a mobile user interface declaratively.

The following example application defines a login screen allowing user to use their mobile to carry out login operation using their mobile.


import {useGlobalInputApp} from 'global-input-react';
import React, {useState} from 'react';

const initData={                              
     form:{
       title: 'Sign In',
       id: '###username###@mycompany.com',  
       fields: [{         
         label: 'Username',
         id: 'username'         
       },{
         label: 'Password',
         id: 'password',                  
      },{
        id: 'login',
        label: 'Sign In',
        type: 'button'        
      }]
    }  
 };
export default ({login}){  
  
  const [username,setUser] = useState('');
  const [password,setPassword] = useState('');
  const {connectionMessage,setOnFieldChanged}=useGlobalInputApp({initData});     
  
  setOnFieldChanged(({field})=>{
      const fds=initData.form.fields;
      switch(field.id){
          case fds[0].id: setUsername(field.value); break;
          case fds[1].id: setPassword(field.value); break;
          case fds[2].id: login(username,password);
      }    
  });
    return (
        <>
           {connectionMessage}                    
        </>
    );
  };

The content of {connectionMessage} returned by the hook contains an encrypted QR Code that you can scan to connect to the application. Having connected, your mobile displays the user interface specified in the initData variable, allowing you to operate on the application. You can use setOnFieldChanged function to set your callback function to receive the form events through the field variable.

The initData specifies a form, in which id is used for autofill operation inside the connected mobile app through filtering the existing data in its encrypted storage. The form contain a set of fields, representing data that device application and the connected mobile need to collaborate on composing. The type of each field defines the related data operation. For example, if the type is "encrypt"/"decrypt", the mobile app initiates the encrypt/decrypt workflow inside the mobile app. This is useful when you would like to secure data stored on other devices or cloud.

Other values returned by the useGlobalInputApp function are listed in the table below:

AttributesDescription
connectionMessageThe variable containing the QR Code for the mobile app to scan to obtain the connection information securely
setFieldValueByIdThe function you can use interact with the form displayed on the connected mobile app.
fieldThe field that contains the id and value of the field sent by the mobile app
WhenWaitingA container React component that you can use it to wrap content that you would like to display only when the application waiting for the user to connect
WhenConnectedA container React component that you can use it to wrap content that you would like to display only when a user has connected to the application
WhenDisconnectedA container React component that you can use it to wrap content that you would like to display only when a user has connected and then disconnected
WhenErrorA container React component that you can use it to wrap content that you would like to display when there is an error, you can use {errorMessage} to find out what has happened, for example <WhenError>{errorMessage}</WhenError>
errorMessageThis value wil be populated when an error is raised

TypeScript support

The type definition file is included within the module. You can obtain more information from this end-to-end test example on how to use this library within a TypeScript application.

Keywords

FAQs

Last updated on 10 Oct 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