|
@@ -7,12 +7,15 @@
|
|
|
<div class="detail">
|
|
<div class="detail">
|
|
|
<div class="top">
|
|
<div class="top">
|
|
|
<span class="tag">未开播</span>
|
|
<span class="tag">未开播</span>
|
|
|
|
|
+ <button @click="addTrack">addTrack</button>
|
|
|
|
|
+ <button @click="handleMedia">handleMedia</button>
|
|
|
|
|
+ <button @click="batchSendOffer">batchSendOffer</button>
|
|
|
<!-- 房东的猫livehouse/音乐节 -->
|
|
<!-- 房东的猫livehouse/音乐节 -->
|
|
|
- {{ networkStore.rtcMap.get(roomId)?.rtcStatus }}
|
|
|
|
|
|
|
+ {{ networkStore.getRtcMap(roomId)?.rtcStatus }}
|
|
|
</div>
|
|
</div>
|
|
|
<div class="bottom">
|
|
<div class="bottom">
|
|
|
<span class="tag">UP 3</span>
|
|
<span class="tag">UP 3</span>
|
|
|
- up名字
|
|
|
|
|
|
|
+ {{ getSocketId() }}
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -69,13 +72,13 @@
|
|
|
</div>
|
|
</div>
|
|
|
<div class="user-list">
|
|
<div class="user-list">
|
|
|
<div
|
|
<div
|
|
|
- v-for="(item, index) in userList"
|
|
|
|
|
|
|
+ v-for="(item, index) in liveUserList"
|
|
|
:key="index"
|
|
:key="index"
|
|
|
class="item"
|
|
class="item"
|
|
|
>
|
|
>
|
|
|
<div class="info">
|
|
<div class="info">
|
|
|
<div class="avatar"></div>
|
|
<div class="avatar"></div>
|
|
|
- <div class="nickname">{{ item.nickname }}</div>
|
|
|
|
|
|
|
+ <div class="nickname">{{ item.socketId }}</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="expr">{{ item.expr }}</div>
|
|
<div class="expr">{{ item.expr }}</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -102,7 +105,7 @@
|
|
|
import { onMounted, ref, watch } from 'vue';
|
|
import { onMounted, ref, watch } from 'vue';
|
|
|
import { useRoute } from 'vue-router';
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
|
|
|
-import { liveTypeEnum } from '@/interface';
|
|
|
|
|
|
|
+import { IAdminIn, liveTypeEnum } from '@/interface';
|
|
|
import { WebRTCClass } from '@/network/webRtc';
|
|
import { WebRTCClass } from '@/network/webRtc';
|
|
|
import {
|
|
import {
|
|
|
WebSocketClass,
|
|
WebSocketClass,
|
|
@@ -113,22 +116,26 @@ import { useAppStore } from '@/store/app';
|
|
|
import { useNetworkStore } from '@/store/network';
|
|
import { useNetworkStore } from '@/store/network';
|
|
|
|
|
|
|
|
const networkStore = useNetworkStore();
|
|
const networkStore = useNetworkStore();
|
|
|
-
|
|
|
|
|
|
|
+const route = useRoute();
|
|
|
|
|
+const appStore = useAppStore();
|
|
|
const roomIdRef = ref<HTMLInputElement>();
|
|
const roomIdRef = ref<HTMLInputElement>();
|
|
|
const joinRef = ref<HTMLButtonElement>();
|
|
const joinRef = ref<HTMLButtonElement>();
|
|
|
const leaveRef = ref<HTMLButtonElement>();
|
|
const leaveRef = ref<HTMLButtonElement>();
|
|
|
-const roomId = ref<string>('19990507');
|
|
|
|
|
|
|
+const defaultRoomId = '19990507';
|
|
|
|
|
+const roomId = ref<string>(defaultRoomId);
|
|
|
const websocketInstant = ref<WebSocketClass>();
|
|
const websocketInstant = ref<WebSocketClass>();
|
|
|
-// const userList = ref<{ id: string; rooms: string[] }[]>([]);
|
|
|
|
|
|
|
+// const liveUserList = ref<{ id: string; rooms: string[] }[]>([]);
|
|
|
|
|
+const isDone = ref(false);
|
|
|
const muted = ref(true);
|
|
const muted = ref(true);
|
|
|
const localVideoRef = ref<HTMLVideoElement>();
|
|
const localVideoRef = ref<HTMLVideoElement>();
|
|
|
const localStream = ref();
|
|
const localStream = ref();
|
|
|
const currType = ref(liveTypeEnum.screen); // 1:摄像头,2:录屏
|
|
const currType = ref(liveTypeEnum.screen); // 1:摄像头,2:录屏
|
|
|
const id = ref('');
|
|
const id = ref('');
|
|
|
-
|
|
|
|
|
-const route = useRoute();
|
|
|
|
|
-const appStore = useAppStore();
|
|
|
|
|
|
|
+const joined = ref(false);
|
|
|
|
|
+const rtcNum = ref(1);
|
|
|
const isAdmin = ref(route.query.id === '1234');
|
|
const isAdmin = ref(route.query.id === '1234');
|
|
|
|
|
+const offerSended = ref(new Set());
|
|
|
|
|
+const answerSended = ref(new Set());
|
|
|
|
|
|
|
|
const giftList = ref([
|
|
const giftList = ref([
|
|
|
{ name: '鲜花', ico: '', price: '免费' },
|
|
{ name: '鲜花', ico: '', price: '免费' },
|
|
@@ -155,12 +162,18 @@ const msgList = ref([
|
|
|
{ nickname: '234232', msg: 'shgd544' },
|
|
{ nickname: '234232', msg: 'shgd544' },
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
-const userList = ref([
|
|
|
|
|
- { nickname: '鲜花', avatar: '423425', expr: 100 },
|
|
|
|
|
- { nickname: '肥宅水', avatar: 'sdgdsgsg', expr: 100 },
|
|
|
|
|
- { nickname: '小鸡腿', avatar: '63463gsd', expr: 100 },
|
|
|
|
|
- { nickname: '大鸡腿', avatar: '46326fb26', expr: 100 },
|
|
|
|
|
- { nickname: '一杯咖啡', avatar: 'shgd544', expr: 100 },
|
|
|
|
|
|
|
+const liveUserList = ref<
|
|
|
|
|
+ {
|
|
|
|
|
+ socketId: string;
|
|
|
|
|
+ avatar: string;
|
|
|
|
|
+ expr: number;
|
|
|
|
|
+ }[]
|
|
|
|
|
+>([
|
|
|
|
|
+ // { nickname: '鲜花', avatar: '423425', expr: 100 },
|
|
|
|
|
+ // { nickname: '肥宅水', avatar: 'sdgdsgsg', expr: 100 },
|
|
|
|
|
+ // { nickname: '小鸡腿', avatar: '63463gsd', expr: 100 },
|
|
|
|
|
+ // { nickname: '大鸡腿', avatar: '46326fb26', expr: 100 },
|
|
|
|
|
+ // { nickname: '一杯咖啡', avatar: 'shgd544', expr: 100 },
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
interface IOffer {
|
|
interface IOffer {
|
|
@@ -168,6 +181,9 @@ interface IOffer {
|
|
|
roomId: string;
|
|
roomId: string;
|
|
|
data: {
|
|
data: {
|
|
|
sdp: any;
|
|
sdp: any;
|
|
|
|
|
+ target: string;
|
|
|
|
|
+ sender: string;
|
|
|
|
|
+ receiver: string;
|
|
|
};
|
|
};
|
|
|
isAdmin: boolean;
|
|
isAdmin: boolean;
|
|
|
}
|
|
}
|
|
@@ -197,24 +213,31 @@ onMounted(() => {
|
|
|
sendJoin();
|
|
sendJoin();
|
|
|
localVideoRef.value?.addEventListener('loadstart', () => {
|
|
localVideoRef.value?.addEventListener('loadstart', () => {
|
|
|
console.warn('视频流-loadstart');
|
|
console.warn('视频流-loadstart');
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
|
|
+ const rtc = networkStore.getRtcMap(roomId.value);
|
|
|
if (!rtc) return;
|
|
if (!rtc) return;
|
|
|
rtc.rtcStatus.loadstart = true;
|
|
rtc.rtcStatus.loadstart = true;
|
|
|
rtc.update();
|
|
rtc.update();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- localVideoRef.value?.addEventListener('loadedmetadata', async () => {
|
|
|
|
|
|
|
+ localVideoRef.value?.addEventListener('abort', () => {
|
|
|
|
|
+ console.warn('视频流-abort');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ localVideoRef.value?.addEventListener('pause', () => {
|
|
|
|
|
+ console.warn('视频流-pause');
|
|
|
|
|
+ });
|
|
|
|
|
+ localVideoRef.value?.addEventListener('error', () => {
|
|
|
|
|
+ console.warn('视频流-error');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ localVideoRef.value?.addEventListener('loadedmetadata', () => {
|
|
|
console.warn('视频流-loadedmetadata');
|
|
console.warn('视频流-loadedmetadata');
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
|
|
+ const rtc = networkStore.getRtcMap(roomId.value);
|
|
|
if (!rtc) return;
|
|
if (!rtc) return;
|
|
|
rtc.rtcStatus.loadedmetadata = true;
|
|
rtc.rtcStatus.loadedmetadata = true;
|
|
|
rtc.update();
|
|
rtc.update();
|
|
|
if (isAdmin.value) {
|
|
if (isAdmin.value) {
|
|
|
- websocketInstant.value?.send({
|
|
|
|
|
- msgType: WsMsgTypeEnum.adminIn,
|
|
|
|
|
- data: {},
|
|
|
|
|
- });
|
|
|
|
|
- await sendOffer();
|
|
|
|
|
|
|
+ batchSendOffer();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -230,7 +253,7 @@ watch(
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
function getSocketId() {
|
|
function getSocketId() {
|
|
|
- return networkStore.wsMap.get(roomId.value!)?.socketIo?.id;
|
|
|
|
|
|
|
+ return networkStore.wsMap.get(roomId.value!)?.socketIo?.id || '-1';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function sendJoin() {
|
|
function sendJoin() {
|
|
@@ -239,14 +262,36 @@ function sendJoin() {
|
|
|
instance.send({ msgType: WsMsgTypeEnum.join, data: {} });
|
|
instance.send({ msgType: WsMsgTypeEnum.join, data: {} });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function join() {
|
|
|
|
|
|
|
+function join() {
|
|
|
console.log('join的房间号', roomId.value);
|
|
console.log('join的房间号', roomId.value);
|
|
|
if (!roomId.value) {
|
|
if (!roomId.value) {
|
|
|
console.error('房间号不能为空!');
|
|
console.error('房间号不能为空!');
|
|
|
alert('房间号不能为空!');
|
|
alert('房间号不能为空!');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ handleMedia();
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+function batchSendOffer() {
|
|
|
|
|
+ liveUserList.value.forEach(async (item) => {
|
|
|
|
|
+ if (
|
|
|
|
|
+ !offerSended.value.has(item.socketId) &&
|
|
|
|
|
+ item.socketId !== getSocketId()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ await startNewWebRtc(item.socketId);
|
|
|
|
|
+ await addTrack();
|
|
|
|
|
+ console.warn('new WebRTCClass完成');
|
|
|
|
|
+ console.log('执行sendOffer', {
|
|
|
|
|
+ sender: getSocketId(),
|
|
|
|
|
+ receiver: item.socketId,
|
|
|
|
|
+ });
|
|
|
|
|
+ sendOffer({ sender: getSocketId(), receiver: item.socketId });
|
|
|
|
|
+ offerSended.value.add(item.socketId);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function handleMedia() {
|
|
|
if (isAdmin.value) {
|
|
if (isAdmin.value) {
|
|
|
try {
|
|
try {
|
|
|
if (currType.value === liveTypeEnum.camera) {
|
|
if (currType.value === liveTypeEnum.camera) {
|
|
@@ -280,59 +325,63 @@ function initReceive() {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 当前所有在线用户
|
|
// 当前所有在线用户
|
|
|
- instance.socketIo.on(WsMsgTypeEnum.adminIn, (data) => {
|
|
|
|
|
|
|
+ instance.socketIo.on(WsMsgTypeEnum.adminIn, (data: IAdminIn) => {
|
|
|
console.log('【websocket】收到管理员正在直播', data);
|
|
console.log('【websocket】收到管理员正在直播', data);
|
|
|
- sendOffer();
|
|
|
|
|
|
|
+ if (isDone.value) return;
|
|
|
|
|
+ // sendOffer({ sender: getSocketId(), receiver: data.socketId });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 当前所有在线用户
|
|
// 当前所有在线用户
|
|
|
instance.socketIo.on(WsMsgTypeEnum.liveUser, (data) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.liveUser, (data) => {
|
|
|
console.log('【websocket】当前所有在线用户');
|
|
console.log('【websocket】当前所有在线用户');
|
|
|
if (!instance) return;
|
|
if (!instance) return;
|
|
|
- userList.value = data;
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 收到offer
|
|
// 收到offer
|
|
|
instance.socketIo.on(WsMsgTypeEnum.offer, async (data: IOffer) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.offer, async (data: IOffer) => {
|
|
|
console.warn('【websocket】收到offer', data);
|
|
console.warn('【websocket】收到offer', data);
|
|
|
if (!instance) return;
|
|
if (!instance) return;
|
|
|
- if (data.socketId !== getSocketId()) {
|
|
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
- if (!rtc) return;
|
|
|
|
|
- console.log('收到offer,并且这个offer不是我发的', data);
|
|
|
|
|
|
|
+ if (data.data.receiver === getSocketId()) {
|
|
|
|
|
+ console.log('收到offer,这个offer是发给我的');
|
|
|
|
|
+ const rtc = startNewWebRtc(data.data.sender);
|
|
|
await rtc.setRemoteDescription(data.data.sdp);
|
|
await rtc.setRemoteDescription(data.data.sdp);
|
|
|
const sdp = await rtc.createAnswer();
|
|
const sdp = await rtc.createAnswer();
|
|
|
await rtc.setLocalDescription(sdp);
|
|
await rtc.setLocalDescription(sdp);
|
|
|
websocketInstant.value?.send({
|
|
websocketInstant.value?.send({
|
|
|
msgType: WsMsgTypeEnum.answer,
|
|
msgType: WsMsgTypeEnum.answer,
|
|
|
- data: { sdp },
|
|
|
|
|
|
|
+ data: { sdp, sender: getSocketId(), receiver: data.data.sender },
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- console.log('收到offer,并且这个offer是我发的');
|
|
|
|
|
|
|
+ console.log('收到offer,但是这个offer不是发给我的');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 收到answer
|
|
// 收到answer
|
|
|
instance.socketIo.on(WsMsgTypeEnum.answer, async (data: IOffer) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.answer, async (data: IOffer) => {
|
|
|
console.warn('【websocket】收到answer', data);
|
|
console.warn('【websocket】收到answer', data);
|
|
|
|
|
+ if (isDone.value) return;
|
|
|
if (!instance) return;
|
|
if (!instance) return;
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
|
|
+ const rtc = networkStore.getRtcMap(`${roomId.value}___${data.socketId}`);
|
|
|
|
|
+ console.log(rtc, '收到answer收到answer');
|
|
|
if (!rtc) return;
|
|
if (!rtc) return;
|
|
|
rtc.rtcStatus.answer = true;
|
|
rtc.rtcStatus.answer = true;
|
|
|
rtc.update();
|
|
rtc.update();
|
|
|
- if (data.socketId !== getSocketId()) {
|
|
|
|
|
- console.log('不是我发的answer');
|
|
|
|
|
|
|
+ if (data.data.receiver === getSocketId()) {
|
|
|
|
|
+ console.log('收到answer,这个answer是发给我的');
|
|
|
await rtc.setRemoteDescription(data.data.sdp);
|
|
await rtc.setRemoteDescription(data.data.sdp);
|
|
|
} else {
|
|
} else {
|
|
|
- console.log('是我发的answer');
|
|
|
|
|
|
|
+ console.log('收到answer,但这个answer不是发给我的');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 收到candidate
|
|
// 收到candidate
|
|
|
instance.socketIo.on(WsMsgTypeEnum.candidate, (data: ICandidate) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.candidate, (data: ICandidate) => {
|
|
|
- if (!instance) return;
|
|
|
|
|
console.warn('【websocket】收到candidate', data);
|
|
console.warn('【websocket】收到candidate', data);
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
|
|
+ if (isDone.value) return;
|
|
|
|
|
+ if (!instance) return;
|
|
|
|
|
+ const rtc =
|
|
|
|
|
+ networkStore.getRtcMap(`${roomId.value}___${data.socketId}`) ||
|
|
|
|
|
+ networkStore.getRtcMap(roomId.value);
|
|
|
if (!rtc) return;
|
|
if (!rtc) return;
|
|
|
if (data.socketId !== getSocketId()) {
|
|
if (data.socketId !== getSocketId()) {
|
|
|
console.log('不是我发的candidate');
|
|
console.log('不是我发的candidate');
|
|
@@ -345,6 +394,7 @@ function initReceive() {
|
|
|
?.addIceCandidate(candidate)
|
|
?.addIceCandidate(candidate)
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
console.log('candidate成功');
|
|
console.log('candidate成功');
|
|
|
|
|
+ // rtc.handleStream();
|
|
|
})
|
|
})
|
|
|
.catch((err) => {
|
|
.catch((err) => {
|
|
|
console.error('candidate失败', err);
|
|
console.error('candidate失败', err);
|
|
@@ -363,19 +413,25 @@ function initReceive() {
|
|
|
// 用户加入房间
|
|
// 用户加入房间
|
|
|
instance.socketIo.on(WsMsgTypeEnum.joined, (data) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.joined, (data) => {
|
|
|
console.log('【websocket】用户加入房间完成', data);
|
|
console.log('【websocket】用户加入房间完成', data);
|
|
|
- if (!instance) return;
|
|
|
|
|
- console.warn('开始new WebRTCClass');
|
|
|
|
|
- const rtc = new WebRTCClass({ roomId: roomId.value });
|
|
|
|
|
- rtc.rtcStatus.joined = true;
|
|
|
|
|
- rtc.update();
|
|
|
|
|
|
|
+ joined.value = true;
|
|
|
|
|
+ liveUserList.value.push({
|
|
|
|
|
+ avatar: 'red',
|
|
|
|
|
+ socketId: `${getSocketId()}`,
|
|
|
|
|
+ expr: 1,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 其他用户加入房间
|
|
// 其他用户加入房间
|
|
|
instance.socketIo.on(WsMsgTypeEnum.otherJoin, (data) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.otherJoin, (data) => {
|
|
|
console.log('【websocket】其他用户加入房间', data);
|
|
console.log('【websocket】其他用户加入房间', data);
|
|
|
- if (!instance) return;
|
|
|
|
|
- if (isAdmin.value) {
|
|
|
|
|
- sendOffer();
|
|
|
|
|
|
|
+ liveUserList.value.push({
|
|
|
|
|
+ avatar: 'red',
|
|
|
|
|
+ socketId: data.socketId,
|
|
|
|
|
+ expr: 1,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('当前所有在线用户', JSON.stringify(liveUserList.value));
|
|
|
|
|
+ if (isAdmin.value && joined.value) {
|
|
|
|
|
+ batchSendOffer();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -392,57 +448,85 @@ function initReceive() {
|
|
|
instance.socketIo.on(WsMsgTypeEnum.leaved, (data) => {
|
|
instance.socketIo.on(WsMsgTypeEnum.leaved, (data) => {
|
|
|
console.log('【websocket】用户离开房间完成', data);
|
|
console.log('【websocket】用户离开房间完成', data);
|
|
|
if (!instance) return;
|
|
if (!instance) return;
|
|
|
- instance.close();
|
|
|
|
|
|
|
+ const res = liveUserList.value.filter(
|
|
|
|
|
+ (item) => item.socketId !== data.socketId
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log('当前所有在线用户', JSON.stringify(res));
|
|
|
|
|
+ liveUserList.value = res;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function startMediaDevices() {
|
|
async function startMediaDevices() {
|
|
|
currType.value = liveTypeEnum.camera;
|
|
currType.value = liveTypeEnum.camera;
|
|
|
- // WARN navigator.mediaDevices在localhost和https才能用,http://192.168.1.103:8000局域网用不了
|
|
|
|
|
- const event = await navigator.mediaDevices.getUserMedia({
|
|
|
|
|
- video: true,
|
|
|
|
|
- audio: true,
|
|
|
|
|
- });
|
|
|
|
|
- console.log('getUserMedia成功', event);
|
|
|
|
|
- if (!localVideoRef.value) return;
|
|
|
|
|
- localVideoRef.value.srcObject = event;
|
|
|
|
|
- localStream.value = event;
|
|
|
|
|
- console.log('加轨1');
|
|
|
|
|
- localStream.value.getTracks().forEach((track) => {
|
|
|
|
|
- networkStore.rtcMap.get(roomId.value)?.addTrack(track, localStream.value);
|
|
|
|
|
|
|
+ if (!localStream.value) {
|
|
|
|
|
+ // WARN navigator.mediaDevices在localhost和https才能用,http://192.168.1.103:8000局域网用不了
|
|
|
|
|
+ const event = await navigator.mediaDevices.getUserMedia({
|
|
|
|
|
+ video: true,
|
|
|
|
|
+ audio: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('getUserMedia成功', event);
|
|
|
|
|
+ if (!localVideoRef.value) return;
|
|
|
|
|
+ localVideoRef.value.srcObject = event;
|
|
|
|
|
+ localStream.value = event;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const isAddTrack = ref(false);
|
|
|
|
|
+function addTrack() {
|
|
|
|
|
+ if (!localStream.value) return;
|
|
|
|
|
+ // if (isAddTrack.value || !localStream.value) return;
|
|
|
|
|
+ liveUserList.value.forEach((item) => {
|
|
|
|
|
+ if (item.socketId !== getSocketId()) {
|
|
|
|
|
+ localStream.value.getTracks().forEach((track) => {
|
|
|
|
|
+ const rtc = networkStore.getRtcMap(
|
|
|
|
|
+ `${roomId.value}___${item.socketId}`
|
|
|
|
|
+ );
|
|
|
|
|
+ rtc?.addTrack(track, localStream.value);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
+ isAddTrack.value = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function startGetDisplayMedia() {
|
|
async function startGetDisplayMedia() {
|
|
|
currType.value = liveTypeEnum.screen;
|
|
currType.value = liveTypeEnum.screen;
|
|
|
- // WARN navigator.mediaDevices.getDisplayMedia在localhost和https才能用,http://192.168.1.103:8000局域网用不了
|
|
|
|
|
- const event = await navigator.mediaDevices.getDisplayMedia({
|
|
|
|
|
- video: true,
|
|
|
|
|
- audio: true,
|
|
|
|
|
- });
|
|
|
|
|
- console.log('getDisplayMedia成功', event);
|
|
|
|
|
- if (!localVideoRef.value) return;
|
|
|
|
|
- localVideoRef.value.srcObject = event;
|
|
|
|
|
- localStream.value = event;
|
|
|
|
|
- console.log('加轨2');
|
|
|
|
|
- localStream.value.getTracks().forEach((track) => {
|
|
|
|
|
- console.log(track, networkStore.rtcMap.get(roomId.value));
|
|
|
|
|
- networkStore.rtcMap.get(roomId.value)?.addTrack(track, localStream.value);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (!localStream.value) {
|
|
|
|
|
+ // WARN navigator.mediaDevices.getDisplayMedia在localhost和https才能用,http://192.168.1.103:8000局域网用不了
|
|
|
|
|
+ const event = await navigator.mediaDevices.getDisplayMedia({
|
|
|
|
|
+ video: true,
|
|
|
|
|
+ audio: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('getDisplayMedia成功', event);
|
|
|
|
|
+ if (!localVideoRef.value) return;
|
|
|
|
|
+ localVideoRef.value.srcObject = event;
|
|
|
|
|
+ localStream.value = event;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function sendOffer() {
|
|
|
|
|
|
|
+async function sendOffer({
|
|
|
|
|
+ sender,
|
|
|
|
|
+ receiver,
|
|
|
|
|
+}: {
|
|
|
|
|
+ sender: string;
|
|
|
|
|
+ receiver: string;
|
|
|
|
|
+}) {
|
|
|
|
|
+ if (isDone.value) return;
|
|
|
if (!websocketInstant.value) return;
|
|
if (!websocketInstant.value) return;
|
|
|
- const rtc = networkStore.rtcMap.get(roomId.value);
|
|
|
|
|
|
|
+ const rtc = networkStore.getRtcMap(`${roomId.value}___${receiver}`);
|
|
|
if (!rtc) return;
|
|
if (!rtc) return;
|
|
|
- if (isAdmin.value) {
|
|
|
|
|
- const sdp = await rtc.createOffer();
|
|
|
|
|
- await rtc.setLocalDescription(sdp);
|
|
|
|
|
- websocketInstant.value.send({
|
|
|
|
|
- msgType: WsMsgTypeEnum.offer,
|
|
|
|
|
- data: { sdp },
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const sdp = await rtc.createOffer();
|
|
|
|
|
+ await rtc.setLocalDescription(sdp);
|
|
|
|
|
+ websocketInstant.value.send({
|
|
|
|
|
+ msgType: WsMsgTypeEnum.offer,
|
|
|
|
|
+ data: { sdp, sender, receiver },
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function startNewWebRtc(receiver: string) {
|
|
|
|
|
+ console.warn('开始new WebRTCClass', receiver);
|
|
|
|
|
+ const rtc = new WebRTCClass({ roomId: `${roomId.value}___${receiver}` });
|
|
|
|
|
+ rtc.rtcStatus.joined = true;
|
|
|
|
|
+ rtc.update();
|
|
|
|
|
+ return rtc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function leave() {
|
|
function leave() {
|
|
@@ -532,6 +616,7 @@ function leave() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
.video-wrap {
|
|
.video-wrap {
|
|
|
|
|
+ // height: 100px;
|
|
|
height: 500px;
|
|
height: 500px;
|
|
|
background-color: #18191c;
|
|
background-color: #18191c;
|
|
|
#localVideo {
|
|
#localVideo {
|