123333
This commit is contained in:
@@ -37,13 +37,12 @@ public class MessageHandleApplication {
|
||||
@Autowired
|
||||
private ChatManager chatManager;
|
||||
|
||||
public void processOn(WebSocketSession session, TextMessage message) {
|
||||
String payload = message.getPayload();
|
||||
log.info("调试日志:收到websocket的请求 message={}",payload);
|
||||
if(StringUtil.isEmpty(payload)){
|
||||
public void processOn(WebSocketSession session, String message) {
|
||||
log.info("调试日志:收到websocket的请求 message={}",message);
|
||||
if(StringUtil.isEmpty(message)){
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(payload);
|
||||
JSONObject jsonObject = JSON.parseObject(message);
|
||||
Object method = jsonObject.get("method");
|
||||
if(method == null){
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,12 @@ import org.springframework.web.socket.*;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,6 +33,7 @@ public class RoomWebSocketHandler extends AbstractWebSocketHandler {
|
||||
private OpenLogic openLogic;
|
||||
@Autowired
|
||||
private MessageHandleApplication messageHandleApplication;
|
||||
|
||||
/**
|
||||
* 连接成功后
|
||||
*/
|
||||
@@ -40,15 +47,15 @@ public class RoomWebSocketHandler extends AbstractWebSocketHandler {
|
||||
log.info("[connect] sessionId: {},userId:{}", session.getId(), session.getId());
|
||||
}
|
||||
|
||||
private Map<String,String> getPara(String uri) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
if(StringUtils.isEmpty(uri)){
|
||||
private Map<String, String> getPara(String uri) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (StringUtils.isEmpty(uri)) {
|
||||
return map;
|
||||
}
|
||||
String[] keys = uri.split("&");
|
||||
for (String key : keys) {
|
||||
String[] split = key.split("=");
|
||||
map.put(split[0],split.length > 1 ? split[1] : "");
|
||||
map.put(split[0], split.length > 1 ? split[1] : "");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -63,15 +70,30 @@ public class RoomWebSocketHandler extends AbstractWebSocketHandler {
|
||||
@Override
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||
try {
|
||||
messageHandleApplication.processOn(session,message);
|
||||
}catch (Exception e){
|
||||
log.error("ws消息处理失败!需要开发检查问题!",e);
|
||||
messageHandleApplication.processOn(session, message.getPayload());
|
||||
} catch (Exception e) {
|
||||
log.error("ws消息处理失败!需要开发检查问题!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getString(ByteBuffer buffer) throws CharacterCodingException {
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
CharsetDecoder decoder = charset.newDecoder();
|
||||
CharBuffer charBuffer = decoder.decode(buffer);
|
||||
// charBuffer = decoder.decode(buffer.asReadOnlyBuffer());
|
||||
// buffer.flip();
|
||||
return charBuffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
|
||||
super.handleBinaryMessage(session, message);
|
||||
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage binaryMessage) throws Exception {
|
||||
try {
|
||||
ByteBuffer payload = binaryMessage.getPayload();
|
||||
String message = getString(payload);
|
||||
messageHandleApplication.processOn(session, message);
|
||||
} catch (Exception e) {
|
||||
log.error("ws 二进制消息处理失败!需要开发检查问题!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.ruoyi.cai.ws.constant.RoomStatusEnums;
|
||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||
import com.ruoyi.cai.ws.handler.IMessageHandler;
|
||||
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,6 +22,7 @@ import java.time.LocalDateTime;
|
||||
* 被叫同意接听处理
|
||||
*/
|
||||
@Component("agree")
|
||||
@Slf4j
|
||||
public class AgreeMessageHandle extends AbstractMessageHandle implements IMessageHandler {
|
||||
|
||||
@Autowired
|
||||
@@ -32,11 +34,13 @@ public class AgreeMessageHandle extends AbstractMessageHandle implements IMessag
|
||||
|
||||
@Override
|
||||
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
|
||||
if(!fdCtxData.isReceiver()){
|
||||
if(!fdCtxData.isCaller()){
|
||||
log.warn("调试日志: 只有接收方可以同意直播 roomId={}", room.getRoomId());
|
||||
return;
|
||||
}
|
||||
boolean agree = roomDataCache.setStatusAgree(room.getRoomId());
|
||||
if(!agree){
|
||||
log.warn("调试日志: 接收方同意直播失败,roomId={}",room.getRoomId());
|
||||
return;
|
||||
}
|
||||
// 通知可进行接通
|
||||
|
||||
Reference in New Issue
Block a user