Class HCESession

Class for the session state management.

HCESession is an entry point for the react-native-hce library. This class manages the entire connection with native counterparts managing the HCE emulation.

You should use only one instance of the class should be used per application. That's why we created it with the intention of use as a singleton. To get the instance, use the getInstance static method that will get a current instance and will do the synchronization with native for You.

Hierarchy

  • HCESession

Constructors

Properties

application: null | HCEApplication

The current subject application to emulate in HCE.

NOTE: Do not set the current application by assigning to this property. Use the setApplication instead.

enabled: boolean

Is the HCE Service currently enabled and visible to OS.

NOTE: Do not set the current state by assigning to this property. Use the setEnabled instead.

Events: HCESessionEvents = ...

Object that contains the events that the application can listen to using HCESession.on(...).

Check the HCESessionEvents interface to get the listing of availble events.

Example

Usage of the property in event listener:

hceSession.on(HCESession.Events.HCE_CONNECTED)

Methods

  • Adds event listener to the HCE Session.

    Returns

    Returns the reference to "stop listening" method. To stop listening the event, just call it.

    Example

    import { ToastAndroid } from "react-native"
    import { HCESession } from "react-native-hce"
    ...
    const instance = await HCESession.getInstance();
    const removeListener = instance.on(HCESession.Events.HCE_STATE_READ, () => {
    ToastAndroid.show("The tag has been read! Thank You.", ToastAndroid.LONG);
    removeListener();
    };

    Parameters

    • event: null | string

      The event that application should listen to. You should pass the constant from static Events property. If null, the listener will respond to all events - that can be usable for logging purposes.

    • listener: HCESessionEventListener

      The event listener.

    Returns HCESessionEventListenerCancel

  • Update the subject application to emulate in HCE.

    Parameters

    • application: HCEApplication

      The application to set, must be instance of HCEApplication.

    Returns Promise<void>

  • Toggle the state of HCE service.

    This function allows to enable or disable the native component of HCE Service. If enabled, the native HostApduService will be recognizable by platform's HCE router. If not, service won't be recognized, thus all the interactions between HCE and reader won't be available.

    NOTE: Before switching the service on, use the setApplication first to register the content that You want to emulate using HCE.

    Parameters

    • enable: boolean

      True to enable the service, false to disable.

    Returns Promise<void>

  • Synchronize the class with current native state.

    NOTE: You should not use this function normally. Internal implementation will call it for You, if needed.

    Returns Promise<void>

  • Gets the instance of HCE Session.

    As there is only one HCE Session per application available, use this function to get the instance instead of using the constructor.

    Returns Promise<HCESession>

Generated using TypeDoc