init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.cai.notice;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.cai.notice.data.ImVideoAttachR;
|
||||
import com.ruoyi.cai.notice.data.ImVideoR;
|
||||
import com.ruoyi.cai.notice.data.child.ImVideoAttachData;
|
||||
import com.ruoyi.cai.notice.data.child.ImVideoData;
|
||||
import com.ruoyi.yunxin.YunExecutor;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||
import com.ruoyi.yunxin.resp.SendMsgResp;
|
||||
import com.ruoyi.yunxin.resp.YxCommonR;
|
||||
import com.ruoyi.yunxin.resp.YxDataR;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class YunxinWsServiceV2 {
|
||||
|
||||
@Autowired
|
||||
private Yunxin yunxin;
|
||||
|
||||
/**
|
||||
* 系统自定义消息通知主播接听电话
|
||||
*/
|
||||
public void sendCallAsync(Long roomId,Long callId,Long receiverId){
|
||||
YunExecutor.YUN_EXECUTOR.execute(() -> {
|
||||
ImVideoAttachData data = new ImVideoAttachData();
|
||||
data.setRoomid(roomId);
|
||||
ImVideoAttachR<ImVideoAttachData> res = ImVideoAttachR.ok(data);
|
||||
YxDataR<YxCommonR> r = yunxin.sendAttachMsg(callId, receiverId, res);
|
||||
if(r == null || !r.isSuccess()){
|
||||
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param toUid 接收着ID
|
||||
* @param fromUid 发送着ID
|
||||
* @param status 状态 // 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
||||
* @param calltime 通话时长
|
||||
*/
|
||||
public void sendToCallNotify(Long toUid, Long fromUid, CallNoticeEnum status, Long calltime){
|
||||
YunExecutor.YUN_EXECUTOR.execute(() -> {
|
||||
ImVideoData data = new ImVideoData();
|
||||
data.setStatus(status.getCode());
|
||||
data.setFrom_uid(fromUid);
|
||||
data.setTo_uid(toUid);
|
||||
data.setCall_time(calltime);
|
||||
ImVideoR<ImVideoData> res = ImVideoR.ok(data);
|
||||
YxDataR<SendMsgResp> r = yunxin.sendToUserNotice(toUid, fromUid, res);
|
||||
if(r == null || !r.isSuccess()){
|
||||
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.cai.notice.data;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ImVideoAttachR<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id = 11;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <T> ImVideoAttachR<T> ok(T data) {
|
||||
return restResult(data);
|
||||
}
|
||||
|
||||
|
||||
private static <T> ImVideoAttachR<T> restResult(T data) {
|
||||
ImVideoAttachR<T> r = new ImVideoAttachR<>();
|
||||
r.setData(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.ruoyi.cai.notice.data;
|
||||
|
||||
import com.ruoyi.cai.notice.enums.MessageBaseTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ImVideoR<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <T> ImVideoR<T> ok(T data) {
|
||||
return restResult(MessageBaseTypeEnum.IM_VIDEO_MESSAGE.getCode(), data);
|
||||
}
|
||||
|
||||
|
||||
private static <T> ImVideoR<T> restResult(Integer type, T data) {
|
||||
ImVideoR<T> r = new ImVideoR<>();
|
||||
r.setType(type);
|
||||
r.setData(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ruoyi.cai.notice.data.child;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ImVideoAttachData {
|
||||
private Integer amount = 0;
|
||||
private Long callTime = DateUtil.currentSeconds();
|
||||
private Long gifttotal = 0L;
|
||||
private Integer id = 0;
|
||||
private Integer link_type = 0;
|
||||
private Long time = 0L;
|
||||
private Long toid = 0L;
|
||||
private Long roomid;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.cai.notice.data.child;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ImVideoData {
|
||||
private Integer calltype = 1;
|
||||
// 通话状态,1 取消 2 拒绝 3 超时 4 已通话
|
||||
private Integer status;
|
||||
private Long from_uid;
|
||||
private Long to_uid;
|
||||
private Long call_time;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public enum MessageBaseTypeEnum {
|
||||
@Deprecated
|
||||
REGISTER_SEND_CLEAN(13,"注册发送IM单图文消息"),
|
||||
SEND_GIFT_MESSAGE(14,"发送礼物自定义消息"),
|
||||
IM_VIDEO_MESSAGE(15,"通话通知"),
|
||||
SEND_FOLLOW(16,"自定义被关注消息"),
|
||||
SEND_FOLLOW_DYNAMIC(17,"关注动态"),
|
||||
SEND_ONLINE_ATTENTION(18,"上线了通知"),
|
||||
|
||||
@@ -3,20 +3,17 @@ package com.ruoyi.cai.ws.handler.message;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.cai.domain.UserCall;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
import com.ruoyi.cai.service.UserCallService;
|
||||
import com.ruoyi.yunxin.data.ImDataRes;
|
||||
import com.ruoyi.yunxin.data.ImMsgGen;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.cai.ws.bean.FdCtxData;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import com.ruoyi.cai.ws.constant.HangUpEnums;
|
||||
import com.ruoyi.cai.ws.constant.RoomStatusEnums;
|
||||
import com.ruoyi.cai.ws.handler.IMessageHandler;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
||||
import com.ruoyi.cai.ws.handler.IMessageHandler;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -30,7 +27,8 @@ public class CancelMessageHandler extends AbstractMessageHandle implements IMess
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
@Autowired
|
||||
private Yunxin yunxin;
|
||||
private YunxinWsServiceV2 yunxinWsService;
|
||||
|
||||
@Override
|
||||
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
|
||||
if(!fdCtxData.isCaller()){
|
||||
@@ -51,13 +49,11 @@ public class CancelMessageHandler extends AbstractMessageHandle implements IMess
|
||||
// IM
|
||||
Long receiverId = room.getReceiverId();
|
||||
Long callerId = room.getCallId();
|
||||
yunxinWsService.sendToCallNotifyAsync(receiverId,callerId, CallNoticeEnum.CLOSE,0L);
|
||||
yunxinWsService.sendToCallNotify(receiverId,callerId, CallNoticeEnum.CLOSE,0L);
|
||||
// 更新房间状态
|
||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||
.eq(UserCall::getId,roomId)
|
||||
.set(UserCall::getStatus,RoomStatusEnums.STATUS_CALLER_CANCEL.getCode()));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private YunxinWsService yunxinWsService;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,17 @@ package com.ruoyi.cai.ws.handler.message;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.cai.domain.UserCall;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
import com.ruoyi.cai.service.UserCallService;
|
||||
import com.ruoyi.yunxin.data.ImDataRes;
|
||||
import com.ruoyi.yunxin.data.ImMsgGen;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.cai.ws.bean.FdCtxData;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import com.ruoyi.cai.ws.constant.HangUpEnums;
|
||||
import com.ruoyi.cai.ws.constant.RoomStatusEnums;
|
||||
import com.ruoyi.cai.ws.handler.IMessageHandler;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
|
||||
import com.ruoyi.cai.ws.handler.IMessageHandler;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -30,7 +27,7 @@ public class RefuseMessageHandler extends AbstractMessageHandle implements IMess
|
||||
@Autowired
|
||||
private UserCallService userCallService;
|
||||
@Autowired
|
||||
private YunxinWsService yunxinWsService;
|
||||
private YunxinWsServiceV2 yunxinWsService;
|
||||
|
||||
@Override
|
||||
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
|
||||
@@ -48,7 +45,7 @@ public class RefuseMessageHandler extends AbstractMessageHandle implements IMess
|
||||
//发送IM通知
|
||||
Long receiverId = room.getReceiverId();
|
||||
Long callerId = room.getCallId();
|
||||
yunxinWsService.sendToCallNotifyAsync(callerId,receiverId, CallNoticeEnum.REFUSE,0L);
|
||||
yunxinWsService.sendToCallNotify(callerId,receiverId, CallNoticeEnum.REFUSE,0L);
|
||||
|
||||
// 更新房间状态
|
||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.ruoyi.cai.ws.job;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.cai.domain.UserCall;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
import com.ruoyi.cai.service.UserCallService;
|
||||
import com.ruoyi.yunxin.data.ImDataRes;
|
||||
import com.ruoyi.yunxin.data.ImMsgGen;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import com.ruoyi.cai.ws.bean.UserData;
|
||||
import com.ruoyi.cai.ws.cache.RoomCtxCache;
|
||||
@@ -19,7 +18,6 @@ import com.ruoyi.cai.ws.service.SettleService;
|
||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -130,14 +128,14 @@ public class RoomCheckJobService {
|
||||
nextCreateJob = settleResp.isNextRun();
|
||||
}
|
||||
roomService.closeAllFd(roomId);
|
||||
yunxinWsService.sendToCallNotifyAsync(callUserData.getId(),receiverUserData.getId(), CallNoticeEnum.TIMEOUT,0L);
|
||||
yunxinWsService.sendToCallNotify(callUserData.getId(),receiverUserData.getId(), CallNoticeEnum.TIMEOUT,0L);
|
||||
return JobResp.builder().nextCreateJob(nextCreateJob).build();
|
||||
}
|
||||
return JobResp.builder().nextCreateJob(true).build();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private YunxinWsService yunxinWsService;
|
||||
private YunxinWsServiceV2 yunxinWsService;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.ruoyi.cai.chat.ChatManager;
|
||||
import com.ruoyi.cai.executor.ExecutorConstant;
|
||||
import com.ruoyi.cai.mq.AmqpProducer;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.trd.Agora;
|
||||
@@ -21,7 +22,6 @@ import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||
import com.ruoyi.cai.ws.util.TimeConverter;
|
||||
import com.ruoyi.cai.ws.util.WsExceptionUtil;
|
||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -54,7 +54,7 @@ public class OpenLogic {
|
||||
@Autowired
|
||||
private ChatManager chatManager;
|
||||
@Autowired
|
||||
private YunxinWsService yunxinWsService;
|
||||
private YunxinWsServiceV2 yunxinWsService;
|
||||
|
||||
public void processOn(WebSocketSession session) {
|
||||
Map<String, Object> attributes = session.getAttributes();
|
||||
|
||||
@@ -6,9 +6,8 @@ import com.ruoyi.cai.dto.video.VideoSettleResp;
|
||||
import com.ruoyi.cai.dto.video.WithholdingFeeUserResp;
|
||||
import com.ruoyi.cai.manager.ConsumerManager;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
import com.ruoyi.yunxin.data.ImDataRes;
|
||||
import com.ruoyi.yunxin.data.ImMsgGen;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import com.ruoyi.cai.ws.cache.OnlineDataCache;
|
||||
import com.ruoyi.cai.ws.cache.RoomCtxCache;
|
||||
@@ -17,9 +16,7 @@ import com.ruoyi.cai.ws.constant.HangUpEnums;
|
||||
import com.ruoyi.cai.ws.dto.WsR;
|
||||
import com.ruoyi.cai.ws.dto.WsRMsgGen;
|
||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.yunxin.enums.CallNoticeEnum;
|
||||
import com.ruoyi.yunxin.service.YunxinWsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
@@ -44,8 +41,6 @@ public class SettleService {
|
||||
@Autowired
|
||||
private OnlineDataCache onlineDataCache;
|
||||
@Autowired
|
||||
private Yunxin yunxin;
|
||||
@Autowired
|
||||
private RoomCtxCache roomCtxCache;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@@ -157,12 +152,12 @@ public class SettleService {
|
||||
Long callId = room.getCallUserData().getId();
|
||||
Long receiveId = room.getReceiverUserData().getId();
|
||||
if(callTime > 0){
|
||||
yunxinWsService.sendToCallNotifyAsync(callId,receiveId, CallNoticeEnum.CALL_ALREADY,callTime);
|
||||
yunxinWsService.sendToCallNotify(callId,receiveId, CallNoticeEnum.CALL_ALREADY,callTime);
|
||||
}
|
||||
// 接收方通知
|
||||
Long anchorIncome = resp.getAnchorIncome();
|
||||
if(anchorIncome > 0){
|
||||
yunxinWsService.sendToCallNotifyAsync(receiveId,callId,CallNoticeEnum.CALL_ALREADY,callTime);
|
||||
yunxinWsService.sendToCallNotify(receiveId,callId,CallNoticeEnum.CALL_ALREADY,callTime);
|
||||
// 收入通知
|
||||
// ImMsgGen.videoIncome();
|
||||
// yunxin.sendTo(receiveId,null,)
|
||||
@@ -171,6 +166,6 @@ public class SettleService {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private YunxinWsService yunxinWsService;
|
||||
private YunxinWsServiceV2 yunxinWsService;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user