WXL (wul)
8 小时以前 1feb410410781eb56159c8fdd856e68d2c23e0a4
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-b010e0be"],{"4c91":function(e,n,t){},"8d78":function(e,n,t){"use strict";t.r(n);var a=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("div",{staticClass:"demo"},[t("div",{staticClass:"rtcBox"},[t("div",[e._m(0),t("div",{directives:[{name:"show",rawName:"v-show",value:!e.allowHangup&&e.messageOpen,expression:"!allowHangup && messageOpen"}],staticClass:"chat-box"},[t("h5",[e._v("收消息")]),t("p",[e._v(e._s(e.receiveText))])])]),t("div",[t("div",{staticClass:"video-box"},[t("video",{attrs:{src:"",id:"rtcB",controls:"",autoplay:""}}),t("h5",[e._v("B")]),t("button",{attrs:{disabled:e.allowCall},on:{click:e.call}},[e._v("发起连接")]),t("button",{attrs:{disabled:e.allowHangup},on:{click:e.hangup}},[e._v("hangup")])]),t("div",{directives:[{name:"show",rawName:"v-show",value:!e.allowHangup&&e.messageOpen,expression:"!allowHangup && messageOpen"}],staticClass:"chat-box"},[t("h5",[e._v("发消息")]),t("textarea",{directives:[{name:"model",rawName:"v-model",value:e.sendText,expression:"sendText"}],domProps:{value:e.sendText},on:{input:function(n){n.target.composing||(e.sendText=n.target.value)}}}),t("br"),t("button",{on:{click:e.send}},[e._v("发送")])])])])])},c=[function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("div",{staticClass:"video-box"},[t("video",{attrs:{src:"",id:"rtcA",controls:"",autoplay:""}}),t("h5",[e._v("A")])])}],o=t("6ec7"),s=t("6932"),r=(t("e4d7"),t("8ada"),t("e795"),{name:"local1",data:function(){return{peerA:null,peerB:null,channelA:null,channelB:null,offerOption:{offerToReceiveAudio:1,offerToReceiveVideo:1},allowCall:!0,allowHangup:!0,messageOpen:!1,sendText:"",receiveText:""}},methods:{send:function(){this.channelB.send(JSON.stringify({name:this.sendText})),this.sendText=""},start:function(){this.state="2",this.newRecognition.start()},stop:function(){this.state="1",this.newRecognition.stop()},call:function(){var e=this;return Object(s["a"])(Object(o["a"])().m((function n(){var t,a;return Object(o["a"])().w((function(n){while(1)switch(n.p=n.n){case 0:return e.peerA&&e.peerB||e.initPeer(),n.p=1,n.n=2,e.peerB.createOffer(e.offerOption);case 2:return t=n.v,n.n=3,e.onCreateOffer(t);case 3:n.n=5;break;case 4:n.p=4,a=n.v,console.log("createOffer: ",a);case 5:e.allowCall=!0,e.allowHangup=!1;case 6:return n.a(2)}}),n,null,[[1,4]])})))()},hangup:function(){this.peerA.close(),this.peerB.close(),this.channelA.close(),this.channelB.close(),this.peerA=null,this.peerB=null,this.channelA=null,this.channelB=null,this.sendText="",this.receiveText="",this.allowCall=!1,this.allowHangup=!0},onCreateOffer:function(e){var n=this;return Object(s["a"])(Object(o["a"])().m((function t(){var a,c,s,r;return Object(o["a"])().w((function(t){while(1)switch(t.p=t.n){case 0:return t.p=0,t.n=1,n.peerB.setLocalDescription(e);case 1:t.n=3;break;case 2:t.p=2,c=t.v,console.log("Offer-setLocalDescription: ",c);case 3:return t.p=3,t.n=4,n.peerA.setRemoteDescription(e);case 4:t.n=6;break;case 5:t.p=5,s=t.v,console.log("Offer-setRemoteDescription: ",s);case 6:return t.p=6,t.n=7,n.peerA.createAnswer();case 7:return a=t.v,t.n=8,n.onCreateAnswer(a);case 8:t.n=10;break;case 9:t.p=9,r=t.v,console.log("createAnswer: ",r);case 10:return t.a(2)}}),t,null,[[6,9],[3,5],[0,2]])})))()},onCreateAnswer:function(e){var n=this;return Object(s["a"])(Object(o["a"])().m((function t(){var a,c;return Object(o["a"])().w((function(t){while(1)switch(t.p=t.n){case 0:return t.p=0,t.n=1,n.peerA.setLocalDescription(e);case 1:t.n=3;break;case 2:t.p=2,a=t.v,console.log("answer-setLocalDescription: ",a);case 3:return t.p=3,t.n=4,n.peerB.setRemoteDescription(e);case 4:t.n=6;break;case 5:t.p=5,c=t.v,console.log("answer-setRemoteDescription: ",c);case 6:return t.a(2)}}),t,null,[[3,5],[0,2]])})))()},initPeer:function(){var e=this,n=window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection;this.peerA=new n,this.peerA.addStream(this.localstream),this.peerA.onicecandidate=function(n){n.candidate&&e.peerB.addIceCandidate(n.candidate)},this.peerA.ondatachannel=function(n){console.log(n),e.channelA=n.channel,e.channelA.binaryType="arraybuffer",e.channelA.onopen=function(e){console.log("channelA onopen",e)},e.channelA.onclose=function(e){console.log("channelA onclose",e)},e.channelA.onmessage=function(n){e.receiveText=JSON.parse(n.data).name,console.log("channelA onmessage",n.data)}},this.peerB=new n,this.peerB.onaddstream=function(e){console.log("event-stream",e);var n=document.querySelector("#rtcB");n.srcObject=e.stream},this.channelB=this.peerB.createDataChannel("messagechannel"),console.log("this.channelB",this.channelB),this.channelB.binaryType="arraybuffer",this.channelB.onopen=function(n){console.log(1),console.log("channelB onopen",n),e.messageOpen=!0},this.channelB.onclose=function(e){console.log(1),console.log("channelB onclose",e)},this.peerB.onicecandidate=function(n){n.candidate&&e.peerA.addIceCandidate(n.candidate)},this.allowCall=!1},createMedia:function(){var e=this;return Object(s["a"])(Object(o["a"])().m((function n(){var t;return Object(o["a"])().w((function(n){while(1)switch(n.n){case 0:return n.n=1,navigator.mediaDevices.getUserMedia({audio:!0,video:!0});case 1:e.localstream=n.v,console.log(e.localstream),console.log(e.localstream.getVideoTracks(),e.localstream.getAudioTracks()),t=document.querySelector("#rtcA"),t.srcObject=e.localstream,e.initPeer();case 2:return n.a(2)}}),n)})))()}},mounted:function(){var e=this;this.$nextTick((function(){e.createMedia()}))}}),i=r,l=(t("ac77"),t("1805")),u=Object(l["a"])(i,a,c,!1,null,null,null);n["default"]=u.exports},ac77:function(e,n,t){"use strict";t("4c91")}}]);