Commit a68aa190e63ee3cf5cfa4312d1d4d1315c52ab5e

Authored by ww
1 parent b0bc2358

perf: video component implement code

... ... @@ -14604,9 +14604,10 @@ class HandleDynamicEffect {
14604 14604 * @description 播放视频
14605 14605 */
14606 14606 videoPlay() {
14607   - const basicAttr = Sidebar.prototype.enumCellBasicAttribute
14608 14607 const enumAccessMode = HandleDynamicEffect.enumVideoAccessMode
14609 14608 const reg = /(?:.*)(?<=\.)/
  14609 + const graph = this.graph
  14610 + const createVideoTemplate = this.createVideoTemplate
14610 14611 const videoPlayConfig = {
14611 14612 controls: true,
14612 14613 autoPlay: true,
... ... @@ -14620,58 +14621,38 @@ class HandleDynamicEffect {
14620 14621 const { accessMode, videoUrl, id } = additional
14621 14622 const cell = this.getCellByCellId(nodeId)
14622 14623 if (!cell) continue
14623   - const { geometry = {} } = cell
14624   - const { width, height } = geometry
14625   - const idEl = getIdEl()
14626 14624 if (Number(accessMode) === enumAccessMode.MANUAL_ENTER) {
14627   - this.graph.getModel().beginUpdate()
14628   - try {
14629   - let type
14630   - if (videoUrl.replace(reg, '') === 'm3u8') type = 'application/x-mpegURL'
14631   - const template = this.createVideoTemplate(idEl, width, height, videoUrl, type)
14632   - cell.setAttribute('label', template)
14633   - this.graph.refresh(cell);
14634   - } finally {
14635   - this.graph.getModel().endUpdate()
14636   - videojs(idEl,
14637   - {
14638   - ...videoPlayConfig
14639   - },
14640   - function () {
14641   - this.play()
14642   - })
14643   - }
  14625 + handleVideoPlay(videoPlayConfig, cell, videoUrl)
14644 14626 } else {
14645   - getStreamingVideoPlayUrl.call(this, id, nodeId)
  14627 + getStreamingVideoPlayUrl(id, nodeId)
14646 14628 }
14647 14629 }
14648 14630
14649   - async function getStreamingVideoPlayUrl(id, nodeId) {
  14631 + async function getStreamingVideoPlayUrl(id, cell) {
14650 14632 const [err, res = {}] = await to(ConfigurationNodeApi.getStreamingVideoPlayUrl(id))
14651 14633 const { url } = res?.data || {}
14652 14634 if (!url) return
14653   - const cell = this.getCellByCellId(nodeId)
  14635 + handleVideoPlay({ ...videoPlayConfig, hls: { withCredentials: true } }, cell, url)
  14636 + }
  14637 +
  14638 + function handleVideoPlay(videoPlayConfig, cell, videoUrl) {
14654 14639 if (!cell) return
14655 14640 const { geometry = {} } = cell
14656 14641 const { width, height } = geometry
14657 14642 const idEl = getIdEl()
14658   - this.graph.getModel().beginUpdate()
  14643 + console.log({ idEl })
  14644 + graph.getModel().beginUpdate()
14659 14645 try {
14660   - const template = this.createVideoTemplate(idEl, width, height, url, 'application/x-mpegURL')
  14646 + let type
  14647 + if (videoUrl.replace(reg, '') === 'm3u8') type = 'application/x-mpegURL'
  14648 + const template = createVideoTemplate(idEl, width, height, videoUrl, type)
14661 14649 cell.setAttribute('label', template)
14662   - this.graph.refresh(cell);
  14650 + graph.refresh(cell);
14663 14651 } finally {
14664   - this.graph.getModel().endUpdate()
14665   - videojs(idEl,
14666   - {
14667   - ...videoPlayConfig,
14668   - hls: {
14669   - withCredentials: true
14670   - }
14671   - },
14672   - function () {
14673   - this.play()
14674   - })
  14652 + graph.getModel().endUpdate()
  14653 + videojs(idEl, videoPlayConfig, function () {
  14654 + this.play()
  14655 + })
14675 14656 }
14676 14657 }
14677 14658
... ...