// destroy player on unmount componentWillUnmount() { if (this.player) { this.player.dispose() } }
// wrap the player in a div with a `data-vjs-player` attribute // so videojs won't create additional wrapper in the DOM // see https://github.com/videojs/video.js/pull/3856 render() { return ( <div> <div data-vjs-player> {/*这个带有属性的div目前没看到作用,可以去掉*/} <video ref={ node => this.videoNode = node } className="video-js"></video> </div> </div> ) } }
this.videoJsOptions = null } componentDidMount(){ const THIS = this const token = storage.getItem(constant.TOKEN) var toyid = 913 var URL = `wss://XXX.XXX.com//websocket/1.0.0/WEB/${toyid}/${token}` const socket = new WebSocket(URL); socket.onmessage = function(msg){ var data = JSON.parse(msg.data) // var cmd = data.cmd // var code = data.code console.log(data)
// 没有登录 if (typeof data.data === "string") return // users data.data.room.users.users let users = data.data.room.users.users let currentPlayer = users.filter(v => v.play === true) let waitingPlayers = users.filter(v => v.play === false) let videoSrc = data.data.room.video.split(',')[0] let newState = {} if (currentPlayer.length) { newState.currentPlayer = currentPlayer[0] } if (waitingPlayers.length) { newState.waitingPlayers = waitingPlayers } if (videoSrc) { // videoSrc = videoSrc.replace("rtmp", "http") + ".flv" console.log(videoSrc); newState.videoSrc = videoSrc THIS.setOptions(videoSrc) } THIS.setState(newState) } }