Compare commits
3 Commits
19b9621dee
...
e98cd2844d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e98cd2844d | ||
|
|
0de25a0544 | ||
|
|
ae36cb183b |
File diff suppressed because it is too large
Load Diff
@ -83,7 +83,7 @@ const updateTasks = () => {
|
|||||||
tasks.value = Array.from(
|
tasks.value = Array.from(
|
||||||
fileTransferMgrInstance
|
fileTransferMgrInstance
|
||||||
.getAllFileTransfers()
|
.getAllFileTransfers()
|
||||||
.flatMap((transfer) => transfer.getTasks())
|
.flatMap((transfer) => transfer.getTasks()),
|
||||||
);
|
);
|
||||||
// newTasks.forEach((task) => {
|
// newTasks.forEach((task) => {
|
||||||
// const index = tasks.value.findIndex(
|
// const index = tasks.value.findIndex(
|
||||||
@ -109,7 +109,7 @@ updateTasks();
|
|||||||
right: 0;
|
right: 0;
|
||||||
background: white;
|
background: white;
|
||||||
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
|
||||||
z-index: 1000;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.transfer-header {
|
.transfer-header {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
TransferStatus,
|
TransferStatus,
|
||||||
TransferTask,
|
TransferTask,
|
||||||
} from "./fileTransfer";
|
} from "./fileTransfer";
|
||||||
import { message, Modal, notification } from "ant-design-vue";
|
import { message, notification } from "ant-design-vue";
|
||||||
import {
|
import {
|
||||||
randomChars,
|
randomChars,
|
||||||
sign2peerid,
|
sign2peerid,
|
||||||
@ -86,7 +86,10 @@ class Peer extends EventTarget {
|
|||||||
|
|
||||||
// 保存 this 引用
|
// 保存 this 引用
|
||||||
const self = this;
|
const self = this;
|
||||||
|
let handled = false;
|
||||||
const onOk = async () => {
|
const onOk = async () => {
|
||||||
|
if (handled) return;
|
||||||
|
handled = true;
|
||||||
try {
|
try {
|
||||||
let stream: MediaStream;
|
let stream: MediaStream;
|
||||||
|
|
||||||
@ -104,7 +107,7 @@ class Peer extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
call.answer(stream);
|
call.answer(stream);
|
||||||
self.setupMediaConnection(call, type, stream);
|
self.setupMediaConnection(call, type, stream, type !== "desktop");
|
||||||
|
|
||||||
self.dispatchEvent(
|
self.dispatchEvent(
|
||||||
new CustomEvent(
|
new CustomEvent(
|
||||||
@ -112,6 +115,7 @@ class Peer extends EventTarget {
|
|||||||
{
|
{
|
||||||
detail: {
|
detail: {
|
||||||
peerId: call.peer,
|
peerId: call.peer,
|
||||||
|
role: type === "desktop" ? "sharer" : "caller",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -126,20 +130,34 @@ class Peer extends EventTarget {
|
|||||||
message.error("无法访问" + (type === "desktop" ? "屏幕" : "麦克风"));
|
message.error("无法访问" + (type === "desktop" ? "屏幕" : "麦克风"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const onReject = () => {
|
||||||
|
if (handled) return;
|
||||||
|
handled = true;
|
||||||
|
call.close();
|
||||||
|
message.info(
|
||||||
|
"已拒绝" + (type === "desktop" ? "屏幕共享" : "语音通话") + "请求",
|
||||||
|
);
|
||||||
|
};
|
||||||
if (getPermissionSet()[permission]) {
|
if (getPermissionSet()[permission]) {
|
||||||
await onOk();
|
await onOk();
|
||||||
|
} else if (type === "call") {
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent("media-request", {
|
||||||
|
detail: {
|
||||||
|
peerId: call.peer,
|
||||||
|
type,
|
||||||
|
accept: onOk,
|
||||||
|
reject: onReject,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
confirmWin(title, content, "接受", "拒绝")
|
confirmWin(title, content, "接受", "拒绝")
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await onOk();
|
await onOk();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
call.close();
|
onReject();
|
||||||
message.info(
|
|
||||||
"已拒绝" +
|
|
||||||
(type === "desktop" ? "屏幕共享" : "语音通话") +
|
|
||||||
"请求",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -199,23 +217,19 @@ class Peer extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建一个静音的音频流作为占位
|
const offerStream = this.createDesktopOfferStream();
|
||||||
const emptyStream = new MediaStream();
|
|
||||||
// 将音频轨道静音
|
|
||||||
emptyStream.getAudioTracks().forEach((track) => {
|
|
||||||
track.enabled = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const call = this.peer.call(sign2peerid(id), emptyStream, {
|
const call = this.peer.call(sign2peerid(id), offerStream, {
|
||||||
metadata: { type: "desktop" },
|
metadata: { type: "desktop" },
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setupMediaConnection(call, "desktop", emptyStream);
|
this.setupMediaConnection(call, "desktop", offerStream);
|
||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent("desktop-started", {
|
new CustomEvent("desktop-started", {
|
||||||
detail: {
|
detail: {
|
||||||
peerId: call.peer,
|
peerId: call.peer,
|
||||||
|
role: "viewer",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -227,6 +241,22 @@ class Peer extends EventTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private createDesktopOfferStream() {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = 1;
|
||||||
|
canvas.height = 1;
|
||||||
|
const context = canvas.getContext("2d");
|
||||||
|
context?.fillRect(0, 0, 1, 1);
|
||||||
|
|
||||||
|
const stream = canvas.captureStream(1);
|
||||||
|
const [track] = stream.getVideoTracks();
|
||||||
|
if (!track) {
|
||||||
|
throw new Error("无法创建桌面协商视频轨");
|
||||||
|
}
|
||||||
|
track.enabled = false;
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
async requestCall(id: string) {
|
async requestCall(id: string) {
|
||||||
if (!this.remoteConnection) {
|
if (!this.remoteConnection) {
|
||||||
notification.error({
|
notification.error({
|
||||||
@ -435,6 +465,7 @@ class Peer extends EventTarget {
|
|||||||
call: MediaConnection,
|
call: MediaConnection,
|
||||||
type: MediaType,
|
type: MediaType,
|
||||||
localStream: MediaStream | null = null,
|
localStream: MediaStream | null = null,
|
||||||
|
acceptRemoteStream = true,
|
||||||
) {
|
) {
|
||||||
const peerId = call.peer;
|
const peerId = call.peer;
|
||||||
this.updateMediaConnection(peerId, type, {
|
this.updateMediaConnection(peerId, type, {
|
||||||
@ -444,6 +475,7 @@ class Peer extends EventTarget {
|
|||||||
|
|
||||||
call.on("stream", (remoteStream: MediaStream) => {
|
call.on("stream", (remoteStream: MediaStream) => {
|
||||||
console.log("stream", remoteStream);
|
console.log("stream", remoteStream);
|
||||||
|
if (!acceptRemoteStream) return;
|
||||||
// 只有当流中包含相应类型的轨道时才保存连接
|
// 只有当流中包含相应类型的轨道时才保存连接
|
||||||
const hasVideo = remoteStream.getVideoTracks().length > 0;
|
const hasVideo = remoteStream.getVideoTracks().length > 0;
|
||||||
const hasAudio = remoteStream.getAudioTracks().length > 0;
|
const hasAudio = remoteStream.getAudioTracks().length > 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user