Commit c722cbb3 by Future

频道问题处理

parent bad888c7
...@@ -3,8 +3,6 @@ package com.wecloud.rtc.service.impl; ...@@ -3,8 +3,6 @@ package com.wecloud.rtc.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.im.entity.ImApplication; import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient; import com.wecloud.im.entity.ImClient;
import com.wecloud.im.enums.CallTypeEnum;
import com.wecloud.im.enums.FriendStateEnum;
import com.wecloud.im.param.rtc.CandidateForwardParam; import com.wecloud.im.param.rtc.CandidateForwardParam;
import com.wecloud.im.param.rtc.CreateRtcChannelParam; import com.wecloud.im.param.rtc.CreateRtcChannelParam;
import com.wecloud.im.param.rtc.CreateRtcChannelResult; import com.wecloud.im.param.rtc.CreateRtcChannelResult;
...@@ -25,11 +23,10 @@ import com.wecloud.rtc.entity.response.RtcSdpForwardResponse; ...@@ -25,11 +23,10 @@ import com.wecloud.rtc.entity.response.RtcSdpForwardResponse;
import com.wecloud.rtc.service.MangerRtcCacheService; import com.wecloud.rtc.service.MangerRtcCacheService;
import com.wecloud.rtc.service.RtcService; import com.wecloud.rtc.service.RtcService;
import com.wecloud.rtc.service.WsRtcWrite; import com.wecloud.rtc.service.WsRtcWrite;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import com.wecloud.utils.SnowflakeUtil; import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.enums.BaseEnum; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -81,20 +78,20 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -81,20 +78,20 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Override @Override
public ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException { public ApiResult<CreateRtcChannelResult> createAndCall(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException {
ImClient client = imClientService.getCurentClient(); ImClient currentClient = imClientService.getCurentClient();
Long rtcChannelId = SnowflakeUtil.getId(); Long rtcChannelId = SnowflakeUtil.getId();
if (BaseEnum.valueOf(CallTypeEnum.class, createRtcChannelParam.getCallType()) == null) {
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null);
}
// 判断发起方必须在线 // 判断发起方必须在线
boolean onlineStatus = userStateCacheManager.isOnline(client.getId()); boolean onlineStatus = userStateCacheManager.isOnline(currentClient.getId());
if (!onlineStatus) { if (!onlineStatus) {
log.info("发起方必须在线" + client.getFkAppid() + client.getClientId()); log.info("发起方必须在线" + currentClient.getFkAppid() + currentClient.getClientId());
ApiResult.fail();
}
ImClient toClient = imClientService.getCacheImClient(currentClient.getFkAppid(), createRtcChannelParam.getToClient());
if (toClient == null) {
ApiResult.fail(); ApiResult.fail();
} }
// 添加缓存 // 添加缓存
mangerRtcCacheService.create(client.getId(), rtcChannelId); mangerRtcCacheService.create(currentClient.getId(), toClient.getId(), rtcChannelId);
CreateRtcChannelResult createRtcChannelResult = new CreateRtcChannelResult(); CreateRtcChannelResult createRtcChannelResult = new CreateRtcChannelResult();
createRtcChannelResult.setChannelId(rtcChannelId); createRtcChannelResult.setChannelId(rtcChannelId);
...@@ -104,10 +101,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -104,10 +101,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
rtcCallResponse.setCallType(createRtcChannelParam.getCallType()); rtcCallResponse.setCallType(createRtcChannelParam.getCallType());
// rtcCallResponse.setConversationId(createRtcChannelParam.getConversationId()); // rtcCallResponse.setConversationId(createRtcChannelParam.getConversationId());
rtcCallResponse.setChannelId(rtcChannelId); rtcCallResponse.setChannelId(rtcChannelId);
rtcCallResponse.setClientId(client.getClientId()); rtcCallResponse.setClientId(currentClient.getClientId());
rtcCallResponse.setTimestamp(System.currentTimeMillis()); rtcCallResponse.setTimestamp(System.currentTimeMillis());
ImClient toClient = imClientService.getCacheImClient(client.getFkAppid(), createRtcChannelParam.getToClient());
wsRtcWrite.rtcCall(rtcCallResponse, toClient.getId()); wsRtcWrite.rtcCall(rtcCallResponse, toClient.getId());
// TODO 待开发 下发安卓和ios系统推送 // TODO 待开发 下发安卓和ios系统推送
...@@ -128,7 +124,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -128,7 +124,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(joinRtcChannelParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(joinRtcChannelParam.getChannelId());
// 移除自己 // 移除自己
clientListByRtcChannelId.remove(client.getClientId()); clientListByRtcChannelId.remove(client.getId().toString());
for (String toClientId : clientListByRtcChannelId) { for (String toClientId : clientListByRtcChannelId) {
...@@ -148,12 +144,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -148,12 +144,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
public ApiResult<Boolean> reject(RejectRtcChannelParam rejectRtcChannelParam) { public ApiResult<Boolean> reject(RejectRtcChannelParam rejectRtcChannelParam) {
ImClient client = imClientService.getCurentClient(); ImClient client = imClientService.getCurentClient();
ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(rejectRtcChannelParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(rejectRtcChannelParam.getChannelId());
// 移除自己 // 移除自己
clientListByRtcChannelId.remove(client.getClientId()); clientListByRtcChannelId.remove(client.getId().toString());
for (String toClientId : clientListByRtcChannelId) { for (String toClientId : clientListByRtcChannelId) {
...@@ -171,40 +165,37 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -171,40 +165,37 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Override @Override
public ApiResult<Boolean> leave(LeaveRtcChannelParam leaveRtcChannelParam) { public ApiResult<Boolean> leave(LeaveRtcChannelParam leaveRtcChannelParam) {
ImClient currentClient = imClientService.getCurentClient();
ImClient client = imClientService.getCurentClient(); this.leave(leaveRtcChannelParam, currentClient);
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
this.leave(leaveRtcChannelParam, client);
return ApiResult.ok(true); return ApiResult.ok(true);
} }
private void leave(LeaveRtcChannelParam leaveRtcChannelParam, ImClient client) { private void leave(LeaveRtcChannelParam leaveRtcChannelParam, ImClient currentClient) {
// 修改缓存 // 修改缓存
mangerRtcCacheService.leave(client.getId(), leaveRtcChannelParam.getChannelId()); mangerRtcCacheService.leave(currentClient.getId(), leaveRtcChannelParam.getChannelId());
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(leaveRtcChannelParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(leaveRtcChannelParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) { for (String toClientId : clientListByRtcChannelId) {
// ws向接收方发送通知 // ws向接收方发送通知
RtcClientLeaveResponse rtcClientLeaveResponse = new RtcClientLeaveResponse(); RtcClientLeaveResponse rtcClientLeaveResponse = new RtcClientLeaveResponse();
rtcClientLeaveResponse.setChannelId(leaveRtcChannelParam.getChannelId()); rtcClientLeaveResponse.setChannelId(leaveRtcChannelParam.getChannelId());
rtcClientLeaveResponse.setClientId(client.getClientId()); rtcClientLeaveResponse.setClientId(currentClient.getClientId());
rtcClientLeaveResponse.setTimestamp(System.currentTimeMillis()); rtcClientLeaveResponse.setTimestamp(System.currentTimeMillis());
wsRtcWrite.clientLeave(rtcClientLeaveResponse, Long.valueOf(toClientId)); wsRtcWrite.clientLeave(rtcClientLeaveResponse, Long.valueOf(toClientId));
} }
// 判断频道内是否无其他人了 // 判断频道内是否无其他人了
if (mangerRtcCacheService.channelIsEmpty(leaveRtcChannelParam.getChannelId())) { if (CollectionUtils.isEmpty(clientListByRtcChannelId)) {
// 移除频道信息 // 移除频道信息
mangerRtcCacheService.delChannelInfo(leaveRtcChannelParam.getChannelId()); mangerRtcCacheService.delChannelInfo(leaveRtcChannelParam.getChannelId());
} else if (clientListByRtcChannelId.size() == 1){
// 频道内只有一个人了 -- 删除频道 并将这个人设为离开
mangerRtcCacheService.leave(Long.valueOf(clientListByRtcChannelId.get(0)), leaveRtcChannelParam.getChannelId());
mangerRtcCacheService.delChannelInfo(leaveRtcChannelParam.getChannelId());
} }
} }
...@@ -230,7 +221,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -230,7 +221,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(sdpForwardParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(sdpForwardParam.getChannelId());
// 移除自己 // 移除自己
clientListByRtcChannelId.remove(client.getClientId()); clientListByRtcChannelId.remove(client.getId().toString());
for (String toClientId : clientListByRtcChannelId) { for (String toClientId : clientListByRtcChannelId) {
...@@ -271,7 +262,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -271,7 +262,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(candidateForwardParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(candidateForwardParam.getChannelId());
// 移除自己 // 移除自己
clientListByRtcChannelId.remove(client.getClientId()); clientListByRtcChannelId.remove(client.getId().toString());
for (String toClientId : clientListByRtcChannelId) { for (String toClientId : clientListByRtcChannelId) {
......
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