1 line
13 KiB
Plaintext
1 line
13 KiB
Plaintext
"use strict";function _toConsumableArray(o){return _arrayWithoutHoles(o)||_iterableToArray(o)||_unsupportedIterableToArray(o)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,e){if(o){if("string"==typeof o)return _arrayLikeToArray(o,e);var r=Object.prototype.toString.call(o).slice(8,-1);return"Map"===(r="Object"===r&&o.constructor?o.constructor.name:r)||"Set"===r?Array.from(o):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(o,e):void 0}}function _iterableToArray(o){if("undefined"!=typeof Symbol&&null!=o[Symbol.iterator]||null!=o["@@iterator"])return Array.from(o)}function _arrayWithoutHoles(o){if(Array.isArray(o))return _arrayLikeToArray(o)}function _arrayLikeToArray(o,e){(null==e||e>o.length)&&(e=o.length);for(var r=0,a=new Array(e);r<e;r++)a[r]=o[r];return a}self.importScripts("common.js");var receiveVideoUrl="",firstRequestWs=1;function Downloader(){this.logger=new Logger("Downloader"),this.isChonglian=1,this.fetchFirst=!0,this.comein=!0,this.downloadNum={};for(var o=1;o<17;o++)this.downloadNum["malv"+o]=0,this.downloadNum["ismalvtimeInter"+o]=!0,this.downloadNum["controller"+o]="",this.downloadNum["recordVideoData"+o]=new Uint8Array(0),this.downloadNum["chushihua"+o]=!0}Uint8Array.prototype.concat=function(o,e){o=Array.from(o),e=Array.from(e),o=o.concat(e);return new Uint8Array(o)},Downloader.prototype.getFileInfo=function(o,e){this.logger.logInfo("Getting file size "+o+".");o={t:kGetFileInfoRsp,i:{sz:20<<20,st:200},num:e};self.postMessage(o)},Downloader.prototype.sendDataws=function(o,t,e,n,d,l,s,i,r,u){""!=o&&(this.reader=o);var m=this;this.reader.read().then(function(o){var e,r,a=o.done,o=o.value;a?(console.log("liu结束"),r={t:kliuover,num:d,rongqiId:i,devCode:u},self.postMessage(r)):o.byteLength&&(m.downloadNum["malv"+d]+=o.byteLength,m.downloadNum["ismalvtimeInter"+d]&&(m.downloadNum["ismalvtimeInter"+d]=!1,m.downloadNum["malv"+d]=0,e=setTimeout(function(){m.downloadNum["ismalvtimeInter"+d]=!0;var o={t:6,num:d,rongqiId:i,malv:m.downloadNum["malv"+d]};self.postMessage(o),clearTimeout(e)},2e3)),r={t:kFileData,s:t,e:t+o.byteLength,d:o.buffer,q:n,num:d,status:l,showName:s,downloadData:m.downloadNum["recordVideoData"+d],chushihua:m.downloadNum["chushihua"+d],rongqiId:i,malv:m.downloadNum["malv"+d],ismalv:m.downloadNum["ismalvtimeInter"+d],devCode:u},"1"===l&&(a=new Uint8Array(r.d),m.downloadNum["recordVideoData"+d]=m.downloadNum["recordVideoData"+d].concat(m.downloadNum["recordVideoData"+d],a)),self.postMessage(r,[r.d]),"2"===l&&0!==m.downloadNum["recordVideoData"+d].byteLength&&(m.downloadNum["recordVideoData"+d]=new Uint8Array(0)),m.downloadNum["chushihua"+d]=!1)})};var totalLength=0;function iserror(o,e,r,a,t){console.log("进入错误提示");var n,d,l={401:"登录失败,请重新登录",500:"服务内部错误(设备类)",503:"超过服务处理能力(设备类)",531:"消息格式错误(设备类)",532:"还有其他客户端在看此路视频(设备类)",533:"设备(含摄像机/dvr/nvr)未加载到程序中或设备不存在或设备未登陆(设备类)",534:"设备不支持此接口(设备类)",535:"设备登陆失败,请检查IP,端口号和登录名密码(设备类)",536:"设备连接失败,请检查网络情况和设备配置情况(设备类)",537:"RTP失败(设备类)",538:"SPS失败(设备类)",539:"RTCP超时(设备类)",540:"SDK执行失败,请检查PTS配置(设备类)",541:"不支持此方法(设备类)",542:"未定义的设备错误(设备类)",551:"SIP服务器内部错误(设备类)",552:"SIP协商有问题(设备类)",553:"SIP不支持的请求类型(设备类)",554:"SIP未找到请求项(设备类)",555:"SIP消息格式错误(设备类)",556:"SIP忙(设备类)",557:"SIP未知错误(设备类)",571:"RTSP错误的请求(设备类)",572:"RTSP不支持的请求类型(设备类)",573:"RTSP不允许该方法(设备类)",574:"RTSP的Session不匹配(设备类)",575:"RTSP超时(设备类)",576:"RTSP的报文太大(设备类)",577:"RTSP的URI太长(设备类)",578:"RTSP的媒体类型不支持(设备类)",579:"RTSP不理解此参数(设备类)",580:"RTSP没找到Session(设备类)",581:"RTSP此方法和当前状态不匹配(设备类)",582:"RTSP的Range字段不争取(设备类)",583:"RTSP传输方式不支持(设备类)",584:"RTSP当前负荷满(设备类)",585:"RTSP不支持此版本(设备类)",586:"RTSP响应超时(设备类)",587:"RTSP解析失败(设备类)",588:"RTSP发送失败(设备类)",589:"RTSP当前内部错误(设备类)",621:"流媒体不在线(平台类)",622:"视频打开超时(设备类)",626:"当前服务端资源不足,请稍后再尝试。(平台类)",627:"管理员禁止(平台类)",629:"设备故障,前端未注册(设备类)",641:"前端不在线(设备类)",642:"前端响应超时(设备类)",715:"录像回放建立失败(设备类)",901:"视频请求信令发送失败(设备类)",902:"视频播放URL错误(平台类)",903:"视频播放格式错误(平台类)",904:"转码服务未收到视频数据(设备类)",905:"请求HTTP视频流应答失败(平台类)",906:"分配UDP端口失败(平台类)",907:"绑定UDP端口失败(平台类)",908:"视频请求返回的IP为空(平台类)",909:"视频请求返回的端口为空(平台类)",910:"语音对讲建立TCP链接失败(平台类)",911:"不支持的非标码流格式,请用OCX播放",801:"对侧平台视频调阅数(所有人)达到上限,关闭其他视频再操作"},s=[];for(n in l)s.push(n),r&&r==n&&(d={t:kErrorTip,num:o,errorDes:l[n],errorCode:r,rongqiId:e,devCode:t},self.postMessage(d));s.indexOf(r)<0&&(a=a||"当前设备网络故障无法播放",d={t:kErrorTip,num:o,errorDes:a,errorCode:r,rongqiId:e,devCode:t},self.postMessage(d))}function downloadFileFuc(l,s,i,u,m,c,w,h,f,o){var g=o;g.fetchFirst&&(g.firstArgs=Array.prototype.slice.call(arguments)),l.indexOf("ws://")<0?g.fetchFirst?(g.fetchFirst=!1,receiveVideoUrl="http://",g.downloadNum["controller"+m]=new AbortController,o=g.downloadNum["controller"+m].signal,console.log("开始建立fetch连接"),fetch(l,{signal:o}).then(function(o){if(console.log("是否返回错误码:",o.headers.has("Sguvp_errorcode")),o.headers.has("Sguvp_errorcode")){var e,r,a=o.headers.get("Sguvp_errorcode"),t=o.headers.get("Sguvp_errordesc"),n=(console.log("进入错误提示"),{401:"登录失败,请重新登录",500:"服务内部错误(设备类)",503:"超过服务处理能力(设备类)",531:"消息格式错误(设备类)",532:"还有其他客户端在看此路视频(设备类)",533:"设备(含摄像机/dvr/nvr)未加载到程序中或设备不存在或设备未登陆(设备类)",534:"设备不支持此接口(设备类)",535:"设备登陆失败,请检查IP,端口号和登录名密码(设备类)",536:"设备连接失败,请检查网络情况和设备配置情况(设备类)",537:"RTP失败(设备类)",538:"SPS失败(设备类)",539:"RTCP超时(设备类)",540:"SDK执行失败,请检查PTS配置(设备类)",541:"不支持此方法(设备类)",542:"未定义的设备错误(设备类)",551:"SIP服务器内部错误(设备类)",552:"SIP协商有问题(设备类)",553:"SIP不支持的请求类型(设备类)",554:"SIP未找到请求项(设备类)",555:"SIP消息格式错误(设备类)",556:"SIP忙(设备类)",557:"SIP未知错误(设备类)",571:"RTSP错误的请求(设备类)",572:"RTSP不支持的请求类型(设备类)",573:"RTSP不允许该方法(设备类)",574:"RTSP的Session不匹配(设备类)",575:"RTSP超时(设备类)",576:"RTSP的报文太大(设备类)",577:"RTSP的URI太长(设备类)",578:"RTSP的媒体类型不支持(设备类)",579:"RTSP不理解此参数(设备类)",580:"RTSP没找到Session(设备类)",581:"RTSP此方法和当前状态不匹配(设备类)",582:"RTSP的Range字段不争取(设备类)",583:"RTSP传输方式不支持(设备类)",584:"RTSP当前负荷满(设备类)",585:"RTSP不支持此版本(设备类)",586:"RTSP响应超时(设备类)",587:"RTSP解析失败(设备类)",588:"RTSP发送失败(设备类)",589:"RTSP当前内部错误(设备类)",621:"流媒体不在线(平台类)",622:"视频打开超时(设备类)",626:"当前服务端资源不足,请稍后再尝试。(平台类)",627:"管理员禁止(平台类)",629:"设备故障,前端未注册(设备类)",641:"前端不在线(设备类)",642:"前端响应超时(设备类)",715:"录像回放建立失败(设备类)",901:"视频请求信令发送失败(设备类)",902:"视频播放URL错误(平台类)",903:"视频播放格式错误(平台类)",904:"转码服务未收到视频数据(设备类)",905:"请求HTTP视频流应答失败(平台类)",906:"分配UDP端口失败(平台类)",907:"绑定UDP端口失败(平台类)",908:"视频请求返回的IP为空(平台类)",909:"视频请求返回的端口为空(平台类)",910:"语音对讲建立TCP链接失败(平台类)",911:"不支持的非标码流格式,请用OCX播放",801:"对侧平台视频调阅数(所有人)达到上限,关闭其他视频再操作"}),d=[];for(e in n)d.push(e),a&&a==e&&(r={t:kErrorTip,num:m,errorDes:n[e],errorCode:a,rongqiId:h,devCode:f},self.postMessage(r));d.indexOf(a)<0&&(t=t||"当前设备网络故障无法播放",r={t:kErrorTip,num:m,errorDes:t,errorCode:a,rongqiId:h,devCode:f},self.postMessage(r))}else console.log("进入读取流"),g.sendData(o.body.getReader(),s,i,u,m,c,w,h,l,f)}).catch(function(o){console.log("",o)})):g.sendData("",s,i,u,m,c,w,h,l,f):(receiveVideoUrl="ws://",g.fetchFirst?(g.fetchFirst=!1,g.downloadNum["controller"+m]=new WebSocket(l),g.downloadNum["controller"+m].onopen=function(o){console.log("open ws")},g.downloadNum["controller"+m].onmessage=function(o){var e;g.comein&&(g.comein=!1,"string"==typeof o.data?g.isChonglian<7?e=setTimeout(function(){g.downloadNum["controller"+m]="",g.downloadNum["malv"+m]=0,g.downloadNum["ismalvtimeInter"+m]=!0,g.downloadNum["recordVideoData"+m]=new Uint8Array(0),g.downloadNum["chushihua"+m]=!0,g.fetchFirst=!0,g.comein=!0,g.isChonglian++,g.firstArgs.splice(g.firstArgs.length-1,1,g),downloadFileFuc.apply(void 0,_toConsumableArray(g.firstArgs)),clearTimeout(e)},5e3):iserror(m,h,JSON.parse(o.data).resultCode,JSON.parse(o.data).resultHint):g.sendDataws(o.data.stream().getReader(),s,i,u,m,c,w,h,l,f))}):g.downloadNum["controller"+m].onmessage=function(o){var e;"string"==typeof o.data?g.isChonglian<7?e=setTimeout(function(){g.downloadNum["controller"+m]="",g.downloadNum["malv"+m]=0,g.downloadNum["ismalvtimeInter"+m]=!0,g.downloadNum["recordVideoData"+m]=new Uint8Array(0),g.downloadNum["chushihua"+m]=!0,g.fetchFirst=!0,g.comein=!0,g.isChonglian++,g.firstArgs.splice(g.firstArgs.length-1,1,g),downloadFileFuc.apply(void 0,_toConsumableArray(g.firstArgs)),clearTimeout(e)},6e3):iserror(m,h,JSON.parse(o.data).resultCode,JSON.parse(o.data).resultHint):g.sendDataws(o.data.stream().getReader(),s,i,u,m,c,w,h,l,f)})}Downloader.prototype.sendData=function(o,t,e,n,d,l,s,i,r,u){""!=o&&(this.reader=o);var m=this;this.reader.read().then(function(o){var e,r,a=o.done,o=o.value;a&&(console.log("Stream done."),r={t:kliuover,num:d,rongqiId:i,devCode:u},self.postMessage(r)),o.byteLength&&(m.downloadNum["malv"+d]+=o.byteLength,m.downloadNum["ismalvtimeInter"+d]&&(m.downloadNum["ismalvtimeInter"+d]=!1,m.downloadNum["malv"+d]=0,e=setTimeout(function(){m.downloadNum["ismalvtimeInter"+d]=!0;var o={t:6,num:d,rongqiId:i,malv:m.downloadNum["malv"+d]};self.postMessage(o),clearTimeout(e)},2e3)),r={t:kFileData,s:t,e:t+o.byteLength,d:o.buffer,q:n,num:d,status:l,showName:s,downloadData:m.downloadNum["recordVideoData"+d],chushihua:m.downloadNum["chushihua"+d],rongqiId:i,malv:m.downloadNum["malv"+d],ismalv:m.downloadNum["ismalvtimeInter"+d],devCode:u},"1"===l&&(a=new Uint8Array(r.d),m.downloadNum["recordVideoData"+d]=m.downloadNum["recordVideoData"+d].concat(m.downloadNum["recordVideoData"+d],a)),self.postMessage(r,[r.d]),"2"===l&&0!==m.downloadNum["recordVideoData"+d].byteLength&&(m.downloadNum["recordVideoData"+d]=new Uint8Array(0)),m.downloadNum["chushihua"+d]=!1)})},Downloader.prototype.downloadFile=function(o,e,r,a,t,n,d,l,s){downloadFileFuc(o,e,r,a,t,n,d,l,s,this)},Downloader.prototype.stopStream=function(o){"ws://"==receiveVideoUrl?this.downloadNum["controller"+o]&&(this.downloadNum["controller"+o].onclose=function(){console.log("ws已经关闭完成"),this.downloadNum["controller"+o]=""},console.log("进入开始关闭websocket"),this.downloadNum["controller"+o].close(),this.downloadNum["controller"+o]=""):this.downloadNum["controller"+o]&&(this.downloadNum["controller"+o].abort(),this.downloadNum["controller"+o]=""),self.close()},self.downloader=new Downloader,self.onmessage=function(o){if(self.downloader){var e=o.data;switch(e.t){case kGetFileInfoReq:self.downloader.getFileInfo(e.u,e.num);break;case kDownloadFileReq:self.downloader.downloadFile(e.u,e.s,e.e,e.q,e.num,e.luzhistatus,e.showName,e.rongqiId,e.devCode);break;case kCloseDownloaderReq:self.downloader.stopStream(e.num);break;default:self.downloader.logger.logError("Unsupport messsage "+e.t)}}else console.log("[ER] Downloader not initialized!")}; |