App.jsx 2.68 KB
Newer Older
喻天's avatar
喻天 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import React from 'react';

import style from './App.less';

// import pubsub from 'pubsub-js'

class App extends React.Component {
  constructor(props) {
    super(props);
    this.jessibuca = null;
    this.showOperateBtns = true;
    this.$container = null;
    this.forceNoOffscreen = false;

    this.state = {
      isPlaying: false,
    };
  }
  createAll() {
    let { VideoInfo, JessibucaObj } = this.props;
    this.destroy();
    if (VideoInfo.url) {
程恺文's avatar
程恺文 committed
23
      this.create(this.refs[`myVideo` + VideoInfo.id], `key`, JessibucaObj);
喻天's avatar
喻天 committed
24
      setTimeout(() => {
程恺文's avatar
程恺文 committed
25 26
        let code =window.independence?window.siteCode:(window.globalConfig?.userInfo?.LocalSite||localStorage.getItem('token'))
        this.play(VideoInfo.url + `/${VideoInfo.dataRate == 'Sub' ? 2 : 1}?Civ_Site=${code}`, `key`);
喻天's avatar
喻天 committed
27 28 29 30 31
      }, 10);
    }
  }
  componentDidMount() {
    this.createAll();
喻天's avatar
喻天 committed
32 33 34 35 36

    this.jessibuca.on('pause', function (data) {
      // console.log('timeUpdate', ts);
      console.log('pause:', data);
    });
喻天's avatar
喻天 committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  }
  componentWillUnmount() {
    this.destroy();
  }
  create(dom, key, obj) {
    if (this.jessibuca) this.jessibuca.destroy();

    let jsc = {
      videoBuffer: 0.2, // 缓存时长
      isResize: false,
      text: '',
      isFlv: false,
      loadingText: '加载中',
      debug: false,
      recordType: 'mp4',
程恺文's avatar
程恺文 committed
52
      loadingTimeout: 10,
喻天's avatar
喻天 committed
53 54
      loadingText: '视频加载中',
      loadingTimeoutReplay: true,
程恺文's avatar
程恺文 committed
55
      timeout: 10,
喻天's avatar
喻天 committed
56
      controlAutoHide: true,
程恺文's avatar
程恺文 committed
57
      heartTimeout: 10,
喻天's avatar
喻天 committed
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
      heartTimeoutReplay: true,
      showBandwidth: true, // 显示网速
      operateBtns: {
        fullscreen: true,
        screenshot: true,
        play: true,
        record: true,
        audio: true,
      },
      isNotMute: false,
    };
    jsc = {
      ...jsc,
      ...obj,
      container: dom,
    };
    if (dom) {
      this.jessibuca = new window.Jessibuca(jsc);
    }
  }

  play(url, key) {
    if (this.jessibuca) {
      this.jessibuca.play(url);
      this.setState({
        isPlaying: true,
      });
    }
  }

  pause() {
    if (this.jessibucaArr) {
      debugger;
      for (let key in this.jessibucaArr) {
        this.jessibucaArr[key].pause();
      }
      this.setState({
        isPlaying: false,
      });
    }
  }

  destroy() {
    if (this.jessibuca) {
      this.jessibuca.destroy();
      this.setState({
        isPlaying: false,
      });
    }
  }
  renderCheckedArr() {
    let { VideoInfo } = this.props;
    return (
      <div className={style.containerOut}>
程恺文's avatar
程恺文 committed
112
        {<div className={style.container} key={VideoInfo.id} ref={`myVideo` + VideoInfo.id}></div>}
喻天's avatar
喻天 committed
113 114 115 116 117 118 119 120 121
      </div>
    );
  }
  render() {
    return <div className={style.root}>{this.renderCheckedArr()}</div>;
  }
}

export default App;