From a2c18aed7da4b84e118ae2f3a28779607d5ecff7 Mon Sep 17 00:00:00 2001 From: 艾金辉 <1144154118@qq.com> Date: 星期六, 22 七月 2023 09:39:47 +0800 Subject: [PATCH] 根据carId获取车辆 --- ruoyi-common/src/main/java/com/ruoyi/common/websocket/service/ChatServerEndpoint.java | 20 +++++++++----------- 1 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/websocket/service/ChatServerEndpoint.java b/ruoyi-common/src/main/java/com/ruoyi/common/websocket/service/ChatServerEndpoint.java index 7ed66be..5e7303d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/websocket/service/ChatServerEndpoint.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/websocket/service/ChatServerEndpoint.java @@ -23,12 +23,12 @@ @Component @Slf4j(topic = "websocket") -@ServerEndpoint("/websocket") +@ServerEndpoint("/websocket/{userId}") public class ChatServerEndpoint { @OnOpen - public void openSession( Session session) { - String userId = SecurityUtils.getUserId(); + public void openSession( @PathParam("userId")String userId, Session session) { + ONLINE_USER_SESSIONS.put(userId, session); String message = "鐢ㄦ埛[" + userId + "] 鎴愬姛杩炴帴锛�"; log.info("鐢ㄦ埛鐧诲綍锛�"+message); @@ -36,23 +36,21 @@ } @OnMessage - public void onMessage( String message) { + public void onMessage(@PathParam("userId")String userId, String message) { log.info("鏀跺埌娑堟伅锛�"+message); - String userId = SecurityUtils.getUserId(); Session session = ONLINE_USER_SESSIONS.get(userId); sendMessage(session,message); // sendMessageAll("鐢ㄦ埛[" + userid + "] : " + message); } @OnClose - public void onClose( Session session) { - String userId = SecurityUtils.getUserId(); + public void onClose( @PathParam("userId")String userId,Session session) { //褰撳墠鐨凷ession 绉婚櫎 ONLINE_USER_SESSIONS.remove(userId); - //骞朵笖閫氱煡鍏朵粬浜哄綋鍓嶇敤鎴峰凡缁忕寮�鑱婂ぉ瀹や簡 - String message="鐢ㄦ埛[" + userId + "] 鏂紑杩炴帴锛�"; - sendMessage(session,message); - log.info("鍙戦�佹秷鎭細"+message); +// //骞朵笖閫氱煡鍏朵粬浜哄綋鍓嶇敤鎴峰凡缁忕寮�鑱婂ぉ瀹や簡 +// String message="鐢ㄦ埛[" + userId + "] 鏂紑杩炴帴锛�"; +// sendMessage(session,message); +// log.info("鍙戦�佹秷鎭細"+message); try { session.close(); } catch (IOException e) { -- Gitblit v1.9.3