index_mute.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="videoBox">
  3. <div class="box">
  4. <div class="list">
  5. <ul>
  6. <li
  7. v-for="(item, index) in cList"
  8. :key="index"
  9. @click="play(item.uuid)"
  10. >
  11. {{ item.name }}
  12. </li>
  13. </ul>
  14. </div>
  15. <video
  16. id="test"
  17. crossorigin="anonymous"
  18. autoplay
  19. playsinline
  20. muted
  21. controls
  22. />
  23. </div>
  24. <div class="contrl">
  25. <n-button @click="contrl(8)">
  26. </n-button>
  27. <n-button @click="contrl(2)">
  28. </n-button>
  29. <n-button @click="contrl(4)">
  30. </n-button>
  31. <n-button @click="contrl(6)">
  32. </n-button>
  33. <n-button @click="contrl(10)">
  34. 放大
  35. </n-button>
  36. <n-button @click="contrl(11)">
  37. 缩小
  38. </n-button>
  39. <n-button @click="capPhoto">
  40. 截图
  41. </n-button>
  42. <n-button @click="capVideo">
  43. 录像
  44. </n-button>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import axios from '@/utils/axios'
  50. import { onMounted, ref } from 'vue'
  51. import WebRtcPlayer from '@/utils/SRSWebRtcPlayer'
  52. const TOKEN = '2fc01ae175e8676b6a3edc32d2d76cb3'
  53. const cList = ref()
  54. const CUUID = ref('')
  55. let play1 = null as any
  56. // 获取摄像头播放地址
  57. const getCamer = async () => {
  58. const { data } = await axios.post('http://47.108.192.202:8089', {
  59. code: 'categorycamera.list',
  60. token: TOKEN,
  61. body: {}
  62. })
  63. // 35可控
  64. // cList.value = data.filter((el: { name: string }) => (el.name.includes('35')))
  65. cList.value = data
  66. console.log('摄像头列表', cList.value)
  67. }
  68. // 播放
  69. const play = async (uuid: string) => {
  70. if (play1) play1.close()
  71. CUUID.value = uuid
  72. play1 = new WebRtcPlayer({
  73. HOST: '47.108.192.202',
  74. TOKEN,
  75. UUID: uuid,
  76. PROFILE: 0,
  77. PORT: 1985,
  78. DOM: document.getElementById('test')
  79. })
  80. }
  81. /**
  82. * 云台控制
  83. * @param command 指令:数字键盘1-9去掉5,10:焦距放大,11:焦距缩小 12:亮度,13:色彩饱和度,14:对比度,15:清晰度
  84. * @param number [云台速度|焦距参数|色彩饱和度]等值 亮度值 0-100
  85. */
  86. const contrl = (command: number, number = 1) => {
  87. if (!play1) return
  88. play1.contrl('http://47.108.192.202:8089', CUUID.value, TOKEN, command, number)
  89. }
  90. // 截图
  91. const capPhoto = () => {
  92. if (!play1) return
  93. const base64 = play1.capPhoto(document.getElementById('test'))
  94. console.log('截图', base64)
  95. }
  96. // 录像
  97. const capVideo = async () => {
  98. if (!play1) return
  99. const blob = await play1.capVideo(document.getElementById('test'), 1000 * 5)
  100. console.log('录像', blob)
  101. }
  102. // 获取目录
  103. // const proList = async () => {
  104. // const { data } = await axios.post('http://20.20.20.9:8089', {
  105. // code: 'category.list',
  106. // token: '833cd2ff8851509d0c4b2cab0dbdb74d',
  107. // body: {}
  108. // })
  109. // // 零食取一个测试
  110. // console.log(666, data)
  111. // }
  112. onMounted(() => {
  113. getCamer()
  114. })
  115. </script>
  116. <style lang="less" scoped>
  117. .videoBox {
  118. .box {
  119. display: flex;
  120. justify-content: center;
  121. .list {
  122. width: 150px;
  123. color: white;
  124. li {
  125. padding: 10px;
  126. &:hover {
  127. color: aqua;
  128. cursor: pointer;
  129. }
  130. }
  131. }
  132. video {
  133. width: 800px;
  134. height: 500px;
  135. background: none;
  136. object-fit: fill;
  137. font-size: 0;
  138. }
  139. }
  140. .contrl {
  141. margin-top: 10px;
  142. text-align: center;
  143. button {
  144. margin-left: 10px;
  145. }
  146. }
  147. }
  148. </style>