Commit 6a7d8a2773a16f7937c14481b71c6736d01788ac

Authored by ww
1 parent 92abb1c7

feat: implement video play m3u8 type

... ... @@ -31,6 +31,11 @@
31 31 <script src="./js/plugin/echarts/echarts.js"></script>
32 32
33 33 <script src="./plugins/axios.min.js"></script>
  34 +
  35 + <link href="https://vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
  36 + <script src="https://vjs.zencdn.net/7.10.2/video.min.js"></script>
  37 +
  38 + <!-- <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script> -->
34 39 <!-- <script src="./js/jquery/jquery-3.3.1.min.js"></script>-->
35 40 <link rel="stylesheet" href="https://cdnjs.loli.net/ajax/libs/layui/2.6.8/css/layui.min.css"
36 41 integrity="sha512-iQBJbsNHXUcgEIgWThd2dr8tOdKPvICwqjPEZYY81z3eMya44A5MiAqfWSCh+Ee1YzNYkdrI982Qhwgr8LEYOQ=="
... ... @@ -419,6 +424,7 @@
419 424 cursor: pointer;
420 425 margin: 5px;
421 426 }
  427 +
422 428 </style>
423 429 <!-- Workaround for binary XHR in IE 9/10, see App.loadUrl -->
424 430 <!--[if (IE 9)|(IE 10)]><!-->
... ... @@ -559,6 +565,7 @@
559 565 opacity: 0;
560 566 }
561 567 }
  568 +
562 569 </style>
563 570 </head>
564 571
... ...
... ... @@ -3,7 +3,7 @@
3 3 Sidebar.prototype.addBasicComponentsPalette = function () {
4 4 this.setCurrentSearchEntryLibrary('component');
5 5 const dt = 'basic'
6   - const gn = `mxgraph.${ dt }`
  6 + const gn = `mxgraph.${dt}`
7 7 const currentDate = getCurrentDate();
8 8 const basicAttr = this.enumCellBasicAttribute
9 9 const componentType = this.enumComponentType
... ... @@ -14,14 +14,14 @@
14 14 const cell = new mxCell('Title', new mxGeometry(0, 0, 100, 40), transparentBg);
15 15 cell.setVertex(true)
16 16 this.setCellAttributes(cell, { [basicAttr.COMPONENT_TYPE]: componentType.TITLE })
17   - return this.createVertexTemplateFromCells([ cell ], cell.geometry.width, cell.geometry.height, 'Title');
  17 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Title');
18 18 })),
19 19
20 20 this.addEntry(this.getTagsForStencil(gn, 'variable', dt).join(' '), mxUtils.bind(this, function () {
21 21 const cell = new mxCell('变量', new mxGeometry(0, 0, 100, 40), transparentBg);
22 22 cell.setVertex(true)
23 23 this.setCellAttributes(cell, { [basicAttr.COMPONENT_TYPE]: componentType.VARIABLE })
24   - return this.createVertexTemplateFromCells([ cell ], cell.geometry.width, cell.geometry.height, '变量');
  24 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '变量');
25 25 })),
26 26
27 27 this.addEntry(this.getTagsForStencil(gn, 'line', dt).join(' '), mxUtils.bind(this, function () {
... ... @@ -33,7 +33,7 @@
33 33 cell.edge = true;
34 34 cell.setVertex(true)
35 35 this.setCellAttributes(cell, { [basicAttr.COMPONENT_TYPE]: componentType.LINE })
36   - return this.createEdgeTemplateFromCells([ cell ], 60, 40, '线条');
  36 + return this.createEdgeTemplateFromCells([cell], 60, 40, '线条');
37 37 })),
38 38 this.addEntry('real time', mxUtils.bind(this, function () {
39 39 const template = `<div class="thingKit-component__real-time"><div class="real-time__date">%currentDate%</div> <div style="font-size:30px" class="real-time__now">HH:mm:ss</div></div>`
... ... @@ -44,19 +44,43 @@
44 44 placeholders: '1',
45 45 currentDate: currentDate,
46 46 })
47   - return this.createVertexTemplateFromCells([ cell ], cell.geometry.width, cell.geometry.height, '实时时间');
  47 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '实时时间');
48 48 })),
49 49 this.addEntry(this.getTagsForStencil('mxgraph.basic', '变量图片', 'basic').join(' '), mxUtils.bind(this, function () {
50 50 const cell = new mxCell('', new mxGeometry(0, 0, 194, 95), 'image;image=images/thingskit/img-placeholder.png;imageAspect=0;');
51 51 cell.setVertex(true)
52 52 this.setCellAttributes(cell, { [basicAttr.COMPONENT_TYPE]: componentType.VAR_IMAGE })
53   - return this.createVertexTemplateFromCells([ cell ], cell.geometry.width, cell.geometry.height, '变量图片');
  53 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '变量图片');
54 54 })),
55 55 this.addEntry(this.getTagsForStencil('mxgraph.basic', '视频', 'basic').join(' '), mxUtils.bind(this, function () {
56   - const cell = new mxCell('', new mxGeometry(0, 0, 100, 95), 'image;image=images/thingskit/video.svg;imageAspect=0;');
  56 + const m3u8 = 'http://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8'
  57 + const mp4 = 'http://vjs.zencdn.net/v/oceans.mp4'
  58 + const m3u8Type = 'application/x-mpegURL'
  59 + const mp4Type = 'video/mp4'
  60 + // const cell = new mxCell('<video></video>', new mxGeometry(0, 0, 100, 95), 'image;image=images/thingskit/video.svg;imageAspect=0;');
  61 + const template = `
  62 + <video
  63 + id="my-player"
  64 + class="video-js"
  65 + controls
  66 + preload="auto"
  67 + muted="muted"
  68 + poster="/thingskit-drawio/images/youtube.png"
  69 + data-setup='{}'>
  70 + <source src="${mp4}" type="${mp4Type}">
  71 + <p class="vjs-no-js">
  72 + To view this video please enable JavaScript, and consider upgrading to a
  73 + web browser that
  74 + <a href="https://videojs.com/html5-video-support/" target="_blank">
  75 + supports HTML5 video
  76 + </a>
  77 + </p>
  78 + </video>
  79 + `
  80 + const cell = new mxCell(template, new mxGeometry(0, 0, 100, 95), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
57 81 cell.setVertex(true)
58 82 this.setCellAttributes(cell, { [basicAttr.COMPONENT_TYPE]: componentType.VIDEO })
59   - return this.createVertexTemplateFromCells([ cell ], cell.geometry.width, cell.geometry.height, '视频');
  83 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '视频');
60 84 })),
61 85 ];
62 86
... ... @@ -70,7 +94,7 @@
70 94 var year = date.getFullYear();
71 95 var month = date.getMonth() + 1;
72 96 var dates = date.getDate();
73   - arr = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ]
  97 + arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
74 98 var day = date.getDay();
75 99 return year + '年' + month + '月' + dates + '日 ' + arr[day];
76 100 }
... ... @@ -83,7 +107,7 @@
83 107 const allTimeNode = document.querySelectorAll('.thingKit-component__real-time .real-time__now')
84 108 for (const time of allTimeNode) {
85 109 const date = new Date()
86   - time.innerHTML = `${ date.getHours() < 10 ? '0' : '' }${ date.getHours() }:${ date.getMinutes() < 10 ? '0' : '' }${ date.getMinutes() }:${ date.getSeconds() < 10 ? '0' : '' }${ date.getSeconds() }`
  110 + time.innerHTML = `${date.getHours() < 10 ? '0' : ''}${date.getHours()}:${date.getMinutes() < 10 ? '0' : ''}${date.getMinutes()}:${date.getSeconds() < 10 ? '0' : ''}${date.getSeconds()}`
87 111 }
88 112 }, 1000)
89 113 }
... ...
... ... @@ -13339,6 +13339,7 @@ class HandleDynamicEffect {
13339 13339 * @description 生成映射关系 && 初始化推送消息
13340 13340 */
13341 13341 generatorMappingRelation() {
  13342 + this.videoPlay()
13342 13343 const tsSubCmds = []
13343 13344 this.enableActList.forEach(each => {
13344 13345 const { id, type, attr, deviceId, slaveDeviceId } = each
... ... @@ -13533,6 +13534,54 @@ class HandleDynamicEffect {
13533 13534 }
13534 13535 }
13535 13536
  13537 +
  13538 + videoPlay() {
  13539 + const basicAttr = Sidebar.prototype.enumCellBasicAttribute
  13540 + const videoCell = this.DispatchInstance.contentAllCell.filter(cell => cell.getAttribute(basicAttr.COMPONENT_TYPE) === 'video')
  13541 + const options = {
  13542 + hls: {
  13543 + withCredentials: true
  13544 + }
  13545 + }
  13546 + var player = videojs('my-player', options, function onPlayerReady() {
  13547 + videojs.log('Your player is ready!');
  13548 +
  13549 + // In this context, `this` is the player that was created by Video.js.
  13550 + this.play();
  13551 +
  13552 + // How about an event listener?
  13553 + this.on('ended', function () {
  13554 + videojs.log('Awww...over so soon?!');
  13555 + });
  13556 + });
  13557 +
  13558 + console.log(player)
  13559 + // for (const cell of videoCell) {
  13560 + // this.graph.getModel().beginUpdate()
  13561 + // try {
  13562 + // const options = {
  13563 + // hls: {
  13564 + // withCredentials: true
  13565 + // }
  13566 + // }
  13567 + // var player = videojs('my-player', options, function onPlayerReady() {
  13568 + // videojs.log('Your player is ready!');
  13569 +
  13570 + // // In this context, `this` is the player that was created by Video.js.
  13571 + // this.play();
  13572 +
  13573 + // // How about an event listener?
  13574 + // this.on('ended', function () {
  13575 + // videojs.log('Awww...over so soon?!');
  13576 + // });
  13577 + // });
  13578 + // this.graph.refresh(cell);
  13579 + // } finally {
  13580 + // this.graph.getModel().endUpdate()
  13581 + // }
  13582 + // }
  13583 + }
  13584 +
13536 13585 /**
13537 13586 * @description 验证是否满足条件列表中的任意一条
13538 13587 * @param subscriptionId
... ...