mirror of
https://gitee.com/republicline/rax-remote-v2.git
synced 2025-08-24 07:44:57 +08:00
fixed: 修正断连逻辑
This commit is contained in:
parent
48a763cf10
commit
39341f6c20
|
@ -88,13 +88,13 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
if ("webResponseConnection".equals(msgType)) {
|
if ("webResponseConnection".equals(msgType)) {
|
||||||
String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
||||||
// 给unity端发送网页端拒绝连接
|
// 给unity端发送网页端拒绝连接
|
||||||
aiMedicineTimer.sendConnectionResponseToUnity(databaseName, webConnectionFlag);
|
aiMedicineTimer.sendConnectionResponseToUnity(patientName,idNum,date,databaseName, webConnectionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理web端请求或断开连接
|
// 处理web端请求或断开连接
|
||||||
if ("webRequestConnection".equals(msgType)) {
|
if ("webRequestConnection".equals(msgType)) {
|
||||||
String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
||||||
aiMedicineTimer.sendWebRequestConnectionMsg(databaseName, webRequestFlag);
|
aiMedicineTimer.sendWebRequestConnectionMsg(patientName,idNum,date,databaseName, webRequestFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理发送给药相关
|
// 处理发送给药相关
|
||||||
|
|
|
@ -71,13 +71,13 @@ public class MachineFeedbackHandler implements WebSocketHandler {
|
||||||
if ("unityRequestConnection".equals(msgType)) {
|
if ("unityRequestConnection".equals(msgType)) {
|
||||||
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||||
// u3d端请求网页端连接或断开
|
// u3d端请求网页端连接或断开
|
||||||
aiMedicineTimer.sendUnityRequestConnectionMsg(databaseName, unityConnectionFlag);
|
aiMedicineTimer.sendUnityRequestConnectionMsg(patientName, idNum, date, databaseName, unityConnectionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// u3d相应网页端的请求
|
// u3d相应网页端的请求
|
||||||
if ("unityResponseConnection".equals(msgType)) {
|
if ("unityResponseConnection".equals(msgType)) {
|
||||||
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
String unityConnectionFlag = jsonObject.getString("unityConnectionFlag");
|
||||||
aiMedicineTimer.sendConnectionResponseToWeb(databaseName, unityConnectionFlag);
|
aiMedicineTimer.sendConnectionResponseToWeb(patientName, idNum, date,databaseName, unityConnectionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
if (aiMedicineTimer.getWebSession(databaseName) != null) {
|
||||||
|
|
|
@ -18,10 +18,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
public class AIMedicineTimer {
|
public class AIMedicineTimer {
|
||||||
|
|
||||||
// 存放sessionId与dbName的映射关系
|
// 存放sessionId与dbName的映射关系
|
||||||
private static final Map<String, WebSocketSession> webDbSessionMap = new ConcurrentHashMap();
|
private static final Map<String, WebSocketSession> webDbSessionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// 存放sessionId的状态
|
// 存放sessionId的状态
|
||||||
private static final Map<WebSocketSession, Boolean> webStatusMap = new ConcurrentHashMap();
|
private static final Map<WebSocketSession, Boolean> webStatusMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// unity 端的dbname 和 sessionId 映射
|
// unity 端的dbname 和 sessionId 映射
|
||||||
private static final Map<String, WebSocketSession> u3DDbSessionMap = new ConcurrentHashMap<>();
|
private static final Map<String, WebSocketSession> u3DDbSessionMap = new ConcurrentHashMap<>();
|
||||||
|
@ -30,7 +30,7 @@ public class AIMedicineTimer {
|
||||||
private static final Map<WebSocketSession, Boolean> u3DStatusMap = new ConcurrentHashMap<>();
|
private static final Map<WebSocketSession, Boolean> u3DStatusMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// unity响应web端的信息
|
// unity响应web端的信息
|
||||||
public void sendConnectionResponseToWeb(String databaseName, String flag) throws IOException {
|
public void sendConnectionResponseToWeb(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||||
WebSocketSession webSession = getWebSession(databaseName);
|
WebSocketSession webSession = getWebSession(databaseName);
|
||||||
if (webSession != null) {
|
if (webSession != null) {
|
||||||
JSONObject unityMsg = new JSONObject();
|
JSONObject unityMsg = new JSONObject();
|
||||||
|
@ -39,6 +39,9 @@ public class AIMedicineTimer {
|
||||||
setU3DStatus(databaseName, true);
|
setU3DStatus(databaseName, true);
|
||||||
unityMsg.put("msgType", "unityResponseConnection");
|
unityMsg.put("msgType", "unityResponseConnection");
|
||||||
unityMsg.put("unityConnectionFlag", "1");
|
unityMsg.put("unityConnectionFlag", "1");
|
||||||
|
unityMsg.put("patientName", patientName);
|
||||||
|
unityMsg.put("idNum", idNum);
|
||||||
|
unityMsg.put("date", date);
|
||||||
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||||
}
|
}
|
||||||
if ("0".equals(flag)) {
|
if ("0".equals(flag)) {
|
||||||
|
@ -48,6 +51,9 @@ public class AIMedicineTimer {
|
||||||
unityMsg = new JSONObject();
|
unityMsg = new JSONObject();
|
||||||
unityMsg.put("msgType", "unityResponseConnection");
|
unityMsg.put("msgType", "unityResponseConnection");
|
||||||
unityMsg.put("unityConnectionFlag", "0");
|
unityMsg.put("unityConnectionFlag", "0");
|
||||||
|
unityMsg.put("patientName", patientName);
|
||||||
|
unityMsg.put("idNum", idNum);
|
||||||
|
unityMsg.put("date", date);
|
||||||
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
webSession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -59,17 +65,22 @@ public class AIMedicineTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unity端请求网页端连接或断开连接
|
// unity端请求网页端连接或断开连接
|
||||||
public void sendUnityRequestConnectionMsg(String databaseName, String flag) throws IOException {
|
public void sendUnityRequestConnectionMsg(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||||
WebSocketSession webSession = getWebSession(databaseName);
|
WebSocketSession webSession = getWebSession(databaseName);
|
||||||
System.out.println("webSession = " + webSession);
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
if ("1".equals(flag)) {
|
if ("1".equals(flag)) {
|
||||||
|
jsonObject.put("patientName",patientName);
|
||||||
|
jsonObject.put("idNum",idNum);
|
||||||
|
jsonObject.put("date",date);
|
||||||
jsonObject.put("msgType", "unityRequestConnection");
|
jsonObject.put("msgType", "unityRequestConnection");
|
||||||
jsonObject.put("unityConnectionFlag", "1");
|
jsonObject.put("unityConnectionFlag", "1");
|
||||||
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||||
setU3DStatus(databaseName, true);
|
setU3DStatus(databaseName, true);
|
||||||
}
|
}
|
||||||
if ("0".equals(flag)) {
|
if ("0".equals(flag)) {
|
||||||
|
jsonObject.put("patientName",patientName);
|
||||||
|
jsonObject.put("idNum",idNum);
|
||||||
|
jsonObject.put("date",date);
|
||||||
jsonObject.put("msgType", "unityRequestConnection");
|
jsonObject.put("msgType", "unityRequestConnection");
|
||||||
jsonObject.put("unityConnectionFlag", "0");
|
jsonObject.put("unityConnectionFlag", "0");
|
||||||
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
webSession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||||
|
@ -93,37 +104,44 @@ public class AIMedicineTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// web端请求unity端连接或断开连接
|
// web端请求unity端连接或断开连接
|
||||||
public void sendWebRequestConnectionMsg(String databaseName, String flag) throws IOException {
|
public void sendWebRequestConnectionMsg(String patientName,String idNum, String date,String databaseName, String flag) throws IOException {
|
||||||
WebSocketSession unitySession = getUnitySession(databaseName);
|
WebSocketSession unitySession = getUnitySession(databaseName);
|
||||||
System.out.println("unitySession = " + unitySession);
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
if ("1".equals(flag)) {
|
if ("1".equals(flag)) {
|
||||||
System.out.println("网站端请求连接");
|
jsonObject.put("patientName",patientName);
|
||||||
|
jsonObject.put("idNum",idNum);
|
||||||
|
jsonObject.put("date",date);
|
||||||
jsonObject.put("msgType", "webRequestConnection");
|
jsonObject.put("msgType", "webRequestConnection");
|
||||||
jsonObject.put("webConnectionFlag", "1");
|
jsonObject.put("webConnectionFlag", "1");
|
||||||
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||||
setWebStatus(databaseName,true);
|
setWebStatus(databaseName,true);
|
||||||
}
|
}
|
||||||
if ("0".equals(flag)) {
|
if ("0".equals(flag)) {
|
||||||
|
jsonObject.put("patientName",patientName);
|
||||||
|
jsonObject.put("idNum",idNum);
|
||||||
|
jsonObject.put("date",date);
|
||||||
jsonObject.put("msgType", "webRequestConnection");
|
jsonObject.put("msgType", "webRequestConnection");
|
||||||
jsonObject.put("webConnectionFlag", "0");
|
jsonObject.put("webConnectionFlag", "0");
|
||||||
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
unitySession.sendMessage(new TextMessage(jsonObject.toJSONString().getBytes()));
|
||||||
setU3DStatus(databaseName, false);
|
setU3DStatus(databaseName, false);
|
||||||
// 把网页端的sessionStatus置为false
|
|
||||||
setWebStatus(databaseName, false);
|
setWebStatus(databaseName, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendConnectionResponseToUnity(String databaseName, String flag) throws IOException {
|
public void sendConnectionResponseToUnity(String patientName,String idNum,String date,String databaseName, String flag) throws IOException {
|
||||||
WebSocketSession unitySession = getUnitySession(databaseName);
|
WebSocketSession unitySession = getUnitySession(databaseName);
|
||||||
if (unitySession != null) {
|
if (unitySession != null) {
|
||||||
JSONObject unityMsg = new JSONObject();
|
JSONObject unityMsg = new JSONObject();
|
||||||
if ("1".equals(flag)) {
|
if ("1".equals(flag)) {
|
||||||
// 网页端同意连接
|
|
||||||
setWebStatus(databaseName, true);
|
|
||||||
unityMsg.put("msgType", "webResponseConnection");
|
unityMsg.put("msgType", "webResponseConnection");
|
||||||
unityMsg.put("webConnectionFlag", "1");
|
unityMsg.put("webConnectionFlag", "1");
|
||||||
|
unityMsg.put("patientName", patientName);
|
||||||
|
unityMsg.put("idNum", idNum);
|
||||||
|
unityMsg.put("date", date);
|
||||||
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||||
|
// 网页端同意连接
|
||||||
|
setWebStatus(databaseName, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
if ("0".equals(flag)) {
|
if ("0".equals(flag)) {
|
||||||
// 网页端拒绝连接
|
// 网页端拒绝连接
|
||||||
|
@ -131,6 +149,9 @@ public class AIMedicineTimer {
|
||||||
unityMsg = new JSONObject();
|
unityMsg = new JSONObject();
|
||||||
unityMsg.put("msgType", "connection refused");
|
unityMsg.put("msgType", "connection refused");
|
||||||
unityMsg.put("webConnectionFlag", "0");
|
unityMsg.put("webConnectionFlag", "0");
|
||||||
|
unityMsg.put("patientName", patientName);
|
||||||
|
unityMsg.put("idNum", idNum);
|
||||||
|
unityMsg.put("date", date);
|
||||||
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
unitySession.sendMessage(new TextMessage(unityMsg.toJSONString().getBytes()));
|
||||||
// 把unity的sessionStatus置为false
|
// 把unity的sessionStatus置为false
|
||||||
setU3DStatus(databaseName, false);
|
setU3DStatus(databaseName, false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user