From 065142057ba3983af899991085e37ac1ec502320 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期二, 19 九月 2023 14:06:30 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java | 69 ++++++++++++++++++----------------
1 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java
index 299d2e3..0a0c592 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java
@@ -1,13 +1,14 @@
package com.ruoyi.media.service.impl;
+import com.ruoyi.utils.process.CmdUtils;
import com.sun.jna.Platform;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-import java.io.BufferedReader;
+import javax.annotation.PreDestroy;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@@ -19,40 +20,44 @@
* @Version: 1.0
**/
@Component
+@Slf4j(topic = "cmd")
public class WebrtcService {
+ String processName = "webrtc-streamer.exe";
+ @Value("${webrtc.host}")
+ String webrtcHost;
+ @Value("${webrtc.enabled}")
+ Boolean webrtcEnabled;
+
@PostConstruct
public void init() {
- if (Platform.isWindows()) {
- // String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + "setup.bat";
- // String[] cmd = {"cmd", "/c", "start", exePath};
- String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + "webrtc-streamer.exe";
- List<String> cmd = new ArrayList<>();
- cmd.add(exePath);
- cmd.add("-o");
- cmd.add("-H127.0.0.1:8000");
- commandStart(cmd);
+ if (webrtcEnabled) {
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + processName;
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add("-H" + webrtcHost);
+ cmd.add("-o");
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(processName, cmd, null);
+ // 鍚姩cmd绐楀彛
+// String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
+// CmdUtils.commandStart(command);
+ }
}
}
- public static void commandStart(List<String> command) {
- command.forEach(v -> System.out.print(v + " "));
- System.out.println();
- System.out.println();
- ProcessBuilder builder = new ProcessBuilder();
- //姝e父淇℃伅鍜岄敊璇俊鎭悎骞惰緭鍑�
- builder.redirectErrorStream(true);
- builder.command(command);
- //寮�濮嬫墽琛屽懡浠�
- Process process = null;
- try {
- process = builder.start();
-// //濡傛灉浣犳兂鑾峰彇鍒版墽琛屽畬鍚庣殑淇℃伅锛岄偅涔堜笅闈㈢殑浠g爜涔熸槸闇�瑕佺殑
-// String line = "";
-// BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
-// while ((line = br.readLine()) != null) {
-// System.out.println(line);
-// }
- } catch (IOException e) {
- e.printStackTrace();
+
+ @PreDestroy
+ public void destroyMediaMtx() {
+ if (webrtcEnabled) {
+ log.info("閿�姣亀ebrtc-streamer");
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
}
}
}
--
Gitblit v1.9.3