function HkDevice(appKey, appSecret) {
|
this.appKey = appKey; //在萤石云获取
|
this.appSecret = appSecret; //在萤石云获取
|
this.accessToken = null;
|
this.livelist = null;
|
this.devicelist = null;
|
this.cameralist = null;
|
this.post = function(url, data, success) {
|
jQuery.ajax({
|
sender: this,
|
type: "POST",
|
url: url,
|
data: data,
|
dataType: "json",
|
success: function(data) {
|
success(this.sender, data);
|
}
|
});
|
};
|
|
/**
|
* 根据appKey和secret获取accessToken
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.getAccessToken = function(ret) {
|
this.post(
|
"https://open.ys7.com/api/lapp/token/get",
|
{ appKey: this.appKey, appSecret: this.appSecret },
|
function(sender, data) {
|
if (data.code == "200") {
|
sender.accessToken = data.data.accessToken;
|
}
|
ret(data);
|
}
|
);
|
};
|
|
/**
|
* 获取用户下直播视频列表
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.getLiveVideoList = function(ret) {
|
this.post(
|
"https://open.ys7.com/api/lapp/live/video/list",
|
{ accessToken: this.accessToken, pageStart: "0", pageSize: "50" },
|
function(sender, data) {
|
if (data.code == "200") {
|
sender.livelist = data.data;
|
}
|
ret(data);
|
}
|
);
|
};
|
|
/**
|
* 获取设备列表
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.getDeviceList = function(ret) {
|
this.post(
|
"https://open.ys7.com/api/lapp/device/list",
|
{ accessToken: this.accessToken, pageStart: "0", pageSize: "50" },
|
function(sender, data) {
|
if (data.code == "200") {
|
sender.devicelist = data.data;
|
}
|
ret(data);
|
}
|
);
|
};
|
|
/**
|
* 获取摄像头列表
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.getCamerasList = function(ret) {
|
var mPageStart = "0";
|
var mPageStartIndex = 0;
|
var mCamerasList = {
|
code: "200",
|
data: []
|
};
|
var cl_this = this;
|
|
function mGetCamerasList() {
|
cl_this.post(
|
"https://open.ys7.com/api/lapp/camera/list",
|
{
|
accessToken: cl_this.accessToken,
|
pageStart: mPageStart,
|
pageSize: "50"
|
},
|
function(sender, data) {
|
if (data.code == "200") {
|
mCamerasList.data = mCamerasList.data.concat(data.data);
|
mPageStartIndex++;
|
if (data.page.total > mPageStartIndex * 50) {
|
mPageStart = mPageStartIndex + "";
|
mGetCamerasList();
|
} else {
|
sender.cameralist = mCamerasList.data;
|
ret(mCamerasList);
|
}
|
}
|
}
|
);
|
}
|
|
mGetCamerasList();
|
};
|
|
/**
|
* 开始云台控制
|
* @param {Object} option
|
* {deviceSerial:设备序列号,
|
* channelNo:通道号,
|
* direction:镜像方向:操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距。 ,
|
* speed:云台速度:0-慢,1-适中,2-快}
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.setPtzTurn = function(option, ret) {
|
if (
|
!(
|
option.deviceSerial &&
|
option.channelNo &&
|
option.direction != undefined &&
|
option.speed
|
)
|
) {
|
ret();
|
return;
|
}
|
this.post(
|
"https://open.ys7.com/api/lapp/device/ptz/start",
|
{
|
accessToken: this.accessToken,
|
deviceSerial: option.deviceSerial,
|
channelNo: option.channelNo,
|
direction: option.direction,
|
speed: option.speed
|
},
|
function(sender, data) {
|
if (data.code == "200") {
|
}
|
ret(data);
|
}
|
);
|
};
|
|
/**
|
* 停止云台控制
|
* @param {Object} option
|
* {deviceSerial:设备序列号,
|
* channelNo:通道号}
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.setPtzStop = function(option, ret) {
|
if (!(option.deviceSerial && option.channelNo)) {
|
ret();
|
return;
|
}
|
this.post(
|
"https://open.ys7.com/api/lapp/device/ptz/stop",
|
{
|
accessToken: this.accessToken,
|
deviceSerial: option.deviceSerial,
|
channelNo: option.channelNo
|
},
|
function(sender, data) {
|
if (data.code == "200") {
|
}
|
ret(data);
|
}
|
);
|
};
|
/**
|
* 镜像翻转
|
* @param {Object} option
|
* {deviceSerial:设备序列号,
|
* channelNo:通道号,
|
* command:镜像方向:0-上下, 1-左右, 2-中心}
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.setPtzMirror = function(option, ret) {
|
if (!(option.deviceSerial && option.channelNo && option.command)) {
|
ret();
|
return;
|
}
|
this.post(
|
"https://open.ys7.com/api/lapp/device/ptz/stop",
|
{
|
accessToken: this.accessToken,
|
deviceSerial: option.deviceSerial,
|
channelNo: option.channelNo,
|
command: option.command
|
},
|
function(sender, data) {
|
if (data.code == "200") {
|
}
|
ret(data);
|
}
|
);
|
};
|
|
/**
|
* 根据时间获取历史影像
|
* @param {Object} option
|
* {deviceSerial:设备序列号,
|
* channelNo:通道号,
|
* startTime:起始时间,时间格式为:1378345128000。非必选,默认为当天0点
|
* endTime:结束时间,时间格式为:1378345128000。非必选,默认为当前时间
|
* recType:回放源,0-系统自动选择,1-云存储,2-本地录像。非必选,默认为0
|
* @param {function} ret 异步回调请求结果
|
*/
|
this.getPlaybackRecord = function(option, ret) {
|
if (!option.deviceSerial) {
|
ret();
|
return;
|
}
|
this.post(
|
"https://open.ys7.com/api/lapp/video/by/time",
|
{
|
accessToken: this.accessToken,
|
deviceSerial: option.deviceSerial,
|
channelNo: option.channelNo,
|
//"startTime":option.startTime,
|
//"endTime":option.endTime,
|
recType: 0
|
},
|
function(sender, data) {
|
if (data.code == "200") {
|
}
|
ret(data);
|
}
|
);
|
};
|
}
|