Procházet zdrojové kódy

feat: 多路径代理

lvkun před 3 roky
rodič
revize
abeae2039a

+ 6 - 0
config/proxy.ts

@@ -5,10 +5,16 @@
 
 module.exports = {
   dev: {
+    '/rts-api': {
+      target: 'http://124.222.113.37:8080',
+      changeOrigin: true,
+      pathRewrite: { '^/rts-api': '' }
+    },
     '/api': {
       target: 'http://124.222.113.37:8888',
       changeOrigin: true,
       pathRewrite: { '^/api': '' }
     }
+
   }
 }

+ 164 - 0
src/api/rts/stream.ts

@@ -0,0 +1,164 @@
+import request from '@/service/request'
+
+export const getStreams = () => {
+  return request<RTS.STREAM.List[]>({
+    url: '/api/streams',
+    method: 'GET'
+  })
+}
+
+export const getStreamsDetail = (streamPath: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/api/stream?streamPath=${streamPath}`,
+    method: 'GET'
+  })
+}
+
+export const getSnap = (streamPath: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/snap/${streamPath}`,
+    method: 'GET'
+  })
+}
+
+export const closeStream = (streamPath: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/api/closestream?streamPath=${streamPath}`,
+    method: 'GET'
+  })
+}
+
+export const getPullList = () => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/api/list/pull',
+    method: 'GET'
+  })
+}
+
+export const stopPull = (url: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/api/stoppull?url=${url}`,
+    method: 'GET'
+  })
+}
+
+export const createRtspPull = (params: {streamPath: string, target: string, save: number}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/rtsp/api/pull',
+    method: 'GET',
+    params
+  })
+}
+
+export const createRtmpPull = (params: {streamPath: string, target: string, save: number}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/rtmp/api/pull',
+    method: 'GET',
+    params
+  })
+}
+
+export const getPushList = () => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/api/list/push',
+    method: 'GET'
+  })
+}
+
+export const stopPush = (url: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/api/stoppush?url=${url}`,
+    method: 'GET'
+  })
+}
+
+export const createRtspPush = (params: {streamPath: string, target: string, save: number}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/rtsp/api/push',
+    method: 'GET',
+    params
+  })
+}
+
+export const createRtmpPush = (params: {streamPath: string, target: string, save: number}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/rtsp/api/push',
+    method: 'GET',
+    params
+  })
+}
+
+/** 查看存储列表 */
+export const getRecordList = (type: 'mp4' | 'ts' | 'flv') => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/record/api/list?type=${type}`,
+    method: 'GET'
+  })
+}
+
+/** 正在存储的视频流 */
+export const getRecording = () => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/record/api/list/recording',
+    method: 'GET'
+  })
+}
+
+/** 开始存储 */
+export const postRecord = (params: {type: 'mp4' | 'ts' | 'flv', streamPath: string }) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/record/api/start?type=flv&streamPath=live/rtc',
+    method: 'GET',
+    params
+  })
+}
+
+/** 停止录制 */
+export const stopRecord = (id: string) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/record/api/stop?id=xxx',
+    method: 'GET'
+  })
+}
+
+/** 录制播放 */
+export const playRecord = (streamPath: 'flv'| 'mp4' | 'm3u8' | 'h264'| 'h265') => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/record/.${streamPath}`,
+    method: 'GET'
+  })
+}
+
+/** 获取配置 RTSP */
+export const getConfig = (name: 'RTSP' | 'RTMP' | 'HLS' | 'HDL' | 'GB28181') => {
+  return request<RTS.STREAM.Detail[]>({
+    url: `/api/getconfig?name=${name}`,
+    method: 'GET'
+  })
+}
+
+/** 系统监控 */
+export const getSummary = () => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/api/summary',
+    method: 'GET'
+  })
+}
+
+/** 系统监控 流 */
+export const getMonitorStream = (params: {time: string, streamPath: string}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/monitor/api/list/stream',
+    method: 'GET',
+    params
+  })
+}
+
+/** 系统监控 轨道 */
+export const getMonitorTrack = (params: {time: string, streamPath: string}) => {
+  return request<RTS.STREAM.Detail[]>({
+    url: '/monitor/api/list/track?streamPath=xxxx',
+    method: 'GET',
+    params
+  })
+}

+ 1 - 0
src/controller/rts/index.ts

@@ -0,0 +1 @@
+export { RtsController } from './rts'

+ 7 - 0
src/controller/rts/rts.ts

@@ -0,0 +1,7 @@
+import { getStreams } from '@/api/rts/stream'
+
+export class RtsController {
+  static async getStreams () {
+    return getStreams()
+  }
+}

+ 4 - 1
src/pages/Iot/device/index.vue

@@ -49,6 +49,7 @@
       :pagination="searchState"
       @change="changePage"
     >
+
       <template #bodyCell="{column, record}">
         <template v-if="column.key === 'id'" >
           <a @click="goDetailPage(record.id)">{{record.id}}</a>
@@ -119,7 +120,7 @@
 
 <script lang="ts" setup >
 import { DeviceContriller, ModelController } from '@/controller/index'
-import { onMounted, reactive } from 'vue'
+import { onMounted, reactive, ref, toRefs, nextTick } from 'vue'
 import { Form, message } from 'ant-design-vue'
 import { DeviceAuthTypeEnum } from '@/enum/common'
 import { useRouter } from 'vue-router'
@@ -271,6 +272,8 @@ const getDevicePage = async () => {
 }
 
 const getDeviceStatistics = async () => {
+  console.log('223')
+
   const data = await DeviceContriller.statistics({ modelId: state.modelId })
   state.deviceCount = data as any
 }

+ 25 - 1
src/pages/rts/stream/index.vue

@@ -1,6 +1,13 @@
-<template><h1/></template>
+<template>
+  <a-card>
+
+  </a-card>
+</template>
 
 <script lang="ts" setup >
+import { RtsController } from '@/controller/rts'
+import { onMounted, reactive } from 'vue'
+
 const columns = [
   {
     title: 'StreamPath',
@@ -42,6 +49,23 @@ const columns = [
     key: 'action'
   }
 ]
+
+const queryParamsState = reactive({
+
+})
+
+const state = reactive({
+  loading: false
+})
+
+const getStreamList = async () => {
+  await RtsController.getStreams()
+}
+
+onMounted(() => {
+  getStreamList()
+})
+
 </script>
 
 <style></style>

+ 8 - 0
src/router/before.ts

@@ -1,7 +1,15 @@
 
 import router from './index'
+import { setBaseUrl } from '@/service/request'
 
 router.beforeEach((to, from, next) => {
   console.log('触发了路由守卫')
+  console.log(to.meta.title)
+  if (to.meta.title === '物联网') {
+    console.log('233')
+    setBaseUrl('/api')
+  } else {
+    setBaseUrl('/rts-api')
+  }
   next()
 })

+ 6 - 2
src/router/index.ts

@@ -4,7 +4,9 @@ const routes: Array<ROUTER.RoutesProps> = [
   {
     path: '/',
     name: '物联网',
-    title: '物联网',
+    meta: {
+      title: '物联网'
+    },
     component: () => import('@/layout/layout.vue'),
     redirect: '/dashboard',
     children: [
@@ -131,7 +133,9 @@ const routes: Array<ROUTER.RoutesProps> = [
   {
     path: '/rts',
     name: '视联网',
-    title: '视联网',
+    meta: {
+      title: '视联网'
+    },
     component: () => import('@/layout/layout.vue'),
     redirect: '/stream',
     children: [

+ 6 - 1
src/service/request.ts

@@ -1,8 +1,9 @@
 import { message } from 'ant-design-vue'
 import axios, { AxiosInstance, AxiosResponse } from 'axios'
+import { useRoute, useRouter } from 'vue-router'
 
 const instance = axios.create({
-  baseURL: '/api',
+  baseURL: '',
   timeout: 10000
 })
 
@@ -33,6 +34,10 @@ instance.interceptors.response.use(function (response) {
   return response.data
 }, error => Promise.reject(error))
 
+export const setBaseUrl = (baseURL: string) => {
+  instance.defaults.baseURL = baseURL
+}
+
 export default function request <T> (config: any) {
   return instance.request<AxiosInstance, SERVICE.Response<T>>(config)
 }

+ 57 - 0
src/type/rts.d.ts

@@ -0,0 +1,57 @@
+declare namespace RTS {
+
+  namespace STREAM {
+    interface List {
+      'Path': string,
+      'State': number,
+      'Subscribers': number,
+      'Tracks': ['h264', 'aac'],
+      'StartTime': number,
+      'Type': 'HLSPuller',
+      'BPS': Number
+    }
+
+    interface Detail {
+      'StartTime': string,
+      'WaitTimeout': number,
+      'PublishTimeout': number,
+      'WaitCloseTimeout': number,
+      'Path': string,
+      'Publisher': any,
+      'State': number,
+      'Subscribers': null,
+      'Tracks': any,
+      'AppName': string,
+      'StreamName': string
+    }
+  }
+
+  namespace SUMMARY {
+    interface Detail {
+      'Address': string,
+      'Memory': {
+        'Total': number,
+        'Free': number,
+        'Used': number,
+        'Usage': number
+      },
+      'CPUUsage': number,
+      'HardDisk': {
+        'Total': number,
+        'Free': number,
+        'Used': number,
+        'Usage': number
+      },
+      'NetWork': [
+        {
+          'Name': string,
+          'Receive': number,
+          'Sent': number,
+          'ReceiveSpeed': 0,
+          'SentSpeed': 0
+        }
+      ]
+    }
+  }
+
+}