ZengTao
2024-07-17 ae378101afe2a486c22b35cd03d9c2082143197a
hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java
@@ -22,12 +22,6 @@
    public static ConfigurableApplicationContext applicationContext;
    // 解决无法注入mapper问题 //使用方法
    // homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class);
    public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) {
        WebSocketServer.applicationContext = configurableApplicationContext;
    }
    private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
    private List<String> messages;
    /**
@@ -49,6 +43,8 @@
    public void onOpen(Session session, @PathParam("username") String username) {
        this.username = username;
        this.session = session;
        this.session.setMaxTextMessageBufferSize(12*1024*1024);
        this.session.setMaxBinaryMessageBufferSize(12*1024*1024);
        List<WebSocketServer> webSocketServers = sessionMap.get(username);
        if (webSocketServers == null) {
            ArrayList<WebSocketServer> arrayListwebserver = new ArrayList<WebSocketServer>();
@@ -102,7 +98,7 @@
     *
     * @param message 客户端发送过来的消息
     */
    @OnMessage
    @OnMessage(maxMessageSize = 5242880)
    public void onMessage(String message, Session session, @PathParam("username") String username) {
        log.info("服务端收到用户username={}的消息:{}", username, message);
        JSONObject obj = JSONUtil.parseObj(message);
@@ -111,8 +107,6 @@
        JSONObject jsonObject = new JSONObject();
        jsonObject.set("message", text);
        this.messages.add(text);
        this.sendMessage(jsonObject.toString()); // JSONUtil.toJsonStr(jsonObject)
    }
    @OnError