From f80e47e95e51575eabd574ae539ccbe40b4675d0 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Thu, 22 Oct 2020 15:48:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/regime/Liveing.vue | 52 ++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/views/regime/Liveing.vue b/src/views/regime/Liveing.vue index 7c129b2..84216b9 100644 --- a/src/views/regime/Liveing.vue +++ b/src/views/regime/Liveing.vue @@ -9,7 +9,7 @@
直播页面
- +
@@ -36,10 +36,10 @@
-
-
-
asdsada
- +
+
+
asdsada
+
@@ -204,7 +204,30 @@ export default defineComponent({ let localStream: any; let statie = true; let userSing = ''; - function pingmu(){ + let type = false; + async function qiehuan(){ + // 1 屏幕分享 2 摄像头 + client.unpublish(localStream) + localStream = type ? TRTC.createStream({ userid: 10, audio: true, screen: true }) : TRTC.createStream({ userId: 10, audio: true, video: true }); + type = !type; + localStream.initialize().then(()=>{ + client + .publish(localStream) + .catch((error: string) => { + console.error('本地流发布失败 ' + error); + }) + .then(() => { + const el = document.querySelector("#local_stream"); + if(el){ + el.innerHTML = "" + } + localStream.play('local_stream'); + console.log('本地流发布成功'); + }); + }); + + } + function pingmu(){ localStream = TRTC.createStream({ userid: 10, audio: true, screen: true }); localStream @@ -255,7 +278,19 @@ export default defineComponent({ mode: 'rtc', sdkAppId: '1400400340', userId: 10, - userSig: userSig + userSig: 'eJw1zMsKwjAUBNB-yVrqzatowaU7UcQgGNxEG5tLUGNSxQf*u7FWmM2cgXkRNVsVNxtJRVgBZNB1rO2pxQN2TP*aam9CwJpUVADkcAG-xd4DRptdSskAem3x*LUSOOdjoL0mbPLpvtx5rRbb4RIla86XBxNGKTePI391T64N6jQFgRu3ThPy-gBYczBk' + }); + client.on('stream-added', (event: { stream: any }) => { + const remoteStream = event.stream; + console.log('远端流增加: ' + remoteStream.getId()); + //订阅远端流 + client.subscribe(remoteStream); + }); + client.on('stream-subscribed', (event: { stream: any }) => { + const remoteStream = event.stream; + console.log('远端流订阅成功:' + remoteStream.getId()); + // 播放远端流 + remoteStream.play('s-' + remoteStream.getId()); }); client .join({ roomId: 11 }) @@ -293,7 +328,8 @@ export default defineComponent({ }) return{ - fenxiang + fenxiang, + qiehuan } }, });