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