Compare commits
No commits in common. "e98cd2844d4284260306fb658422a84e9b4b90c2" and "19b9621dee34bbce9d0b84b9c5577bc35497e72e" have entirely different histories.
e98cd2844d
...
19b9621dee
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: 10;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.transfer-header {
|
.transfer-header {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
TransferStatus,
|
TransferStatus,
|
||||||
TransferTask,
|
TransferTask,
|
||||||
} from "./fileTransfer";
|
} from "./fileTransfer";
|
||||||
import { message, notification } from "ant-design-vue";
|
import { message, Modal, notification } from "ant-design-vue";
|
||||||
import {
|
import {
|
||||||
randomChars,
|
randomChars,
|
||||||
sign2peerid,
|
sign2peerid,
|
||||||
@ -86,10 +86,7 @@ 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;
|
||||||
|
|
||||||
@ -107,7 +104,7 @@ class Peer extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
call.answer(stream);
|
call.answer(stream);
|
||||||
self.setupMediaConnection(call, type, stream, type !== "desktop");
|
self.setupMediaConnection(call, type, stream);
|
||||||
|
|
||||||
self.dispatchEvent(
|
self.dispatchEvent(
|
||||||
new CustomEvent(
|
new CustomEvent(
|
||||||
@ -115,7 +112,6 @@ class Peer extends EventTarget {
|
|||||||
{
|
{
|
||||||
detail: {
|
detail: {
|
||||||
peerId: call.peer,
|
peerId: call.peer,
|
||||||
role: type === "desktop" ? "sharer" : "caller",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -130,34 +126,20 @@ 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(() => {
|
||||||
onReject();
|
call.close();
|
||||||
|
message.info(
|
||||||
|
"已拒绝" +
|
||||||
|
(type === "desktop" ? "屏幕共享" : "语音通话") +
|
||||||
|
"请求",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -217,19 +199,23 @@ 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), offerStream, {
|
const call = this.peer.call(sign2peerid(id), emptyStream, {
|
||||||
metadata: { type: "desktop" },
|
metadata: { type: "desktop" },
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setupMediaConnection(call, "desktop", offerStream);
|
this.setupMediaConnection(call, "desktop", emptyStream);
|
||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent("desktop-started", {
|
new CustomEvent("desktop-started", {
|
||||||
detail: {
|
detail: {
|
||||||
peerId: call.peer,
|
peerId: call.peer,
|
||||||
role: "viewer",
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -241,22 +227,6 @@ 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({
|
||||||
@ -465,7 +435,6 @@ 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, {
|
||||||
@ -475,7 +444,6 @@ 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