通话逻辑

This commit is contained in:
张良(004796)
2023-12-29 12:45:41 +08:00
parent 973c9545af
commit 244fadd1e6
33 changed files with 746 additions and 69 deletions

View File

@@ -0,0 +1,40 @@
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<String> sessionKeys = roomCtxCache.getSessionKeysByRoomId(roomId);
for (WsR wsR : r) {
RoomWebSocketUtil.sendSendMessage(sessionKeys, wsR);
}
}
}