From f5f6165cdfcad0cff0d3686e228187ec64d52302 Mon Sep 17 00:00:00 2001 From: qiushui Date: Fri, 21 Jan 2022 10:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=90=83=E6=9C=BA=E8=BD=AC?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/CameraController.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/web/src/main/java/com/zhehekeji/web/controller/CameraController.java b/web/src/main/java/com/zhehekeji/web/controller/CameraController.java index 2a642ad..a6b9d74 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/CameraController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/CameraController.java @@ -1,5 +1,6 @@ package com.zhehekeji.web.controller; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.zhehekeji.common.util.ValidatorUtil; import com.zhehekeji.core.pojo.Result; @@ -17,7 +18,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import java.io.IOException; +import java.io.*; import java.util.List; @Api(value = "camera",tags = "球机管理") @@ -121,4 +122,39 @@ public class CameraController { cameraControlModule.toPtz(ptzId,req.getCameraId()); return Result.success(); } + + @GetMapping("/downloadConfig") + @ApiOperation(value = "下载") + public Result downloadConfig() throws IOException { + File file = new File("./config.json"); + if (file.exists()) { // 如果已存在,删除旧文件 + file.delete(); + } + file.createNewFile(); + List cameras = cameraService.allCameras(); + JSONObject jsonObject = new JSONObject(); + JSONObject server = new JSONObject(); + server.put("http_port",":8083"); + String [] strings = new String[1]; + strings[0] = "stun:stun.l.google.com:19302"; + server.put("ice_servers",strings); + server.put("ice_username",""); + server.put("ice_credential",""); + jsonObject.put("server",server); + JSONObject streams = new JSONObject(); + cameras.forEach(camera -> { + JSONObject obj = new JSONObject(); + obj.put("on_demand",false); + obj.put("disable_audio",true); + obj.put("url",camera.getRtsp()); + streams.put("camera"+camera.getId(),obj); + }); + jsonObject.put("streams",streams); + Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); + write.write(jsonObject.toJSONString()); + write.flush(); + write.close(); + return Result.success(); + } + }