From 8a86c66098091e50421ce5aa230d7d013042168d Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期四, 10 八月 2023 15:03:29 +0800
Subject: [PATCH] 优化mqtt数据中文乱码

---
 ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 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..c4be437 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,49 @@
  * @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);
+                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() {
+        if (mediamtxEnabled) {
+            log.info("閿�姣乵ediaMtx");
             if (CmdUtils.isProcessRunning(processName)) {
                 // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
                 CmdUtils.stopProcess(processName);
             }
-            // 鍚姩鍚庡彴杩涚▼
-             CmdUtils.commandStart(processName,cmd);
-            // 鍚姩cmd绐楀彛
-//            String[] command = {"cmd","/c","start",exePath,ymlPath};
-//            CmdUtils.commandStart(command);
         }
     }
 

--
Gitblit v1.9.3