文件名从 src/main/java/com/fzzy/gateway/sc2023/websocket/WebSocketDeviceLed.java 修改 |
| | |
| | | package com.fzzy.gateway.sc2023.websocket; |
| | | package com.fzzy.gateway.hx2023.websocket; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.gateway.sc2023.data.WebSocketPacket; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.WebSocketPacket; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @ServerEndpoint(value = "/device-message-sender/${productId}/${deviceId}") |
| | | @ServerEndpoint(value = "/device-message-sender/{productId}/{deviceId}") |
| | | public class WebSocketDeviceLed { |
| | | |
| | | private static Map<String, Session> sessionPool = new ConcurrentHashMap<>(); |
| | |
| | | sessionPool.put(key, session); |
| | | sessionIds.put(session.getId(), key); |
| | | |
| | | ScConstant.updateOnline(deviceId); |
| | | |
| | | log.info("new webSocket,clientId={}", key); |
| | | } |
| | | |
| | |
| | | |
| | | sessionPool.remove(key); |
| | | sessionIds.remove(session.getId()); |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | |
| | | log.info("WebSocket杩炴帴鍏抽棴={}", key); |
| | | |
| | |
| | | |
| | | String key = sessionIds.get(session.getId()); |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | |
| | | sessionPool.remove(key); |
| | | sessionIds.remove(session.getId()); |
| | | error.printStackTrace(); |