code_app/test/webscan/demo/sftdevice.js

263 lines
6.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//高拍仪与身份证读卡器设备
var ws_gpysfz={
type:1,
port:9456,
text:"高拍仪与身份证识读机",
url:"ws://127.0.0.1:9456/",
ws:null,
connected:false
};
//手写签名设备
var ws_sxsb={
type:2,
port:9457,
text:"手写签名",
url:"ws://127.0.0.1:9457/",
ws:null,
connected:false
};
//扫描仪设备
var ws_smy={
type:3,
port:9458,
text:"扫描设备",
url:"ws://127.0.0.1:9458/",
ws:null,
connected:false
};
//日志输出
function addlog(obj){
console.log(obj);
if(typeof(obj)=="string" && typeof(addDebugLog)!="undefined"){
addDebugLog(obj);
}
}
function sendWsData(ws,msg){
try{
var jsData = typeof(msg)=="string"?msg:JSON.stringify(msg);
if(typeof(addSendLog)!="undefined"){
addSendLog(jsData);
}
ws.send(jsData);
return true;
}
catch(e){
addlog("发送 " + msg + " 消息失败");
addlog(e);
return false;
}
}
function sendMessage(obj,msg){
var bRet=false;
if(obj.ws!=null&&obj.ws.readyState==1){
bRet = sendWsData(obj.ws,msg);
}
else{
addlog(obj.url + " 未连接成功!");
}
return bRet;
}
//发送高拍仪身份证消息
function sendGpySfzMessage(msg){
return sendMessage(ws_gpysfz,msg);
}
//发送手写签名消息
function sendSxqmMessage(msg){
return sendMessage(ws_sxsb,msg);
}
//发送扫描仪消息
function sendSmyMessage(msg){
return sendMessage(ws_smy,msg);
}
//接收消息 自动调用 processMessage 函数
function recvMessage(msg){
if(typeof(processMessage)!="undefined"){
processMessage(msg);
}
}
function onUpdateStatus(t,p,f){
if(typeof(updateStatus)!="undefined"){
updateStatus(t,p,f);
}
}
//初始化WebSocket连接
function ConnectServer(device) {
try{
device.connected = false;
if ('WebSocket' in window || window.WebSocket) {
device.ws = new WebSocket(device.url);
}
else if ('MozWebSocket' in window) {
device.ws = new MozWebSocket(device.url);
}
else {
alert("浏览器版本太低请使用Chrome、Firefox浏览器");
return;
}
if(device.ws!=null){
device.ws.onopen = function () {
device.connected = true;
onUpdateStatus(device.type,device.port,true);
}
device.ws.onclose = function (e) {
device.connected = false;
onUpdateStatus(device.type,device.port,false);
}
device.ws.onmessage = function (e) {
var txt = "";
if (typeof (e.data) == "string") {
txt = e.data;
}
else{
try {
txt = JSON.stringify(e.data);
}
catch (e){
txt = "";
addlog("数据解析失败!");
addlog(e);
}
}
if(txt!="") {
recvMessage(txt);
}
}
device.ws.onerror = function (e) {
addlog(e);
};
device.ws.open();//连接 websocket
addlog(device.url+" 初始化完成!");
}
else{
onUpdateStatus(device.type,device.port,false);
addlog(device.url+" 初始化失败!");
}
}
catch(e){
addlog(device.url+" 连接失败!");
addlog(e);
}
}
//初始化司法厅设备
function InitDevice(){
ConnectServer(ws_gpysfz);
ConnectServer(ws_sxsb);
ConnectServer(ws_smy);
}
//高拍仪接口函数
//发送获取视频设备列表消息
function SendGetVideoDevices(){
return sendGpySfzMessage({"Func":"GetVideoDevices","arg":"0"});
}
//发送获取音频设备列表消息
function SendGetAudioDevices(){
return sendGpySfzMessage({"Func":"GetAudioDevices","arg":"0"});
}
//发送获取分辨率列表消息
function SendGetResolution(index){
return sendGpySfzMessage({"Func":"GetResolution","arg":""+index});
}
//发送切换视频分辨率消息
function SendChangeVideoResolution(index){
return sendGpySfzMessage({"Func":"ChangeVideoResolution","arg":""+index});
}
//发送打开指定视频消息
function SendStartVideo(index){
return sendGpySfzMessage({"Func":"StartVideo","arg":""+index});
}
//发送打开主视频消息
function SendStartRunMain(){
return sendGpySfzMessage({"Func":"StartRunMain","arg":"0"});
}
//发送打开副视频消息
function SendStartRunSub(){
return sendGpySfzMessage({"Func":"StartRunSub","arg":"0"});
}
//发送关闭视频消息
function SendStopVideo(){
return sendGpySfzMessage({"Func":"StopVideo","arg":"0"});
}
//发送文件方式拍照消息
function SendCaptureFile(filename){
return sendGpySfzMessage({"Func":"CaptureFile","arg":""+filename});
}
//发送Base64方式拍照消息
function SendCaptureBase64(format){
return sendGpySfzMessage({"Func":"CaptureBase64","arg":""+format});
}
//发送左旋转消息
function SendRotateLeft(angle){
return sendGpySfzMessage({"Func":"RotateLeft","arg":""+angle});
}
//发送右旋转消息
function SendRotateRight(angle){
return sendGpySfzMessage({"Func":"RotateRight","arg":""+angle});
}
//发送放大消息
function SendZoomIn(){
return sendGpySfzMessage({"Func":"ZoomIn","arg":"0"});
}
//发送缩小消息
function SendZoomOut(){
return sendGpySfzMessage({"Func":"ZoomOut","arg":"0"});
}
//发送切换裁剪方式消息
function SendChangeCutType(cutType){
return sendGpySfzMessage({"Func":"ChangeCutType","arg":""+cutType});
}
//发送设置色彩模式消息
function SendSetColorType(colorType){
return sendGpySfzMessage({"Func":"SetColorType","arg":""+colorType});
}
//发送设置JPG图片压缩率消息
function SendSetJPGQuality(quality){
return sendGpySfzMessage({"Func":"SetJPGQuality","arg":""+quality});
}
//身份证识读机接口函数
//发送读取身份证消息
function SendReadIDCard(){
return sendGpySfzMessage({"Func":"ReadIDCard","arg":"0"});
}
//手写签名设备接口函数
//发送开始签字消息
function SendStartSign(){
return sendSxqmMessage({"Func":"StartSign","arg":"0"});
}
//发送关闭签字消息
function SendCloseSign(){
return sendSxqmMessage({"Func":"CloseSign","arg":"0"});
}
//扫描设备接口函数
//发送获取所有SANE/twain源名称消息
function SendGetDeviceList(){
return sendSmyMessage({"Func":"GetDeviceList","arg":"0"});
}
//发送选择SANE/twain源名称消息
function SendSelectDevice(index){
return sendSmyMessage({"Func":"SelectDevice","arg":""+index});
}
//发送设置色彩模式消息
function SendSetScanColorType(colorType){
return sendSmyMessage({"Func":"SetScanColorType","arg":""+colorType});
}
//发送设置扫描分辨率消息
function SendSetDPI(dpi){
return sendSmyMessage({"Func":"SetDPI","arg":""+dpi});
}
//发送设置单双面消息
function SendSetDuplex(duplex){
return sendSmyMessage({"Func":"SetDuplex","arg":""+duplex});
}
//发送设置JPG图片压缩率消息
function SendSetScanJPGQuality(quality){
return sendSmyMessage({"Func":"SetScanJPGQuality","arg":""+quality});
}
//发送开始扫描消息
function SendStartScan(page){
return sendSmyMessage({"Func":"StartScan","arg":""+page});
}