1.1.0 • Published 5 years ago
react-native-smokerlyzemodule v1.1.0
react-native-smokerlyzemodule
Getting started
$ npm install react-native-smokerlyzemodule --save
Mostly automatic installation
$ react-native link react-native-smokerlyzemodule
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-smokerlyzemodule
and addRNSmokerlyzemodule.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNSmokerlyzemodule.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNSmokerlyzemodulePackage;
to the imports at the top of the file - Add
new RNSmokerlyzemodulePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-smokerlyzemodule' project(':react-native-smokerlyzemodule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smokerlyzemodule/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-smokerlyzemodule')
Windows
- In Visual Studio add the
RNSmokerlyzemodule.sln
innode_modules/react-native-smokerlyzemodule/windows/RNSmokerlyzemodule.sln
folder to their solution, reference from their app. - Open up your
MainPage.cs
app
- Add
using Smokerlyzemodule.RNSmokerlyzemodule;
to the usings at the top of the file - Add
new RNSmokerlyzemodulePackage()
to theList<IReactPackage>
returned by thePackages
method
Usage
import {SmokerlyzeModule,EventSmokerlyze} from 'react-native-smokerlyzemodule';
/***********/
//khoi tao ,chay thiet bi
SmokerlyzeModule.Init().then((res)=>console.log(res));
//khai báo đăng kí nhận event đã cắm jack audio vào:
EventSmokerlyze.OnPlugin(event=>{console.log("data",event);}); // bool event.ready: true/false
/************/
//sau khi khoi tao xong thì sẽ đợi khoảng 5 giay thì nhận được event thiết bị đã sẵn sàng :OnDeviceReady:
//khai báo đăng kí nhận event:
EventSmokerlyze.OnDeviceReady(event=>{console.log("Ready to test",event);}); // bool event.ready: true/false
/************/
// sau khi thiết bị đã sẵn sàng thì bắt đầu test:
SmokerlyzeModule.StartTest().then(res=>console.log(res));
/**************/
// sau khi da bắt đầu test thành công, thì ta sẽ nhận được event OnStartTest
EventSmokerlyze.OnStartTest(event=>{console.log("startCountDown (bat dau hit vao)",event);});//bắt đầu giai đoạn chờ hít vào vao :(int) event.time: số miligiay đợi để tới giai đoạn thở ra
/**********/
// sau khi đã hết thời gian hít vào thì event OnStartBlew sẽ đc kích hoặt : (int) event.time: trả về khoảng thời gian để thổi hơi ra
EventSmokerlyze.OnStartBlew(event=>{console.log("StartTest (bat dau thoi)",event);});//bắt đầu giai đoạn đang thổi ra
/************/
// OnDeviceProgress: cập nhật dữ liệu khi đang test
EventSmokerlyze.OnProgress(event=>{console.log("Progress",event);});//du lieu trong giai doan thoi ra: (double) event.progress : value: 0-700, event.ppm : chi so ppm
/**************/
//khi ket thuc thì sẽ kích hoặt event FinishTest
EventSmokerlyze.OnFinishTest(event=>{console.log("FinishTest (Da thoi xong)",event);});//ket thuc test
/***********/
//để dừng việc test lại:
EventSmokerlyze.StopTest().then(res=>console.log(res));// res: true
/***********/
//Remove event đã đăng kí:
EventSmokerlyze.RemoveOnDeviceReady();
EventSmokerlyze.RemoveEventStartTest();
EventSmokerlyze.RemoveEventStartBlew();
EventSmokerlyze.RemoveEventProgress();
EventSmokerlyze.RemoveEventFinishTest();
//add Permissions
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />