新增huawei rtc 呼叫

This commit is contained in:
wanggeng 2021-12-07 16:10:45 +08:00
parent a3fa8f8eb8
commit 8650856864
5 changed files with 91 additions and 5 deletions

View File

@ -0,0 +1,17 @@
package cn.com.tenlion.usercenter.consts;
/**
* @ClassName: ISmartCityUserCenterConts
* @Description: 常量
* @Author: wanggeng
* @Date: 2021/12/7 11:00 AM
* @Version: 1.0
*/
public interface ISmartCityUserCenterConsts {
/**
* APP客户端名称
*/
String APP_CLIENT_NAME = "city-governance";
}

View File

@ -9,7 +9,11 @@ package cn.com.tenlion.usercenter.enums.websocket;
*/
public enum WebSocketCustomTypeEnum {
LOCATION_REALTIME(11001, "实时定位");
LOCATION_REALTIME(11001, "实时定位"),
HUAWEI_RTC_CALL(11002, "华为实时通讯呼叫"),
HUAWEI_RTC_CALL_LOGIN_SUCCESS(11201, "华为实时通讯呼叫登录成功"),
HUAWEI_RTC_CALL_NOT_SUPPORTED(11401, "华为实时通讯呼叫不支持"),
HUAWEI_RTC_CALL_LOGIN_FAILED(11402, "华为实时通讯呼叫登录失败");
private int value;
private String summary;

View File

@ -0,0 +1,22 @@
package cn.com.tenlion.usercenter.service.huaweirtc;
import ink.wgink.exceptions.websocket.UserOfflineException;
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketClientMessage;
/**
* @ClassName: IVideoCallService
* @Description: 视频通话
* @Author: wanggeng
* @Date: 2021/12/7 10:46 AM
* @Version: 1.0
*/
public interface IHuaweiRtcService {
/**
* 视频呼叫
*
* @param channel
* @param webSocketClientMessage
*/
void rtcCall(WebSocketClientMessage webSocketClientMessage) throws UserOfflineException;
}

View File

@ -0,0 +1,32 @@
package cn.com.tenlion.usercenter.service.huaweirtc.impl;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.service.huaweirtc.IHuaweiRtcService;
import ink.wgink.exceptions.websocket.UserOfflineException;
import ink.wgink.exceptions.websocket.useroffline.RtcUserOfflineException;
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketClientMessage;
import ink.wgink.pojo.session.WebSocketSession;
import org.springframework.stereotype.Service;
/**
* @ClassName: VideoCallServiceImpl
* @Description: 视频通话
* @Author: wanggeng
* @Date: 2021/12/7 10:47 AM
* @Version: 1.0
*/
@Service
public class HuaweiRtcServiceImpl implements IHuaweiRtcService {
@Override
public void rtcCall(WebSocketClientMessage webSocketClientMessage) throws UserOfflineException {
String receiverUserId = webSocketClientMessage.getTo();
WebSocketSession onlineUser = WebSocketChannelManager.getInstance().getOnlineUser(receiverUserId, ISmartCityUserCenterConsts.APP_CLIENT_NAME);
if (onlineUser == null) {
throw new RtcUserOfflineException("用户不在线");
}
WebSocketChannelManager.getInstance().sendText(onlineUser.getChannel(), webSocketClientMessage);
}
}

View File

@ -2,10 +2,12 @@ package cn.com.tenlion.usercenter.service.websocket;
import cn.com.tenlion.usercenter.enums.websocket.WebSocketCustomTypeEnum;
import cn.com.tenlion.usercenter.service.userrealtimelocation.IUserRealtimeLocationService;
import cn.com.tenlion.usercenter.service.huaweirtc.IHuaweiRtcService;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
import ink.wgink.exceptions.websocket.BaseSocketException;
import ink.wgink.exceptions.websocket.CustomHandleException;
import ink.wgink.module.instantmessage.service.IWebSocketTextCustomService;
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketClientMessage;
import ink.wgink.module.map.pojo.vos.userlocation.UserLocationVO;
import io.netty.channel.Channel;
@ -24,17 +26,26 @@ public class WebSocketTextCustomServiceImpl extends DefaultBaseService implement
@Autowired
private IUserRealtimeLocationService userRealtimeLocationService;
@Autowired
private IHuaweiRtcService huaweiRtcService;
@Override
public void handle(Channel channel, WebSocketClientMessage webSocketClientMessage) throws CustomHandleException {
public void handle(Channel fromChannel, WebSocketClientMessage webSocketClientMessage) throws BaseSocketException {
try {
if (WebSocketCustomTypeEnum.LOCATION_REALTIME.getValue() == webSocketClientMessage.getType()) {
UserLocationVO userLocationVO = JSONObject.parseObject(webSocketClientMessage.getBody(), UserLocationVO.class);
userRealtimeLocationService.save(userLocationVO);
} else if (WebSocketCustomTypeEnum.HUAWEI_RTC_CALL.getValue() == webSocketClientMessage.getType()) {
huaweiRtcService.rtcCall(webSocketClientMessage);
} else if (WebSocketCustomTypeEnum.HUAWEI_RTC_CALL_LOGIN_SUCCESS.getValue() == webSocketClientMessage.getType()) {
huaweiRtcService.rtcCall(webSocketClientMessage);
} else if (WebSocketCustomTypeEnum.HUAWEI_RTC_CALL_LOGIN_FAILED.getValue() == webSocketClientMessage.getType()) {
huaweiRtcService.rtcCall(webSocketClientMessage);
} else if (WebSocketCustomTypeEnum.HUAWEI_RTC_CALL_NOT_SUPPORTED.getValue() == webSocketClientMessage.getType()) {
huaweiRtcService.rtcCall(webSocketClientMessage);
}
} catch (Exception e) {
e.printStackTrace();
throw new CustomHandleException(e.getMessage());
throw new CustomHandleException(e.getMessage(), e);
}
}
}