RTMP: RTMP是Real Time Messaging Protocol(实时消息传输协议)的缩写,是Adobe公司为Flash/AIR平台和服务器之间音、视频及数据传输开发的实时消息传送协议。RTMP协议基于TCP,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP协议中,视频必须是H264编码,音频必须是AAC或MP3编码,且多以flv格式封包。RTMP是目前最主流的流媒体传输协议,对CDN支持良好,实现难度较低,是大多数的直播平台的选择。不过RTMP有着一个最大的不足——不支持浏览器,且Adobe已不再更新。因此直播服务要支持浏览器的话,需要另外的推送协议支持。
// 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) } }