shuishen
2026-02-10 abd285e6d013128aa57c9e30e851b2aa76d60ec5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-04-28 10:47:08
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2025-01-21 13:16:01
 * @FilePath: \srs-police-affairs\src\components\hkVideo\index.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <div class="h-five-player-video">
    <video-loading v-show="loading"></video-loading>
 
    <!-- v-loading="loading" element-loading-background="rgba(0, 0, 0, 0)" -->
    <div class="video-container" :id="elementId"></div>
  </div>
</template>
 
<script>
import { getPreviewUrl, getTalkURLs, playbackURLs } from '@/api/sm/hk/hk'
export default {
  name: "hkVideo",
  props: {
    //默认分屏,2:2x2布局
    currentSplit: {
      type: Number,
      default: 1
    },
    //最大分屏,4:4x4布局
    maxSplit: {
      type: Number,
      default: 1
    },
    jsBasePath: {
      type: String,
      default: process.env.BASE_URL
    }
  },
 
  inject: {
    "ContentDetailsEle": {
      default: () => {
        return {
          zoomFlag: undefined
        }
      }
    }
  },
 
 
  data () {
    return {
      loading: false,
      curWindIndex: 0,
      previewWindList: [],
      publicPath: process.env.BASE_URL,
      dialogVisible: false,
      player: null,
      elementId: '',
      talkUrl: ''
    }
  },
 
  watch: {
    'ContentDetailsEle.zoomFlag': {
      handler (newData) {
        if (newData != undefined && (typeof newData === 'boolean') && this.player != null) {
          this.resize()
        }
      }
    }
  },
 
  created () {
    this.elementId = this.uuid()
  },
 
  mounted () {
    const that = this
    window.addEventListener('resize', this.resize)
 
    this.$nextTick(() => {
      this.createPlayer()
    })
 
    document.addEventListener('visibilitychange', this.openState)
  },
 
  methods: {
    openState (e) {
      const that = this
 
      let state = document.visibilityState
      if (state == 'hidden') {
        that.stop()
        that.stopAll()
        that.stopTalk()
      }
      if (state == 'visible') {
        console.log(document.visibilityState)
      }
    },
 
    uuid () {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
          v = c == 'x' ? r : (r & 0x3 | 0x8)
        return v.toString(16)
      })
    },
 
    resize () {
      // 设置播放容器的宽高并监听窗口大小变化
      this.player && this.player.JS_Resize()
    },
 
    // 行点击事件--视频预览
    initData (data, index = 0) {
      const that = this
      this.loading = true
      this.title = data.video_name
      this.dialogVisible = true
      this.talkUrl = ''
      const param = {
        cameraIndexCode: data.cameraIndexCode,
        type: data.sysResource,
        protocol: 'ws',
        streamType: data.streamType
      }
 
      getPreviewUrl(param).then(previewData => {
        that.$nextTick(() => {
          if (previewData.data.data.indexOf('36.134.79.80:6014') != -1) {
            previewData.data.data = previewData.data.data.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
          }
 
          if (previewData.data.data.indexOf('223.76.234.232:6014') != -1) {
            previewData.data.data = previewData.data.data.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
          }
 
          that.play(previewData.data.data, data, index)
        })
      }).catch(e => {
        that.loading = false
      })
    },
 
    /* 预览&对讲 */
    play (url, data, windowIndex = '') {
      const { cameraIndexCode = '', video_name: name = '', sysResource, streamType } = data
 
      const that = this
      let {
        player
      } = this,
        index = windowIndex,
        playURL = url
 
      player.JS_Play(playURL, {
        playURL,
        mode: 0
      }, index).then(
        () => {
          player.JS_CloseSound(index)
 
          // 播放成功后,加入到已播放的列表
          // 判断是否多屏
          if (this.maxSplit == 1) {
            this.previewWindList = [
              {
                index: index,
                cameraIndexCode: cameraIndexCode,
                name: name,
                sysResource,
                streamType: streamType
              }
            ]
          } else {
            this.previewWindList = this.previewWindList.filter(item => item.cameraIndexCode != cameraIndexCode)
            this.previewWindList.push({
              index: index,
              cameraIndexCode: cameraIndexCode,
              name: name,
              sysResource,
              streamType: streamType
            })
          }
          // 向父组件发送
          this.$emit('changePreviewWindList', this.previewWindList)
          // 切换窗口,下一个
          var next = index + 1
          this.player.JS_SelectWnd(next).then(
            () => {
              this.$emit('windowChange', next)
              // console.info('JS_SelectWnd success');
              // do you want...
            },
            (err) => {
              // console.info('JS_SelectWnd failed');
              // do you want...
            }
          )
          this.loading = false
        },
        e => {
          this.loading = false
        }
      )
    },
 
    stop () {
      this.player.JS_Stop()
    },
 
    stopAll () {
      this.player.JS_StopRealPlayAll()
    },
 
    startTalk (curPlayData = {}) {
      const that = this
      this.player.JS_SetConnectTimeOut(0, 1000)
 
      if (that.savePlayIndexCode != curPlayData.cameraIndexCode) {
        that.talkUrl = ''
      }
 
      if (that.talkUrl) {
        this.player.JS_StartTalk(that.talkUrl).then(
          () => { console.log('talkStart success') },
          e => {
            this.$message({
              type: "error",
              message: e
            })
          }
        )
      } else {
        that.savePlayIndexCode = curPlayData.cameraIndexCode
        getTalkURLs({
          cameraIndexCode: curPlayData.cameraIndexCode,
          type: curPlayData.sysResource,
          protocol: 'ws',
          streamType: curPlayData.streamType
        }).then(talkData => {
          console.log(talkData)
          that.$nextTick(() => {
            let resultUrl = ''
 
            if (JSON.parse(talkData.data.data) && JSON.parse(talkData.data.data).data && JSON.parse(talkData.data.data).data.url) {
              resultUrl = JSON.parse(talkData.data.data).data.url
 
              if (resultUrl.indexOf('36.134.79.80:6014') != -1) {
                resultUrl = resultUrl.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
              }
              if (resultUrl.indexOf('223.76.234.232:6014') != -1) {
                resultUrl = resultUrl.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
              }
 
              that.talkUrl = resultUrl
            }
 
            that.player.JS_StartTalk(that.talkUrl).then(
              () => {
                console.log('talkStart success')
              },
              e => {
                if (e == '0x12f900008') {
                  this.$message({
                    type: "error",
                    message: '当前视频站点暂不支持语音对讲!'
                  })
                } else {
                  this.$message({
                    type: "error",
                    message: e
                  })
                }
              }
            )
          })
        })
      }
    },
 
    stopTalk () {
      this.player.JS_StopTalk().then(
        () => { console.log('talkStop success') },
        e => { console.error(e) }
      )
    },
 
    // 视频回放
    playBack (param, startTime, endTime) {
      this.loading = true
      playbackURLs(param).then(res => {
        this.$nextTick(() => {
          const data = JSON.parse(res.data.data)
          var url = data.data.url
 
          if (url != null && url != '') {
            if (url.indexOf('36.134.79.80:6014') != -1) {
              url = url.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
            }
            if (url.indexOf('223.76.234.232:6014') != -1) {
              url = url.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
            }
 
            // 截取后面的时间
            url = url.split("?")[0]
            this.startPlayBack(url, startTime, endTime, 0)
          } else {
            this.loading = false
 
            this.$message({
              message: '当前时间段没有录像',
              type: 'warning'
            })
          }
        })
      }).catch(e => {
        this.loading = false
      })
    },
 
    createPlayer () {
      const that = this
 
      this.player = new window.JSPlugin({
        szId: this.elementId,
        szBasePath: `${that.publicPath}hk/h5/`,
        iMaxSplit: this.maxSplit || 4,
        iCurrentSplit: this.currentSplit || 1,
        openDebug: false
      })
 
      // 事件回调绑定
      this.player.JS_SetWindowControlCallback({
        windowEventSelect: iWndIndex => { //插件选中窗口回调
          this.$emit('windowChange', iWndIndex)
        },
        pluginErrorHandler: (iWndIndex, iErrorCode, oError) => { //插件错误回调
          this.loading = false
          this.$emit('pluginError', iErrorCode)
        },
        windowEventOver: function (iWndIndex) { //鼠标移过回调
        },
        windowEventOut: function (iWndIndex) { //鼠标移出回调
        },
        windowEventUp: function (iWndIndex) { //鼠标mouseup事件回调
        },
        windowFullCcreenChange: function (bFull) { //全屏切换回调
        },
        firstFrameDisplay: function (iWndIndex, iWidth, iHeight) { //首帧显示回调
        },
        performanceLack: function () { //性能不足回调
        }
      })
    },
 
    //分屏
    setLayout (splitNum) {
      this.isChangeLayout = true
      this.player.JS_ArrangeWindow(splitNum).then(() => { }).catch(e => {
      }).finally(() => {
        setTimeout(() => {
          this.isChangeLayout = false
        }, 200)
      })
    },
    /** 
     * 录像回放
     * @param url:流媒体url
     * @param windowIndex:窗口号
     * @param config:播放配置
     * @param startTime :回放开始时间,格式类型:2021-06-29T00:00:00Z
     * @param endTime:回放结束时间,格式类型:2021-06-29T00:00:00Z
     */
    startPlayBack (url, startTime, endTime, windowIndex = this.curWindIndex, config = {}) {
      const that = this
      this.player.JS_Play(url, {
        playURL: url,
        mode: 0 //解码类型:0=普通模式; 1=高级模式 默认为0,h5高级模式才能播放
      }, windowIndex, startTime, endTime).then(
        () => {
          that.player.JS_CloseSound(windowIndex)
          this.loading = false
        },
        e => {
          this.loading = false
        }
      )
    },
    // 整体全屏
    wholeFullScreen () {
      this.player.JS_FullScreenDisplay(true).then(
        () => {
        },
        e => {
        }
      )
    },
    //单窗口全屏
    singleFullScreen (windowIndex = this.curWindIndex) {
      this.player.JS_FullScreenSingle(windowIndex).then(() => {
      }).catch(e => {
        console.log(e)
      })
    },
  },
 
  destroyed () {
    window.removeEventListener('resize', this.resize)
    document.removeEventListener('visibilitychange', this.openState)
 
    this.stop()
    this.stopAll()
    this.stopTalk()
  }
}
</script>
 
<style lang="scss" scoped>
.h-five-player-video {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
 
  &>.video-container {
    width: 0;
    flex: 1;
    height: 100%;
  }
}
</style>