|
@@ -3,6 +3,7 @@ package com.ym.mec.biz.handler;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.ym.mec.biz.dal.dto.WebSocketClientDetail;
|
|
import com.ym.mec.biz.dal.dto.WebSocketClientDetail;
|
|
import com.ym.mec.biz.dal.dto.WebSocketInfo;
|
|
import com.ym.mec.biz.dal.dto.WebSocketInfo;
|
|
|
|
+import com.ym.mec.biz.dal.enums.WebsocketTypeEnum;
|
|
import com.ym.mec.biz.service.SoundSocketService;
|
|
import com.ym.mec.biz.service.SoundSocketService;
|
|
import com.ym.mec.biz.service.WebSocketEventHandler;
|
|
import com.ym.mec.biz.service.WebSocketEventHandler;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -30,21 +31,21 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
*/
|
|
*/
|
|
public static final Map<String, WebSocketClientDetail> WS_CLIENTS = new ConcurrentHashMap<>();
|
|
public static final Map<String, WebSocketClientDetail> WS_CLIENTS = new ConcurrentHashMap<>();
|
|
|
|
|
|
- private static Map<String, WebSocketEventHandler> appMap = new ConcurrentHashMap<>();
|
|
+ private static Map<WebsocketTypeEnum, WebSocketEventHandler> appMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
* @describe 注册应用
|
|
* @describe 注册应用
|
|
* @author Joburgess
|
|
* @author Joburgess
|
|
* @date 2021/8/5 0005
|
|
* @date 2021/8/5 0005
|
|
- * @param tag:
|
|
+ * @param websocketType:
|
|
* @param webSocketEventHandler:
|
|
* @param webSocketEventHandler:
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
- public static boolean regist(String tag, WebSocketEventHandler webSocketEventHandler){
|
|
+ public static boolean regist(WebsocketTypeEnum websocketType, WebSocketEventHandler webSocketEventHandler){
|
|
- if (appMap.containsKey(tag)){
|
|
+ if (appMap.containsKey(websocketType)){
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- appMap.put(tag, webSocketEventHandler);
|
|
+ appMap.put(websocketType, webSocketEventHandler);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -67,15 +68,12 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
String phone = session.getPrincipal().getName().split(":")[1];
|
|
String phone = session.getPrincipal().getName().split(":")[1];
|
|
LOGGER.info("{}: {}", phone, message.getPayload());
|
|
LOGGER.info("{}: {}", phone, message.getPayload());
|
|
WebSocketInfo webSocketInfo = JSON.parseObject(message.getPayload(), WebSocketInfo.class);
|
|
WebSocketInfo webSocketInfo = JSON.parseObject(message.getPayload(), WebSocketInfo.class);
|
|
- String tag = "";
|
|
+
|
|
|
|
+ WebsocketTypeEnum websocketType = WebsocketTypeEnum.SOUND_COMPARE;
|
|
if(webSocketInfo.getHeader().containsKey(SoundSocketService.TAG)){
|
|
if(webSocketInfo.getHeader().containsKey(SoundSocketService.TAG)){
|
|
- tag = webSocketInfo.getHeader().get(SoundSocketService.TAG);
|
|
+ websocketType = WebsocketTypeEnum.valueOf(webSocketInfo.getHeader().get(SoundSocketService.TAG));
|
|
- }
|
|
|
|
- if(StringUtils.isNotBlank(tag)){
|
|
|
|
- appMap.get(tag).receiveTextMessage(session, phone, message);
|
|
|
|
- }else{
|
|
|
|
- appMap.values().forEach(e->e.receiveTextMessage(session, phone, message));
|
|
|
|
}
|
|
}
|
|
|
|
+ appMap.get(websocketType).receiveTextMessage(session, phone, message);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|