diff --git a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java index acd6092f..9a7912d2 100644 --- a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java +++ b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp; +import com.genersoft.iot.vmp.jt1078.util.ClassUtil; import com.genersoft.iot.vmp.utils.GitUtil; import com.genersoft.iot.vmp.utils.SpringBeanFactory; import lombok.extern.slf4j.Slf4j; @@ -33,6 +34,7 @@ public class VManageBootstrap extends SpringBootServletInitializer { public static void main(String[] args) { VManageBootstrap.args = args; VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args); + ClassUtil.context = VManageBootstrap.context; GitUtil gitUtil = SpringBeanFactory.getBean("gitUtil"); if (gitUtil == null) { log.info("获取版本信息失败"); @@ -62,6 +64,5 @@ public class VManageBootstrap extends SpringBootServletInitializer { ); SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig(); sessionCookieConfig.setHttpOnly(true); - } } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisRpcConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisRpcConfig.java index 6607acec..a70563fb 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisRpcConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisRpcConfig.java @@ -7,9 +7,7 @@ import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcClassHandler; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcMessage; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; -import com.genersoft.iot.vmp.jt1078.util.ClassUtil; -import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; -import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping; +import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -19,11 +17,9 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; @@ -53,34 +49,37 @@ public class RedisRpcConfig implements MessageListener { private final static Map protocolHash = new HashMap<>(); - // 启动时执行 - @PostConstruct - public void init(){ - List> classList = ClassUtil.getClassList("com.genersoft.iot.vmp.service.redisMsg.control", RedisRpcController.class); - for (Class handlerClass : classList) { - String controllerPath = handlerClass.getAnnotation(RedisRpcController.class).value(); - // 扫描其下的方法 - Method[] methods = handlerClass.getDeclaredMethods(); - for (Method method : methods) { - RedisRpcMapping annotation = method.getAnnotation(RedisRpcMapping.class); - if (annotation != null) { - String methodPath = annotation.value(); - if (methodPath != null) { - protocolHash.put(controllerPath + "/" + methodPath, new RedisRpcClassHandler(handlerClass, method)); - } - } - - } - - } - for (String s : protocolHash.keySet()) { - System.out.println(s); - } - if (log.isDebugEnabled()) { - log.debug("消息ID缓存表 protocolHash:{}", protocolHash); - } + public void addHandler(String path, RedisRpcClassHandler handler) { + protocolHash.put(path, handler); } +// @Override +// public void run(String... args) throws Exception { +// List> classList = ClassUtil.getClassList("com.genersoft.iot.vmp.service.redisMsg.control", RedisRpcController.class); +// for (Class handlerClass : classList) { +// String controllerPath = handlerClass.getAnnotation(RedisRpcController.class).value(); +// Object bean = ClassUtil.getBean(controllerPath, handlerClass); +// // 扫描其下的方法 +// Method[] methods = handlerClass.getDeclaredMethods(); +// for (Method method : methods) { +// RedisRpcMapping annotation = method.getAnnotation(RedisRpcMapping.class); +// if (annotation != null) { +// String methodPath = annotation.value(); +// if (methodPath != null) { +// protocolHash.put(controllerPath + "/" + methodPath, new RedisRpcClassHandler(bean, method)); +// } +// } +// +// } +// +// } +// for (String s : protocolHash.keySet()) { +// System.out.println(s); +// } +// if (log.isDebugEnabled()) { +// log.debug("消息ID缓存表 protocolHash:{}", protocolHash); +// } +// } @Override public void onMessage(Message message, byte[] pattern) { @@ -100,7 +99,7 @@ public class RedisRpcConfig implements MessageListener { log.error("[redis rpc 解析失败] {}", JSON.toJSONString(redisRpcMessage)); } } catch (Exception e) { - log.error("[redis rpc 解析异常] ", e); + log.error("[redis rpc 解析异常] {}",new String(msg.getBody()), e); } } }); @@ -122,7 +121,7 @@ public class RedisRpcConfig implements MessageListener { } log.info("[redis-rpc] << {}", request); RedisRpcClassHandler redisRpcClassHandler = protocolHash.get(request.getUri()); - Class objectClass = redisRpcClassHandler.getObjectClass(); + RpcController controller = redisRpcClassHandler.getController(); Method method = redisRpcClassHandler.getMethod(); // 没有携带目标ID的可以理解为哪个wvp有结果就哪个回复,携带目标ID,但是如果是不存在的uri则直接回复404 if (userSetting.getServerId().equals(request.getToId())) { @@ -133,7 +132,7 @@ public class RedisRpcConfig implements MessageListener { sendResponse(response); return; } - RedisRpcResponse response = (RedisRpcResponse)method.invoke(objectClass, request); + RedisRpcResponse response = (RedisRpcResponse)method.invoke(controller, request); if(response != null) { sendResponse(response); } @@ -141,7 +140,7 @@ public class RedisRpcConfig implements MessageListener { if (method == null) { return; } - RedisRpcResponse response = (RedisRpcResponse)method.invoke(objectClass, request); + RedisRpcResponse response = (RedisRpcResponse)method.invoke(controller, request); if (response != null) { sendResponse(response); } @@ -234,6 +233,8 @@ public class RedisRpcConfig implements MessageListener { return callbacks.size(); } + + // @Scheduled(fixedRate = 1000) //每1秒执行一次 // public void execute(){ // logger.info("callbacks的长度: " + callbacks.size()); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/redis/bean/RedisRpcClassHandler.java b/src/main/java/com/genersoft/iot/vmp/conf/redis/bean/RedisRpcClassHandler.java index 8c49a79f..1fab24bb 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/redis/bean/RedisRpcClassHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/redis/bean/RedisRpcClassHandler.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.conf.redis.bean; +import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; import lombok.Data; import java.lang.reflect.Method; @@ -7,11 +8,11 @@ import java.lang.reflect.Method; @Data public class RedisRpcClassHandler { - private Class objectClass; + private RpcController controller; private Method method; - public RedisRpcClassHandler(Class objectClass, Method method) { - this.objectClass = objectClass; + public RedisRpcClassHandler(RpcController controller, Method method) { + this.controller = controller; this.method = method; } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/util/ClassUtil.java b/src/main/java/com/genersoft/iot/vmp/jt1078/util/ClassUtil.java index 9c3fd286..def0c0eb 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/util/ClassUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/util/ClassUtil.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.jt1078.util; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -12,6 +13,12 @@ import java.util.List; @Slf4j public class ClassUtil { + public static ConfigurableApplicationContext context; + + public static T getBean(String beanName, Class clazz) { + return context.getBean(beanName, clazz); + } + public static Object getBean(Class clazz) { if (clazz != null) { try { diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcChannelPlayController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcChannelPlayController.java index d6f3a5af..bcd58c3e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcChannelPlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcChannelPlayController.java @@ -1,35 +1,28 @@ package com.genersoft.iot.vmp.service.redisMsg.control; -import com.alibaba.fastjson2.JSONObject; -import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcMessage; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; -import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService; import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; -import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; -import com.genersoft.iot.vmp.media.bean.MediaServer; -import com.genersoft.iot.vmp.media.event.hook.Hook; -import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; -import com.genersoft.iot.vmp.media.event.hook.HookType; -import com.genersoft.iot.vmp.media.service.IMediaServerService; -import com.genersoft.iot.vmp.service.ISendRtpServerService; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping; +import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; import javax.sip.message.Response; +@Component @Slf4j @RedisRpcController("channel") -public class RedisRpcChannelPlayController { +public class RedisRpcChannelPlayController extends RpcController { @Autowired private UserSetting userSetting; diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcSendRtpController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcSendRtpController.java index 1077f578..ee5d1e18 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcSendRtpController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcSendRtpController.java @@ -5,27 +5,26 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; -import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService; -import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaServer; -import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.service.ISendRtpServerService; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping; +import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; import javax.sip.message.Response; +@Component @Slf4j @RedisRpcController("sendRtp") -public class RedisRpcSendRtpController { +public class RedisRpcSendRtpController extends RpcController { @Autowired private SSRCFactory ssrcFactory; @@ -39,17 +38,6 @@ public class RedisRpcSendRtpController { @Autowired private UserSetting userSetting; - @Autowired - private HookSubscribe hookSubscribe; - - @Autowired - private RedisTemplate redisTemplate; - - @Autowired - private IGbChannelService channelService; - - @Autowired - private IGbChannelPlayService channelPlayService; /** * 获取发流的信息 diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java index 3465bdc8..e1ef57b5 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java @@ -8,8 +8,6 @@ import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcMessage; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; -import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService; -import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.event.hook.Hook; @@ -19,13 +17,16 @@ import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.service.ISendRtpServerService; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping; +import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +@Component @Slf4j @RedisRpcController("streamPush") -public class RedisRpcStreamPushController { +public class RedisRpcStreamPushController extends RpcController { @Autowired private SSRCFactory ssrcFactory; @@ -45,11 +46,6 @@ public class RedisRpcStreamPushController { @Autowired private RedisTemplate redisTemplate; - @Autowired - private IGbChannelService channelService; - - @Autowired - private IGbChannelPlayService channelPlayService; private void sendResponse(RedisRpcResponse response){ log.info("[redis-rpc] >> {}", response); diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RedisRpcController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RedisRpcController.java index 79cdcb37..f314b0c0 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RedisRpcController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RedisRpcController.java @@ -1,13 +1,10 @@ package com.genersoft.iot.vmp.service.redisMsg.dto; -import org.springframework.stereotype.Component; - import java.lang.annotation.*; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented -@Component public @interface RedisRpcController { /** * 请求路径 diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RpcController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RpcController.java new file mode 100644 index 00000000..4544812f --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/dto/RpcController.java @@ -0,0 +1,33 @@ +package com.genersoft.iot.vmp.service.redisMsg.dto; + + +import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig; +import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcClassHandler; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.PostConstruct; +import java.lang.reflect.Method; + +public class RpcController { + + @Autowired + private RedisRpcConfig redisRpcConfig; + + + @PostConstruct + public void init() { + String controllerPath = this.getClass().getAnnotation(RedisRpcController.class).value(); + // 扫描其下的方法 + Method[] methods = this.getClass().getDeclaredMethods(); + for (Method method : methods) { + RedisRpcMapping annotation = method.getAnnotation(RedisRpcMapping.class); + if (annotation != null) { + String methodPath = annotation.value(); + if (methodPath != null) { + redisRpcConfig.addHandler(controllerPath + "/" + methodPath, new RedisRpcClassHandler(this, method)); + } + } + + } + } +} diff --git a/web_src/src/components/StreamPushList.vue b/web_src/src/components/StreamPushList.vue index 6ee690ef..230af4c6 100755 --- a/web_src/src/components/StreamPushList.vue +++ b/web_src/src/components/StreamPushList.vue @@ -33,9 +33,9 @@ download='推流通道导入.zip'>下载模板 批量移除 + :disabled="multipleSelection.length === 0" type="danger" @click="batchDel">移除 - 添加通道 + 添加