bugfix 修复开启多个门禁websocket频繁断开问题;bugfix仅扫描门禁显示提示窗
This commit is contained in:
parent
65563f5b75
commit
64b4fe31a3
@ -333,7 +333,7 @@ const baseUrl = "/"
|
|||||||
修改 `backend/microservice-provider-access-8002/src/main/resources/static/access/assets/js/websocket.js` 文件
|
修改 `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://
|
> 注意,如果使用了 SSL 证书,那么 ws:// 要换成 wss://
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
* FIXME 环境配置
|
* FIXME 环境配置
|
||||||
*
|
*
|
||||||
* window.wsUrl
|
* window.wsUrl
|
||||||
* - 线上环境:'wss://epp.only4.work/access/websocket/1'
|
* - 线上环境:'wss://epp.only4.work/access/websocket/'
|
||||||
* - 开发环境:'ws://127.0.0.1:80/access/websocket/1'; 'ws://127.0.0.1:8002/access/websocket/1';
|
* - 开发环境:'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 实例对象
|
window.ws = null; // WebSocket 实例对象
|
||||||
|
|
||||||
@ -15,9 +16,20 @@ window.ws = null; // WebSocket 实例对象
|
|||||||
return
|
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() {
|
function createConn() {
|
||||||
// 创建webscoket 对象
|
// 创建webscoket 对象
|
||||||
const ws = new WebSocket(window.wsUrl)
|
const ws = new WebSocket(getWsUrl() /* window.wsUrl */)
|
||||||
// 执行上面的语句之后,客户端就会与服务器进行连接
|
// 执行上面的语句之后,客户端就会与服务器进行连接
|
||||||
|
|
||||||
// readyState返回当前实例对象的当前状态
|
// readyState返回当前实例对象的当前状态
|
||||||
@ -47,8 +59,10 @@ window.ws = null; // WebSocket 实例对象
|
|||||||
switch (result.action) {
|
switch (result.action) {
|
||||||
case 'onscan':
|
case 'onscan':
|
||||||
case 'onopen':
|
case 'onopen':
|
||||||
console.log(result.action)
|
if (window.currentGate && result.gateId === window.currentGate.id) {
|
||||||
window.showResult(result.action)
|
console.log(result.action)
|
||||||
|
window.showResult(result.action)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("switch=>default", result.action)
|
console.log("switch=>default", result.action)
|
||||||
|
@ -18,7 +18,7 @@ public class WebSocketServer {
|
|||||||
private Session session;
|
private Session session;
|
||||||
|
|
||||||
// session集合,存放对应的session
|
// session集合,存放对应的session
|
||||||
private static ConcurrentHashMap<Integer, Session> sessionPool = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<String, Session> sessionPool = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象。
|
// concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象。
|
||||||
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<>();
|
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<>();
|
||||||
@ -30,7 +30,7 @@ public class WebSocketServer {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
*/
|
*/
|
||||||
@OnOpen
|
@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);
|
log.info("WebSocket建立连接中,连接用户ID:{}", userId);
|
||||||
try {
|
try {
|
||||||
Session historySession = sessionPool.get(userId);
|
Session historySession = sessionPool.get(userId);
|
||||||
@ -84,7 +84,7 @@ public class WebSocketServer {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param message 发送的消息
|
* @param message 发送的消息
|
||||||
*/
|
*/
|
||||||
public static void sendMessageByUser(Integer userId, String message) {
|
public static void sendMessageByUser(String userId, String message) {
|
||||||
log.info("用户ID:" + userId + ",推送内容:" + message);
|
log.info("用户ID:" + userId + ",推送内容:" + message);
|
||||||
Session session = sessionPool.get(userId);
|
Session session = sessionPool.get(userId);
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user