hilink-ts
v3.0.1
Published
智能家居hilink扩展h5应用工具开发
Downloads
283
Readme
hilink-ts
npm i hilink-ts -S
- 获取设备数据更方便
old
interface IResult {
services: [];
}
JSON.hParse = function (res: string) {
let data,
dataStr = res;
// 去除object外多余的 "
dataStr = dataStr.replace(/"{/g, "{");
dataStr = dataStr.replace(/}"/g, "}");
// \\ -普通反斜杠; \n -换行符; \r -回车符; \t -制表符; \f -换页符; \t -垂直制表符;
dataStr = dataStr.replace(/\\|\n|\r|\t|\f|\t/g, "");
data = JSON.parse(dataStr);
return data;
};
// web页面中需实现该函数,用来获取执行结果
function resultCallback(resultStr: string) {
var result: IResult = JSON.hParse(resultStr); // 请求的返回结果
console.log(result);
}
hilink.getDevCacheAll("0", "", "resultCallback");
new
// 从本地查询设备状态
import { getDevCacheAll } from "hilink-ts";
interface IResult {
services: [];
}
function resultCallback(data: IResult) {
console.log(data);
}
getDevCacheAll("0", "", resultCallback);
- 不用配置全局默认方法
old
window["deviceEventCallback"] = function (res) {};
window.onPause = function (res) {};
window.onResume = function (res) {};
window.onNetworkChanged = function (res) {};
new
import { init } from "hilink-ts";
init();