1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

bugfix 修复开启多个门禁websocket频繁断开问题;bugfix仅扫描门禁显示提示窗

This commit is contained in:
程序员小墨 2023-04-25 02:04:40 +08:00
parent 65563f5b75
commit 64b4fe31a3
3 changed files with 24 additions and 10 deletions

View File

@ -333,7 +333,7 @@ const baseUrl = "/"
修改 `backend/microservice-provider-access-8002/src/main/resources/static/access/assets/js/websocket.js` 文件
```
window.wsUrl = 'ws://【⚠此处修改为你的业务域名】/access/websocket/1';
window.wsUrl = 'ws://【⚠此处修改为你的业务域名】/access/websocket/';
```
> 注意,如果使用了 SSL 证书,那么 ws:// 要换成 wss://

View File

@ -2,10 +2,11 @@
* FIXME 环境配置
*
* window.wsUrl
* - 线上环境'wss://epp.only4.work/access/websocket/1'
* - 开发环境'ws://127.0.0.1:80/access/websocket/1'; 'ws://127.0.0.1:8002/access/websocket/1';
* - 线上环境'wss://epp.only4.work/access/websocket/'
* - 开发环境'ws://127.0.0.1:80/access/websocket/'
* 'ws://127.0.0.1:8002/access/websocket/'
*/
window.wsUrl = 'ws://127.0.0.1:80/access/websocket/1';
window.wsUrl = 'ws://127.0.0.1:80/access/websocket/';
window.ws = null; // WebSocket 实例对象
@ -15,9 +16,20 @@ window.ws = null; // WebSocket 实例对象
return
}
function getWsUrl() {
function getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
return `${window.wsUrl}${getUUID()}`
}
function createConn() {
// 创建webscoket 对象
const ws = new WebSocket(window.wsUrl)
const ws = new WebSocket(getWsUrl() /* window.wsUrl */)
// 执行上面的语句之后,客户端就会与服务器进行连接
// readyState返回当前实例对象的当前状态
@ -47,8 +59,10 @@ window.ws = null; // WebSocket 实例对象
switch (result.action) {
case 'onscan':
case 'onopen':
console.log(result.action)
window.showResult(result.action)
if (window.currentGate && result.gateId === window.currentGate.id) {
console.log(result.action)
window.showResult(result.action)
}
break;
default:
console.log("switch=>default", result.action)

View File

@ -18,7 +18,7 @@ public class WebSocketServer {
private Session session;
// session集合,存放对应的session
private static ConcurrentHashMap<Integer, Session> sessionPool = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, Session> sessionPool = new ConcurrentHashMap<>();
// concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<>();
@ -30,7 +30,7 @@ public class WebSocketServer {
* @param userId 用户ID
*/
@OnOpen
public void onOpen(Session session, @PathParam(value = "userId") Integer userId) {
public void onOpen(Session session, @PathParam(value = "userId") String userId) {
log.info("WebSocket建立连接中,连接用户ID{}", userId);
try {
Session historySession = sessionPool.get(userId);
@ -84,7 +84,7 @@ public class WebSocketServer {
* @param userId 用户ID
* @param message 发送的消息
*/
public static void sendMessageByUser(Integer userId, String message) {
public static void sendMessageByUser(String userId, String message) {
log.info("用户ID" + userId + ",推送内容:" + message);
Session session = sessionPool.get(userId);
try {