提交 54c58976 authored 作者: wangqiang's avatar wangqiang

Merge remote-tracking branch 'origin/master'

...@@ -343,9 +343,18 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -343,9 +343,18 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
if ("remote_control".equals(mqttRpcDataMessage.getMethod())) {// 远程控制请求 if ("remote_control".equals(mqttRpcDataMessage.getMethod())) {// 远程控制请求
log.info("收到远程控制请求!!!"); log.info("收到远程控制请求!!!");
if (vncServerIsRunning()) {
log.warn("VNC Server 已在运行中,忽略此次请求");
return;
}
SysConfigUtil.saveProperty("control.request", "1"); SysConfigUtil.saveProperty("control.request", "1");
return; return;
} }
if ("remote_control_exit".equals(mqttRpcDataMessage.getMethod())) {
remoteControlController.timer.cancel();
Runtime.getRuntime().exec("cmd /c net stop uvnc_service");
return;
}
if ("remote_control_accept".equals(mqttRpcDataMessage.getMethod())) { if ("remote_control_accept".equals(mqttRpcDataMessage.getMethod())) {
log.info("远程控制请求接受!!! params: {}", mqttRpcDataMessage.getParams()); log.info("远程控制请求接受!!! params: {}", mqttRpcDataMessage.getParams());
Long minutes = Convert.toLong(mqttRpcDataMessage.getParams()); Long minutes = Convert.toLong(mqttRpcDataMessage.getParams());
...@@ -359,6 +368,19 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -359,6 +368,19 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
} }
} }
private static boolean vncServerIsRunning() throws IOException {
Process process = Runtime.getRuntime().exec("cmd /c sc query uvnc_service");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("STATE")) return line.endsWith("RUNNING");
}
process.destroy();
}
return false;
}
private void onGatewayAttributesGet(String message) { private void onGatewayAttributesGet(String message) {
log.info("Configuration arrived! {}", message); log.info("Configuration arrived! {}", message);
JsonNode payload = fromString(message); JsonNode payload = fromString(message);
......
...@@ -72,7 +72,7 @@ public class RemoteControlController { ...@@ -72,7 +72,7 @@ public class RemoteControlController {
return startVncServer(minutes); return startVncServer(minutes);
} }
private Timer timer = new Timer(); public Timer timer = new Timer();
public synchronized R<Void> startVncServer(long minutes) public synchronized R<Void> startVncServer(long minutes)
throws IOException, ConfigParser.DuplicateSectionException, ConfigParser.NoSectionException, InterruptedException { throws IOException, ConfigParser.DuplicateSectionException, ConfigParser.NoSectionException, InterruptedException {
...@@ -141,7 +141,7 @@ public class RemoteControlController { ...@@ -141,7 +141,7 @@ public class RemoteControlController {
String mac = MacAddrUtil.get(); String mac = MacAddrUtil.get();
JSONObject rsp = JSONUtil.parseObj(HttpUtil.get(gateway + StrUtil.format(deviceInfoUrl, mac))); JSONObject rsp = JSONUtil.parseObj(HttpUtil.get(gateway + StrUtil.format(deviceInfoUrl, mac)));
if (ObjectUtil.notEqual(rsp.getInt("code"), 0)) { if (ObjectUtil.notEqual(rsp.getInt("code"), 0)) {
log.warn("查询设备信息失败, msg: {}", rsp.getStr("msg")); log.error("查询设备信息失败, msg: {}", rsp.getStr("msg"));
return null; return null;
} }
return remoteId = rsp.getJSONObject("data").getStr("remoteId"); return remoteId = rsp.getJSONObject("data").getStr("remoteId");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论