Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions src/util/mediaPipeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,7 @@ class MediaPipeUtils {
}
this.sourceTarget = target;
try {
const isMobile = typeof window.orientation !== 'undefined';
const isPortrait = isMobile && window.screen.orientation.type.includes('portrait');
const width = isPortrait ? this.VIDEO_HEIGHT: this.VIDEO_WIDTH;
const height = isPortrait ? this.VIDEO_WIDTH: this.VIDEO_HEIGHT;
const stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
deviceId: {
exact: inputSource[1],
},
width,
height,
},
});
this.stream = stream;
this.stream = await this.getVideoStream(inputSource[1]);
this.video.srcObject = this.stream;
this.video.width = this.VIDEO_WIDTH;
this.video.height = this.VIDEO_HEIGHT;
Expand Down Expand Up @@ -379,22 +365,38 @@ class MediaPipeUtils {
this.setForceFlipState(this.flipState, 0);
}

async getVideoStream(source: string) {
const isMobile = typeof window.orientation !== 'undefined';
const isPortrait = isMobile && window.screen.orientation.type.includes('portrait');
const width = isPortrait ? this.VIDEO_HEIGHT: this.VIDEO_WIDTH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert ·

Suggested change
const width = isPortrait ? this.VIDEO_HEIGHT: this.VIDEO_WIDTH;
const width = isPortrait ? this.VIDEO_HEIGHT : this.VIDEO_WIDTH;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <space-infix-ops> reported by reviewdog 🐶
Operator ':' must be spaced.

Suggested change
const width = isPortrait ? this.VIDEO_HEIGHT: this.VIDEO_WIDTH;
const width = isPortrait ? this.VIDEO_HEIGHT : this.VIDEO_WIDTH;

const height = isPortrait ? this.VIDEO_WIDTH: this.VIDEO_HEIGHT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert ·

Suggested change
const height = isPortrait ? this.VIDEO_WIDTH: this.VIDEO_HEIGHT;
const height = isPortrait ? this.VIDEO_WIDTH : this.VIDEO_HEIGHT;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <space-infix-ops> reported by reviewdog 🐶
Operator ':' must be spaced.

Suggested change
const height = isPortrait ? this.VIDEO_WIDTH: this.VIDEO_HEIGHT;
const height = isPortrait ? this.VIDEO_WIDTH : this.VIDEO_HEIGHT;

return await navigator.mediaDevices.getUserMedia({
video: {
deviceId: { exact: source },
width,
height,
},
});
}

registerRotateEvent = () => {
const isMobile = typeof window.orientation !== 'undefined';
const reloadVideo = async () => {
const target = this.sourceTarget || 0;
const stream = await this.getVideoStream(this.videoInputList[target][1]);
this.video.srcObject = stream;
this.stream = stream;
};
if (isMobile && !window.screen.orientation.onchange) {
window.screen.orientation.onchange = reloadVideo;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert ;

Suggested change
}
};


async turnOnWebcam() {
let stream;
try {
const target = this.sourceTarget || 0;

const isMobile = typeof window.orientation !== 'undefined';
const isPortrait = isMobile && window.screen.orientation.type.includes('portrait');
const width = isPortrait ? this.VIDEO_HEIGHT: this.VIDEO_WIDTH;
const height = isPortrait ? this.VIDEO_WIDTH: this.VIDEO_HEIGHT;
stream = await navigator.mediaDevices.getUserMedia({
video: {
deviceId: { exact: this.videoInputList[target][1] },
width,
height,
},
});
stream = await this.getVideoStream(this.videoInputList[target][1]);
} catch (err) {
throw new Entry.Utils.IncompatibleError('IncompatibleError', [
Lang.Workspace.check_webcam_error,
Expand All @@ -404,6 +406,7 @@ class MediaPipeUtils {
this.stream = stream;
try {
await this.video.play();
this.registerRotateEvent();
} catch {}
GEHelper.drawVideoElement(this.canvasVideo);
this.overlayCanvases.forEach((canvas: PIXI.Sprite | createjs.Bitmap) => {
Expand Down