Commit d8cf426e by Future

单人音视频拉黑逻辑

parent 101c6560
...@@ -274,7 +274,6 @@ public class NormalChatAction { ...@@ -274,7 +274,6 @@ public class NormalChatAction {
boolean beBlack = imClientBlacklistService.isBeBlack(heClientId, meClientId); boolean beBlack = imClientBlacklistService.isBeBlack(heClientId, meClientId);
if (beBlack) { if (beBlack) {
log.info("被对方拉黑了, meId={},heClientId={}", meClientId, heClientId); log.info("被对方拉黑了, meId={},heClientId={}", meClientId, heClientId);
// 响应发送方 // 响应发送方
WsResponse<HashMap<String, Long>> responseModel = new WsResponse<>(); WsResponse<HashMap<String, Long>> responseModel = new WsResponse<>();
ApiResult<Boolean> result = ApiResult.result(ApiCode.IS_BE_BLACK); ApiResult<Boolean> result = ApiResult.result(ApiCode.IS_BE_BLACK);
...@@ -282,28 +281,24 @@ public class NormalChatAction { ...@@ -282,28 +281,24 @@ public class NormalChatAction {
responseModel.setCode(result.getCode()); responseModel.setCode(result.getCode());
responseModel.setMsg(result.getMessage()); responseModel.setMsg(result.getMessage());
responseModel.setReqId(reqId); responseModel.setReqId(reqId);
channelSender.sendMsgLocal((NioSocketChannel)channel, responseModel); channelSender.sendMsgLocal((NioSocketChannel)channel, responseModel);
return true; return true;
} }
// 是否把对方拉黑 // 是否把对方拉黑
// boolean black = imClientBlacklistService.isBeBlack(meClientId, heClientId); boolean black = imClientBlacklistService.isBeBlack(meClientId, heClientId);
// if (black) { if (black) {
// log.info("你把对方拉黑了, meId={},heClientId={}", meClientId, heClientId); log.info("你把对方拉黑了, meId={},heClientId={}", meClientId, heClientId);
// // 响应发送方 // 响应发送方
// WsResponse<HashMap<String, Long>> responseModel = new WsResponse<>(); WsResponse<HashMap<String, Long>> responseModel = new WsResponse<>();
// ApiResult<Boolean> result = ApiResult.result(ApiCode.IS_TO_BLACK); ApiResult<Boolean> result = ApiResult.result(ApiCode.IS_TO_BLACK);
// responseModel.setCmd(WsResponseCmdEnum.RES.getCmdCode()); responseModel.setCmd(WsResponseCmdEnum.RES.getCmdCode());
// responseModel.setCode(result.getCode()); responseModel.setCode(result.getCode());
// responseModel.setMsg(result.getMessage()); responseModel.setMsg(result.getMessage());
// responseModel.setReqId(reqId); responseModel.setReqId(reqId);
// channelSender.sendMsgLocal((NioSocketChannel)channel, responseModel);
// channelSender.sendMsgLocal((NioSocketChannel)channel, responseModel); return true;
// }
// return true;
// }
return false; return false;
} }
......
...@@ -42,7 +42,7 @@ public class ImRtcController extends BaseController { ...@@ -42,7 +42,7 @@ public class ImRtcController extends BaseController {
*/ */
@PostMapping("/createAndCall") @PostMapping("/createAndCall")
@ApiOperation(value = "创建频道,并邀请客户端加入", notes = "创建频道,并邀请客户端加入") @ApiOperation(value = "创建频道,并邀请客户端加入", notes = "创建频道,并邀请客户端加入")
public ApiResult<CreateRtcChannelResult> createAndCall(@RequestBody CreateRtcChannelParam createRtcChannelParam) throws Exception { public ApiResult<CreateRtcChannelResult> createAndCall(@RequestBody CreateRtcChannelParam createRtcChannelParam) {
if (BaseEnum.valueOf(CallTypeEnum.class, createRtcChannelParam.getCallType()) == null) { if (BaseEnum.valueOf(CallTypeEnum.class, createRtcChannelParam.getCallType()) == null) {
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null); return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null);
} }
......
...@@ -43,7 +43,7 @@ public interface MangerRtcCacheService { ...@@ -43,7 +43,7 @@ public interface MangerRtcCacheService {
* @param clientId * @param clientId
* @param rtcChannelId 雪花算法生成频道id * @param rtcChannelId 雪花算法生成频道id
*/ */
void create(Long clientId, Long toClientId, Long rtcChannelId) throws JsonProcessingException; void create(Long clientId, Long toClientId, Long rtcChannelId);
/** /**
* 加入频道 * 加入频道
......
...@@ -18,7 +18,7 @@ public interface RtcService { ...@@ -18,7 +18,7 @@ public interface RtcService {
/** /**
* 创建一个频道,并向接收方发送系统推送 * 创建一个频道,并向接收方发送系统推送
*/ */
ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException; ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam);
/** /**
* 加入频道 * 加入频道
......
...@@ -11,6 +11,7 @@ import com.wecloud.im.param.rtc.LeaveRtcChannelParam; ...@@ -11,6 +11,7 @@ import com.wecloud.im.param.rtc.LeaveRtcChannelParam;
import com.wecloud.im.param.rtc.RejectRtcChannelParam; import com.wecloud.im.param.rtc.RejectRtcChannelParam;
import com.wecloud.im.param.rtc.SdpForwardParam; import com.wecloud.im.param.rtc.SdpForwardParam;
import com.wecloud.im.service.ImApplicationService; import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientBlacklistService;
import com.wecloud.im.service.ImClientService; import com.wecloud.im.service.ImClientService;
import com.wecloud.im.ws.cache.UserStateCacheManager; import com.wecloud.im.ws.cache.UserStateCacheManager;
import com.wecloud.im.ws.cache.UserStateListener; import com.wecloud.im.ws.cache.UserStateListener;
...@@ -25,6 +26,7 @@ import com.wecloud.rtc.service.RtcService; ...@@ -25,6 +26,7 @@ import com.wecloud.rtc.service.RtcService;
import com.wecloud.rtc.service.WsRtcWrite; import com.wecloud.rtc.service.WsRtcWrite;
import com.wecloud.utils.SnowflakeUtil; import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.api.ApiResult; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -54,6 +56,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -54,6 +56,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Autowired @Autowired
private UserStateCacheManager userStateCacheManager; private UserStateCacheManager userStateCacheManager;
@Autowired
private ImClientBlacklistService imClientBlacklistService;
@Override @Override
public void onLineEvent(Long client, Integer platform, String longChannelId) { public void onLineEvent(Long client, Integer platform, String longChannelId) {
// nothing need to do // nothing need to do
...@@ -77,7 +82,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -77,7 +82,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
} }
@Override @Override
public ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException { public ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
Long rtcChannelId = SnowflakeUtil.getId(); Long rtcChannelId = SnowflakeUtil.getId();
// 判断发起方必须在线 // 判断发起方必须在线
...@@ -90,6 +95,8 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -90,6 +95,8 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
if (toClient == null) { if (toClient == null) {
ApiResult.fail(); ApiResult.fail();
} }
// 拉黑逻辑
black(currentClient, toClient);
// 添加缓存 // 添加缓存
mangerRtcCacheService.create(currentClient.getId(), toClient.getId(), rtcChannelId); mangerRtcCacheService.create(currentClient.getId(), toClient.getId(), rtcChannelId);
...@@ -286,4 +293,25 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -286,4 +293,25 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
return ApiResult.ok(true); return ApiResult.ok(true);
} }
/**
* 判断是否被拉黑
*
* @param currentClient
* @param toClient
* @return
*/
private void black(ImClient currentClient, ImClient toClient) {
// 判断是否被拉黑
boolean beBlack = imClientBlacklistService.isBeBlack(toClient.getClientId(), currentClient.getClientId());
if (beBlack) {
throw new BusinessException("被对方拉黑了");
}
// 是否把对方拉黑
boolean black = imClientBlacklistService.isBeBlack(currentClient.getClientId(), toClient.getClientId());
if (black) {
throw new BusinessException("你把对方拉黑了");
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment