You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
7.0 KiB
JavaScript

4 years ago
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-dfe57506"],{"0e85":function(e,t,n){"use strict";var i=n("7710"),c=n.n(i);c.a},7710:function(e,t,n){var i=n("7bdd");"string"===typeof i&&(i=[[e.i,i,""]]),i.locals&&(e.exports=i.locals);var c=n("499e").default;c("8761e2f0",i,!0,{sourceMap:!1,shadowMode:!1})},"7abc":function(e,t,n){"use strict";n("4160"),n("d3b7"),n("159b"),n("96cf");var i=n("1da1");function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}var r=n("ade3"),l=function(){function e(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};c(this,e),Object(r["a"])(this,"webrtc",null),Object(r["a"])(this,"video",null),Object(r["a"])(this,"server",null),Object(r["a"])(this,"codecLink",null),Object(r["a"])(this,"rsdpLink",null),Object(r["a"])(this,"stream",new MediaStream),Object(r["a"])(this,"uuid",null),Object(r["a"])(this,"options",{onStatusChange:null}),console.log("new uuid:"+n),this.server=e.server,this.video=t,this.uuid=n,Object.assign(this.options,i),this.createLinks(),this.play()}return s(e,[{key:"createLinks",value:function(){this.codecLink="//"+this.server+"/stream/codec/"+this.uuid,this.rsdpLink="//"+this.server+"/stream/receiver/"+this.uuid}},{key:"play",value:function(){var e=this;this.webrtc=new RTCPeerConnection({iceServers:[{urls:["stun:stun.l.google.com:19302"]}]}),this.webrtc||console.log("no"),this.webrtc.onnegotiationneeded=this.handleNegotiationNeeded.bind(this),this.webrtc.ontrack=this.onTrack.bind(this),fetch(this.codecLink).then((function(t){t.json().then((function(t){t.forEach((function(t,n){e.webrtc.addTransceiver(t.Type,{direction:"sendrecv"})}))}))})).catch((function(e){console.log(e)})),this.webrtc.onconnectionstatechange=function(){"connected"==e.webrtc.connectionState||"connecting"==e.webrtc.connectionState?console.log("uuid:"+e.uuid+" status:"+e.webrtc.connectionState):(console.log(e.webrtc.connectionState),e.load(e.uuid))}}},{key:"handleNegotiationNeeded",value:function(){var e=Object(i["a"])(regeneratorRuntime.mark((function e(){var t,n,i=this;return regeneratorRuntime.wrap((function(e){while(1)switch(e.prev=e.next){case 0:return e.next=2,this.webrtc.createOffer();case 2:return t=e.sent,e.next=5,this.webrtc.setLocalDescription(t);case 5:n=new FormData,n.append("suuid",this.uuid),n.append("data",btoa(this.webrtc.localDescription.sdp)),fetch(this.rsdpLink,{method:"POST",body:n}).then((function(e){e.text().then((function(e){i.webrtc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:atob(e)}))}))})).catch((function(e){}));case 9:case"end":return e.stop()}}),e,this)})));function t(){return e.apply(this,arguments)}return t}()},{key:"onTrack",value:function(e){this.stream.addTrack(e.track),this.video.srcObject=this.stream,this.video.play()}},{key:"load",value:function(e){this.destroy(),this.uuid=e,this.createLinks(),this.play()}},{key:"destroy",value:function(){console.log("destroy uuid:"+this.uuid),this.webrtc.close(),this.webrtc=null,this.video.srcObject=null,this.stream=new MediaStream}},{key:"getImageUrl",value:function(){var e=document.createElement("canvas");e.width=this.video.videoWidth,e.height=this.video.videoHeight,e.getContext("2d").drawImage(video,0,0,e.width,e.height);var t=e.toDataURL();return e.remove(),t}}],[{key:"setServer",value:function(e){this.server=e}}]),e}();Object(r["a"])(l,"server","127.0.0.1:8083");t["a"]=l},"7bdd":function(e,t,n){var i=n("24fb");t=i(!1),t.push([e.i,"",""]),e.exports=t},"7e7c":function(e,t,n){"use strict";n.r(t);var i=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{attrs:{id:"videos"}},[e.isFullscreen?e._e():n("a-button",{attrs:{type:"primary"},on:{click:e.full}},[e._v(" 全屏"),n("a-icon",{attrs:{type:"right"}})],1),e.isFullscreen?n("a-button",{attrs:{type:"primary"},on:{click:e.full}},[n("a-icon",{attrs:{type:"left"}}),e