From 24e5c4c50ccfa0db3b617cdef4984ffed21cf6f5 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Thu, 29 Oct 2020 15:46:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LivePlaying.vue | 1 - src/types/trtc-js-sdk.d.ts | 2 + src/views/regime/Liveing.vue | 76 +++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/components/LivePlaying.vue b/src/components/LivePlaying.vue index 28a6bcd..1ad4d06 100644 --- a/src/components/LivePlaying.vue +++ b/src/components/LivePlaying.vue @@ -8,7 +8,6 @@ width: 797px; height: 449px; border-radius: 17px; - background-color: #0f0; overflow: hidden; >video{ width: 100%; diff --git a/src/types/trtc-js-sdk.d.ts b/src/types/trtc-js-sdk.d.ts index 46c2043..70b0464 100644 --- a/src/types/trtc-js-sdk.d.ts +++ b/src/types/trtc-js-sdk.d.ts @@ -1,4 +1,6 @@ declare module 'trtc-js-sdk' { export function createClient(info: any): any export function createStream(info: any): any + export function checkSystemRequirements(): any + export function isScreenShareSupported(): any } diff --git a/src/views/regime/Liveing.vue b/src/views/regime/Liveing.vue index 73b36e2..03c0252 100644 --- a/src/views/regime/Liveing.vue +++ b/src/views/regime/Liveing.vue @@ -4,7 +4,7 @@
直播页面
- +
@@ -30,8 +30,8 @@ -
-
+
+
{{item.name}}
@@ -51,11 +51,7 @@
asdsada
--> -
-
-
测试
- -
+
@@ -219,11 +215,15 @@ export default defineComponent({ const roominfo = ref([]); console.log(useRoute()) const id = useRoute().query.id; - + TRTC.checkSystemRequirements().then((result: any) => { + if(!result) { + message.error("您的浏览器不支持视频通话,请下载新版chrome浏览器") + } + }) async function qiehuan(){ // 1 屏幕分享 2 摄像头 client.unpublish(localStream) - localStream = type ? TRTC.createStream({ userid: store.state.userinfo.memberid, audio: true, screen: true }) : TRTC.createStream({ userId: 10, audio: true, video: true }); + localStream = type ? TRTC.createStream({ userid: store.state.userinfo.memberid, audio: true, screen: true }) : TRTC.createStream({ userId: 10, audio: false, video: true }); type = !type; localStream.initialize().then(()=>{ client @@ -232,10 +232,7 @@ export default defineComponent({ console.error('本地流发布失败 ' + error); }) .then(() => { - const el = document.querySelector("#local_stream"); - if(el){ - el.innerHTML = "" - } + localStream.play('local_stream'); console.log('本地流发布成功'); }); @@ -243,21 +240,38 @@ export default defineComponent({ } async function pingmu(){ + const result = await TRTC.checkSystemRequirements() + console.log(result,11111) + if(!result) { + message.error("您的浏览器不支持屏幕分享,请下载新版chrome"); + return ; + } + localStream = TRTC.createStream({ userid: store.state.userinfo.memberid, audio: true, screen: true }); const id = localStream.getId(); await localStream .initialize() .catch((error: string) => { console.error('初始化本地流失败 ' + error); + message.error("请选择分享的内容") + + setTimeout(()=>{ + pingmu() + }, 1000) }) .then(() => { console.log('初始化本地流成功'); client .publish(localStream) .catch((error: string) => { - console.error('本地流发布失败 ' + error); + console.log('本地流发布失败 ' + error); + }) .then(() => { + const el = document.querySelector("#local_stream"); + if(el){ + el.innerHTML = "" + } localStream.play('local_stream'); console.log('本地流发布成功'); console.log(id , 123) @@ -280,6 +294,10 @@ export default defineComponent({ console.error('本地流发布失败 ' + error); }) .then(() => { + const el = document.querySelector("#local_stream"); + if(el){ + el.innerHTML = "" + } localStream.play('local_stream'); console.log('本地流发布成功'); console.log(id, 123) @@ -317,7 +335,7 @@ export default defineComponent({ remoteStream.play('s-' + remoteStream.userId_); }); client - .join({ roomId: roominfo.value.roomid }) + .join({ roomId: 12 }) .catch((error: string) => { console.error('进房失败 ' + error); }) @@ -333,12 +351,16 @@ export default defineComponent({ await client.unpublish(localStream).then(() => { // 关闭屏幕分享流 console.log("关闭") - client.leave().then(() => { - // leaving room success - console.log("关闭成功") - }).catch((error: string) => { - console.error('leaving room failed: ' + error); - }); + // client.leave().then(() => { + // // leaving room success + // console.log("关闭成功") + // }).catch((error: string) => { + // console.error('leaving room failed: ' + error); + // }); + const el = document.querySelector("#local_stream"); + if(el){ + el.innerHTML = "" + } }); statie ? await shexiang() : await pingmu(); statie = !statie; @@ -356,9 +378,15 @@ export default defineComponent({ } onMounted(async ()=>{ - userSing = await usersig(store.state.userinfo.memberid); + const si = setInterval(async ()=>{ + if(store.state.userinfo.memberid != 0 && store.state.userinfo.memberid){ + clearInterval(si); + userSing = await usersig(store.state.userinfo.memberid); + init(pingmu, userSing); + + } + }) - init(pingmu, userSing); }) return{