devicePlayer.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. <template>
  2. <div id="devicePlayer" v-loading="isLoging">
  3. <el-dialog title="视频播放" top="0" :close-on-click-modal="false" :visible.sync="showVideoDialog" @close="close()">
  4. <div style="width: 100%; height: 100%">
  5. <el-tabs type="card" :stretch="true" v-model="activePlayer" @tab-click="changePlayer"
  6. v-if="Object.keys(this.player).length > 1">
  7. <el-tab-pane label="Jessibuca" name="jessibuca">
  8. <jessibucaPlayer v-if="activePlayer === 'jessibuca'" ref="jessibuca" :visible.sync="showVideoDialog"
  9. :videoUrl="videoUrl" :error="videoError" :message="videoError" height="100px"
  10. :hasAudio="hasAudio" fluent autoplay live></jessibucaPlayer>
  11. </el-tab-pane>
  12. <el-tab-pane label="WebRTC" name="webRTC">
  13. <rtc-player v-if="activePlayer === 'webRTC'" ref="webRTC" :visible.sync="showVideoDialog"
  14. :videoUrl="videoUrl" :error="videoError" :message="videoError" height="100px"
  15. :hasAudio="hasAudio" fluent autoplay live></rtc-player>
  16. </el-tab-pane>
  17. <el-tab-pane label="h265web">h265web敬请期待</el-tab-pane>
  18. <el-tab-pane label="wsPlayer">wsPlayer 敬请期待</el-tab-pane>
  19. </el-tabs>
  20. <jessibucaPlayer v-if="Object.keys(this.player).length == 1 && this.player.jessibuca" ref="jessibuca"
  21. :visible.sync="showVideoDialog" :videoUrl="videoUrl" :error="videoError" :message="videoError"
  22. height="100px" :hasAudio="hasAudio" fluent autoplay live></jessibucaPlayer>
  23. <rtc-player v-if="Object.keys(this.player).length == 1 && this.player.webRTC" ref="jessibuca"
  24. :visible.sync="showVideoDialog" :videoUrl="videoUrl" :error="videoError" :message="videoError"
  25. height="100px" :hasAudio="hasAudio" fluent autoplay live></rtc-player>
  26. </div>
  27. <div id="shared" style="text-align: right; margin-top: 1rem;">
  28. <el-tabs v-model="tabActiveName" @tab-click="tabHandleClick">
  29. <el-tab-pane label="实时视频" name="media">
  30. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  31. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">播放地址:</span>
  32. <el-input v-model="getPlayerShared.sharedUrl" :disabled="true">
  33. <template slot="append">
  34. <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="getPlayerShared.sharedUrl"
  35. @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
  36. </template>
  37. </el-input>
  38. </div>
  39. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  40. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">iframe:</span>
  41. <el-input v-model="getPlayerShared.sharedIframe" :disabled="true">
  42. <template slot="append">
  43. <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="getPlayerShared.sharedIframe"
  44. @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
  45. </template>
  46. </el-input>
  47. </div>
  48. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  49. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">资源地址:</span>
  50. <el-input v-model="getPlayerShared.sharedRtmp" :disabled="true">
  51. <el-button slot="append" icon="el-icon-document-copy" title="点击拷贝"
  52. v-clipboard="getPlayerShared.sharedRtmp"
  53. @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></el-button>
  54. <el-dropdown slot="prepend" v-if="streamInfo" trigger="click" @command="copyUrl">
  55. <el-button>
  56. 更多地址<i class="el-icon-arrow-down el-icon--right"></i>
  57. </el-button>
  58. <el-dropdown-menu slot="dropdown">
  59. <el-dropdown-item v-if="streamInfo.flv" :command="streamInfo.flv">
  60. <el-tag>FLV:</el-tag>
  61. <span>{{ streamInfo.flv }}</span>
  62. </el-dropdown-item>
  63. <el-dropdown-item v-if="streamInfo.https_flv" :command="streamInfo.https_flv">
  64. <el-tag>FLV(https):</el-tag>
  65. <span>{{ streamInfo.https_flv }}</span>
  66. </el-dropdown-item>
  67. <el-dropdown-item v-if="streamInfo.ws_flv" :command="streamInfo.ws_flv">
  68. <el-tag>FLV(ws):</el-tag>
  69. <span>{{ streamInfo.ws_flv }}</span>
  70. </el-dropdown-item>
  71. <el-dropdown-item v-if="streamInfo.wss_flv" :command="streamInfo.wss_flv">
  72. <el-tag>FLV(wss):</el-tag>
  73. <span>{{ streamInfo.wss_flv }}</span>
  74. </el-dropdown-item>
  75. <el-dropdown-item v-if="streamInfo.fmp4" :command="streamInfo.fmp4">
  76. <el-tag>FMP4:</el-tag>
  77. <span>{{ streamInfo.fmp4 }}</span>
  78. </el-dropdown-item>
  79. <el-dropdown-item v-if="streamInfo.https_fmp4" :command="streamInfo.https_fmp4">
  80. <el-tag>FMP4(https):</el-tag>
  81. <span>{{ streamInfo.https_fmp4 }}</span>
  82. </el-dropdown-item>
  83. <el-dropdown-item v-if="streamInfo.ws_fmp4" :command="streamInfo.ws_fmp4">
  84. <el-tag>FMP4(ws):</el-tag>
  85. <span>{{ streamInfo.ws_fmp4 }}</span>
  86. </el-dropdown-item>
  87. <el-dropdown-item v-if="streamInfo.wss_fmp4" :command="streamInfo.wss_fmp4">
  88. <el-tag>FMP4(wss):</el-tag>
  89. <span>{{ streamInfo.wss_fmp4 }}</span>
  90. </el-dropdown-item>
  91. <el-dropdown-item v-if="streamInfo.hls" :command="streamInfo.hls">
  92. <el-tag>HLS:</el-tag>
  93. <span>{{ streamInfo.hls }}</span>
  94. </el-dropdown-item>
  95. <el-dropdown-item v-if="streamInfo.https_hls" :command="streamInfo.https_hls">
  96. <el-tag>HLS(https):</el-tag>
  97. <span>{{ streamInfo.https_hls }}</span>
  98. </el-dropdown-item>
  99. <el-dropdown-item v-if="streamInfo.ws_hls" :command="streamInfo.ws_hls">
  100. <el-tag>HLS(ws):</el-tag>
  101. <span>{{ streamInfo.ws_hls }}</span>
  102. </el-dropdown-item>
  103. <el-dropdown-item v-if="streamInfo.wss_hls" :command="streamInfo.wss_hls">
  104. <el-tag>HLS(wss):</el-tag>
  105. <span>{{ streamInfo.wss_hls }}</span>
  106. </el-dropdown-item>
  107. <el-dropdown-item v-if="streamInfo.ts" :command="streamInfo.ts">
  108. <el-tag>TS:</el-tag>
  109. <span>{{ streamInfo.ts }}</span>
  110. </el-dropdown-item>
  111. <el-dropdown-item v-if="streamInfo.https_ts" :command="streamInfo.https_ts">
  112. <el-tag>TS(https):</el-tag>
  113. <span>{{ streamInfo.https_ts }}</span>
  114. </el-dropdown-item>
  115. <el-dropdown-item v-if="streamInfo.ws_ts" :command="streamInfo.ws_ts">
  116. <el-tag>TS(ws):</el-tag>
  117. <span>{{ streamInfo.ws_ts }}</span>
  118. </el-dropdown-item>
  119. <el-dropdown-item v-if="streamInfo.wss_ts" :command="streamInfo.wss_ts">
  120. <el-tag>TS(wss):</el-tag>
  121. <span>{{ streamInfo.wss_ts }}</span>
  122. </el-dropdown-item>
  123. <el-dropdown-item v-if="streamInfo.rtc" :command="streamInfo.rtc">
  124. <el-tag>RTC:</el-tag>
  125. <span>{{ streamInfo.rtc }}</span>
  126. </el-dropdown-item>
  127. <el-dropdown-item v-if="streamInfo.rtcs" :command="streamInfo.rtcs">
  128. <el-tag>RTCS:</el-tag>
  129. <span>{{ streamInfo.rtcs }}</span>
  130. </el-dropdown-item>
  131. <el-dropdown-item v-if="streamInfo.rtmp" :command="streamInfo.rtmp">
  132. <el-tag>RTMP:</el-tag>
  133. <span>{{ streamInfo.rtmp }}</span>
  134. </el-dropdown-item>
  135. <el-dropdown-item v-if="streamInfo.rtmps" :command="streamInfo.rtmps">
  136. <el-tag>RTMPS:</el-tag>
  137. <span>{{ streamInfo.rtmps }}</span>
  138. </el-dropdown-item>
  139. <el-dropdown-item v-if="streamInfo.rtsp" :command="streamInfo.rtsp">
  140. <el-tag>RTSP:</el-tag>
  141. <span>{{ streamInfo.rtsp }}</span>
  142. </el-dropdown-item>
  143. <el-dropdown-item v-if="streamInfo.rtsps" :command="streamInfo.rtsps">
  144. <el-tag>RTSPS:</el-tag>
  145. <span>{{ streamInfo.rtsps }}</span>
  146. </el-dropdown-item>
  147. </el-dropdown-menu>
  148. </el-dropdown>
  149. </el-input>
  150. </div>
  151. </el-tab-pane>
  152. <!--{"code":0,"data":{"paths":["22-29-30.mp4"],"rootPath":"/home/kkkkk/Documents/ZLMediaKit/release/linux/Debug/www/record/hls/kkkkk/2020-05-11/"}}-->
  153. <!--遥控界面-->
  154. <el-tab-pane label="云台控制" name="control" v-if="showPtz">
  155. <div style="display: flex; justify-content: left;">
  156. <div class="control-wrapper">
  157. <div class="control-btn control-top" @mousedown="ptzCamera('up')" @mouseup="ptzCamera('stop')">
  158. <i class="el-icon-caret-top"></i>
  159. <div class="control-inner-btn control-inner"></div>
  160. </div>
  161. <div class="control-btn control-left" @mousedown="ptzCamera('left')" @mouseup="ptzCamera('stop')">
  162. <i class="el-icon-caret-left"></i>
  163. <div class="control-inner-btn control-inner"></div>
  164. </div>
  165. <div class="control-btn control-bottom" @mousedown="ptzCamera('down')" @mouseup="ptzCamera('stop')">
  166. <i class="el-icon-caret-bottom"></i>
  167. <div class="control-inner-btn control-inner"></div>
  168. </div>
  169. <div class="control-btn control-right" @mousedown="ptzCamera('right')" @mouseup="ptzCamera('stop')">
  170. <i class="el-icon-caret-right"></i>
  171. <div class="control-inner-btn control-inner"></div>
  172. </div>
  173. <div class="control-round">
  174. <div class="control-round-inner"><i class="fa fa-pause-circle"></i></div>
  175. </div>
  176. <div style="position: absolute; left: 7.25rem; top: 1.25rem" @mousedown="ptzCamera('zoomin')"
  177. @mouseup="ptzCamera('stop')"><i class="el-icon-zoom-in control-zoom-btn"
  178. style="font-size: 1.875rem;"></i></div>
  179. <div style="position: absolute; left: 7.25rem; top: 3.25rem; font-size: 1.875rem;"
  180. @mousedown="ptzCamera('zoomout')" @mouseup="ptzCamera('stop')"><i
  181. class="el-icon-zoom-out control-zoom-btn"></i></div>
  182. <div class="contro-speed" style="position: absolute; left: 4px; top: 7rem; width: 9rem;">
  183. <el-slider v-model="controSpeed" :max="255"></el-slider>
  184. </div>
  185. </div>
  186. <div class="control-panel">
  187. <el-button-group>
  188. <el-tag style="position :absolute; left: 0rem; top: 0rem; width: 5rem; text-align: center"
  189. size="medium">预置位编号
  190. </el-tag>
  191. <el-input-number style="position: absolute; left: 5rem; top: 0rem; width: 6rem" size="mini"
  192. v-model="presetPos" controls-position="right" :precision="0" :step="1" :min="1"
  193. :max="255"></el-input-number>
  194. <el-button style="position: absolute; left: 11rem; top: 0rem; width: 5rem" size="mini"
  195. icon="el-icon-add-location" @click="presetPosition(129, presetPos)">设置
  196. </el-button>
  197. <el-button style="position: absolute; left: 27rem; top: 0rem; width: 5rem" size="mini" type="primary"
  198. icon="el-icon-place" @click="presetPosition(130, presetPos)">调用
  199. </el-button>
  200. <el-button style="position: absolute; left: 16rem; top: 0rem; width: 5rem" size="mini"
  201. icon="el-icon-delete-location" @click="presetPosition(131, presetPos)">删除
  202. </el-button>
  203. <el-tag style="position :absolute; left: 0rem; top: 2.5rem; width: 5rem; text-align: center"
  204. size="medium">巡航速度
  205. </el-tag>
  206. <el-input-number style="position: absolute; left: 5rem; top: 2.5rem; width: 6rem" size="mini"
  207. v-model="cruisingSpeed" controls-position="right" :precision="0" :min="1"
  208. :max="4095"></el-input-number>
  209. <el-button style="position: absolute; left: 11rem; top: 2.5rem; width: 5rem" size="mini"
  210. icon="el-icon-loading" @click="setSpeedOrTime(134, cruisingGroup, cruisingSpeed)">设置
  211. </el-button>
  212. <el-tag style="position :absolute; left: 16rem; top: 2.5rem; width: 5rem; text-align: center"
  213. size="medium">停留时间
  214. </el-tag>
  215. <el-input-number style="position: absolute; left: 21rem; top: 2.5rem; width: 6rem" size="mini"
  216. v-model="cruisingTime" controls-position="right" :precision="0" :min="1"
  217. :max="4095"></el-input-number>
  218. <el-button style="position: absolute; left: 27rem; top: 2.5rem; width: 5rem" size="mini"
  219. icon="el-icon-timer" @click="setSpeedOrTime(135, cruisingGroup, cruisingTime)">设置
  220. </el-button>
  221. <el-tag style="position :absolute; left: 0rem; top: 4.5rem; width: 5rem; text-align: center"
  222. size="medium">巡航组编号
  223. </el-tag>
  224. <el-input-number style="position: absolute; left: 5rem; top: 4.5rem; width: 6rem" size="mini"
  225. v-model="cruisingGroup" controls-position="right" :precision="0" :min="0"
  226. :max="255"></el-input-number>
  227. <el-button style="position: absolute; left: 11rem; top: 4.5rem; width: 5rem" size="mini"
  228. icon="el-icon-add-location" @click="setCommand(132, cruisingGroup, presetPos)">添加点
  229. </el-button>
  230. <el-button style="position: absolute; left: 16rem; top: 4.5rem; width: 5rem" size="mini"
  231. icon="el-icon-delete-location" @click="setCommand(133, cruisingGroup, presetPos)">删除点
  232. </el-button>
  233. <el-button style="position: absolute; left: 21rem; top: 4.5rem; width: 5rem" size="mini"
  234. icon="el-icon-delete" @click="setCommand(133, cruisingGroup, 0)">删除组
  235. </el-button>
  236. <el-button style="position: absolute; left: 27rem; top: 5rem; width: 5rem" size="mini" type="primary"
  237. icon="el-icon-video-camera-solid" @click="setCommand(136, cruisingGroup, 0)">巡航
  238. </el-button>
  239. <el-tag style="position :absolute; left: 0rem; top: 7rem; width: 5rem; text-align: center"
  240. size="medium">扫描速度
  241. </el-tag>
  242. <el-input-number style="position: absolute; left: 5rem; top: 7rem; width: 6rem" size="mini"
  243. v-model="scanSpeed" controls-position="right" :precision="0" :min="1"
  244. :max="4095"></el-input-number>
  245. <el-button style="position: absolute; left: 11rem; top: 7rem; width: 5rem" size="mini"
  246. icon="el-icon-loading" @click="setSpeedOrTime(138, scanGroup, scanSpeed)">设置
  247. </el-button>
  248. <el-tag style="position :absolute; left: 0rem; top: 9rem; width: 5rem; text-align: center"
  249. size="medium">扫描组编号
  250. </el-tag>
  251. <el-input-number style="position: absolute; left: 5rem; top: 9rem; width: 6rem" size="mini"
  252. v-model="scanGroup" controls-position="right" :precision="0" :step="1" :min="0"
  253. :max="255"></el-input-number>
  254. <el-button style="position: absolute; left: 11rem; top: 9rem; width: 5rem" size="mini"
  255. icon="el-icon-d-arrow-left" @click="setCommand(137, scanGroup, 1)">左边界
  256. </el-button>
  257. <el-button style="position: absolute; left: 16rem; top: 9rem; width: 5rem" size="mini"
  258. icon="el-icon-d-arrow-right" @click="setCommand(137, scanGroup, 2)">右边界
  259. </el-button>
  260. <el-button style="position: absolute; left: 27rem; top: 7rem; width: 5rem" size="mini" type="primary"
  261. icon="el-icon-video-camera-solid" @click="setCommand(137, scanGroup, 0)">扫描
  262. </el-button>
  263. <el-button style="position: absolute; left: 27rem; top: 9rem; width: 5rem" size="mini" type="danger"
  264. icon="el-icon-switch-button" @click="ptzCamera('stop')">停止
  265. </el-button>
  266. </el-button-group>
  267. </div>
  268. </div>
  269. </el-tab-pane>
  270. <el-tab-pane label="编码信息" name="codec" v-loading="tracksLoading">
  271. <p>
  272. 无法播放或者没有声音?&nbsp&nbsp&nbsp试一试&nbsp
  273. <el-button size="mini" type="primary" v-if="!coverPlaying" @click="coverPlay">转码播放</el-button>
  274. <el-button size="mini" type="danger" v-if="coverPlaying" @click="convertStopClick">停止转码</el-button>
  275. </p>
  276. <div class="trank">
  277. <p v-if="tracksNotLoaded" style="text-align: center;padding-top: 3rem;">暂无数据</p>
  278. <div v-for="(item, index) in tracks" style="width: 50%; float: left" loading>
  279. <span>流 {{ index }}</span>
  280. <div class="trankInfo" v-if="item.codec_type == 0">
  281. <p>格式: {{ item.codec_id_name }}</p>
  282. <p>类型: 视频</p>
  283. <p>分辨率: {{ item.width }} x {{ item.height }}</p>
  284. <p>帧率: {{ item.fps }}</p>
  285. </div>
  286. <div class="trankInfo" v-if="item.codec_type == 1">
  287. <p>格式: {{ item.codec_id_name }}</p>
  288. <p>类型: 音频</p>
  289. <p>采样位数: {{ item.sample_bit }}</p>
  290. <p>采样率: {{ item.sample_rate }}</p>
  291. </div>
  292. </div>
  293. </div>
  294. </el-tab-pane>
  295. <el-tab-pane label="语音对讲" name="broadcast">
  296. <div style="padding: 0 10px">
  297. <el-switch v-model="broadcastMode" :disabled="broadcastStatus !== -1" active-color="#409EFF" active-text="喊话"
  298. inactive-text="对讲"></el-switch>
  299. </div>
  300. <div class="trank" style="text-align: center;">
  301. <el-button @click="broadcastStatusClick()" :type="getBroadcastStatus()" :disabled="broadcastStatus === -2"
  302. circle icon="el-icon-microphone" style="font-size: 32px; padding: 24px;margin-top: 24px;"/>
  303. <p>
  304. <span v-if="broadcastStatus === -2">正在释放资源</span>
  305. <span v-if="broadcastStatus === -1">点击开始对讲</span>
  306. <span v-if="broadcastStatus === 0">等待接通中...</span>
  307. <span v-if="broadcastStatus === 1">请说话</span>
  308. </p>
  309. </div>
  310. </el-tab-pane>
  311. </el-tabs>
  312. </div>
  313. </el-dialog>
  314. </div>
  315. </template>
  316. <script>
  317. import rtcPlayer from '../dialog/rtcPlayer.vue'
  318. import LivePlayer from '@liveqing/liveplayer'
  319. import crypto from 'crypto'
  320. import jessibucaPlayer from '../common/jessibuca.vue'
  321. export default {
  322. name: 'devicePlayer',
  323. props: {},
  324. components: {
  325. LivePlayer, jessibucaPlayer, rtcPlayer,
  326. },
  327. computed: {
  328. getPlayerShared: function () {
  329. return {
  330. sharedUrl: window.location.origin + '/#/play/wasm/' + encodeURIComponent(this.videoUrl),
  331. sharedIframe: '<iframe src="' + window.location.origin + '/#/play/wasm/' + encodeURIComponent(this.videoUrl) + '"></iframe>',
  332. sharedRtmp: this.videoUrl
  333. };
  334. }
  335. },
  336. created() {
  337. console.log("created")
  338. console.log(this.player)
  339. this.broadcastStatus = -1;
  340. if (Object.keys(this.player).length === 1) {
  341. this.activePlayer = Object.keys(this.player)[0]
  342. }
  343. },
  344. data() {
  345. return {
  346. video: 'http://lndxyj.iqilu.com/public/upload/2019/10/14/8c001ea0c09cdc59a57829dabc8010fa.mp4',
  347. videoUrl: '',
  348. activePlayer: "jessibuca",
  349. // 如何你只是用一种播放器,直接注释掉不用的部分即可
  350. player: {
  351. jessibuca: ["ws_flv", "wss_flv"],
  352. webRTC: ["rtc", "rtcs"],
  353. },
  354. showVideoDialog: false,
  355. streamId: '',
  356. app: '',
  357. mediaServerId: '',
  358. convertKey: '',
  359. deviceId: '',
  360. channelId: '',
  361. tabActiveName: 'media',
  362. hasAudio: false,
  363. loadingRecords: false,
  364. recordsLoading: false,
  365. isLoging: false,
  366. controSpeed: 30,
  367. timeVal: 0,
  368. timeMin: 0,
  369. timeMax: 1440,
  370. presetPos: 1,
  371. cruisingSpeed: 100,
  372. cruisingTime: 5,
  373. cruisingGroup: 0,
  374. scanSpeed: 100,
  375. scanGroup: 0,
  376. tracks: [],
  377. coverPlaying: false,
  378. tracksLoading: false,
  379. showPtz: true,
  380. showRrecord: true,
  381. tracksNotLoaded: false,
  382. sliderTime: 0,
  383. seekTime: 0,
  384. recordStartTime: 0,
  385. showTimeText: "00:00:00",
  386. streamInfo: null,
  387. broadcastMode: true,
  388. broadcastRtc: null,
  389. broadcastStatus: -1, // -2 正在释放资源 -1 默认状态 0 等待接通 1 接通成功
  390. };
  391. },
  392. methods: {
  393. tabHandleClick: function (tab, event) {
  394. console.log(tab)
  395. var that = this;
  396. that.tracks = [];
  397. that.tracksLoading = true;
  398. that.tracksNotLoaded = false;
  399. if (tab.name === "codec") {
  400. this.$axios({
  401. method: 'get',
  402. url: '/zlm/' + this.mediaServerId + '/index/api/getMediaInfo?vhost=__defaultVhost__&schema=rtsp&app=' + this.app + '&stream=' + this.streamId
  403. }).then(function (res) {
  404. that.tracksLoading = false;
  405. if (res.data.code == 0 && res.data.tracks) {
  406. that.tracks = res.data.tracks;
  407. } else {
  408. that.tracksNotLoaded = true;
  409. that.$message({
  410. showClose: true,
  411. message: '获取编码信息失败,',
  412. type: 'warning'
  413. });
  414. }
  415. }).catch(function (e) {
  416. });
  417. }
  418. },
  419. changePlayer: function (tab) {
  420. console.log(this.player[tab.name][0])
  421. this.activePlayer = tab.name;
  422. this.videoUrl = this.getUrlByStreamInfo()
  423. console.log(this.videoUrl)
  424. },
  425. openDialog: function (tab, deviceId, channelId, param) {
  426. if (this.showVideoDialog) {
  427. return;
  428. }
  429. this.tabActiveName = tab;
  430. this.channelId = channelId;
  431. this.deviceId = deviceId;
  432. this.streamId = "";
  433. this.mediaServerId = "";
  434. this.app = "";
  435. this.videoUrl = ""
  436. if (!!this.$refs[this.activePlayer]) {
  437. this.$refs[this.activePlayer].pause();
  438. }
  439. switch (tab) {
  440. case "media":
  441. this.play(param.streamInfo, param.hasAudio)
  442. break;
  443. case "streamPlay":
  444. this.tabActiveName = "media";
  445. this.showRrecord = false;
  446. this.showPtz = false;
  447. this.play(param.streamInfo, param.hasAudio)
  448. break;
  449. case "control":
  450. break;
  451. }
  452. },
  453. play: function (streamInfo, hasAudio) {
  454. this.streamInfo = streamInfo;
  455. this.hasAudio = hasAudio;
  456. this.isLoging = false;
  457. // this.videoUrl = streamInfo.rtc;
  458. this.videoUrl = this.getUrlByStreamInfo();
  459. this.streamId = streamInfo.stream;
  460. this.app = streamInfo.app;
  461. this.mediaServerId = streamInfo.mediaServerId;
  462. this.playFromStreamInfo(false, streamInfo)
  463. },
  464. getUrlByStreamInfo() {
  465. console.log(this.streamInfo)
  466. if (location.protocol === "https:") {
  467. this.videoUrl = this.streamInfo[this.player[this.activePlayer][1]]
  468. } else {
  469. this.videoUrl = this.streamInfo[this.player[this.activePlayer][0]]
  470. }
  471. return this.videoUrl;
  472. },
  473. coverPlay: function () {
  474. var that = this;
  475. this.coverPlaying = true;
  476. this.$refs[this.activePlayer].pause()
  477. that.$axios({
  478. method: 'post',
  479. url: '/api/play/convert/' + that.streamId
  480. }).then(function (res) {
  481. if (res.data.code === 0) {
  482. that.convertKey = res.data.key;
  483. setTimeout(() => {
  484. that.isLoging = false;
  485. that.playFromStreamInfo(false, res.data.data);
  486. }, 2000)
  487. } else {
  488. that.isLoging = false;
  489. that.coverPlaying = false;
  490. that.$message({
  491. showClose: true,
  492. message: '转码失败',
  493. type: 'error'
  494. });
  495. }
  496. }).catch(function (e) {
  497. console.log(e)
  498. that.coverPlaying = false;
  499. that.$message({
  500. showClose: true,
  501. message: '播放错误',
  502. type: 'error'
  503. });
  504. });
  505. },
  506. convertStopClick: function () {
  507. this.convertStop(() => {
  508. this.$refs[this.activePlayer].play(this.videoUrl)
  509. });
  510. },
  511. convertStop: function (callback) {
  512. var that = this;
  513. that.$refs.videoPlayer.pause()
  514. this.$axios({
  515. method: 'post',
  516. url: '/api/play/convertStop/' + this.convertKey
  517. }).then(function (res) {
  518. if (res.data.code == 0) {
  519. console.log(res.data.msg)
  520. } else {
  521. console.error(res.data.msg)
  522. }
  523. if (callback) callback();
  524. }).catch(function (e) {
  525. });
  526. that.coverPlaying = false;
  527. that.convertKey = "";
  528. // if (callback )callback();
  529. },
  530. playFromStreamInfo: function (realHasAudio, streamInfo) {
  531. this.showVideoDialog = true;
  532. this.hasaudio = realHasAudio && this.hasaudio;
  533. this.$refs[this.activePlayer].play(this.getUrlByStreamInfo(streamInfo))
  534. },
  535. close: function () {
  536. console.log('关闭视频');
  537. if (!!this.$refs[this.activePlayer]) {
  538. this.$refs[this.activePlayer].pause();
  539. }
  540. this.videoUrl = '';
  541. this.coverPlaying = false;
  542. this.showVideoDialog = false;
  543. if (this.convertKey != '') {
  544. this.convertStop();
  545. }
  546. this.convertKey = ''
  547. this.stopBroadcast()
  548. },
  549. copySharedInfo: function (data) {
  550. console.log('复制内容:' + data);
  551. this.coverPlaying = false;
  552. this.tracks = []
  553. let _this = this;
  554. this.$copyText(data).then(
  555. function (e) {
  556. _this.$message({
  557. showClose: true,
  558. message: '复制成功',
  559. type: 'success'
  560. });
  561. },
  562. function (e) {
  563. _this.$message({
  564. showClose: true,
  565. message: '复制失败,请手动复制',
  566. type: 'error'
  567. });
  568. }
  569. );
  570. },
  571. ptzCamera: function (command) {
  572. console.log('云台控制:' + command);
  573. let that = this;
  574. this.$axios({
  575. method: 'post',
  576. url: '/api/ptz/control/' + this.deviceId + '/' + this.channelId + '?command=' + command + '&horizonSpeed=' + this.controSpeed + '&verticalSpeed=' + this.controSpeed + '&zoomSpeed=' + this.controSpeed
  577. }).then(function (res) {
  578. });
  579. },
  580. //////////////////////播放器事件处理//////////////////////////
  581. videoError: function (e) {
  582. console.log("播放器错误:" + JSON.stringify(e));
  583. },
  584. presetPosition: function (cmdCode, presetPos) {
  585. console.log('预置位控制:' + this.presetPos + ' : 0x' + cmdCode.toString(16));
  586. let that = this;
  587. this.$axios({
  588. method: 'post',
  589. url: '/api/ptz/front_end_command/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '&parameter1=0&parameter2=' + presetPos + '&combindCode2=0'
  590. }).then(function (res) {
  591. });
  592. },
  593. setSpeedOrTime: function (cmdCode, groupNum, parameter) {
  594. let that = this;
  595. let parameter2 = parameter % 256;
  596. let combindCode2 = Math.floor(parameter / 256) * 16;
  597. console.log('前端控制:0x' + cmdCode.toString(16) + ' 0x' + groupNum.toString(16) + ' 0x' + parameter2.toString(16) + ' 0x' + combindCode2.toString(16));
  598. this.$axios({
  599. method: 'post',
  600. url: '/api/ptz/front_end_command/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '&parameter1=' + groupNum + '&parameter2=' + parameter2 + '&combindCode2=' + combindCode2
  601. }).then(function (res) {
  602. });
  603. },
  604. setCommand: function (cmdCode, groupNum, parameter) {
  605. let that = this;
  606. console.log('前端控制:0x' + cmdCode.toString(16) + ' 0x' + groupNum.toString(16) + ' 0x' + parameter.toString(16) + ' 0x0');
  607. this.$axios({
  608. method: 'post',
  609. url: '/api/ptz/front_end_command/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '&parameter1=' + groupNum + '&parameter2=' + parameter + '&combindCode2=0'
  610. }).then(function (res) {
  611. });
  612. },
  613. copyUrl: function (dropdownItem) {
  614. console.log(dropdownItem)
  615. this.$copyText(dropdownItem).then((e) => {
  616. this.$message.success("成功拷贝到粘贴板");
  617. }, (e) => {
  618. })
  619. },
  620. getBroadcastStatus() {
  621. if (this.broadcastStatus == -2) {
  622. return "primary"
  623. }
  624. if (this.broadcastStatus == -1) {
  625. return "primary"
  626. }
  627. if (this.broadcastStatus == 0) {
  628. return "warning"
  629. }
  630. if (this.broadcastStatus == 1) {
  631. return "danger"
  632. }
  633. },
  634. broadcastStatusClick() {
  635. if (this.broadcastStatus == -1) {
  636. // 默认状态, 开始
  637. this.broadcastStatus = 0
  638. // 发起语音对讲
  639. this.$axios({
  640. method: 'get',
  641. url: '/api/play/broadcast/' + this.deviceId + '/' + this.channelId + "?timeout=30&broadcastMode=" + this.broadcastMode
  642. }).then( (res)=> {
  643. if (res.data.code === 0) {
  644. let streamInfo = res.data.data.streamInfo;
  645. if (document.location.protocol.includes("https")) {
  646. this.startBroadcast(streamInfo.rtcs)
  647. }else {
  648. this.startBroadcast(streamInfo.rtc)
  649. }
  650. }else {
  651. this.$message({
  652. showClose: true,
  653. message: res.data.msg,
  654. type: "error",
  655. });
  656. }
  657. });
  658. }else if (this.broadcastStatus === 1) {
  659. this.broadcastStatus = -1;
  660. this.broadcastRtc.close()
  661. }
  662. },
  663. startBroadcast(url){
  664. // 获取推流鉴权Key
  665. this.$axios({
  666. method: 'post',
  667. url: '/api/user/userInfo',
  668. }).then( (res)=> {
  669. if (res.data.code !== 0) {
  670. this.$message({
  671. showClose: true,
  672. message: "获取推流鉴权Key失败",
  673. type: "error",
  674. });
  675. this.broadcastStatus = -1;
  676. }else {
  677. let pushKey = res.data.data.pushKey;
  678. // 获取推流鉴权KEY
  679. url += "&sign=" + crypto.createHash('md5').update(pushKey, "utf8").digest('hex')
  680. console.log("开始语音喊话: " + url)
  681. this.broadcastRtc = new ZLMRTCClient.Endpoint({
  682. debug: true, // 是否打印日志
  683. zlmsdpUrl: url, //流地址
  684. simulecast: false,
  685. useCamera: false,
  686. audioEnable: true,
  687. videoEnable: false,
  688. recvOnly: false,
  689. })
  690. // webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_ON_REMOTE_STREAMS,(e)=>{//获取到了远端流,可以播放
  691. // console.error('播放成功',e.streams)
  692. // this.broadcastStatus = 1;
  693. // });
  694. //
  695. // webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_ON_LOCAL_STREAM,(s)=>{// 获取到了本地流
  696. // this.broadcastStatus = 1;
  697. // // document.getElementById('selfVideo').srcObject=s;
  698. // // this.eventcallbacK("LOCAL STREAM", "获取到了本地流")
  699. // });
  700. this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_NOT_SUPPORT,(e)=>{// 获取到了本地流
  701. console.error('不支持webrtc',e)
  702. this.$message({
  703. showClose: true,
  704. message: '不支持webrtc, 无法进行语音喊话',
  705. type: 'error'
  706. });
  707. this.broadcastStatus = -1;
  708. });
  709. this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_ICE_CANDIDATE_ERROR, (e) => {// ICE 协商出错
  710. console.error('ICE 协商出错')
  711. this.$message({
  712. showClose: true,
  713. message: 'ICE 协商出错',
  714. type: 'error'
  715. });
  716. this.broadcastStatus = -1;
  717. });
  718. this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, (e) => {// offer anwser 交换失败
  719. console.error('offer anwser 交换失败', e)
  720. this.$message({
  721. showClose: true,
  722. message: 'offer anwser 交换失败' + e,
  723. type: 'error'
  724. });
  725. this.broadcastStatus = -1;
  726. });
  727. this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_ON_CONNECTION_STATE_CHANGE, (e) => {// offer anwser 交换失败
  728. console.log('状态改变', e)
  729. if (e === "connecting") {
  730. this.broadcastStatus = 0;
  731. } else if (e === "connected") {
  732. this.broadcastStatus = 1;
  733. } else if (e === "disconnected") {
  734. this.broadcastStatus = -1;
  735. }
  736. });
  737. this.broadcastRtc.on(ZLMRTCClient.Events.CAPTURE_STREAM_FAILED, (e) => {// offer anwser 交换失败
  738. console.log('捕获流失败', e)
  739. this.$message({
  740. showClose: true,
  741. message: '捕获流失败' + e,
  742. type: 'error'
  743. });
  744. this.broadcastStatus = -1;
  745. });
  746. }
  747. }).catch((e) => {
  748. this.$message({
  749. showClose: true,
  750. message: e,
  751. type: 'error'
  752. });
  753. this.broadcastStatus = -1;
  754. });
  755. },
  756. stopBroadcast() {
  757. this.broadcastRtc.close();
  758. this.broadcastStatus = -1;
  759. this.$axios({
  760. method: 'get',
  761. url: '/api/play/broadcast/stop/' + this.deviceId + '/' + this.channelId
  762. }).then((res) => {
  763. if (res.data.code == 0) {
  764. // this.broadcastStatus = -1;
  765. // this.broadcastRtc.close()
  766. } else {
  767. this.$message({
  768. showClose: true,
  769. message: res.data.msg,
  770. type: "error",
  771. });
  772. }
  773. });
  774. }
  775. }
  776. };
  777. </script>
  778. <style>
  779. .control-wrapper {
  780. position: relative;
  781. width: 6.25rem;
  782. height: 6.25rem;
  783. max-width: 6.25rem;
  784. max-height: 6.25rem;
  785. border-radius: 100%;
  786. margin-top: 1.5rem;
  787. margin-left: 0.5rem;
  788. float: left;
  789. }
  790. .control-panel {
  791. position: relative;
  792. top: 0;
  793. left: 5rem;
  794. height: 11rem;
  795. max-height: 11rem;
  796. }
  797. .control-btn {
  798. display: flex;
  799. justify-content: center;
  800. position: absolute;
  801. width: 44%;
  802. height: 44%;
  803. border-radius: 5px;
  804. border: 1px solid #78aee4;
  805. box-sizing: border-box;
  806. transition: all 0.3s linear;
  807. }
  808. .control-btn:hover {
  809. cursor: pointer
  810. }
  811. .control-btn i {
  812. font-size: 20px;
  813. color: #78aee4;
  814. display: flex;
  815. justify-content: center;
  816. align-items: center;
  817. }
  818. .control-btn i:hover {
  819. cursor: pointer
  820. }
  821. .control-zoom-btn:hover {
  822. cursor: pointer
  823. }
  824. .control-round {
  825. position: absolute;
  826. top: 21%;
  827. left: 21%;
  828. width: 58%;
  829. height: 58%;
  830. background: #fff;
  831. border-radius: 100%;
  832. }
  833. .control-round-inner {
  834. position: absolute;
  835. left: 13%;
  836. top: 13%;
  837. display: flex;
  838. justify-content: center;
  839. align-items: center;
  840. width: 70%;
  841. height: 70%;
  842. font-size: 40px;
  843. color: #78aee4;
  844. border: 1px solid #78aee4;
  845. border-radius: 100%;
  846. transition: all 0.3s linear;
  847. }
  848. .control-inner-btn {
  849. position: absolute;
  850. width: 60%;
  851. height: 60%;
  852. background: #fafafa;
  853. }
  854. .control-top {
  855. top: -8%;
  856. left: 27%;
  857. transform: rotate(-45deg);
  858. border-radius: 5px 100% 5px 0;
  859. }
  860. .control-top i {
  861. transform: rotate(45deg);
  862. border-radius: 5px 100% 5px 0;
  863. }
  864. .control-top .control-inner {
  865. left: -1px;
  866. bottom: 0;
  867. border-top: 1px solid #78aee4;
  868. border-right: 1px solid #78aee4;
  869. border-radius: 0 100% 0 0;
  870. }
  871. .control-top .fa {
  872. transform: rotate(45deg) translateY(-7px);
  873. }
  874. .control-left {
  875. top: 27%;
  876. left: -8%;
  877. transform: rotate(45deg);
  878. border-radius: 5px 0 5px 100%;
  879. }
  880. .control-left i {
  881. transform: rotate(-45deg);
  882. }
  883. .control-left .control-inner {
  884. right: -1px;
  885. top: -1px;
  886. border-bottom: 1px solid #78aee4;
  887. border-left: 1px solid #78aee4;
  888. border-radius: 0 0 0 100%;
  889. }
  890. .control-left .fa {
  891. transform: rotate(-45deg) translateX(-7px);
  892. }
  893. .control-right {
  894. top: 27%;
  895. right: -8%;
  896. transform: rotate(45deg);
  897. border-radius: 5px 100% 5px 0;
  898. }
  899. .control-right i {
  900. transform: rotate(-45deg);
  901. }
  902. .control-right .control-inner {
  903. left: -1px;
  904. bottom: -1px;
  905. border-top: 1px solid #78aee4;
  906. border-right: 1px solid #78aee4;
  907. border-radius: 0 100% 0 0;
  908. }
  909. .control-right .fa {
  910. transform: rotate(-45deg) translateX(7px);
  911. }
  912. .control-bottom {
  913. left: 27%;
  914. bottom: -8%;
  915. transform: rotate(45deg);
  916. border-radius: 0 5px 100% 5px;
  917. }
  918. .control-bottom i {
  919. transform: rotate(-45deg);
  920. }
  921. .control-bottom .control-inner {
  922. top: -1px;
  923. left: -1px;
  924. border-bottom: 1px solid #78aee4;
  925. border-right: 1px solid #78aee4;
  926. border-radius: 0 0 100% 0;
  927. }
  928. .control-bottom .fa {
  929. transform: rotate(-45deg) translateY(7px);
  930. }
  931. .trank {
  932. width: 80%;
  933. height: 180px;
  934. text-align: left;
  935. padding: 0 10%;
  936. overflow: auto;
  937. }
  938. .trankInfo {
  939. width: 80%;
  940. padding: 0 10%;
  941. }
  942. </style>