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
9.6 KiB
JavaScript

4 years ago
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-95d7389c"],{"3ea2":function(t,e,n){"use strict";n("4160"),n("d3b7"),n("159b"),n("96cf");var i=n("1da1");function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}var s=n("ade3"),c=function(){function t(e,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};a(this,t),Object(s["a"])(this,"webrtc",null),Object(s["a"])(this,"video",null),Object(s["a"])(this,"server",null),Object(s["a"])(this,"codecLink",null),Object(s["a"])(this,"rsdpLink",null),Object(s["a"])(this,"stream",new MediaStream),Object(s["a"])(this,"uuid",null),Object(s["a"])(this,"options",{onStatusChange:null}),console.log("new uuid:"+n),this.server=t.server,this.video=e,this.uuid=n,Object.assign(this.options,i),this.createLinks(),this.play()}return o(t,[{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 t=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(e){e.json().then((function(e){e.forEach((function(e,n){t.webrtc.addTransceiver(e.Type,{direction:"sendrecv"})}))}))})).catch((function(t){console.log(t)})),this.webrtc.onconnectionstatechange=function(){"connected"==t.webrtc.connectionState||"connecting"==t.webrtc.connectionState?console.log("uuid:"+t.uuid+" status:"+t.webrtc.connectionState):(console.log(t.webrtc.connectionState),t.load(t.uuid))}}},{key:"handleNegotiationNeeded",value:function(){var t=Object(i["a"])(regeneratorRuntime.mark((function t(){var e,n,i=this;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,this.webrtc.createOffer();case 2:return e=t.sent,t.next=5,this.webrtc.setLocalDescription(e);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(t){t.text().then((function(t){i.webrtc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:atob(t)}))}))})).catch((function(t){}));case 9:case"end":return t.stop()}}),t,this)})));function e(){return t.apply(this,arguments)}return e}()},{key:"onTrack",value:function(t){this.stream.addTrack(t.track),this.video.srcObject=this.stream,this.video.play()}},{key:"load",value:function(t){this.destroy(),this.uuid=t,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 t=document.createElement("canvas");t.width=this.video.videoWidth,t.height=this.video.videoHeight,t.getContext("2d").drawImage(video,0,0,t.width,t.height);var e=t.toDataURL();return t.remove(),e}}],[{key:"setServer",value:function(t){this.server=t}}]),t}();Object(s["a"])(c,"server","127.0.0.1:8083");e["a"]=c},"41c4":function(t,e,n){var i=n("24fb");e=i(!1),e.push([t.i,".alarm .ant-form-item-label[data-v-4fa80a1b]{text-align:left}.realTime[data-v-4fa80a1b]{padding:10px}",""]),t.exports=e},"634a":function(t,e,n){var i=n("41c4");"string"===typeof i&&(i=[[t.i,i,""]]),i.locals&&(t.exports=i.locals);var a=n("499e").default;a("17dbe64a",i,!0,{sourceMap:!1,shadowMode:!1})},a630:function(t,e,n){var i=n("23e7"),a=n("4df4"),r=n("1c7e"),o=!r((function(t){Array.from(t)}));i({target:"Array",stat:!0,forced:o},{from:a})},b85c:function(t,e,n){"use strict";n.d(e,"a",(function(){return r}));n("a4d3"),n("e01a"),n("d28b"),n("d3b7"),n("3ca3"),n("ddb0"),n("a630"),n("fb6a"),n("b0c0"),n("25f0");function i(t,e){(null==e||e>t.length)