package com.ruoyi.websocket.handler; import com.ruoyi.cai.ws.bean.FdCtxData; import com.ruoyi.cai.ws.cache.RoomCtxCache; import com.ruoyi.websocket.dto.WsR; import com.ruoyi.websocket.util.RoomWebSocketUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @Component public abstract class AbstractMessageHandle implements IMessageHandler { @Autowired private RoomCtxCache roomCtxCache; protected void sendToCurrent(FdCtxData fdCtxData, WsR r){ RoomWebSocketUtil.sendSendMessage(fdCtxData.getSessionKey(), r); } protected void sendToTar(FdCtxData fdCtxData, WsR r) { String sessionKey = roomCtxCache.getSessionKeyByRoomIdAndUserType(fdCtxData.getRoomId(), fdCtxData.getTarUserType()); RoomWebSocketUtil.sendSendMessage(sessionKey, r); } protected void sendToReceiver(String roomId, WsR r){ String receiverSessionKey = roomCtxCache.getSessionKeyReceiverByRoomId(roomId); RoomWebSocketUtil.sendSendMessage(receiverSessionKey, r); } protected void sendToAll(String roomId, WsR ... r ){ List sessionKeys = roomCtxCache.getSessionKeysByRoomId(roomId); for (WsR wsR : r) { RoomWebSocketUtil.sendSendMessage(sessionKeys, wsR); } } }