Skip to content

Latest commit

 

History

History
80 lines (60 loc) · 2.15 KB

web-standalone.md

File metadata and controls

80 lines (60 loc) · 2.15 KB

Using LibHaLo as a standalone JavaScript library in a classic HTML application

You can use LibHaLo as a single standalone JavaScript file, which could be included in a classic HTML application.

Pre-built JavaScript library

Please check GitHub releases page in order to grab the recent build of libhalo.js library.

Basic usage

Include the libhalo.js on your webpage:

<script src="libhalo.js"></script>

Create a minimal user interface:

<div id="statusText">Please click on the button below.</div>
<button onclick="btnPressed();">Click here</button>

Call the library inside the button click routine:

async function btnPressed() {
    let command = {
        name: "sign",
        keyNo: 1,
        digest: "6e76e202b71892e9ee32a634eefcf522ba1c4cb4eadd7e4562ced1270214c41e"
    };
    
    document.getElementById('statusText').innerText = "Please tap NFC tag to the back of your smartphone...";

    try {
        let res = await execHaloCmdWeb(command);
        // display operation result
        document.getElementById('statusText').innerText = JSON.stringify(res, null, 4);
    } catch (e) {
        // display error
        document.getElementById('statusText').innerText = e;
    }
}

Usage examples

Please review the following demonstrative applications:

Advanced usage

Building library from source

If you don't want to use the pre-built library file, you can build the library on your own.

  1. Install Node.JS
  2. Clone the libhalo repository.
    git clone https://github.com/arx-research/libhalo.git
    cd libhalo
    
  3. Install dependencies.
    npm install
    
  4. Build the library.
    cd web
    webpack
    
  5. Done! The library will be built in web/dist directory.