bonc-htmlplayer
Advanced tools
Comparing version 1.0.16 to 1.0.17
{ | ||
"name": "bonc-htmlplayer", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "东方国信的html播放器内核", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
import Event from '../../util/event'; | ||
import { appendByteArray } from '../../util/utils.js'; | ||
import {downloadMp4} from '../../util/utils.js' | ||
var downloaddata = [] | ||
export function download(){ | ||
var len = 0 | ||
downloaddata.forEach(item => { | ||
len+= item.byteLength | ||
}); | ||
var file = new Uint8Array(len) | ||
var offset = 0 | ||
downloaddata.forEach(item => { | ||
file.set(item,offset) | ||
offset+=item.byteLength | ||
}); | ||
downloadMp4(file.buffer) | ||
} | ||
// import {downloadMp4} from '../../util/utils.js' | ||
export default class BufferController extends Event { | ||
@@ -132,11 +118,10 @@ constructor(sourceBuffer,type,videoNode) { | ||
try{ | ||
console.log(`type=${this.type}`) | ||
this.sourceBuffer.appendBuffer(this.queue); | ||
this.dispatch('bufferAppended',this.type) | ||
// console.log(this.type) | ||
downloaddata.push(this.queue) | ||
this.queue = new Uint8Array(); | ||
}catch (e){ | ||
debugger | ||
console.log(e) | ||
console.log(e,this.type) | ||
if (e.name === 'QuotaExceededError'){ | ||
@@ -143,0 +128,0 @@ console.error(`${this.type} buffer quota full`); |
@@ -6,3 +6,3 @@ import { MP4 } from '../../util/mp4-generator.js'; | ||
import Event from '../../util/event'; | ||
import localRecorder from '../../util/mp4download/mp4download' | ||
export default class RemuxController extends Event { | ||
@@ -15,12 +15,14 @@ | ||
this.tracks = {}; | ||
this._timeStempAudio=0; | ||
this.hasAudio=false; | ||
this._timeStempAudio = 0; | ||
this.hasAudio = false; | ||
this.mediaDuration = streaming ? Infinity : 1000; | ||
this.videoseg=0; | ||
this.audioseg=0; | ||
this._samplingFrequencyIndex=4; | ||
this.videoseg = 0; | ||
this.audioseg = 0; | ||
this._samplingFrequencyIndex = 4; | ||
this.sampleIndex = 8 | ||
this.extensionSamplingIndex = 5 | ||
} | ||
set samplingFrequencyIndex(index){ | ||
this._samplingFrequencyIndex=index; | ||
set samplingFrequencyIndex(index) { | ||
this._samplingFrequencyIndex = index; | ||
} | ||
@@ -51,8 +53,8 @@ | ||
flush(){ | ||
if (!this.initialized){ | ||
if (this.isReady()){ | ||
flush() { | ||
if (!this.initialized) { | ||
if (this.isReady()) { | ||
this.dispatch('ready'); | ||
for (let type of this.trackTypes){ | ||
if(type=='video'){ | ||
for (let type of this.trackTypes) { | ||
if (type == 'video') { | ||
let track = this.tracks[type]; | ||
@@ -62,3 +64,3 @@ console.log(track.mp4track) | ||
type: type, | ||
isStart:true, | ||
isStart: true, | ||
payload: MP4.initSegment([track.mp4track], this.mediaDuration, track.mp4track.timescale), | ||
@@ -68,7 +70,6 @@ }; | ||
this.dispatch('buffer', data); | ||
} | ||
else if(type=='audio'){ | ||
if(this.hasAudio==true){ | ||
let xvdAudio= {}; | ||
else if (type == 'audio') { | ||
let xvdAudio= {}; | ||
xvdAudio.id = 2; | ||
@@ -83,2 +84,3 @@ xvdAudio.type = 'audio'; | ||
let channelConfiguration=1; | ||
debugger | ||
console.log('this._samplingFrequencyIndex==',this._samplingFrequencyIndex); | ||
@@ -100,11 +102,12 @@ config[0] = audioObjectType << 3; | ||
this.dispatch('buffer', data); | ||
} | ||
}else{ | ||
console.log('audio is false') | ||
} | ||
} | ||
//debug.log('Initial segment 封装完成.'); | ||
this.initialized = true; | ||
//this.startSuccess(); | ||
this.dispatch('videoPrepare') ; | ||
this.dispatch('videoPrepare'); | ||
} | ||
@@ -114,8 +117,7 @@ } | ||
{ | ||
for (let type of this.trackTypes){ | ||
if(type=='video'){ | ||
for (let type of this.trackTypes) { | ||
if (type == 'video') { | ||
let track = this.tracks[type]; | ||
let pay = track.getPayload(); | ||
if (pay && pay.byteLength) | ||
{ | ||
if (pay && pay.byteLength) { | ||
this.videoseg++; | ||
@@ -130,5 +132,3 @@ // moof movie fragment | ||
const mdat = MP4.mdat(pay); | ||
if(localRecorder.isRecording){ | ||
localRecorder.cache.push(pay) | ||
} | ||
let payload = appendByteArray(moof, mdat); | ||
@@ -141,3 +141,3 @@ let data = { | ||
this.dispatch('buffer', data); | ||
let duration = secToTime(track.dts / 1000); | ||
let duration = secToTime(track.dts / 1000); | ||
//debug.log('封装普通帧'); | ||
@@ -148,4 +148,3 @@ // 清空track,释放track所占内存空间 | ||
} | ||
else if(type=='audio') | ||
{ | ||
else if (type == 'audio') { | ||
if(this.hasAudio==true) | ||
@@ -218,8 +217,7 @@ { | ||
remux(data){ | ||
remux(data) { | ||
for (let type of this.trackTypes) { | ||
let samples = data[type]; | ||
if (type === 'audio' && this.tracks.video && !this.tracks.video.readyToDecode) continue; /* if video is present, don't add audio until video get ready */ | ||
if (samples.length > 0) | ||
{ | ||
if (samples.length > 0) { | ||
this.tracks[type].remux(samples); | ||
@@ -226,0 +224,0 @@ } |
@@ -78,2 +78,3 @@ | ||
this.track.codec = 'mp4a.40.' + objectType; | ||
debugger | ||
this.track.channelCount = channelCount; | ||
@@ -80,0 +81,0 @@ this.track.config = config; |
import { extractNALubonc } from './utils' | ||
import RemuxController from './controller/remux.js'; | ||
import BufferController ,{download} from './controller/buffer.js'; | ||
import BufferController from './controller/buffer.js'; | ||
import { NALU } from '../util/nalu.js'; | ||
@@ -88,15 +88,9 @@ import localRecorder from '../util/webmdownload/webmdownload' | ||
// 开始录像 | ||
localRecord(){ | ||
// localRecorder.app = this.app; | ||
// localRecorder.localRecord() | ||
this.recoder.startRecord() | ||
localRecord(name){ | ||
this.recoder.startRecord(name) | ||
} | ||
// 结束录像 | ||
finishRecord(){ | ||
// localRecorder.finishRecord() | ||
this.recoder.endRecord() | ||
} | ||
download2 (){ | ||
download() | ||
} | ||
@@ -172,6 +166,3 @@ // 倒放的状态 | ||
this.bufferControllers[type].on('error', this.onBufferError.bind(this)); | ||
// this.bufferControllers['video'].on('bufferAppended',()=>{ | ||
// if(this.app.node.buffered.length>0) | ||
// console.log('append之后',this.app.node.buffered.end(0),this.app.node.buffered.start(0)); | ||
// }) | ||
} | ||
@@ -395,2 +386,3 @@ } | ||
for (let type in this.bufferControllers) { | ||
// console.log(type) | ||
this.bufferControllers[type].doAppend(); | ||
@@ -404,7 +396,9 @@ } | ||
let bufferLength = this.app.node.buffered.end(0) - this.app.node.currentTime; | ||
this.bufferControllers['video'].rangeList = this.bufferControllers['video'].rangeList.filter((item) => { | ||
// console.log(item[1], this.app.node.currentTime, item[1] - this.app.node.currentTime) | ||
return item[1] > this.app.node.currentTime; | ||
}) | ||
if (bufferLength > 0 && bufferLength < 3) { | ||
if(bufferLength<0){ | ||
console.log('this.app.node.buffered.end(0)',this.app.node.buffered.end(0)) | ||
console.log('this.app.node.currentTime',this.app.node.currentTime) | ||
console.log('播超了') | ||
this.app.node.pause(); | ||
}else if (bufferLength > 0 && bufferLength < 3) { | ||
this.app.node.play(); | ||
@@ -411,0 +405,0 @@ this.app.node.playbackRate = 1; |
396
src/index.js
import Event from './util/event'; | ||
import {validateChannelInfo,validateConfigs} from './util/viladate'; | ||
import {BLoadXML,Xml2String,fullScreen,getChannelInfo} from './util/utils'; | ||
import {xmlPlayBody, | ||
import { validateChannelInfo, validateConfigs } from './util/viladate'; | ||
import { BLoadXML, Xml2String, fullScreen, getChannelInfo, dealRecordSearchInfo } from './util/utils'; | ||
import { | ||
xmlPlayBody, | ||
xmlPlayBackSearch, | ||
@@ -9,4 +10,6 @@ xmlPlayRecord, | ||
xmlPlayStartRecord, | ||
xmlPlayReverse} from './util/orderList'; | ||
xmlPlayReverse | ||
} from './util/orderList'; | ||
import WebSocketUtil from './util/WebSocketUtil'; | ||
import TimeSelector from './util/timeSelector' | ||
import H264Mp4Player from './h264player/player'; | ||
@@ -16,25 +19,25 @@ import H264CanvasPlayer from './h264canvasplayer/player'; | ||
window.MediaSource = window.MediaSource || window.WebKitMediaSource; | ||
class Html5Player extends Event{ | ||
/* | ||
名词解释 | ||
MSE media source extension | ||
*/ | ||
/* | ||
类的成员 对象 | ||
this.node video标签的dom对象 在构造函数中的validateConfigs执行的时候被赋值 | ||
this.state 播放器的状态 0未播放 1 正在播放 | ||
this.boncws WebSocket 实例 | ||
*/ | ||
/* | ||
类的状态变量 | ||
this.mseReady = true | ||
回调: | ||
1.视频准备中的回调 | ||
2.视频开始播放的回调 | ||
3.网络断开的回调 | ||
*/ | ||
constructor(configs){ | ||
class Html5Player extends Event { | ||
/* | ||
名词解释 | ||
MSE media source extension | ||
*/ | ||
/* | ||
类的成员 对象 | ||
this.node video标签的dom对象 在构造函数中的validateConfigs执行的时候被赋值 | ||
this.state 播放器的状态 0未播放 1 正在播放 | ||
this.boncws WebSocket 实例 | ||
*/ | ||
/* | ||
类的状态变量 | ||
this.mseReady = true | ||
回调: | ||
1.视频准备中的回调 | ||
2.视频开始播放的回调 | ||
3.网络断开的回调 | ||
*/ | ||
constructor(configs) { | ||
super(); | ||
let defaults = { | ||
let defaults = { | ||
flushingTime: 1000, | ||
@@ -45,3 +48,3 @@ clearBuffer: true, | ||
}; | ||
this.options = defaults; | ||
this.options = defaults; | ||
this.configs = configs; | ||
@@ -52,5 +55,10 @@ this.state = 0; | ||
//实例化WebsocketUtil类 | ||
this.webSocketController = new WebSocketUtil(this); | ||
if (this.configs.multiServer) { | ||
this.webSocketController = new TimeSelector(this); | ||
} else { | ||
this.webSocketController = new WebSocketUtil(this); | ||
} | ||
//实例化mp4Coder类 | ||
switch(configs.playerClassName){ | ||
switch (configs.playerClassName) { | ||
case 'H264CanvasPlayer': | ||
@@ -60,43 +68,39 @@ this._player = new H264CanvasPlayer(this); | ||
default: | ||
validateConfigs.call(this,configs) //对配置项进行验证 | ||
validateConfigs.call(this, configs) //对配置项进行验证 | ||
this._player = new H264Mp4Player(this); | ||
break; | ||
} | ||
//this.H264Mp4Player = new H264Mp4Player(this); | ||
// this.H264CanvasPlayer = new H264CanvasPlayer(this); | ||
const centerInfo = configs.centerInfo; | ||
if(centerInfo){ | ||
getChannelInfo.call(this,centerInfo.centerUrl,centerInfo.channelId,centerInfo.callBack); | ||
if (centerInfo) { | ||
getChannelInfo.call(this, centerInfo.centerUrl, centerInfo.channelId, centerInfo.callBack); | ||
} | ||
this.on('videoBufferAdd',this.videoBufferAdd.bind(this)); | ||
this.on('restartclose',this.restartAfterclose.bind(this)); | ||
this.on('changeclose',this.changeAfterclose.bind(this)); | ||
this.on('currentTime',function(time){ | ||
this.on('videoBufferAdd', this.videoBufferAdd.bind(this)); | ||
this.on('restartclose', this.restartAfterclose.bind(this)); | ||
this.on('changeclose', this.changeAfterclose.bind(this)); | ||
this.on('currentTime', function (time) { | ||
//time 为ms | ||
this.currentTime = time; | ||
}.bind(this)); | ||
this.on('onRecordInfo',function(jsondata){ | ||
if(parseInt(jsondata.Response.SumNum)>0){ | ||
if(jsondata.Response.RecordList.Item instanceof Array){ | ||
this.recordStartTime = new Date(jsondata.Response.RecordList.Item[0].StartTime).getTime() ; | ||
this.recordEndTime = new Date(jsondata.Response.RecordList.Item[0].EndTime).getTime() ; | ||
for(var i = 1 ;i<jsondata.Response.RecordList.Item.length; i++){ | ||
var time0 = new Date(jsondata.Response.RecordList.Item[i].StartTime).getTime(); | ||
var time1 = new Date(jsondata.Response.RecordList.Item[i].EndTime).getTime(); | ||
if(this.recordStartTime>time0){ | ||
this.recordStartTime = time0 ; | ||
} | ||
if(this.recordEndTime<time1){ | ||
this.recordEndTime = time1 ; | ||
} | ||
} | ||
this.on('onRecordInfo', function (jsondata) { | ||
// 如果是单个回放服务器 | ||
if(this.webSocketController instanceof WebSocketUtil){ | ||
this.recordInfo = dealRecordSearchInfo(jsondata); | ||
// this.recordStartTime = recordInfo.recordStartTime; | ||
// this.recordEndTime = recordInfo.recordEndTime; | ||
}else if(this.webSocketController instanceof TimeSelector){ | ||
// 如果是多个回放服务器 | ||
if(this.recordInfo){ | ||
this.recordInfo.push(dealRecordSearchInfo(jsondata)); | ||
}else{ | ||
this.recordStartTime = new Date(jsondata.Response.RecordList.Item.StartTime).getTime() ; | ||
this.recordEndTime = new Date(jsondata.Response.RecordList.Item.EndTime).getTime() ; | ||
this.recordInfo = [dealRecordSearchInfo(jsondata)]; | ||
} | ||
}else{ | ||
throw 'webSocketController 类型未知' | ||
} | ||
}.bind(this)); | ||
@@ -108,22 +112,62 @@ // this.on('elementInfo',function(elementInfo){ | ||
/** | ||
* 判断是否只有一个websocket连接 | ||
*/ | ||
ifSingleWebsocket(){ | ||
if(this.webSocketController instanceof WebSocketUtil){ | ||
return true | ||
}else{ | ||
return false | ||
} | ||
} | ||
/** | ||
* 查询录像 | ||
* @param {object} xmljson | ||
*/ | ||
searchRecord(xmljson){ | ||
this.playback = true; | ||
let playBody = BLoadXML(xmlPlayBackSearch); | ||
console.log(new Date(xmljson.endTime).getTime()/1000) | ||
playBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = new Date(xmljson.endTime).getTime()/1000; | ||
playBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = new Date(xmljson.startTime).getTime()/1000; | ||
playBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue =xmljson.channelId; | ||
this.channelId = xmljson.channelId; | ||
playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue =xmljson.streamServerPort; | ||
playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue =xmljson.streamServerIP; | ||
searchRecord(xmljson) { | ||
if (Array.isArray(xmljson)) { | ||
this.configs.multiServer = xmljson.length | ||
// 多个服务器的情况 | ||
if(this.webSocketController instanceof WebSocketUtil){ | ||
var tempWebSocketController = this.webSocketController | ||
this.webSocketController = new TimeSelector(this,tempWebSocketController); | ||
} | ||
this.webSocketController.WebSocketUtils.forEach((item,index) => { | ||
// debugger | ||
this.playback = true; | ||
console.log(BLoadXML) | ||
let playBody = BLoadXML(xmlPlayBackSearch); | ||
// console.log(new Date(xmljson[index].endTime).getTime() / 1000) | ||
playBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = new Date(xmljson[index].endTime).getTime() / 1000; | ||
playBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = new Date(xmljson[index].startTime).getTime() / 1000; | ||
playBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = xmljson[index].channelId; | ||
this.channelId = this.channelId instanceof Array ? this.channelId.push(xmljson[index].channelId) : [xmljson[index].channelId]; | ||
playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue = xmljson[index].streamServerPort; | ||
playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue = xmljson[index].streamServerIP; | ||
item.xmlPlayBody = Xml2String(playBody); | ||
item.url = 'ws://' + playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue + ':' + playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue; | ||
item.WebSocketInit('playback'); | ||
}) | ||
this.webSocketController.noVideoNum = 0; | ||
// console.log(this.webSocketController.WebSocketUtils) | ||
} else { | ||
// 单服务器 | ||
this.playback = true; | ||
let playBody = BLoadXML(xmlPlayBackSearch); | ||
this.xmlPlayBody=Xml2String(playBody); | ||
console.log(new Date(xmljson.endTime).getTime() / 1000) | ||
playBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = new Date(xmljson.endTime).getTime() / 1000; | ||
playBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = new Date(xmljson.startTime).getTime() / 1000; | ||
playBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = xmljson.channelId; | ||
this.channelId = xmljson.channelId; | ||
playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue = xmljson.streamServerPort; | ||
playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue = xmljson.streamServerIP; | ||
this.webSocketController.xmlPlayBody = Xml2String(playBody); | ||
this.webSocketController.url = 'ws://'+playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue+':'+playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue; | ||
this.webSocketController.WebSocketInit('playback'); | ||
this.xmlPlayBody = Xml2String(playBody); | ||
this.webSocketController.xmlPlayBody = Xml2String(playBody); | ||
this.webSocketController.url = 'ws://' + playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue + ':' + playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue; | ||
this.webSocketController.WebSocketInit('playback'); | ||
} | ||
} | ||
@@ -134,4 +178,4 @@ /** | ||
*/ | ||
openVideo(jsonbonc){ | ||
if(!jsonbonc && !this.jsonbonc){ | ||
openVideo(jsonbonc) { | ||
if (!jsonbonc && !this.jsonbonc) { | ||
console.warn('通道数据不存在,请确定是否完成通道信息的获取') | ||
@@ -142,11 +186,11 @@ return; | ||
//验证jsonbonc | ||
if(!this.jsonbonc){ | ||
if (!this.jsonbonc) { | ||
this.jsonbonc = jsonbonc; | ||
} | ||
if(!jsonbonc){ | ||
if (!jsonbonc) { | ||
jsonbonc = this.jsonbonc | ||
} | ||
if(!this._player) { | ||
switch(this.configs.playerClassName){ | ||
if (!this._player) { | ||
switch (this.configs.playerClassName) { | ||
case 'H264CanvasPlayer': | ||
@@ -161,10 +205,10 @@ this._player = new H264CanvasPlayer(this); | ||
console.log('开始') | ||
if(!validateChannelInfo(jsonbonc)){ | ||
if (!validateChannelInfo(jsonbonc)) { | ||
throw new Error('视频channel信息异常'); | ||
} | ||
//如果当前播放器正在播放视频,先关闭当前视频 | ||
if(this.state !== 0){ | ||
if (this.state !== 0) { | ||
this.closeVideo() | ||
} | ||
var playBody=BLoadXML(xmlPlayBody); | ||
var playBody = BLoadXML(xmlPlayBody); | ||
playBody.getElementsByTagName('DeviceType')[0].firstChild.nodeValue = jsonbonc.DeviceType; | ||
@@ -179,3 +223,3 @@ playBody.getElementsByTagName('DeviceIP')[0].firstChild.nodeValue = jsonbonc.DeviceIP; | ||
this.webSocketController.url = 'ws://'+playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue+':'+playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue; | ||
this.webSocketController.url = 'ws://' + playBody.getElementsByTagName('StreamServerIP')[0].firstChild.nodeValue + ':' + playBody.getElementsByTagName('StreamServerPort')[0].firstChild.nodeValue; | ||
this.webSocketController.xmlPlayBody = Xml2String(playBody); | ||
@@ -187,7 +231,6 @@ this.webSocketController.WebSocketInit(); | ||
* 下载视频 | ||
* @param { | ||
* } info | ||
* @param {info} | ||
*/ | ||
download(info){ | ||
var {startTime,endTime,ip,port,filename,channelId} = info | ||
download(info) { | ||
var { startTime, endTime, ip, port, filename, channelId } = info | ||
var url = `http://${ip}:${port}/${filename}.flv?channelid=${channelId}&starttime=${startTime}&endtime=${endTime}` | ||
@@ -206,4 +249,4 @@ var a = document.createElement("a"); | ||
*/ | ||
playVideoback(second){ | ||
if(second>30){ | ||
playVideoback(second) { | ||
if (second > 30) { | ||
console.error('不得超过30s') | ||
@@ -218,5 +261,5 @@ return | ||
this.node.currentTime -= second; | ||
setTimeout(()=>{ | ||
setTimeout(() => { | ||
this.webSocketController.socketDataMerge.ifDispatchBuf = true; | ||
},second*1000) | ||
}, second * 1000) | ||
} | ||
@@ -226,20 +269,20 @@ /** | ||
*/ | ||
playRecord(param){ | ||
playRecord(param) { | ||
this.reverse = false; | ||
var playRecodrBody = BLoadXML(xmlPlayRecord) | ||
playRecodrBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue =param.channelId ; | ||
playRecodrBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = param.channelId; | ||
playRecodrBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = param.startTime; | ||
playRecodrBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = param.endTime; | ||
playRecodrBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = param.speed; | ||
this.webSocketController.recordPlay(Xml2String(playRecodrBody)) | ||
this.webSocketController.recordPlay(playRecodrBody); | ||
} | ||
startRecord(){ | ||
try{ | ||
this._player.localRecord() | ||
}catch(err){ | ||
startRecord(name) { | ||
try { | ||
this._player.localRecord(name) | ||
} catch (err) { | ||
// this._player.isRecording = false; | ||
} | ||
} | ||
finishRecord(){ | ||
finishRecord() { | ||
this._player.finishRecord() | ||
@@ -251,12 +294,25 @@ } | ||
*/ | ||
closeVideo(reason='normal'){ | ||
if(!this.webSocketController.boncws) return; | ||
this.webSocketController.boncws.normalClose(reason); | ||
clearInterval(this.webSocketController.heartLiveInterval) | ||
closeVideo(reason = 'normal', ifnew = true) { | ||
if (!this.webSocketController.boncws) return; | ||
if(this.webSocketController instanceof TimeSelector){ | ||
this.webSocketController.WebSocketUtils.forEach(val=>{ | ||
val.boncws.normalClose(reason); | ||
clearInterval(val.heartLiveInterval); | ||
}) | ||
}else{ | ||
this.webSocketController.boncws.normalClose(reason); | ||
clearInterval(this.webSocketController.heartLiveInterval); | ||
} | ||
// this.H264Mp4Player.destroy(); | ||
this.node.src = ''; | ||
this._player.destroy(); | ||
this._player=null; | ||
this._player = null; | ||
this.currentTime = null; | ||
switch(this.configs.playerClassName){ | ||
if (ifnew == false) { | ||
return | ||
} | ||
switch (this.configs.playerClassName) { | ||
case 'H264CanvasPlayer': | ||
@@ -266,3 +322,3 @@ this._player = new H264CanvasPlayer(this); | ||
default: | ||
validateConfigs.call(this,this.configs) //对配置项进行验证 | ||
validateConfigs.call(this, this.configs) //对配置项进行验证 | ||
this._player = new H264Mp4Player(this); | ||
@@ -273,10 +329,10 @@ break; | ||
/**重启视频 */ | ||
restartVideo(){ | ||
restartVideo() { | ||
this.closeVideo('restart'); | ||
//this.openVideo(this.jsonbonc) | ||
} | ||
restartAfterclose(){ | ||
restartAfterclose() { | ||
this.openVideo(this.jsonbonc) | ||
} | ||
/** | ||
@@ -300,9 +356,10 @@ * 开启码率计算 | ||
*/ | ||
setPlayRate(rateVal){ | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
this.speed = rateVal; | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = rateVal; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.currentTime; | ||
this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
setPlayRate(rateVal) { | ||
// var playxml = xmlPlayControl; | ||
// var playxmlBody = BLoadXML(playxml); | ||
// this.speed = rateVal; | ||
// playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = rateVal; | ||
// playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.currentTime; | ||
// this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
this.webSocketController.setPlayRate(rateVal) | ||
} | ||
@@ -312,8 +369,9 @@ /** | ||
*/ | ||
pause(){ | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = 0; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.currentTime; | ||
this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
pause() { | ||
// var playxml = xmlPlayControl; | ||
// var playxmlBody = BLoadXML(playxml); | ||
// playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = 0; | ||
// // playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.currentTime; | ||
// this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
this.webSocketController.pause(); | ||
} | ||
@@ -323,38 +381,38 @@ /** | ||
*/ | ||
playContinue(){ | ||
var playtime ; | ||
// 判断是否存在倒放的定时器,如果存在倒放的定时器要销毁 | ||
if(this.currentTime){ | ||
console.log(new Date(this.currentTime)) | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed; | ||
playtime = this.currentTime ; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = playtime; | ||
this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
}else{ | ||
var playxml = xmlPlayRecord; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.recordStartTime/1000; | ||
playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.recordEndTime/1000; | ||
playxmlBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = this.channelId; | ||
this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
} | ||
playContinue() { | ||
// var playtime; | ||
// // 判断是否存在倒放的定时器,如果存在倒放的定时器要销毁 | ||
// if (this.currentTime) { | ||
// console.log(new Date(this.currentTime)) | ||
// var playxml = xmlPlayControl; | ||
// var playxmlBody = BLoadXML(playxml); | ||
// playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed; | ||
// playtime = this.currentTime; | ||
// playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = playtime; | ||
// this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
// } else { | ||
// var playxml = xmlPlayRecord; | ||
// var playxmlBody = BLoadXML(playxml); | ||
// playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed; | ||
// playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.recordInfo.recordStartTime / 1000; | ||
// playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.recordInfo.recordEndTime / 1000; | ||
// playxmlBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = this.channelId; | ||
// this.webSocketController.playControl(Xml2String(playxmlBody)) | ||
// } | ||
this.webSocketController.playContinue() | ||
} | ||
playForward(){ | ||
playForward() { | ||
var playxml = xmlPlayRecord; | ||
var playxmlBody = BLoadXML(playxml); | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed; | ||
var playtime = this.currentTime ; | ||
var playtime = this.currentTime; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = playtime; | ||
playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.recordEndTime/1000; | ||
playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.recordEndTime / 1000; | ||
playxmlBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = this.channelId; | ||
this.webSocketController.playControl(Xml2String(playxmlBody)); | ||
if(this._player.reversePlayInterval){ | ||
if (this._player.reversePlayInterval) { | ||
this._player.clearReverseInterval(); | ||
@@ -369,9 +427,9 @@ this.reverse = false; | ||
*/ | ||
reversePlay(){ | ||
reversePlay() { | ||
this.reverse = true; | ||
var playxml = xmlPlayReverse; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed*1; | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.speed * 1; | ||
// playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.currentTime; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.recordStartTime; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.recordInfo.recordStartTime; | ||
// playxmlBody.getElementsByTagName('CmdType')[0].firstChild.nodeValue = 'ReversePlay'; | ||
@@ -387,3 +445,3 @@ // playxmlBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = this.channelId; | ||
*/ | ||
singleFramePlay(){ | ||
singleFramePlay() { | ||
var playxml = xmlPlayControl; | ||
@@ -399,3 +457,3 @@ var playxmlBody = BLoadXML(playxml); | ||
*/ | ||
singleFrameReversePlay(){ | ||
singleFrameReversePlay() { | ||
var playxml = xmlPlayControl; | ||
@@ -407,3 +465,3 @@ var playxmlBody = BLoadXML(playxml); | ||
this.webSocketController.playControl(Xml2String(playxmlBody)); | ||
} | ||
@@ -415,3 +473,3 @@ | ||
*/ | ||
changeVideo(jsonbonc){ | ||
changeVideo(jsonbonc) { | ||
// debugger | ||
@@ -423,4 +481,4 @@ this.jsonbonc = jsonbonc; | ||
// changeVideo(jsonbonc){ | ||
@@ -439,3 +497,3 @@ // var playBody=BLoadXML(xmlPlayBody); | ||
changeAfterclose(){ | ||
changeAfterclose() { | ||
this.openVideo(this.jsonbonc) | ||
@@ -447,21 +505,21 @@ } | ||
*/ | ||
fullScreen(){ | ||
fullScreen() { | ||
fullScreen(this.node) | ||
} | ||
videoBufferAdd(videoBuffer){ | ||
videoBufferAdd(videoBuffer) { | ||
//this.H264Mp4Player.playBuffer(videoBuffer); | ||
// this.H264CanvasPlayer.playBuffer(videoBuffer); | ||
if(this.reverse){ | ||
if (this.reverse) { | ||
// 倒放 ,需要将裸流加入到倒放队列 | ||
this._player.playBfferReverse(videoBuffer) | ||
}else{ | ||
} else { | ||
// 正放 | ||
this._player.playBuffer(videoBuffer) ; | ||
} | ||
this._player.playBuffer(videoBuffer); | ||
} | ||
} | ||
} | ||
export default Html5Player; |
@@ -9,2 +9,3 @@ import ByteArray from './ByteArray' ; | ||
const xotree = new ObjTree(); | ||
let srMap= [ 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 ]; | ||
//company 1112757248 'BST ' | ||
@@ -108,2 +109,5 @@ class SocketDataMerge { | ||
// console.log(imsgType) | ||
if(imsgType==2501){ | ||
console.log(imsgType) | ||
} | ||
switch(imsgType){ | ||
@@ -129,2 +133,3 @@ case 1603: // 视频数据 | ||
var timestamp = biXPelsPerMeter*1000 + Math.floor(biYPelsPerMeter/1000); | ||
this.app.startTime = timestamp; | ||
@@ -143,2 +148,3 @@ // console.log(biHeight,biWidth) | ||
if(timestamp){ | ||
// console.log(timestamp) | ||
this.app.dispatch('currentTime',timestamp*1000); | ||
@@ -156,20 +162,22 @@ } | ||
case 1604: | ||
console.log('1604') | ||
// var audioSize=socketBA.ReadUint32(); | ||
// var audioSampleRate=socketBA.ReadUint32(); | ||
// var biHeight=socketBA.ReadUint32(); | ||
// var biPlanes=socketBA.ReadUint16(); | ||
// var biBitCount=socketBA.ReadUint16(); | ||
// var biCompression=socketBA.ReadUint32(); | ||
// var audioSizeImage=socketBA.ReadUint32(); | ||
// var auXPelsPerMeter=socketBA.ReadUint32(); | ||
// var auYPelsPerMeter=socketBA.ReadUint32(); | ||
// var auClrUsed=socketBA.ReadUint32(); | ||
// var auClrImportant=socketBA.ReadUint32(); | ||
var audioSize=socketBA.ReadUint32(true); | ||
var audioSampleRate=socketBA.ReadUint32(true); | ||
var biHeight=socketBA.ReadUint32(true); | ||
var biPlanes=socketBA.ReadUint16(true); | ||
var biBitCount=socketBA.ReadUint16(true); | ||
var biCompression=socketBA.ReadUint32(true); | ||
var audioSizeImage=socketBA.ReadUint32(true); | ||
var auXPelsPerMeter=socketBA.ReadUint32(true); | ||
var auYPelsPerMeter=socketBA.ReadUint32(true); | ||
var auClrUsed=socketBA.ReadUint32(true); | ||
var auClrImportant=socketBA.ReadUint32(true); | ||
// var aacRawbuffer = socketBA.SliceNewAB(audioSizeImage); | ||
// var aacRawu8a=new Uint8Array(aacRawbuffer); | ||
// // debugger | ||
// // console.log(this.app) | ||
// this.app._player.nalsbonAudioarr.push(aacRawu8a) | ||
var aacRawbuffer = socketBA.SliceNewAB(audioSizeImage); | ||
var aacRawu8a=new Uint8Array(aacRawbuffer); | ||
var sampleRateIndex = srMap.findIndex(item=>item===audioSampleRate); | ||
this.app._player.remuxController.samplingFrequencyIndex = sampleRateIndex | ||
this.app._player.nalsbonAudioarr.push(aacRawu8a) | ||
break; | ||
@@ -221,3 +229,3 @@ case 2500: // 人脸的几何框信息 | ||
// console.log('xml图形消息') | ||
},60000,1) | ||
},2000,1) | ||
this.drawfunc() | ||
@@ -224,0 +232,0 @@ } |
@@ -30,3 +30,5 @@ export function appendByteArray(buffer1, buffer2) | ||
//xml字符串转成dom对象 | ||
/** | ||
* xml字符串转成dom对象 | ||
*/ | ||
export function BLoadXML(xmlString){ | ||
@@ -199,20 +201,36 @@ var xmlDoc=null; | ||
/** | ||
* | ||
* @param {Buffer} file 二进制的buffer | ||
* 处理回放服务返回的录像信息对象 | ||
* @param {*} jsondata | ||
*/ | ||
export function downloadMp4 (file) { | ||
let blob = new Blob([file], { | ||
type: "text/plain;base64" | ||
}); | ||
let reader = new FileReader(); | ||
reader.readAsDataURL(blob); | ||
reader.onload = function (e) { | ||
let a = document.createElement('a'); | ||
a.download = 'filename.mp4'; | ||
a.href = e.target.result; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
export function dealRecordSearchInfo(jsondata){ | ||
if (parseInt(jsondata.Response.SumNum) > 0) { | ||
var recordStartTime,recordEndTime; | ||
if (jsondata.Response.RecordList.Item instanceof Array) { | ||
recordStartTime = new Date(jsondata.Response.RecordList.Item[0].StartTime).getTime(); | ||
recordEndTime = new Date(jsondata.Response.RecordList.Item[0].EndTime).getTime(); | ||
for (var i = 1; i < jsondata.Response.RecordList.Item.length; i++) { | ||
var time0 = new Date(jsondata.Response.RecordList.Item[i].StartTime).getTime(); | ||
var time1 = new Date(jsondata.Response.RecordList.Item[i].EndTime).getTime(); | ||
if (recordStartTime > time0) { | ||
recordStartTime = time0; | ||
} | ||
if (recordEndTime < time1) { | ||
recordEndTime = time1; | ||
} | ||
} | ||
return { | ||
recordStartTime,recordEndTime | ||
} | ||
} else { | ||
recordStartTime = new Date(jsondata.Response.RecordList.Item.StartTime).getTime(); | ||
recordEndTime = new Date(jsondata.Response.RecordList.Item.EndTime).getTime(); | ||
return { | ||
recordStartTime,recordEndTime | ||
} | ||
} | ||
} | ||
} |
@@ -10,2 +10,3 @@ //对于传进来的configs中的各个值进行校验 | ||
this.node = document.getElementById(videoId); | ||
window.videoNode = this.node; | ||
@@ -16,2 +17,3 @@ if(!this.node){ | ||
this.node.muted = true | ||
this.node.muted = false | ||
} | ||
@@ -18,0 +20,0 @@ |
@@ -10,3 +10,3 @@ | ||
} | ||
startRecord() { | ||
startRecord(name) { | ||
const stream = this.mediaElement.captureStream(); | ||
@@ -17,3 +17,3 @@ var that = this | ||
this.recorder.onstop = function () { | ||
downloadMovie(that.data) | ||
downloadMovie(that.data,name) | ||
} | ||
@@ -40,3 +40,3 @@ | ||
function downloadMovie(file) { | ||
function downloadMovie(file,name) { | ||
let blob = new Blob(file, { | ||
@@ -48,4 +48,5 @@ type: "video/mp4" | ||
a.href = url; | ||
a.download = 'filename.webm'; | ||
var filename = name || 'filename.webm' | ||
a.download = filename; | ||
a.click(); | ||
} |
@@ -1,10 +0,10 @@ | ||
import {xmlHeader,xmlHeartBody,xmlCloseBody} from './orderList'; | ||
import { xmlHeader, xmlHeartBody, xmlCloseBody, xmlPlayControl ,xmlPlayRecord} from './orderList'; | ||
import ByteArray from './ByteArray'; | ||
import {ByteLengthOf,MergeBuffer} from './utils' | ||
import { ByteLengthOf, MergeBuffer, Xml2String, BLoadXML } from './utils' | ||
import SocketDataMerge from './SocketDataMerge' | ||
import ObjTree from 'objtree' | ||
// reason 'change' | ||
window.WebSocket.prototype.normalClose=function(reason){ | ||
window.WebSocket.prototype.normalClose = function (reason) { | ||
this.closeReason = reason || 'normal'; | ||
this.close(3001,this.closeReason); | ||
this.close(3001, this.closeReason); | ||
// console.time('close') | ||
@@ -14,3 +14,3 @@ // console.log('close 方法已执行') | ||
function Uint8ArrayToString(fileData){ | ||
function Uint8ArrayToString(fileData) { | ||
var dataString = ""; | ||
@@ -20,6 +20,6 @@ for (var i = 0; i < fileData.length; i++) { | ||
} | ||
return dataString | ||
} | ||
export default class WebSocketUtil{ | ||
export default class WebSocketUtil { | ||
/* | ||
@@ -33,3 +33,3 @@ heartLiveInterval 心跳保活定时器的id | ||
*/ | ||
constructor(app){ | ||
constructor(app) { | ||
this.app = app; | ||
@@ -39,7 +39,7 @@ this.boncws = null; | ||
this.startOrder = null; | ||
this.normalDisconnect =false; | ||
this.normalDisconnect = false; | ||
this.socketDataMerge = new SocketDataMerge(this.app); | ||
this.closed = false; | ||
this.finishSearch = false ; | ||
this.WebSocketOpen = this.WebSocketOpen.bind(this); | ||
this.finishSearch = false; | ||
this.WebSocketOpen = this.WebSocketOpen.bind(this); | ||
this.handleError = this.handleError.bind(this); | ||
@@ -54,46 +54,46 @@ this.webSocketPlayBackOpen = this.webSocketPlayBackOpen.bind(this); | ||
*/ | ||
WebSocketInit(type){ | ||
if(!this.url){ | ||
WebSocketInit(type) { | ||
if (!this.url) { | ||
throw new Error('url不存在,无法启动') | ||
} | ||
if(type==='playback'){ | ||
if (type === 'playback') { | ||
this.type = type | ||
if(this.boncws!==null){ | ||
if(this.boncws.readyState==1){ | ||
if (this.boncws !== null) { | ||
if (this.boncws.readyState == 1) { | ||
} | ||
this.boncws.removeEventListener('open',this.webSocketPlayBackOpen); | ||
this.boncws.removeEventListener('open', this.webSocketPlayBackOpen); | ||
this.boncws.removeEventListener('message', this.WebSocketPlayBackMessage); | ||
this.boncws.removeEventListener('close',this.WebSocketClose.bind(this)); | ||
this.boncws=null; | ||
this.boncws.removeEventListener('close', this.WebSocketClose.bind(this)); | ||
this.boncws = null; | ||
console.log('websocket需要重新实例化') | ||
} | ||
this.boncws=new WebSocket(this.url); | ||
this.boncws = new WebSocket(this.url); | ||
this.boncws.binaryType = 'arraybuffer'; | ||
this.boncws.addEventListener('open',this.webSocketPlayBackOpen); | ||
this.boncws.addEventListener('open', this.webSocketPlayBackOpen); | ||
this.boncws.addEventListener('message', this.WebSocketPlayBackMessage); | ||
this.boncws.addEventListener('close',this.WebSocketClose.bind(this)); | ||
this.boncws.addEventListener('error',this.handleError) | ||
}else{ | ||
if(this.boncws!==null){ | ||
this.boncws.removeEventListener('open',this.WebSocketOpen.bind(this)); | ||
this.boncws.addEventListener('close', this.WebSocketClose.bind(this)); | ||
this.boncws.addEventListener('error', this.handleError) | ||
} else { | ||
if (this.boncws !== null) { | ||
this.boncws.removeEventListener('open', this.WebSocketOpen.bind(this)); | ||
this.boncws.removeEventListener('message', this.WebSocketMessage.bind(this)); | ||
this.boncws.removeEventListener('close',this.WebSocketClose.bind(this)); | ||
this.boncws=null; | ||
this.boncws.removeEventListener('close', this.WebSocketClose.bind(this)); | ||
this.boncws = null; | ||
console.log('websocket需要重新实例化') | ||
} | ||
this.boncws=new WebSocket(this.url); | ||
this.boncws = new WebSocket(this.url); | ||
this.boncws.binaryType = 'arraybuffer'; | ||
this.boncws.addEventListener('open',this.WebSocketOpen.bind(this)); | ||
this.boncws.addEventListener('open', this.WebSocketOpen.bind(this)); | ||
this.boncws.addEventListener('message', this.WebSocketMessage.bind(this)); | ||
this.boncws.addEventListener('close',this.WebSocketClose.bind(this)); | ||
this.boncws.addEventListener('error',this.handleError) | ||
this.boncws.addEventListener('close', this.WebSocketClose.bind(this)); | ||
this.boncws.addEventListener('error', this.handleError) | ||
} | ||
} | ||
/** | ||
@@ -104,13 +104,13 @@ * websocket连接完成的回调 | ||
*/ | ||
WebSocketOpen(){ | ||
if(this.closed===true){ | ||
WebSocketOpen() { | ||
if (this.closed === true) { | ||
this.app.dispatch('startSuccess') | ||
} | ||
this.closed = false; | ||
var strxml= xmlHeader+this.xmlPlayBody; | ||
var mun= ByteLengthOf(strxml); | ||
var strxml = xmlHeader + this.xmlPlayBody; | ||
var mun = ByteLengthOf(strxml); | ||
//写入28个字节头 | ||
var ab=new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
sendBA.WriteUint32(0x0100);//版本号(ver): | ||
@@ -121,3 +121,3 @@ sendBA.WriteString('BST ');//公司必须是4个字节所以加个空格,服务器限制公司名bst | ||
sendBA.WriteUint32(mun);////指令长度 | ||
sendBA.WriteUint32((mun+28));//数据全长 | ||
sendBA.WriteUint32((mun + 28));//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -132,14 +132,14 @@ //写入xml字符串 | ||
webSocketPlayBackOpen(){ | ||
webSocketPlayBackOpen() { | ||
this.finishSearch = false; | ||
if(this.closed===true){ | ||
if (this.closed === true) { | ||
this.app.dispatch('startSuccess') | ||
} | ||
this.closed = false; | ||
var strxml= xmlHeader+this.xmlPlayBody; | ||
var mun= ByteLengthOf(strxml); | ||
var strxml = xmlHeader + this.xmlPlayBody; | ||
var mun = ByteLengthOf(strxml); | ||
//写入28个字节头 | ||
var ab= new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
sendBA.WriteUint32(0x0100);//版本号(ver): | ||
@@ -150,3 +150,3 @@ sendBA.WriteString('BST ');//公司必须是4个字节所以加个空格,服务器限制公司名bst | ||
sendBA.WriteUint32(mun);////指令长度 | ||
sendBA.WriteUint32((mun+28));//数据全长 | ||
sendBA.WriteUint32((mun + 28));//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -161,8 +161,9 @@ //写入xml字符串 | ||
recordPlay(playinfo){ | ||
var strxml= xmlHeader+playinfo; | ||
var mun= ByteLengthOf(strxml); | ||
recordPlay(playinfo) { | ||
playinfo = Xml2String(playinfo) | ||
var strxml = xmlHeader + playinfo; | ||
var mun = ByteLengthOf(strxml); | ||
//写入28个字节头 | ||
var ab=new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
sendBA.WriteUint32(0x0100);//版本号(ver): | ||
@@ -172,4 +173,4 @@ sendBA.WriteString('BST ');//公司必须是4个字节所以加个空格,服务器限制公司名bst | ||
sendBA.WriteUint32(0x00000000);//指令类型 | ||
sendBA.WriteUint32(mun);////指令长度 | ||
sendBA.WriteUint32((mun+28));//数据全长 | ||
sendBA.WriteUint32(mun);//指令长度 | ||
sendBA.WriteUint32((mun + 28));//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -182,13 +183,20 @@ //写入xml字符串 | ||
setPlayRate(rateVal) { | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
this.speed = rateVal; | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = rateVal; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.currentTime; | ||
this.playControl(Xml2String(playxmlBody)) | ||
} | ||
playControl(playinfo){ | ||
if(!this.boncws){ | ||
playControl(playinfo) { | ||
if (!this.boncws) { | ||
return; | ||
} | ||
var strxml= xmlHeader+playinfo; | ||
var mun= ByteLengthOf(strxml); | ||
var strxml = xmlHeader + playinfo; | ||
var mun = ByteLengthOf(strxml); | ||
//写入28个字节头 | ||
var ab=new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
sendBA.WriteUint32(0x0100);//版本号(ver): | ||
@@ -199,3 +207,3 @@ sendBA.WriteString('BST ');//公司必须是4个字节所以加个空格,服务器限制公司名bst | ||
sendBA.WriteUint32(mun);////指令长度 | ||
sendBA.WriteUint32((mun+28));//数据全长 | ||
sendBA.WriteUint32((mun + 28));//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -207,21 +215,21 @@ //写入xml字符串 | ||
} | ||
WebSocketClose(e){ //websocket异常关闭,需要重连 | ||
WebSocketClose(e) { //websocket异常关闭,需要重连 | ||
// console.timeEnd('close') | ||
// console.log(this.socketDataMerge.videoDataQueue) | ||
if(this.boncws.closeReason==='normal'){ | ||
if (this.boncws.closeReason === 'normal') { | ||
console.log('normal')//正常关闭 | ||
this.boncws.closeReason ='' | ||
this.boncws.closeReason = '' | ||
//事件解绑定 | ||
this.boncws.removeEventListener('open',this.WebSocketOpen); | ||
this.boncws.removeEventListener('open', this.WebSocketOpen); | ||
this.boncws.removeEventListener('message', this.WebSocketMessage); | ||
this.boncws.removeEventListener('close',this.WebSocketClose); | ||
this.boncws.removeEventListener('close', this.WebSocketClose); | ||
console.log('websocket端口成功') | ||
}else if(this.boncws.closeReason==='change'){ | ||
} else if (this.boncws.closeReason === 'change') { | ||
//因某些原因需要关闭 | ||
this.app.dispatch('changeclose') | ||
}else if(this.boncws.closeReason==='restart'){ | ||
} else if (this.boncws.closeReason === 'restart') { | ||
this.app.dispatch('restartclose') | ||
}else{ | ||
} else { | ||
//非正常断开连接、需要重连 | ||
if(!this.closed){ | ||
if (!this.closed) { | ||
console.log('发出断开的消息') | ||
@@ -231,6 +239,6 @@ this.app.dispatch('disconnectNetWork') | ||
} | ||
console.log('abnormal') | ||
setTimeout(() => { | ||
console.log('websocket 重新连接' , this.type) | ||
console.log('websocket 重新连接', this.type) | ||
this.WebSocketInit(); | ||
@@ -240,3 +248,3 @@ }, 2000); | ||
} | ||
} | ||
@@ -248,3 +256,3 @@ | ||
*/ | ||
WebSocketMessage(evt){ | ||
WebSocketMessage(evt) { | ||
//console.time("str") //开始 | ||
@@ -255,18 +263,29 @@ this.socketDataMerge.addDataPackage(evt); | ||
/** | ||
* 暂停 | ||
*/ | ||
pause() { | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = 0; | ||
this.playControl(Xml2String(playxmlBody)) | ||
} | ||
/** | ||
* 回放视频的websocket接收消息的回放 | ||
*/ | ||
WebSocketPlayBackMessage (evt){ | ||
if(this.finishSearch){ | ||
WebSocketPlayBackMessage(evt) { | ||
if (this.finishSearch) { | ||
this.socketDataMerge.addDataPackage(evt); | ||
}else{ | ||
var socketBA= new ByteArray(evt.data); | ||
let verbonc=socketBA.ReadUint32();//verbonc | ||
let company=socketBA.ReadUint32();//company 厂家(company)BST | ||
let imsgType=socketBA.ReadUint32();////消息类型 | ||
let linType=socketBA.ReadUint32();//指令类型 | ||
let iCmdLen=socketBA.ReadUint32();//指令长度 | ||
} else { | ||
var socketBA = new ByteArray(evt.data); | ||
let verbonc = socketBA.ReadUint32();//verbonc | ||
let company = socketBA.ReadUint32();//company 厂家(company)BST | ||
let imsgType = socketBA.ReadUint32();////消息类型 | ||
let linType = socketBA.ReadUint32();//指令类型 | ||
let iCmdLen = socketBA.ReadUint32();//指令长度 | ||
socketBA.ReadUint32();//数据全长 | ||
socketBA.ReadUint32();//保留字段 | ||
if(socketBA.bytesAvailable<iCmdLen){ | ||
if (socketBA.bytesAvailable < iCmdLen) { | ||
throw new Error('服务器错误') | ||
@@ -277,19 +296,26 @@ } | ||
const xotree = new ObjTree(); | ||
var jsonData = xotree.parseXML( xbn ); | ||
var jsonData = xotree.parseXML(xbn); | ||
// 取本次查询结果的起始时间和结束时间 | ||
console.log(jsonData) | ||
if(xbn.indexOf('Response')==-1){ | ||
var arr = jsonData.Response.RecordList ? jsonData.Response.RecordList.Item : false; | ||
if (arr) { | ||
this.recordStartTime = new Date(arr[0].StartTime).valueOf(); | ||
this.recordEndTime = new Date(arr[arr.length - 1].EndTime).valueOf(); | ||
} | ||
console.log(arr) | ||
if (xbn.indexOf('Response') == -1) { | ||
throw new Error('服务器返回内容错误或丢包'); | ||
} | ||
this.finishSearch = true; | ||
this.finishSearch = true; | ||
this.app.dispatch('onRecordInfo',jsonData); | ||
this.app.dispatch('onRecordInfo', jsonData); | ||
} | ||
} | ||
closeWebSocket(){ | ||
var strxml= xmlHeader + xmlCloseBody; | ||
var mun=ByteLengthOf(strxml); | ||
var ab=new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
closeWebSocket() { | ||
var strxml = xmlHeader + xmlCloseBody; | ||
var mun = ByteLengthOf(strxml); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
//写入28个字节头 | ||
@@ -301,3 +327,3 @@ sendBA.WriteUint32(0x0100);//版本号(ver): | ||
sendBA.WriteUint32(mun);//指令长度 | ||
sendBA.WriteUint32(mun+28);//数据全长 | ||
sendBA.WriteUint32(mun + 28);//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -310,14 +336,13 @@ //写入xml字符串 | ||
/*------------------------定时器 开始---------------------------- */ | ||
/*------------------------定时器 开始---------------------------- */ | ||
/** | ||
* 开启 发送心跳保活的 定时器 | ||
*/ | ||
startHeartLiveInterval(){ | ||
this.heartLiveInterval = setInterval(()=> | ||
{ | ||
startHeartLiveInterval() { | ||
this.heartLiveInterval = setInterval(() => { | ||
// console.log('websocket state',this.boncws.readyState) | ||
var strxml= xmlHeader + xmlHeartBody; | ||
var mun=ByteLengthOf(strxml); | ||
var ab=new ArrayBuffer((mun+28)); | ||
var sendBA= new ByteArray(ab); | ||
var strxml = xmlHeader + xmlHeartBody; | ||
var mun = ByteLengthOf(strxml); | ||
var ab = new ArrayBuffer((mun + 28)); | ||
var sendBA = new ByteArray(ab); | ||
//写入28个字节头 | ||
@@ -329,3 +354,3 @@ sendBA.WriteUint32(0x0100);//版本号(ver): | ||
sendBA.WriteUint32(mun);//指令长度 | ||
sendBA.WriteUint32(mun+28);//数据全长 | ||
sendBA.WriteUint32(mun + 28);//数据全长 | ||
sendBA.WriteUint32(0x00000000);//保留字段 | ||
@@ -335,28 +360,52 @@ //写入xml字符串 | ||
//debug.log('心跳============'); | ||
if(this.boncws.readyState===3){ | ||
if (this.boncws.readyState === 3) { | ||
this.WebSocketInit(this.wsurl);//自动重连 | ||
} | ||
else{ | ||
try{ | ||
else { | ||
try { | ||
// console.log(this.boncws.readyState) | ||
this.boncws.send(sendBA.GetArrayBuffer()); | ||
}catch(err){ | ||
} catch (err) { | ||
// debugger; | ||
console.log(err) | ||
} | ||
} | ||
}, 20000); | ||
} | ||
handleError(e){ | ||
handleError(e) { | ||
console.log(e) | ||
} | ||
/*------------------------定时器 结束---------------------------- */ | ||
/** | ||
* 继续播放 | ||
*/ | ||
playContinue() { | ||
var playtime; | ||
// 判断是否存在倒放的定时器,如果存在倒放的定时器要销毁 | ||
if (this.app.currentTime) { | ||
console.log(new Date(this.app.currentTime)) | ||
var playxml = xmlPlayControl; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.app.speed; | ||
playtime = this.app.currentTime; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = playtime/1000; | ||
this.playControl(Xml2String(playxmlBody)); | ||
} else { | ||
var playxml = xmlPlayRecord; | ||
var playxmlBody = BLoadXML(playxml); | ||
playxmlBody.getElementsByTagName('Speed')[0].firstChild.nodeValue = this.app.speed; | ||
playxmlBody.getElementsByTagName('StartTime')[0].firstChild.nodeValue = this.app.recordInfo.recordStartTime / 1000; | ||
playxmlBody.getElementsByTagName('EndTime')[0].firstChild.nodeValue = this.app.recordInfo.recordEndTime / 1000; | ||
playxmlBody.getElementsByTagName('ChannelID')[0].firstChild.nodeValue = this.app.channelId; | ||
this.playControl(Xml2String(playxmlBody)); | ||
} | ||
/*------------------------播放 开始------------------------------*/ | ||
} | ||
/*------------------------定时器 结束---------------------------- */ | ||
/*------------------------播放 结束------------------------------*/ | ||
/*------------------------播放 开始------------------------------*/ | ||
/*------------------------播放 结束------------------------------*/ | ||
} |
2716264
6133
41