!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i,s=t();for(i in s)("object"==typeof exports?exports:e)[i]=s[i]}}(this,function(){return s={},o.m=i={"../../res/js/index.js": /*!************************************************************!*\ !*** D:/project/tl-opensource/tl-rtc-file/res/js/index.js ***! \************************************************************/ /*! no static exports found */function(e,t){axios.get(window.prefix+"/api/comm/initData",{}).then(e=>{let t=e.data;new Vue({el:"#fileApp",data:function(){let e=null;return io&&(e=io(t.wsHost)),{socket:e,config:t.rtcConfig,options:t.options,isJoined:!1,showReceiveFile:!1,showSendFile:!1,showLogs:!1,numSendFile:150,numReceiveFile:150,numLogs:150,currentMenu:1,logsHeight:0,nickName:"",socketId:0,roomId:"10086",fileReader:null,rtcConns:{},remoteMap:{},chunkSize:262144,offset:0,fileName:null,allSended:!1,currentReceiveSize:0,currentSendingId:"",chooseFile:null,sendFileList:[],receiveFileList:[],logs:[]}},computed:{createDisabled:function(){return this.isJoined||this.fileName||!this.roomId},exsitDisabled:function(){return!this.isJoined},uploadDisabled:function(){return!this.fileName||this.allSended},showSendFileList:function(){return this.sendFileList&&5{t.iceCandidate(i,s,e)},this.rtcConns[s]=i,this.remoteMap[s]||Vue.set(this.remoteMap,s,{id:s}),this.initSendDataChannel(s),i.onremovestream=e=>{t.removeStream(i,s,e)},i}},getOrCreateRtcConnect:function(e){let t=this.getRtcConnect(e);return void 0===t&&(t=this.createRtcConnect(e)),t},initSendDataChannel:function(t){let i=this,e=this.rtcConns[t].createDataChannel("sendDataChannel");e.binaryType="arraybuffer",e.addEventListener("open",()=>{"open"===e.readyState&&i.logs.push("建立连接 : channel open")}),e.addEventListener("close",()=>{"close"===e.readyState&&i.logs.push("连接关闭 : channel close")}),e.addEventListener("error",e=>{i.handlerSendChannelError(e)}),this.rtcConns[t].addEventListener("datachannel",e=>{i.initReceiveDataChannel(e,t)}),this.setRemoteInfo(t,{sendChannel:e})},handlerSendChannelError:function(e){console.error(e.error),this.logs.push("连接断开 : "+e)},submitChooseFile:function(){this.initSendData()},initSendData:function(){let t=this;null!=this.chooseFile&&null!=this.chooseFile?(this.fileReader=new FileReader,this.fileReader.addEventListener("error",e=>{t.logs.push("读取文件错误 : "+e)}),this.fileReader.addEventListener("abort",e=>{t.logs.push("读取文件中断 : "+e)}),this.fileReader.addEventListener("load",this.sendData),this.readSlice(0)):this.logs.push("请先选择文件")},sendData:function(t){let i="",e=!1;for(var s in this.remoteMap)1===(this.remoteMap[s].status||0)&&(e=!0,i=s);if(!e){let e=!0;for(var o in this.remoteMap){o=this.remoteMap[o].status||0;0!==o&&1!==o||(e=!1,this.allSended=!0)}if(e)return;for(var n in this.remoteMap)0===(this.remoteMap[n].status||0)&&(i=n);this.setRemoteInfo(i,{status:1})}if(""!=i){var r=this.remoteMap[i];if(1===(r.status||0)){let e=r.sendChannel;e&&"open"===e.readyState&&(0===this.offset&&(this.addPopup("正在发送给"+i.substr(0,4)+",0%。"),this.logs.push("正在发送给"+i.substr(0,4)+",0%。")),e.send(t.target.result),this.offset+=t.target.result.byteLength,t=this.offset,this.updateSendProcess(i,{process:parseInt(t/this.chooseFile.size*100)}),this.offset===this.chooseFile.size&&(console.log(i+"发送完毕"),this.addPopup("正在发送给"+i.substr(0,4)+",100%。"),this.logs.push("正在发送给"+i.substr(0,4)+",100%。"),this.updateSendProcess(i,{done:!0}),this.offset=0,this.setRemoteInfo(i,{status:2}),this.submitChooseFile()))}}},readSlice:function(e){e=this.chooseFile.slice(this.offset,e+this.chunkSize);this.fileReader.readAsArrayBuffer(e)},receivedAck:function(e,t){this.socket.emit("message",{emitType:"receivedAck",room:this.roomId,from:this.socketId,offset:t,chunkSize:this.chunkSize,to:e})},initReceiveDataChannel:function(t,i){if(i&&t&&this.getRemoteInfo(i)){let e=t.channel;e.binaryType="arraybuffer",e.onmessage=e=>{this.receiveData(e,i)},e.onopen=()=>{e.readyState},e.onclose=()=>{e.readyState},this.setRemoteInfo(i,{receiveChannel:e})}},receiveData:function(t,i){if(t&&i){var s=this.getRemoteInfo(i),o=s.receiveFiles||{},n=o.name,r=o.size,o=o.type;let e=s.receiveBuffer||[];s=s.receivedSize||0;e.push(t.data),s+=t.data.byteLength,this.$refs.receiveProgress.value=s,this.setRemoteInfo(i,{receiveBuffer:e,receivedSize:s}),this.currentReceiveSize+=t.data.byteLength,this.receivedAck(i,s),this.updateReceiveProcess(i,{process:parseInt(s/r*100)}),s===r&&(console.log("接收完毕"),this.logs.push("接收完毕..."),this.$refs.receiveProgress.value=0,this.addPopup("文件[ "+n+" ]接收完毕,可点击右下角查看。"),this.updateReceiveProcess(i,{style:"color: #ff5722;text-decoration: underline;",href:URL.createObjectURL(new Blob(e),{type:o}),done:!0}),this.setRemoteInfo(i,{receiveBuffer:[],receivedSize:0}),this.currentReceiveSize=0)}},closeDataChannels:function(){for(var i in this.remoteMap){var s=i.id;let e=i.sendChannel,t=i.receiveChannel;s&&e&&t&&(e.close(),t.close())}},setRemoteInfo(e,t){var i;e&&t&&((i=this.remoteMap[e])&&(Object.assign(i,t),Vue.set(this.remoteMap,e,i)))},updateReceiveProcess:function(t,i){for(let e=0;e{});i={from:this.socketId,to:t,room:this.roomId,sdp:i.sdp};this.socket.emit("offer",i)},offerFailed:function(e,t,i){this.logs.push("offer失败,"+i)},answerSuccess:function(e,t,i){e.setLocalDescription(i).then(e=>{});i={from:this.socketId,to:t,room:this.roomId,sdp:i.sdp};this.socket.emit("answer",i)},answerFailed:function(e,t,i){this.logs.push("answer失败,"+i)},addIceCandidateSuccess:function(e){this.logs.push("addIceCandidateSuccess成功,"+e)},addIceCandidateFailed:function(e){this.logs.push("addIceCandidate失败,"+e)},socketListener:function(){let o=this;this.socket.on("created",async function(s){o.logs.push("创建房间,"+JSON.stringify(s)),o.socketId=s.id,o.roomId=s.room;for(let e=0;e{o.offerSuccess(i,t,e)},e=>{o.offerFailed(i,t,e)})}o.touchResize()}),this.socket.on("joined",function(e){o.logs.push("加入房间,"+JSON.stringify(e)),o.getOrCreateRtcConnect(e.from),o.addPopup(e.id+"加入了房间。"),o.touchResize()}),this.socket.on("offer",function(t){o.logs.push("offer,"+JSON.stringify(t));let i=o.getOrCreateRtcConnect(t.from);var e={type:"offer",sdp:t.sdp};i.setRemoteDescription(new RTCSessionDescription(e)).then(e=>{}),i.createAnswer(o.options).then(e=>{o.answerSuccess(i,t.from,e)}).catch(e=>{o.answerFailed(i,t.from,e)})}),this.socket.on("answer",function(e){o.logs.push("answer,"+JSON.stringify(e));let t=o.getOrCreateRtcConnect(e.from);e={type:"answer",sdp:e.sdp};t.setRemoteDescription(new RTCSessionDescription(e)).then(e=>{})}),this.socket.on("candidate",function(e){o.logs.push("candidate,"+JSON.stringify(e));let t=o.getOrCreateRtcConnect(e.from);e=new RTCIceCandidate({candidate:e.sdp,sdpMid:e.sdpMid,sdpMLineIndex:e.sdpMLineIndex});t.addIceCandidate(e).then(e=>{o.addIceCandidateSuccess(e)}).catch(e=>{o.addIceCandidateFailed(e)})}),this.socket.on("exit",function(e){void 0!==o.rtcConns[e.from]&&(o.addPopup(e.from+"退出了房间。"),o.logs.push("退出房间,"+JSON.stringify(e)),o.getOrCreateRtcConnect(e.from).close,delete o.rtcConns[e.from],Vue.delete(o.remoteMap,e.from),o.touchResize())}),this.socket.on("sendFileInfo",function(e){var t=e.from;o.setRemoteInfo(t,{receiveFiles:e}),o.addPopup(e.from+"选择了文件 [ "+e.name+" ],即将发送。"),o.logs.push(e.from+"选择了文件 [ "+e.name+" ],即将发送。"),o.$refs.receiveProgress.max=e.size,o.receiveFileList.push({id:t,href:"",name:e.name,type:e.type,size:e.size,process:0,done:!1})}),this.socket.on("receivedAck",function(e){e.to===o.socketId&&o.offset{var e=new Event("resize");window.dispatchEvent(e),t.reCaculateSwiperSize()},100)}},created:function(){let e=this;window.location.hash&&window.location.hash.includes("debug")&&this.loadJS("/static/js/vconsole.min.js",function(){e.loadJS("/static/js/vconsole.js",function(){console.log("load vconsole success")})})},mounted:function(){this.$nextTick(()=>{this.logs.push("socket 初始化中..."),this.socketListener(),this.logs.push("socket 初始化成功")}),this.clickHome(!1),window.onresize=this.initCss},destroyed:function(){}})})}},o.c=s,o.d=function(e,t,i){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(o.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(i,s,function(e){return t[e]}.bind(null,s));return i},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s="../../res/js/index.js");function o(e){if(s[e])return s[e].exports;var t=s[e]={i:e,l:!1,exports:{}};return i[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var i,s});