如何在 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 包时,它失败了,没有更明确的原因。它无法再次获取隐藏的设备,就像这里的图片一样。

那么,谁能给我一些有效的建议? 谢谢。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)