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

2 lines
5.6 KiB

(function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["plugin-webrtc"]=e():t["plugin-webrtc"]=e()})("undefined"!==typeof self?self:this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s="fb15")}({8875:function(t,e,n){var r,o,i;(function(n,s){o=[],r=s,i="function"===typeof r?r.apply(e,o):r,void 0===i||(t.exports=i)})("undefined"!==typeof self&&self,(function(){function t(){if(document.currentScript)return document.currentScript;try{throw new Error}catch(d){var t,e,n,r=/.*at [^(]*\((.*):(.+):(.+)\)$/gi,o=/@([^@]*):(\d+):(\d+)\s*$/gi,i=r.exec(d.stack)||o.exec(d.stack),s=i&&i[1]||!1,a=i&&i[2]||!1,c=document.location.href.replace(document.location.hash,""),l=document.getElementsByTagName("script");s===c&&(t=document.documentElement.outerHTML,e=new RegExp("(?:[^\\n]+?\\n){0,"+(a-2)+"}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*","i"),n=t.replace(e,"$1").trim());for(var u=0;u<l.length;u++){if("interactive"===l[u].readyState)return l[u];if(l[u].src===s)return l[u];if(s===c&&l[u].innerHTML&&l[u].innerHTML.trim()===n)return l[u]}return null}}return t}))},"8dc9":function(t,e,n){},c857:function(t,e,n){"use strict";var r=n("8dc9"),o=n.n(r);o.a},fb15:function(t,e,n){"use strict";if(n.r(e),"undefined"!==typeof window){var r=window.document.currentScript,o=n("8875");r=o(),"currentScript"in document||Object.defineProperty(document,"currentScript",{get:o});var i=r&&r.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);i&&(n.p=i[1])}var s=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[1==t.$parent.titleTabActive?n("pre",[t._v(t._s(t.localSDP))]):2==t.$parent.titleTabActive?n("pre",[t._v(t._s(t.remoteSDP))]):n("div",[n("mu-text-field",{attrs:{label:"streamPath"},model:{value:t.streamPath,callback:function(e){t.streamPath=e},expression:"streamPath"}}),!t.localSDP||t.ask?n("span",{staticClass:"blink"},[t._v("Connecting")]):"connected"!=t.iceConnectionState?[n("m-button",{on:{click:function(e){return t.startSession("publish")}}},[t._v("Publish")]),n("m-button",{on:{click:function(e){return t.startSession("play")}}},[t._v("Play")])]:"connected"==t.iceConnectionState?n("m-button",{on:{click:t.stopSession}},[t._v("Stop")]):t._e(),n("br"),n("video",{ref:"video1",attrs:{width:"640",height:"480",autoplay:"",muted:""},domProps:{srcObject:t.stream,muted:!0}})],2)])},a=[];const c={iceServers:[]};let l=new RTCPeerConnection(c);var u=null,d="live/rtc",p={data(){return{localSDP:l&&l.localDescription&&l.localDescription.sdp,remoteSDP:l&&l.remoteDescription&&l.remoteDescription.sdp,streamPath:d,iceConnectionState:l&&l.iceConnectionState,stream:u,type:"",ask:!1}},methods:{startSession(t){this.type=t,this.ask=!0,this.ajax({type:"POST",processData:!1,data:JSON.stringify(l.localDescription),url:"/webrtc/"+t+"?streamPath="+this.streamPath,dataType:"json"}).then(t=>{this.ask=!1,t.errmsg?this.$toast.error(t.errmsg):(d=this.streamPath,this.remoteSDP=t.sdp,this.$parent.titleTabs=["摄像头","localSDP","remoteSDP"],l.setRemoteDescription(new RTCSessionDescription(t)))})},stopSession(){l.close(),l=new RTCPeerConnection(c),this.remoteSDP="",this.localSDP="",this.connectICE().catch(t=>this.$toast.error(t.message))},async connectICE(){l.addStream(u),await l.setLocalDescription(await l.createOffer()),l.oniceconnectionstatechange=t=>{this.$toast.info(l.iceConnectionState),this.iceConnectionState=l.iceConnectionState},l.onicecandidate=t=>{null===t.candidate&&(this.localSDP=l.localDescription.sdp,this.$parent.titleTabs=["摄像头","localSDP"])},l.ontrack=t=>{"play"==this.type&&t.streams[0]&&(this.stream=u=t.streams[0])}}},async mounted(){if(this.localSDP){let t=["摄像头"];this.localSDP&&t.push("localSDP"),this.remoteSDP&&t.push("remoteSDP"),this.$parent.titleTabs=t}else try{this.stream||(this.stream=u=await navigator.mediaDevices.getUserMedia({video:!0,audio:!0})),await this.connectICE()}catch(t){this.$toast.error(t.message)}}},f=p;n("c857");function m(t,e,n,r,o,i,s,a){var c,l="function"===typeof t?t.options:t;if(e&&(l.render=e,l.staticRenderFns=n,l._compiled=!0),r&&(l.functional=!0),i&&(l._scopeId="data-v-"+i),s?(c=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},l._ssrRegister=c):o&&(c=a?function(){o.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:o),c)if(l.functional){l._injectStyles=c;var u=l.render;l.render=function(t,e){return c.call(e),u(t,e)}}else{var d=l.beforeCreate;l.beforeCreate=d?[].concat(d,c):[c]}return{exports:t,options:l}}var h=m(f,s,a,!1,null,"3d66f6b2",null),S=h.exports;e["default"]=S}})["default"]}));
//# sourceMappingURL=plugin-webrtc.umd.min.js.map