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
7.7 KiB

(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["plugin-webrtc"]=t():e["plugin-webrtc"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s="fb15")}({"3f2c":function(e,t,r){},8875:function(e,t,r){var n,o,a;(function(r,i){o=[],n=i,a="function"===typeof n?n.apply(t,o):n,void 0===a||(e.exports=a)})("undefined"!==typeof self&&self,(function(){function e(){if(document.currentScript)return document.currentScript;try{throw new Error}catch(p){var e,t,r,n=/.*at [^(]*\((.*):(.+):(.+)\)$/gi,o=/@([^@]*):(\d+):(\d+)\s*$/gi,a=n.exec(p.stack)||o.exec(p.stack),i=a&&a[1]||!1,s=a&&a[2]||!1,c=document.location.href.replace(document.location.hash,""),l=document.getElementsByTagName("script");i===c&&(e=document.documentElement.outerHTML,t=new RegExp("(?:[^\\n]+?\\n){0,"+(s-2)+"}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*","i"),r=e.replace(t,"$1").trim());for(var u=0;u<l.length;u++){if("interactive"===l[u].readyState)return l[u];if(l[u].src===i)return l[u];if(i===c&&l[u].innerHTML&&l[u].innerHTML.trim()===r)return l[u]}return null}}return e}))},b2e7:function(e,t,r){"use strict";var n=r("3f2c"),o=r.n(n);o.a},fb15:function(e,t,r){"use strict";if(r.r(t),"undefined"!==typeof window){var n=window.document.currentScript,o=r("8875");n=o(),"currentScript"in document||Object.defineProperty(document,"currentScript",{get:o});var a=n&&n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);a&&(r.p=a[1])}var i=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[0==e.$parent.titleTabActive?r("div",[r("mu-text-field",{attrs:{label:"streamPath"},model:{value:e.streamPath,callback:function(t){e.streamPath=t},expression:"streamPath"}}),e.remoteSDP?r("m-button",{on:{click:e.stopSession}},[e._v("Stop")]):r("m-button",{on:{click:e.publish}},[e._v("Publish")]),e.remoteSDP?r("a",{attrs:{href:e.remoteSDPURL,download:"remoteSDP.txt"}},[e._v("remoteSDP")]):e._e(),r("span"),e.localSDP?r("a",{attrs:{href:e.localSDPURL,download:"localSDP.txt"}},[e._v("localSDP")]):e._e(),r("br"),r("video",{ref:"video1",attrs:{width:"640",height:"480",autoplay:"",muted:""},domProps:{srcObject:e.stream,muted:!0}})],1):1==e.$parent.titleTabActive?r("stream-table",{scopedSlots:e._u([{key:"default",fn:function(t){return[r("m-button",{on:{click:function(r){return e.preview(t)}}},[e._v("Play")]),void 0]}}])}):2==e.$parent.titleTabActive?r("pre",[e._v(e._s(e.localSDP))]):3==e.$parent.titleTabActive?r("pre",[e._v(e._s(e.remoteSDP))]):e._e(),r("webrtc-player",{ref:"player",model:{value:e.previewStreamPath,callback:function(t){e.previewStreamPath=t},expression:"previewStreamPath"}})],1)},s=[],c=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("Modal",e._g(e._b({attrs:{draggable:"",title:e.streamPath},on:{"on-ok":e.onClosePreview,"on-cancel":e.onClosePreview}},"Modal",e.$attrs,!1),e.$listeners),[r("video",{ref:"webrtc",attrs:{width:"488",height:"275",autoplay:"",muted:"",controls:""},domProps:{srcObject:e.stream,muted:!0}}),r("div",{attrs:{slot:"footer"},slot:"footer"},[e.remoteSDP?r("a",{attrs:{href:e.remoteSDPURL,download:"remoteSDP.txt"}},[e._v("remoteSDP")]):e._e(),r("span"),e.localSDP?r("a",{attrs:{href:e.localSDPURL,download:"localSDP.txt"}},[e._v("localSDP")]):e._e()])])},l=[];let u=null;var p={data(){return{iceConnectionState:u&&u.iceConnectionState,stream:null,localSDP:"",remoteSDP:"",remoteSDPURL:"",localSDPURL:"",streamPath:""}},methods:{async play(e){u=new RTCPeerConnection,this.streamPath=e,u.onsignalingstatechange=e=>{console.log(e)},u.oniceconnectionstatechange=e=>{this.$toast.info(u.iceConnectionState),this.iceConnectionState=u.iceConnectionState},u.onicecandidate=e=>{};const t=await this.ajax({url:"/webrtc/preparePlay?streamPath="+this.streamPath,dataType:"json"});t.errmsg?this.$toast.error(t.errmsg):(this.remoteSDP=t.sdp,this.remoteSDPURL=URL.createObjectURL(new Blob([this.remoteSDP],{type:"text/plain"})),u.ontrack=e=>{console.log(e),"monibuca"==e.streams[0].id&&(this.stream=e.streams[0])},await u.setRemoteDescription(new RTCSessionDescription(t)),await u.setLocalDescription(await u.createAnswer()),this.localSDP=u.localDescription.sdp,this.localSDPURL=URL.createObjectURL(new Blob([this.localSDP],{type:"text/plain"})),t=await this.ajax({type:"POST",processData:!1,data:JSON.stringify(u.localDescription),url:"/webrtc/play?streamPath="+this.streamPath,dataType:"json"}),"success"!=t&&this.$toast.error(t.errmsg||t))},onClosePreview(){u.close()}}},d=p;function f(e,t,r,n,o,a,i,s){var c,l="function"===typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=r,l._compiled=!0),n&&(l.functional=!0),a&&(l._scopeId="data-v-"+a),i?(c=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(i)},l._ssrRegister=c):o&&(c=s?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(e,t){return c.call(t),u(e,t)}}else{var p=l.beforeCreate;l.beforeCreate=p?[].concat(p,c):[c]}return{exports:e,options:l}}var m=f(d,c,l,!1,null,null,null),h=m.exports;const S={iceServers:[]};let P=new RTCPeerConnection(S);var v=null,b="live/rtc",D={components:{WebrtcPlayer:h},data(){return{localSDP:P&&P.localDescription&&P.localDescription.sdp,remoteSDP:P&&P.remoteDescription&&P.remoteDescription.sdp,streamPath:b,iceConnectionState:P&&P.iceConnectionState,stream:v,previewStreamPath:!1,localSDPURL:"",remoteSDPURL:""}},methods:{async publish(){P.addStream(v),await P.setLocalDescription(await P.createOffer()),this.localSDP=P.localDescription.sdp,this.localSDPURL=URL.createObjectURL(new Blob([this.localSDP],{type:"text/plain"}));const e=await this.ajax({type:"POST",processData:!1,data:JSON.stringify(P.localDescription),url:"/webrtc/publish?streamPath="+this.streamPath,dataType:"json"});"success"==e?(b=this.streamPath,this.remoteSDP=e.sdp,this.remoteSDPURL=URL.createObjectURL(new Blob([this.remoteSDP],{type:"text/plain"})),P.setRemoteDescription(new RTCSessionDescription(e))):this.$toast.error(e.errmsg||e)},stopSession(){P.close(),P=new RTCPeerConnection(S),this.remoteSDP="",this.localSDP=""},preview({row:e}){this.previewStreamPath=!0,this.$nextTick(()=>this.$refs.player.play(e.StreamPath))}},async mounted(){P.onsignalingstatechange=e=>{console.log(e)},P.oniceconnectionstatechange=e=>{this.$toast.info(P.iceConnectionState),this.iceConnectionState=P.iceConnectionState},P.onicecandidate=e=>{},this.$parent.titleTabs=["publish","play"];try{this.stream||(this.stream=v=await navigator.mediaDevices.getUserMedia({video:!0,audio:!0}))}catch(e){this.$toast.error(e.message)}}},y=D,w=(r("b2e7"),f(y,i,s,!1,null,"b8166bc0",null)),_=w.exports;t["default"]=_}})["default"]}));
//# sourceMappingURL=plugin-webrtc.umd.min.js.map