|
|
|
@ -53,9 +53,17 @@ public class RoomWebSocketController { |
|
|
|
private static final String TYPE_MEMBER_LEFT = "MEMBER_LEFT"; |
|
|
|
private static final String TYPE_MEMBER_LIST = "MEMBER_LIST"; |
|
|
|
private static final String TYPE_PONG = "PONG"; |
|
|
|
/** 对象选中/查看:某成员正在查看某条航线,广播给房间内其他人 */ |
|
|
|
private static final String TYPE_OBJECT_VIEW = "OBJECT_VIEW"; |
|
|
|
/** 取消对象查看 */ |
|
|
|
private static final String TYPE_OBJECT_VIEW_CLEAR = "OBJECT_VIEW_CLEAR"; |
|
|
|
/** 对象编辑锁定:某成员进入编辑,其他人看到锁定 */ |
|
|
|
private static final String TYPE_OBJECT_EDIT_LOCK = "OBJECT_EDIT_LOCK"; |
|
|
|
/** 对象编辑解锁 */ |
|
|
|
private static final String TYPE_OBJECT_EDIT_UNLOCK = "OBJECT_EDIT_UNLOCK"; |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理房间消息:JOIN、LEAVE、PING、CHAT、PRIVATE_CHAT |
|
|
|
* 处理房间消息:JOIN、LEAVE、PING、CHAT、PRIVATE_CHAT、OBJECT_VIEW、OBJECT_EDIT_LOCK |
|
|
|
*/ |
|
|
|
@MessageMapping("/room/{roomId}") |
|
|
|
public void handleRoomMessage(@DestinationVariable Long roomId, @Payload String payload, |
|
|
|
@ -85,9 +93,85 @@ public class RoomWebSocketController { |
|
|
|
handlePrivateChat(roomId, sessionId, loginUser, body); |
|
|
|
} else if (TYPE_PRIVATE_CHAT_HISTORY_REQUEST.equals(type)) { |
|
|
|
handlePrivateChatHistoryRequest(roomId, loginUser, body); |
|
|
|
} else if (TYPE_OBJECT_VIEW.equals(type)) { |
|
|
|
handleObjectView(roomId, sessionId, loginUser, body); |
|
|
|
} else if (TYPE_OBJECT_VIEW_CLEAR.equals(type)) { |
|
|
|
handleObjectViewClear(roomId, sessionId, loginUser, body); |
|
|
|
} else if (TYPE_OBJECT_EDIT_LOCK.equals(type)) { |
|
|
|
handleObjectEditLock(roomId, sessionId, loginUser, body); |
|
|
|
} else if (TYPE_OBJECT_EDIT_UNLOCK.equals(type)) { |
|
|
|
handleObjectEditUnlock(roomId, sessionId, loginUser, body); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** 广播:某成员正在查看某对象(如航线) */ |
|
|
|
private void handleObjectView(Long roomId, String sessionId, LoginUser loginUser, Map<String, Object> body) { |
|
|
|
String objectType = body != null ? String.valueOf(body.get("objectType")) : null; |
|
|
|
Object objectIdObj = body != null ? body.get("objectId") : null; |
|
|
|
if (objectType == null || objectIdObj == null) return; |
|
|
|
|
|
|
|
Map<String, Object> viewer = new HashMap<>(); |
|
|
|
viewer.put("userId", loginUser.getUserId()); |
|
|
|
viewer.put("userName", loginUser.getUsername()); |
|
|
|
viewer.put("nickName", loginUser.getUser().getNickName()); |
|
|
|
viewer.put("sessionId", sessionId); |
|
|
|
|
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("type", TYPE_OBJECT_VIEW); |
|
|
|
msg.put("objectType", objectType); |
|
|
|
msg.put("objectId", objectIdObj); |
|
|
|
msg.put("viewer", viewer); |
|
|
|
messagingTemplate.convertAndSend("/topic/room/" + roomId, msg); |
|
|
|
} |
|
|
|
|
|
|
|
/** 广播:某成员取消查看某对象 */ |
|
|
|
private void handleObjectViewClear(Long roomId, String sessionId, LoginUser loginUser, Map<String, Object> body) { |
|
|
|
String objectType = body != null ? String.valueOf(body.get("objectType")) : null; |
|
|
|
Object objectIdObj = body != null ? body.get("objectId") : null; |
|
|
|
if (objectType == null || objectIdObj == null) return; |
|
|
|
|
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("type", TYPE_OBJECT_VIEW_CLEAR); |
|
|
|
msg.put("objectType", objectType); |
|
|
|
msg.put("objectId", objectIdObj); |
|
|
|
msg.put("sessionId", sessionId); |
|
|
|
messagingTemplate.convertAndSend("/topic/room/" + roomId, msg); |
|
|
|
} |
|
|
|
|
|
|
|
/** 广播:某成员锁定某对象进入编辑 */ |
|
|
|
private void handleObjectEditLock(Long roomId, String sessionId, LoginUser loginUser, Map<String, Object> body) { |
|
|
|
String objectType = body != null ? String.valueOf(body.get("objectType")) : null; |
|
|
|
Object objectIdObj = body != null ? body.get("objectId") : null; |
|
|
|
if (objectType == null || objectIdObj == null) return; |
|
|
|
|
|
|
|
Map<String, Object> editor = new HashMap<>(); |
|
|
|
editor.put("userId", loginUser.getUserId()); |
|
|
|
editor.put("userName", loginUser.getUsername()); |
|
|
|
editor.put("nickName", loginUser.getUser().getNickName()); |
|
|
|
editor.put("sessionId", sessionId); |
|
|
|
|
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("type", TYPE_OBJECT_EDIT_LOCK); |
|
|
|
msg.put("objectType", objectType); |
|
|
|
msg.put("objectId", objectIdObj); |
|
|
|
msg.put("editor", editor); |
|
|
|
messagingTemplate.convertAndSend("/topic/room/" + roomId, msg); |
|
|
|
} |
|
|
|
|
|
|
|
/** 广播:某成员解锁某对象(结束编辑) */ |
|
|
|
private void handleObjectEditUnlock(Long roomId, String sessionId, LoginUser loginUser, Map<String, Object> body) { |
|
|
|
String objectType = body != null ? String.valueOf(body.get("objectType")) : null; |
|
|
|
Object objectIdObj = body != null ? body.get("objectId") : null; |
|
|
|
if (objectType == null || objectIdObj == null) return; |
|
|
|
|
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("type", TYPE_OBJECT_EDIT_UNLOCK); |
|
|
|
msg.put("objectType", objectType); |
|
|
|
msg.put("objectId", objectIdObj); |
|
|
|
msg.put("sessionId", sessionId); |
|
|
|
messagingTemplate.convertAndSend("/topic/room/" + roomId, msg); |
|
|
|
} |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
private Map<String, Object> parsePayload(String payload) { |
|
|
|
try { |
|
|
|
|