如何解决如何在 tomcat 中部署 webhid 应用程序?
我尝试使用 springboot 2.x 构建页面并从隐藏设备获取数据消息,并将其部署在 tomcat 中。 问题是当我尝试使用idea IDE运行应用程序或将其部署在本地tomcat中时,它正常工作并且chrome(v87)可以从hid设备获取所有数据消息,关键代码如下:
var g_iDataCount = 0;
var g_wbDevice = null;
const vendorId = 1234;
const productId = 5678;
async function getopenedDevice() {
if (!("hid" in navigator)) {
alert("HID-DEVICE IS NOT SUPPORTED!!!");
return null;
}
const devices = await navigator.hid.getDevices();
let device = devices.find(d => d.vendorId === vendorId && d.productId === productId);
if (!device) {
device = await navigator.hid.requestDevice({
filters: [{ vendorId,productId }],});
}
if (!device.opened) {
console.log("ready to open device...");
await device.open();
}
g_wbDevice = device;
return device;
}
var bStartRun = false;
$(".div-adc-app").on('click',handleClick);
async function timerReset() {
if (g_wbDevice != null && g_wbDevice != undefined && !g_wbDevice.opened) {
await g_wbDevice.open();
}
}
var intervalId = window.setInterval(timerReset,1000);
async function handleClick() {
const device = await getopenedDevice();
if(device != null && device != undefined)
{
// console.log("devices is : " + device);
device.addEventListener("inputreport",event => {
const { data,device,reportId } = event;
const aBuffer = data.buffer;
//console.log("aBuffer data : " + aBuffer);
var arr = Array.prototype.slice.call(new Uint8Array(data.buffer ));
var status = g_chartStatus.getStatus();
aController.takeAction(arr,status);
$(".div-data-count").html("get report count:" + g_iDataCount++);
if(g_iDataCount % 100 == 0) {
device.open();
}
});
bStartRun = true;
}else {
$(".div-data-count").html("the browser do not support HID device,exit.");
}
}
但是当我尝试在远程 linux 系统(安装了 jdk1.8)中部署 war 包时,它失败了,没有更明确的原因。它无法再次获取隐藏的设备,就像这里的图片一样。
那么,谁能给我一些有效的建议? 谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。