|
@@ -1,8 +1,8 @@
|
|
|
<template>
|
|
|
<div class="trtccom" v-if="show">
|
|
|
<Device @switchDevice="switchDevice" @canUseDevice="canUseDevice" />
|
|
|
- <div class="local" id="local" v-if="isJoined&&role=='leader'"></div>
|
|
|
- <div class="local" :id="clientId" v-if="isJoined&&role=='customer'&&clientId"></div>
|
|
|
+ <div class="local" id="local" v-if="isJoined && role == 'leader'"></div>
|
|
|
+ <div class="local" :id="clientId" v-if="isJoined && role == 'customer' && clientId"></div>
|
|
|
<div class="videoBox userVideo" v-show="props.videoMuted">
|
|
|
<img :src="require('@/assets/images/rtcLive/avatar_small@2x.png')" alt="" />
|
|
|
<img class="loadingTip" :src="require('@/assets/images/rtcLive/loading@2x.png')" alt="" />
|
|
@@ -23,18 +23,14 @@ const emit = defineEmits(["audioMuted", "videoMuted"]);
|
|
|
const store = useStore();
|
|
|
|
|
|
const show = ref(false);
|
|
|
-const clientId = ref('');
|
|
|
-
|
|
|
+const clientId = ref("");
|
|
|
|
|
|
const role = ref(browser.getURLParam("role"));
|
|
|
|
|
|
-
|
|
|
-
|
|
|
const isJoined = computed(() => store.getters["rtc/isJoined"]);
|
|
|
const isPublished = computed(() => store.getters["rtc/isPublished"]);
|
|
|
const userSig = computed(() => store.getters["rtc/userSig"]);
|
|
|
|
|
|
-
|
|
|
const initParamsStates = computed(
|
|
|
() => !!(store.getters["rtc/sdkAppId"] && store.getters["rtc/secretKey"] && store.getters["rtc/roomId"] && store.getters["rtc/userId"])
|
|
|
);
|
|
@@ -83,7 +79,7 @@ TRTC.checkSystemRequirements().then((checkResult) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-async function createLocalStream(video=true) {
|
|
|
+async function createLocalStream(video = true) {
|
|
|
try {
|
|
|
localStream = TRTC.createStream({
|
|
|
userId: store.getters["rtc/userId"],
|
|
@@ -129,6 +125,12 @@ async function handleJoin() {
|
|
|
|
|
|
await createLocalStream();
|
|
|
await handlePublish();
|
|
|
+
|
|
|
+ localClient.on("stream-added", (event) => {
|
|
|
+ const remoteStream = event.stream;
|
|
|
+ // //订阅远端流
|
|
|
+ localClient.subscribe(remoteStream);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
async function handlePublish() {
|
|
@@ -155,14 +157,15 @@ async function handleStartShare() {
|
|
|
try {
|
|
|
await shareClient.join();
|
|
|
await shareClient.publish();
|
|
|
- console.log('Start share screen success');
|
|
|
+ console.log("Start share screen success");
|
|
|
store.isShared = true;
|
|
|
} catch (error) {
|
|
|
console.error(`Start share error: ${error.message_}`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function handleClientJoin() {if (!initParamsStates.value) {
|
|
|
+async function handleClientJoin() {
|
|
|
+ if (!initParamsStates.value) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -176,6 +179,7 @@ async function handleClientJoin() {if (!initParamsStates.value) {
|
|
|
installEventHandlers();
|
|
|
|
|
|
await localClient.join({ roomId: parseInt(store.getters["rtc/roomId"], 10) });
|
|
|
+
|
|
|
store.commit("rtc/setIsJoined", true);
|
|
|
} catch (error) {
|
|
|
console.error(error, "error-----------");
|
|
@@ -183,25 +187,9 @@ async function handleClientJoin() {if (!initParamsStates.value) {
|
|
|
|
|
|
await createLocalStream(false);
|
|
|
await handlePublish();
|
|
|
-
|
|
|
- localClient.on('stream-subscribed', handleSubscribed);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-async function handleSubscribed(event) {
|
|
|
- const remoteStream = event.stream;
|
|
|
- clientId.value = remoteStream.getId();
|
|
|
- await nextTick();
|
|
|
- remoteStream
|
|
|
- .play(clientId.value)
|
|
|
- .then(() => {
|
|
|
- console.log(`RemoteStream play success`);
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.log(`RemoteStream play failed: error: ${error.message_}`);
|
|
|
- });
|
|
|
-}
|
|
|
+async function handleSubscribed(event) {}
|
|
|
|
|
|
async function handleUnpublish() {
|
|
|
if (!isJoined.value) {
|
|
@@ -315,7 +303,7 @@ function handleStreamAdded(event) {
|
|
|
const id = remoteStream.getId();
|
|
|
const userId = remoteStream.getUserId();
|
|
|
|
|
|
- if (remoteStream.getUserId() === `share_${store.userId}`) {
|
|
|
+ if (remoteStream.getUserId() === store.getters["rtc/userId"]) {
|
|
|
// don't need to screen shared by us
|
|
|
localClient.unsubscribe(remoteStream).catch((error) => {
|
|
|
console.error(`unsubscribe failed: ${error.message_}`);
|
|
@@ -328,10 +316,24 @@ function handleStreamAdded(event) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function handleStreamSubscribed(event) {
|
|
|
- const remoteStream = event.stream;
|
|
|
- const userId = remoteStream.getUserId();
|
|
|
- console.log(`RemoteStream subscribed: [${userId}]`);
|
|
|
+async function handleStreamSubscribed(event) {
|
|
|
+ if (role.value == "customer") {
|
|
|
+ const remoteStream = event.stream;
|
|
|
+ clientId.value = remoteStream.getId();
|
|
|
+ await nextTick();
|
|
|
+ remoteStream
|
|
|
+ .play(clientId.value)
|
|
|
+ .then(() => {
|
|
|
+ console.log(`RemoteStream play success`,88888888888888888888);
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.log(`RemoteStream play failed: error: ${error.message_}`);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // const remoteStream = event.stream;
|
|
|
+ // const userId = remoteStream.getUserId();
|
|
|
+ // console.log(`RemoteStream subscribed: [${userId}]`);
|
|
|
}
|
|
|
|
|
|
function handleStreamRemoved(event) {
|
|
@@ -365,10 +367,10 @@ let switchDevice = async ({ videoId, audioId }) => {
|
|
|
let canUseDevice = () => {
|
|
|
console.log("可用");
|
|
|
|
|
|
- if (role.value == 'leader') {
|
|
|
+ if (role.value == "leader") {
|
|
|
handleJoin();
|
|
|
- } else{
|
|
|
- handleClientJoin()
|
|
|
+ } else {
|
|
|
+ handleClientJoin();
|
|
|
}
|
|
|
};
|
|
|
</script>
|