init
This commit is contained in:
@@ -15,6 +15,7 @@ import com.ruoyi.cai.ws.handler.IMessageHandler;
|
|||||||
import com.ruoyi.cai.ws.service.RoomService;
|
import com.ruoyi.cai.ws.service.RoomService;
|
||||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||||
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -50,7 +51,7 @@ public class CancelMessageHandler extends AbstractMessageHandle implements IMess
|
|||||||
// IM
|
// IM
|
||||||
Long receiverId = room.getReceiverId();
|
Long receiverId = room.getReceiverId();
|
||||||
Long callerId = room.getCallId();
|
Long callerId = room.getCallId();
|
||||||
yunxinWsService.sendToCallNotifyAsync(callerId,receiverId,1,0L);
|
yunxinWsService.sendToCallNotifyAsync(receiverId,callerId, CallNoticeEnum.CLOSE,0L);
|
||||||
// 更新房间状态
|
// 更新房间状态
|
||||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||||
.eq(UserCall::getId,roomId)
|
.eq(UserCall::getId,roomId)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.ruoyi.cai.ws.handler.IMessageHandler;
|
|||||||
import com.ruoyi.cai.ws.service.RoomService;
|
import com.ruoyi.cai.ws.service.RoomService;
|
||||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||||
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -29,7 +30,8 @@ public class RefuseMessageHandler extends AbstractMessageHandle implements IMess
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserCallService userCallService;
|
private UserCallService userCallService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private Yunxin yunxin;
|
private YunxinWsService yunxinWsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
|
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
|
||||||
if(!fdCtxData.isReceiver() || !RoomStatusEnums.STATUS_RECEIVER_CONNECT.getCode().equals(room.getStatus())){
|
if(!fdCtxData.isReceiver() || !RoomStatusEnums.STATUS_RECEIVER_CONNECT.getCode().equals(room.getStatus())){
|
||||||
@@ -46,7 +48,7 @@ public class RefuseMessageHandler extends AbstractMessageHandle implements IMess
|
|||||||
//发送IM通知
|
//发送IM通知
|
||||||
Long receiverId = room.getReceiverId();
|
Long receiverId = room.getReceiverId();
|
||||||
Long callerId = room.getCallId();
|
Long callerId = room.getCallId();
|
||||||
yunxinWsService.sendToCallNotifyAsync(callerId,receiverId,1,0L);
|
yunxinWsService.sendToCallNotifyAsync(callerId,receiverId, CallNoticeEnum.REFUSE,0L);
|
||||||
|
|
||||||
// 更新房间状态
|
// 更新房间状态
|
||||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||||
@@ -54,6 +56,5 @@ public class RefuseMessageHandler extends AbstractMessageHandle implements IMess
|
|||||||
.set(UserCall::getStatus,RoomStatusEnums.STATUS_REFUSE.getCode()));
|
.set(UserCall::getStatus,RoomStatusEnums.STATUS_REFUSE.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private YunxinWsService yunxinWsService;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.ruoyi.cai.ws.service.SettleResp;
|
|||||||
import com.ruoyi.cai.ws.service.SettleService;
|
import com.ruoyi.cai.ws.service.SettleService;
|
||||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||||
import com.ruoyi.yunxin.Yunxin;
|
import com.ruoyi.yunxin.Yunxin;
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -129,7 +130,7 @@ public class RoomCheckJobService {
|
|||||||
nextCreateJob = settleResp.isNextRun();
|
nextCreateJob = settleResp.isNextRun();
|
||||||
}
|
}
|
||||||
roomService.closeAllFd(roomId);
|
roomService.closeAllFd(roomId);
|
||||||
yunxinWsService.sendToCallNotifyAsync(callUserData.getId(),receiverUserData.getId(),3,0L);
|
yunxinWsService.sendToCallNotifyAsync(callUserData.getId(),receiverUserData.getId(), CallNoticeEnum.TIMEOUT,0L);
|
||||||
return JobResp.builder().nextCreateJob(nextCreateJob).build();
|
return JobResp.builder().nextCreateJob(nextCreateJob).build();
|
||||||
}
|
}
|
||||||
return JobResp.builder().nextCreateJob(true).build();
|
return JobResp.builder().nextCreateJob(true).build();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.ruoyi.cai.ws.dto.WsR;
|
|||||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||||
import com.ruoyi.yunxin.Yunxin;
|
import com.ruoyi.yunxin.Yunxin;
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RLock;
|
import org.redisson.api.RLock;
|
||||||
@@ -156,12 +157,12 @@ public class SettleService {
|
|||||||
Long callId = room.getCallUserData().getId();
|
Long callId = room.getCallUserData().getId();
|
||||||
Long receiveId = room.getReceiverUserData().getId();
|
Long receiveId = room.getReceiverUserData().getId();
|
||||||
if(callTime > 0){
|
if(callTime > 0){
|
||||||
yunxinWsService.sendToCallNotifyAsync(callId,receiveId,4,callTime);
|
yunxinWsService.sendToCallNotifyAsync(callId,receiveId, CallNoticeEnum.CALL_ALREADY,callTime);
|
||||||
}
|
}
|
||||||
// 接收方通知
|
// 接收方通知
|
||||||
Long anchorIncome = resp.getAnchorIncome();
|
Long anchorIncome = resp.getAnchorIncome();
|
||||||
if(anchorIncome > 0){
|
if(anchorIncome > 0){
|
||||||
yunxinWsService.sendToCallNotifyAsync(receiveId,callId,4,callTime);
|
yunxinWsService.sendToCallNotifyAsync(receiveId,callId,CallNoticeEnum.CALL_ALREADY,callTime);
|
||||||
// 收入通知
|
// 收入通知
|
||||||
// ImMsgGen.videoIncome();
|
// ImMsgGen.videoIncome();
|
||||||
// yunxin.sendTo(receiveId,null,)
|
// yunxin.sendTo(receiveId,null,)
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ public class Yunxin {
|
|||||||
@Resource
|
@Resource
|
||||||
private ImMessageClient messageClient;
|
private ImMessageClient messageClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param toUid 接收者ID
|
||||||
|
* @param fromUid 发送者ID
|
||||||
|
* @param data 数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public YxDataR<SendMsgResp> sendTo(Long toUid,Long fromUid,Object data){
|
public YxDataR<SendMsgResp> sendTo(Long toUid,Long fromUid,Object data){
|
||||||
SendMsgReq req = new SendMsgReq();
|
SendMsgReq req = new SendMsgReq();
|
||||||
req.setFrom(fromUid == null ? yunxinProperties.getDefaultFromUid() : fromUid+"");
|
req.setFrom(fromUid == null ? yunxinProperties.getDefaultFromUid() : fromUid+"");
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.yunxin.data;
|
package com.ruoyi.yunxin.data;
|
||||||
|
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
|
|
||||||
public class ImMsgGen {
|
public class ImMsgGen {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,12 +11,12 @@ public class ImMsgGen {
|
|||||||
* @param to
|
* @param to
|
||||||
* @param callTime
|
* @param callTime
|
||||||
*/
|
*/
|
||||||
public static ImDataRes callNotice(int status,Long from,Long to,long callTime){
|
public static ImDataRes callNotice(CallNoticeEnum status, Long from, Long to, long callTime){
|
||||||
ImDataRes imDataRes = new ImDataRes();
|
ImDataRes imDataRes = new ImDataRes();
|
||||||
imDataRes.setType(15);
|
imDataRes.setType(15);
|
||||||
ImDataRes.ImData imData = new ImDataRes.ImData();
|
ImDataRes.ImData imData = new ImDataRes.ImData();
|
||||||
imData.setCalltype(1);
|
imData.setCalltype(1);
|
||||||
imData.setStatus(status); // 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
imData.setStatus(status.getCode()); // 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
||||||
imData.setFrom_uid(from);
|
imData.setFrom_uid(from);
|
||||||
imData.setTo_uid(to);
|
imData.setTo_uid(to);
|
||||||
imData.setCall_time(callTime);
|
imData.setCall_time(callTime);
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.ruoyi.yunxin.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
// // 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
||||||
|
@Getter
|
||||||
|
public enum CallNoticeEnum {
|
||||||
|
CLOSE(1,"取消"),
|
||||||
|
REFUSE(2,"拒绝"),
|
||||||
|
TIMEOUT(3,"超时"),
|
||||||
|
CALL_ALREADY(4,"已通话"),
|
||||||
|
|
||||||
|
;
|
||||||
|
private final Integer code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
CallNoticeEnum(Integer code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.ruoyi.yunxin.Yunxin;
|
|||||||
import com.ruoyi.yunxin.data.ImDataRes;
|
import com.ruoyi.yunxin.data.ImDataRes;
|
||||||
import com.ruoyi.yunxin.data.ImMsgGen;
|
import com.ruoyi.yunxin.data.ImMsgGen;
|
||||||
import com.ruoyi.yunxin.data.WsSendAttachMsgData;
|
import com.ruoyi.yunxin.data.WsSendAttachMsgData;
|
||||||
|
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||||
import com.ruoyi.yunxin.resp.SendMsgResp;
|
import com.ruoyi.yunxin.resp.SendMsgResp;
|
||||||
import com.ruoyi.yunxin.resp.YxCommonR;
|
import com.ruoyi.yunxin.resp.YxCommonR;
|
||||||
import com.ruoyi.yunxin.resp.YxDataR;
|
import com.ruoyi.yunxin.resp.YxDataR;
|
||||||
@@ -32,10 +33,17 @@ public class YunxinWsService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToCallNotifyAsync(Long from,Long to,Integer status,Long calltime){
|
/**
|
||||||
|
* 发送消息
|
||||||
|
* @param toUid 接收着ID
|
||||||
|
* @param fromUid 发送着ID
|
||||||
|
* @param status 状态 // 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
||||||
|
* @param calltime 通话时长
|
||||||
|
*/
|
||||||
|
public void sendToCallNotifyAsync(Long toUid, Long fromUid, CallNoticeEnum status, Long calltime){
|
||||||
YunExecutor.YUN_EXECUTOR.execute(() -> {
|
YunExecutor.YUN_EXECUTOR.execute(() -> {
|
||||||
ImDataRes imDataRes = ImMsgGen.callNotice(status, from, to, calltime);
|
ImDataRes imDataRes = ImMsgGen.callNotice(status, fromUid, toUid, calltime);
|
||||||
YxDataR<SendMsgResp> r = yunxin.sendTo(from, to, imDataRes);
|
YxDataR<SendMsgResp> r = yunxin.sendTo(toUid, fromUid, imDataRes);
|
||||||
if(r == null || !r.isSuccess()){
|
if(r == null || !r.isSuccess()){
|
||||||
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
|
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user