npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-ttlock

v2.2.2

Published

ttlock react native sdk

Downloads

230

Readme

new update bd7bc4b

react-native-ttlock

Developers Email && Quick Response

[email protected]

Installation

yarn add react-native-ttlock

Add configuration to project

iOS

  1. cd ./ios && pod install && cd ../
  2. In XCode TARGETSinfo ➜ add key Privacy - Bluetooth Peripheral Usage Description value your description for bluetooth and key Privacy - Bluetooth Always Usage Description value your description for bluetooth

Android

  1. AndroidManifest.xml configuration:
    (1) Add 'xmlns:tools="http://schemas.android.com/tools"' to element
    (2) Add 'tools:replace="android:label"' to element
    (3) Additional permissions:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
android 12 needs below permission.
  <!--
 Needed only if your app looks for Bluetooth devices.
         You must add an attribute to this permission, or declare the
         ACCESS_FINE_LOCATION permission, depending on the results when you
         check location usage in your app.
    -->
    <uses-permission
        android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
    <!--
 Needed only if your app makes the device discoverable to Bluetooth
         devices.
    -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <!--
 Needed only if your app communicates with already-paired Bluetooth
         devices.
    -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  1. In order to get the permission request result in ttlock plugin, in MainActivity extends ReactActivity, you need override the onRequestPermissionsResult method and add below code:
    (1) java code:
  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
    TtlockModule ttlockModule = mReactInstanceManager.getCurrentReactContext().getNativeModule(TtlockModule.class);
    ttlockModule.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
  1. When you release the apk, you need disable proguard in release builds.Config buildTypes in build.gradle like this:
repositories {
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
        }
    }
  1. Support min sdk version is 18
defaultConfig {
        minSdkVersion 18
    }

Usage Lock

1 Lock basic operation

1.0 Get bluetooth state

Ttlock.getBluetoothState((state: BluetoothState)=>{
    console.log("bluetooth:",state);
});

1.1 Scan lock

//Start scan lock
android 12 needs request android.permission.BLUETOOTH_SCAN before Ttlock.startScan
Ttlock.startScan((scanLockModal: ScanLockModal) => {
    //todo
});
//Stop scan lock
Ttlock.stopScan();

1.2 Init lock

android 12 needs android.permission.BLUETOOTH_CONNECT permission before calling apis.
All apis needs android.permission.BLUETOOTH_CONNECT permission
const param = {
    lockMac: scanLockModal.lockMac,
    lockVersion: scanLockModal.lockVersion
  }
  Ttlock.initLock(param, (lockData) => {
    Ttlock.stopScan();
    //...
  }, (errorCode, errorDesc) => {
    //...
  })
}

1.3 Reset Lock

Ttlock.resetLock(lockData, () => {
    //...
}, (errorCode, errorDesc) => {
    //...
})

1.4 Set Lock Time

let timestamp = new Date().getTime();
Ttlock.setLockTime(timestamp, lockData, () => {
    //...
}, (errorCode, errorDesc) => {
    //...
});

1.5 Get Lock Time

Ttlock.getLockTime(lockData, (lockTimestamp: number) => {
    //...
}, (errorCode, errorDesc) => {
    //...
});

1.6 Get Lock Operation Record

Ttlock.getLockOperationRecord(LockRecordType.Latest, lockData, successCallback, failedCallback);

1.7 Get Lock State

Ttlock.getLockSwitchState(lockData, (state: LockState) => {
    //...
},  (errorCode, errorDesc) => {
    //...
});

1.8 Set lock automatic locking periodic time

let seconds = 20;
Ttlock.setLockAutomaticLockingPeriodicTime(seconds, lockData, () => {
      //...
},  (errorCode, errorDesc) => {
    //...
});

1.9 Get lock automatic locking periodic time

Ttlock.getLockAutomaticLockingPeriodicTime(lockData, (currentTime: number, maxTime: number, minTime: number) => {
    //...
},  (errorCode, errorDesc) => {
    //...
});

1.10 Set lock remote unlock switch state

let isOn = true;
Ttlock.setLockRemoteUnlockSwitchState(isOn, lockData, (lockDataNew: string) => {
      let text = "set lock remote unlock switch success, please upload lockDataNew to server";
      console.log(text);
}, (errorCode, errorDesc) => {
    //...
});

1.11 Set lock config

/*
enum LockConfigType {
  Audio = 0,
  PasscodeVisible = 1,
  Freeze = 2,
  TamperAlert = 3,
  ResetButton = 4,
  PrivacyLock = 5
}
*/
let isOn = true;
Ttlock.setLockConfig(LockConfigType.Audio, isOn, lockData, () => {
      let text = "config lock success";
      successCallback(text);
}, (errorCode, errorDesc) => {
    //...
});

1.12 Get lock config

/*
enum LockConfigType {
  Audio = 0,
  PasscodeVisible = 1,
  Freeze = 2,
  TamperAlert = 3,
  ResetButton = 4,
  PrivacyLock = 5
}
*/
Ttlock.getLockConfig(LockConfigType.Audio, lockData, (type: number, isOn: boolean) => {
      let text = "type:" + type + "\n" + "isOn:" + isOn;
      successCallback(text);
}, (errorCode, errorDesc) => {
    //...
});

2. Ekey

2.1 Control lock

Ttlock.controlLock(LockControlType.Unlock, lockData, (lockTime: number, electricQuantity: number, uniqueId: number) => {
      let text = "lockTime:" + lockTime + "\n" + "electricQuantity:" + electricQuantity + "\n" + "uniqueId:" + uniqueId;
      successCallback(text);
}, (errorCode, errorDesc) => {
    //...
});

2.2 Reset ekey

Ttlock.resetEkey(lockData, (lockDataNew) => {
    //important: upload lockDataNew to ttlock server. 
    let text = "reset ekey success";
    console.log(text);
}, (errorCode, errorDesc) => {
    //...
});

3. Passcode

3.1 Get passcode https://open.sciener.com/doc/api/v3/keyboardPwd/get 3.2 Custom passcode

 //example: passcode valid one day
let startDate = new Date().getTime();
let endDate = startDate + 24 * 3600 * 1000;
Ttlock.createCustomPasscode("1122", startDate, endDate, lockData, () => {
      successCallback("create cutome passcode success");
}, (errorCode, errorDesc) => {
    //...
});

3.3 Modify passcode

// passcode valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
let oldPasscode = "1122";
let newPasscode = "2233";
Ttlock.modifyPasscode(oldPasscode, newPasscode, startDate, endDate, lockData, () => {
      successCallback("modify passcode success");
}, (errorCode, errorDesc) => {
    //...
});   

3.4 Delete passcode

Ttlock.deletePasscode("2233", lockData, () => {
    successCallback("delete passcode success");
}, (errorCode, errorDesc) => {
    //...
});  

3.5 Reset all passcode ( not contain the admin password )

Ttlock.resetPasscode(lockData, (lockDataNew: string) => {
    //important: upload lockDataNew to ttlock server. 
    console.log("reset passcode success, please upload lockDataNew to server");
}, (errorCode, errorDesc) => {
    //...
});   

3.6 Modify admin passcode

let adminPasscode = "9999";
Ttlock.modifyAdminPasscode(adminPasscode, lockData, () => {
      let text = "modify admin passcode success";
}, (errorCode, errorDesc) => {
    //...
});   

4. Card

4.1 Add card

// card valid one day
let startDate = new Date().getTime();
    let endDate = startDate + 24 * 3600 * 1000;
    Ttlock.addCard(null, startDate, endDate, lockData, () => {
     // progress
}, (cNumber: string) => {
      cardNumber = cNumber;
      let text = "cardNumber:" + cardNumber;
      successCallback(text);
}, (errorCode, errorDesc) => {
    //...    
});   

4.2 Modify card validity period

// card valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
Ttlock.modifyCardValidityPeriod(cardNumber, null, startDate, endDate, lockData, () => {
    let text = "modify card validity period success";
}, (errorCode, errorDesc) => {
    //...        
});   

4.3 Delete card

Ttlock.deleteCard(cardNumber, lockData, () => {
      let text = "delete card success";
}, (errorCode, errorDesc) => {
    //...    
});   

4.4 Clear all cards

Ttlock.clearAllCards(lockData, () => {
    let text = "clear all cards success";
}, (errorCode, errorDesc) => {
    //...    
});   

5. Fingerprint

5.1 Add fingerprint

// card valid one day
let startDate = new Date().getTime();
let endDate = startDate + 24 * 3600 * 1000;
Ttlock.addFingerprint(null, startDate, endDate, lockData, (currentCount: number, totalCount: number) => {
      let text = "currentCount:" + currentCount + "\n" + "totalCount:" + totalCount;
      progressCallback(text);
}, (fNumber: string) => {
      fingerprintNumber = fNumber;
      let text = "fingerprintNumber:" + fingerprintNumber
    }, (errorCode, errorDesc) => {
    //...    
});  

5.2 Modify fingerprint validity period

// fingerprint valid one minute
let startDate = new Date().getTime();
let endDate = startDate + 1 * 60 * 1000;
Ttlock.modifyFingerprintValidityPeriod(fingerprintNumber, null, startDate, endDate, lockData, () => {
      let text = "modify fingerprint validity period success";
}, (errorCode, errorDesc) => {
    //...    
});  

5.3 Delete fingerprint

Ttlock.deleteFingerprint(fingerprintNumber, lockData, () => {
      let text = "delete fingerprint success";
}, (errorCode, errorDesc) => {
    //...    
});  

5.4 Clear all fingerprints

Ttlock.clearAllFingerprints(lockData, () => {
    let text = "clear all fingerprints success";
}, (errorCode, errorDesc) => {
    //...    
});  

6. Passage mode

6.1 Add passage mode

//valid time 8:00 am ---   17:00 pm
let startTime = 8 * 60;
let endTime = 17 * 60;
Ttlock.addPassageMode(LockPassageMode.Weekly, [1, 2, 7], startTime, endTime, lockData, () => {
      let text = "add passage mode success";
}, (errorCode, errorDesc) => {
    //...    
});  

6.2 Clear all passageModes

Ttlock.clearAllPassageModes(lockData, () => {
    let text = "clear all passage modes success";
}, (errorCode, errorDesc) => {
    //...    
});  

7. WIFI

7.1 Wifi lock scan nearby wifi

Ttlock.scanWifi(lockData, (isFinished: boolean, wifiList: []) => {
     
    }, (errorCode, errorDesc) => {
    //...    
});

7.2 Wifi lock config wifi

const wifiName = 'sciener'
const wifiPassword = 'sciener.com'
Ttlock.configWifi(wifiName, wifiPassword, lockData, () => {
      let text = "config lock wifi success";

    }, (errorCode, errorDesc) => {
    //...    
});  

7.3 Wifi lock config server

const serverIp = "121.196.45.110"
const serverPort = "4999"
Ttlock.configServer(serverIp, serverPort, lockData, () => {
      let text = "config lock wifi ip address success";

    }, (errorCode, errorDesc) => {
    //...    
});