appidea / react-native-hce

Emulate smart cards inside React-Native application.
MIT License
73 stars 26 forks source link

Listen for events while emulation doesn't work (HCESession.getInstance();) #18

Closed SurpriseMF3000 closed 2 years ago

SurpriseMF3000 commented 2 years ago

Hello again, the new HCE function and listen() function both don't work because of one error.

Error:

TypeError: _reactNativeHce.default.getInstance is not a function. (In '_reactNativeHce.default.getInstance()', 
'_reactNativeHce.default.getInstance' is undefined)

Issues with this line: const instance = await HCESession.getInstance();

old HCE function (works):

async function startSession() {

  console.log("Session starts!");

  const tag = new NFCTagType4(NFCContentType.Text, "Its working LOLLL Motherfuckers!!!");

  session = await (new HCESession(tag)).start();

  console.log("Successfull");
}

new listen() function:

const listen = async () => {
  const removeListener = session.on(HCESession.Events.HCE_STATE_READ, () => {
    ToastAndroid.show("The tag has been read! Thank You.", ToastAndroid.LONG);
  });

  removeListener();
}

old listen() function:

async function checkHCEStatus(){

  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();
  });

}

The only difference between those two listen() functions is that the old one calls the instance itself and the new one uses the instance from the HCE function.

Thanks for Help

SurpriseMF3000 commented 2 years ago

Fixed with the new update!