diff --git a/kernel-d-socket/pom.xml b/kernel-d-socket/pom.xml
deleted file mode 100644
index 3543520c4..000000000
--- a/kernel-d-socket/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- * 可通过该类直接发送消息,每一个Socket实现的子模块必须实现该接口,以提供统一的操作API - * - * @author majianguo - * @since 2021/6/2 上午9:25 - */ -public interface SocketOperatorApi { - - /** - * 发送消息到指定会话 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param sessionId 会话ID - * @param msg 消息体 - * @author majianguo - * @since 2021/6/11 下午2:19 - **/ - void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException; - - /** - * 发送消息到指定用户的所有会话 - *
- * 如果用户同一个消息类型建立了多个会话,则统一全部发送 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param userId 用户ID - * @param msg 消息体 - * @author majianguo - * @since 2021/6/2 上午9:35 - **/ - void sendMsgOfUserSession(String msgType, String userId, Object msg) throws SocketException; - - /** - * 发送消息到所有会话 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param msg 消息体 - * @author majianguo - * @since 2021/6/2 上午9:35 - **/ - void sendMsgOfAllUserSession(String msgType, Object msg); - - /** - * 根据会话id关闭会话 - * - * @param socketId 会话id - * @author majianguo - * @since 2021/8/13 16:00 - **/ - void closeSocketBySocketId(String socketId); - - /** - * 监听指定类型消息 - *
- * 1.该方法每调用一次即注册一个监听,同一个消息类型多次调用只有最后一次生效 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param callbackInterface 消息监听器 - * @author majianguo - * @since 2021/6/2 上午9:54 - **/ - void msgTypeCallback(String msgType, SocketMsgCallbackInterface callbackInterface); -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java deleted file mode 100644 index 6ac8fc91c..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.constants; - -/** - * socket 模块常量 - * - * @author majianguo - * @since 2021/6/1 上午11:21 - */ -public interface SocketConstants { - - /** - * socket模块的名称 - */ - String SOCKET_MODULE_NAME = "kernel-d-socket"; - - /** - * 异常枚举的步进值 - */ - String SOCKET_EXCEPTION_STEP_CODE = "30"; - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java deleted file mode 100644 index 0ed749b2c..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 客户端消息类型枚举 - *
- * 说明:该枚举适用于服务器接收到客户端发来的消息,判断消息类型时使用 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum ClientMessageTypeEnum { - - /** - * 用户连接鉴权 - */ - USER_CONNECTION_AUTHENTICATION("200000", "用户连接鉴权"), - - /** - * 用户心跳消息类型 - */ - USER_HEART("299999", "用户心跳消息类型"); - - private final String code; - - private final String name; - - ClientMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java deleted file mode 100644 index e17feb395..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 服务端消息类型枚举 - *
- * 说明:该枚举适用于服务器推送给客户端消息时使用 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum ServerMessageTypeEnum { - - /** - * 系统通知消息类型 - */ - SYS_NOTICE_MSG_TYPE("100001", "系统通知消息类型"), - - /** - * 连接消息回复 - */ - SYS_REPLY_MSG_TYPE("100002", "连接消息回复"); - - private final String code; - - private final String name; - - ServerMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java deleted file mode 100644 index bb78f4a15..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 服务端监听器枚举 - *
- * 说明:该枚举适用于服务端监听首次连接和断开连接 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum SystemMessageTypeEnum { - - /** - * 监听首次连接 - */ - SYS_LISTENER_ONOPEN("S00001", "监听首次连接"), - - /** - * 监听断开连接 - */ - SYS_LISTENER_ONCLOSE("S00002", "监听断开连接"), - - /** - * 监听异常信息 - */ - SYS_LISTENER_ONERROR("S00003", "监听异常信息"); - - private final String code; - - private final String name; - - SystemMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java deleted file mode 100644 index 68c0add02..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.exception; - -import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; -import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; -import cn.stylefeng.roses.kernel.socket.api.constants.SocketConstants; - -/** - * Socket模块异常 - * - * @author majianguo - * @since 2021/6/1 上午11:23 - */ -public class SocketException extends ServiceException { - - public SocketException(AbstractExceptionEnum exception) { - super(SocketConstants.SOCKET_MODULE_NAME, exception); - } - - public SocketException(String errorCode, String userTip) { - super(SocketConstants.SOCKET_MODULE_NAME, errorCode, userTip); - } - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java deleted file mode 100644 index cc3f99dca..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.exception.enums; - -import cn.stylefeng.roses.kernel.rule.constants.RuleConstants; -import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; -import cn.stylefeng.roses.kernel.socket.api.constants.SocketConstants; -import lombok.Getter; - -/** - * Socket模块相关异常枚举 - * - * @author majianguo - * @since 2021/6/1 上午11:25 - */ -@Getter -public enum SocketExceptionEnum implements AbstractExceptionEnum { - - /** - * Socket操作异常 - */ - SOCKET_ERROR(RuleConstants.THIRD_ERROR_TYPE_CODE + SocketConstants.SOCKET_EXCEPTION_STEP_CODE + "01", "操作异常,具体信息为:{}"), - - /** - * 会话不存在 - */ - SESSION_NOT_EXIST(RuleConstants.THIRD_ERROR_TYPE_CODE + SocketConstants.SOCKET_EXCEPTION_STEP_CODE + "02", "会话不存在"); - - /** - * 错误编码 - */ - private final String errorCode; - - /** - * 提示用户信息 - */ - private final String userTip; - - SocketExceptionEnum(String errorCode, String userTip) { - this.errorCode = errorCode; - this.userTip = userTip; - } - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java deleted file mode 100644 index d719d95fe..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.message; - -import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession; - -/** - * Socket消息接收回调接口 - * - * @author majianguo - * @since 2021/6/2 上午9:53 - */ -@FunctionalInterface -public interface SocketMsgCallbackInterface { - - /** - * 收到消息的回调 - * - * @param msgType 消息类型 - * @param msg 消息体 - * @param socketSession 本次通信的会话 - * @author majianguo - * @since 2021/6/2 上午9:51 - **/ - void callback(String msgType, Object msg, SocketSession socketSession); -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java deleted file mode 100644 index 460783f11..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.session; - -/** - * socket会话操作接口 - *
- * 该接口面向会话,须基于会话的通道调用。
- * 该接口支持扩展,可参考WebSocket模块中{@link cn.stylefeng.roses.kernel.socket.websocket.operator.channel}包下的类
- *
- * @author majianguo
- * @since 2021/6/1 上午11:46
- */
-public interface SocketSessionOperatorApi {
-
- /**
- * 写出数据,经过责任链
- *
- * @author majianguo
- * @since 2021/6/1 上午11:48
- **/
- void writeAndFlush(Object obj);
-
- /**
- * 写出数据,不经过责任链
- *
- * @author majianguo
- * @since 2021/6/1 上午11:48
- **/
- void writeToChannel(Object obj);
-
- /**
- * 关闭会话
- *
- * @author majianguo
- * @since 2021/6/1 上午11:48
- **/
- void close();
-
- /**
- * 是否存活
- *
- * @return {@link boolean}
- * @author majianguo
- * @since 2021/6/1 上午11:50
- **/
- boolean isInvalid();
-}
diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java
deleted file mode 100644
index 275cb58a1..000000000
--- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package cn.stylefeng.roses.kernel.socket.api.session.pojo;
-
-import cn.stylefeng.roses.kernel.socket.api.session.SocketSessionOperatorApi;
-import lombok.Data;
-
-/**
- * Socket会话
- *
- * @author majianguo
- * @since 2021/6/1 上午11:28
- */
-@Data
-public class SocketSession
- * 维护所有消息类型对应的处理器
- *
- * @author majianguo
- * @since 2021/6/1 下午2:20
- */
-public class SocketMessageCenter {
-
- /**
- * 所有消息监听器维护
- */
- private static final Map
- * 如果是Spring boot项目,通过注入SocketOperatorApi接口操作socket,需将本来交给Spring管理
- *
- * @author majianguo
- * @since 2021/6/2 上午10:41
- */
-public class WebSocketOperator implements SocketOperatorApi {
-
- @Override
- public void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException {
- SocketSession
- * 简单封装Spring Boot的默认WebSocket
- *
- * @author majianguo
- * @since 2021/6/1 下午3:41
- */
-public class GunsSocketOperator implements SocketChannelExpandInterFace {
-
- /**
- * 实际操作的通道
- */
- private Session socketChannel;
-
- public GunsSocketOperator(Session socketChannel) {
- this.socketChannel = socketChannel;
- }
-
- @Override
- public void writeAndFlush(Object obj) {
- try {
- if (socketChannel.isOpen()) {
- socketChannel.getBasicRemote().sendText(JSON.toJSONString(obj));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void writeToChannel(Object obj) {
- if (socketChannel.isOpen()) {
- socketChannel.getAsyncRemote().sendText(JSON.toJSONString(obj));
- }
- }
-
- @Override
- public void close() {
- try {
- if (socketChannel.isOpen()) {
- socketChannel.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public boolean isInvalid() {
- return socketChannel.isOpen();
- }
-}
diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java
deleted file mode 100644
index 35f204013..000000000
--- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel;
-
-import cn.stylefeng.roses.kernel.socket.api.session.SocketSessionOperatorApi;
-
-/**
- * 对Api模块的操作类进行扩展
- *
- * 暂时只写接口,SocketOperatorApi方法不够用时再对此类进行扩展
- *
- * @author majianguo
- * @since 2021/6/1 下午3:44
- */
-public interface SocketChannelExpandInterFace extends SocketSessionOperatorApi {
-
-}
diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java
deleted file mode 100644
index fd06db094..000000000
--- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package cn.stylefeng.roses.kernel.socket.business.websocket.pojo;
-
-import cn.stylefeng.roses.kernel.socket.api.SocketOperatorApi;
-import lombok.Data;
-
-/**
- * WebSocket交互通用对象
- *
- * 特殊说明一下serverMsgType和clientMsgType的区别
- * 1.serverMsgType字段是服务端发送给客户端的字段
- * 例如:服务端发送一个系统消息(type:100001),客户端接收到该消息以后判断需不需要处理,不需要处理跳过即可
- *
- * 2.clientMsgType字段是客户端发送给服务器的字段
- * 例如:客户端发送给服务器一个心跳消息(type:299999),服务端如果需要处理该消息就注册一个该消息的监听器,
- * 那么收到消息服务端会把消息推送给对应的监听器,接口见{@link SocketOperatorApi#msgTypeCallback}
- *
- * @author majianguo
- * @since 2021/6/1 下午2:56
- */
-@Data
-public class WebSocketMessageDTO {
-
- /**
- * 服务端发送的消息类型(客户端如果需要监听该消息类型,注册对应的消息处理器即可)
- */
- private String serverMsgType;
-
- /**
- * 客户端发送的消息类型(服务端需要处理的消息类型)
- */
- private String clientMsgType;
-
- /**
- * 目标Id
- */
- private String toUserId;
-
- /**
- * 发送者ID
- */
- private String formUserId;
-
- /**
- * 具体发送的数据
- */
- private Object data;
-
-}
diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java
deleted file mode 100644
index 8a0428cf9..000000000
--- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java
+++ /dev/null
@@ -1,182 +0,0 @@
-package cn.stylefeng.roses.kernel.socket.business.websocket.server;
-
-import cn.hutool.core.util.ObjectUtil;
-import cn.stylefeng.roses.kernel.auth.api.context.AuthJwtContext;
-import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload;
-import cn.stylefeng.roses.kernel.socket.api.enums.ClientMessageTypeEnum;
-import cn.stylefeng.roses.kernel.socket.api.enums.ServerMessageTypeEnum;
-import cn.stylefeng.roses.kernel.socket.api.enums.SystemMessageTypeEnum;
-import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface;
-import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession;
-import cn.stylefeng.roses.kernel.socket.business.websocket.message.SocketMessageCenter;
-import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GunsSocketOperator;
-import cn.stylefeng.roses.kernel.socket.business.websocket.pojo.WebSocketMessageDTO;
-import cn.stylefeng.roses.kernel.socket.business.websocket.session.SessionCenter;
-import com.alibaba.fastjson.JSON;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import javax.websocket.*;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
-import java.io.IOException;
-
-/**
- * 消息监听处理器
- *
- * @author majianguo
- * @since 2021/6/1 下午2:35
- */
-@Slf4j
-@ServerEndpoint(value = "/webSocket/{token}")
-@Component
-public class WebSocketServer {
-
- /**
- * 连接建立调用的方法
- *
- * 暂时无用,需要在建立连接的时候做一些事情的话可以修改这里
- *
- * @param session 会话信息
- * @author majianguo
- * @since 2021/6/21 下午5:14
- **/
- @OnOpen
- public void onOpen(Session session, @PathParam("token") String token) {
- String userId = null;
- try {
- // 解析用户信息
- DefaultJwtPayload defaultPayload = AuthJwtContext.me().getDefaultPayload(token);
- userId = defaultPayload.getUserId().toString();
- } catch (io.jsonwebtoken.JwtException e) {
- try {
- session.close();
- } catch (IOException ioException) {
- ioException.printStackTrace();
- }
- }
-
- // 操作api包装
- GunsSocketOperator gunsSocketOperator = new GunsSocketOperator(session);
-
- // 回复消息
- WebSocketMessageDTO replyMsg = new WebSocketMessageDTO();
- replyMsg.setServerMsgType(ServerMessageTypeEnum.SYS_REPLY_MSG_TYPE.getCode());
- replyMsg.setToUserId(userId);
-
- // 创建会话对象
- SocketSession
- * 维护所有的会话
- *
- * @author majianguo
- * @since 2021/6/1 下午1:43
- */
-public class SessionCenter {
-
- /**
- * 所有用户会话维护
- */
- private static ConcurrentMap>> values = SessionCenter.getSocketSessionMap().values();
- WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO();
- webSocketMessageDTO.setData(msg);
- webSocketMessageDTO.setServerMsgType(msgType);
- for (List