独立摄像头创建
This commit is contained in:
parent
6b5e402f3a
commit
ecadc3933c
@ -88,7 +88,11 @@ class Peer extends EventTarget {
|
|||||||
? "摄像头请求"
|
? "摄像头请求"
|
||||||
: "语音通话请求";
|
: "语音通话请求";
|
||||||
const mediaName =
|
const mediaName =
|
||||||
type === "desktop" ? "屏幕共享" : type === "camera" ? "摄像头" : "语音通话";
|
type === "desktop"
|
||||||
|
? "屏幕共享"
|
||||||
|
: type === "camera"
|
||||||
|
? "摄像头"
|
||||||
|
: "语音通话";
|
||||||
const content = `${call.peer} 请求与您进行${mediaName},是否接受?`;
|
const content = `${call.peer} 请求与您进行${mediaName},是否接受?`;
|
||||||
const permission =
|
const permission =
|
||||||
type === "desktop"
|
type === "desktop"
|
||||||
@ -300,6 +304,22 @@ class Peer extends EventTarget {
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private createCameraOfferStream() {
|
||||||
|
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({
|
||||||
@ -344,7 +364,7 @@ class Peer extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const offerStream = this.createDesktopOfferStream();
|
const offerStream = this.createCameraOfferStream();
|
||||||
|
|
||||||
const call = this.peer.call(sign2peerid(id), offerStream, {
|
const call = this.peer.call(sign2peerid(id), offerStream, {
|
||||||
metadata: { type: "camera" },
|
metadata: { type: "camera" },
|
||||||
@ -371,7 +391,9 @@ class Peer extends EventTarget {
|
|||||||
// 结束媒体连接
|
// 结束媒体连接
|
||||||
endMedia(peerId?: string, type?: MediaType) {
|
endMedia(peerId?: string, type?: MediaType) {
|
||||||
if (peerId) {
|
if (peerId) {
|
||||||
const mediaTypes: MediaType[] = type ? [type] : ["desktop", "call", "camera"];
|
const mediaTypes: MediaType[] = type
|
||||||
|
? [type]
|
||||||
|
: ["desktop", "call", "camera"];
|
||||||
mediaTypes.forEach((mediaType) => {
|
mediaTypes.forEach((mediaType) => {
|
||||||
this.endMediaConnection(peerId, mediaType);
|
this.endMediaConnection(peerId, mediaType);
|
||||||
if (this.remoteConnection) {
|
if (this.remoteConnection) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user