From 08674069805545af85ef872e28ee28e5fdc30cee Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 04 八月 2023 13:19:11 +0800
Subject: [PATCH] 优化minio工具类 集成webrtc-streamer部署启动 集成minio部署启动 集成mediaMtx部署启动

---
 ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
index 3bdf604..d10da3b 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -15,6 +15,7 @@
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 import java.io.BufferedReader;
 import java.io.File;
@@ -33,33 +34,47 @@
  * @Version: 1.0
  **/
 @Service
-@Slf4j
+@Slf4j(topic = "cmd")
 public class MediaService implements IMediaService {
 
     @Resource
     MediaClient mediaClient;
     @Value("${mediamtx.host}")
     String mediamtxHost;
+    @Value("${mediamtx.enabled}")
+    Boolean mediamtxEnabled;
+
+    String processName = "mediamtx.exe";
 
     @PostConstruct
     public void initMediaMtx() {
-        if (Platform.isWindows()) {
-            String processName="mediamtx.exe";
-            String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
-            String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
+        if (mediamtxEnabled) {
+            if (Platform.isWindows()) {
+                String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
+                String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
 
-            List<String> cmd = new ArrayList<>();
-            cmd.add(exePath);
-            cmd.add(ymlPath);
-            if (CmdUtils.isProcessRunning(processName)) {
-                // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
-                CmdUtils.stopProcess(processName);
-            }
-            // 鍚姩鍚庡彴杩涚▼
-             CmdUtils.commandStart(processName,cmd);
-            // 鍚姩cmd绐楀彛
+                List<String> cmd = new ArrayList<>();
+                cmd.add(exePath);
+                cmd.add(ymlPath);
+                if (CmdUtils.isProcessRunning(processName)) {
+                    // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+                    CmdUtils.stopProcess(processName);
+                }
+                // 鍚姩鍚庡彴杩涚▼
+                CmdUtils.commandStart(processName, cmd, null);
+                // 鍚姩cmd绐楀彛
 //            String[] command = {"cmd","/c","start",exePath,ymlPath};
 //            CmdUtils.commandStart(command);
+            }
+        }
+    }
+
+    @PreDestroy
+    public void destroyMediaMtx() {
+        log.info("閿�姣乵ediaMtx");
+        if (CmdUtils.isProcessRunning(processName)) {
+            // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+            CmdUtils.stopProcess(processName);
         }
     }
 

--
Gitblit v1.9.3