diff --git a/src/main/java/cn/com/tenlion/usercenter/consts/ISmartCityUserCenterConsts.java b/src/main/java/cn/com/tenlion/usercenter/consts/ISmartCityUserCenterConsts.java new file mode 100644 index 0000000..399d908 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/consts/ISmartCityUserCenterConsts.java @@ -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"; + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/enums/websocket/WebSocketCustomTypeEnum.java b/src/main/java/cn/com/tenlion/usercenter/enums/websocket/WebSocketCustomTypeEnum.java index 3c987b2..edb7da9 100644 --- a/src/main/java/cn/com/tenlion/usercenter/enums/websocket/WebSocketCustomTypeEnum.java +++ b/src/main/java/cn/com/tenlion/usercenter/enums/websocket/WebSocketCustomTypeEnum.java @@ -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; diff --git a/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/IHuaweiRtcService.java b/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/IHuaweiRtcService.java new file mode 100644 index 0000000..4caa7ce --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/IHuaweiRtcService.java @@ -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; +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/impl/HuaweiRtcServiceImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/impl/HuaweiRtcServiceImpl.java new file mode 100644 index 0000000..562a463 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/huaweirtc/impl/HuaweiRtcServiceImpl.java @@ -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); + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/websocket/WebSocketTextCustomServiceImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/websocket/WebSocketTextCustomServiceImpl.java index 3e9dcdf..8dba15b 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/websocket/WebSocketTextCustomServiceImpl.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/websocket/WebSocketTextCustomServiceImpl.java @@ -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); } } }