-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] feat(camera-tab): added aspectRatio #762
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import { debounce } from '../utils/debounce.js'; | ||
import { UploadSource } from '../utils/UploadSource.js'; | ||
|
||
const DEFAULT_VIDEO_CONFIG = { | ||
width: { | ||
ideal: 1920, | ||
}, | ||
|
@@ -632,15 +632,15 @@ | |
|
||
_capture = async () => { | ||
const constraints = { | ||
video: DEFAULT_VIDEO_CONFIG, | ||
video: { | ||
aspectRatio: this.cfg.aspectRatio, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What browser will do if this type of constraint is not supported? |
||
}, | ||
Comment on lines
+635
to
+637
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate aspectRatio before using in constraints. The aspectRatio is directly used from config without validation. This could lead to invalid constraints if the config contains incorrect values. Consider adding validation: video: {
- aspectRatio: this.cfg.aspectRatio,
+ ...(this.cfg.aspectRatio && Object.keys(this.cfg.aspectRatio).length > 0
+ ? { aspectRatio: this.cfg.aspectRatio }
+ : DEFAULT_VIDEO_CONFIG),
},
|
||
audio: this.cfg.enableAudioRecording ? {} : false, | ||
}; | ||
|
||
if (this._selectedCameraId) { | ||
constraints.video = { | ||
deviceId: { | ||
exact: this._selectedCameraId, | ||
}, | ||
constraints.video.deviceId = { | ||
exact: this._selectedCameraId, | ||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ const allConfigKeys = /** @type {(keyof import('../../types').ConfigType)[]} */ | |
* 'fileValidators', | ||
* 'collectionValidators', | ||
* 'mediaRecorerOptions', | ||
* 'aspectRatio', | ||
* ]} | ||
*/ | ||
export const complexConfigKeys = [ | ||
|
@@ -33,6 +34,7 @@ export const complexConfigKeys = [ | |
'fileValidators', | ||
'collectionValidators', | ||
'mediaRecorerOptions', | ||
'aspectRatio', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks too common config property name for me. Maybe something like |
||
]; | ||
|
||
/** @type {(key: keyof import('../../types').ConfigType) => key is keyof import('../../types').ConfigComplexType} */ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -171,6 +171,7 @@ const mapping = { | |||||||||||||||||||||||||||||
mediaRecorerOptions: asObject, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
maxVideoRecordingDuration: asNumber, | ||||||||||||||||||||||||||||||
aspectRatio: asObject, | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance validation for aspectRatio values The current validation only ensures the value is an object. Consider adding specific validation for aspect ratio format to prevent runtime issues with camera initialization. Example implementation: - aspectRatio: asObject,
+ aspectRatio: (value) => {
+ const obj = asObject(value);
+ if (obj === null) return null;
+
+ for (const [key, ratio] of Object.entries(obj)) {
+ if (!/^\d+:\d+$/.test(key) || !/^\d+(\.\d+)?$/.test(ratio)) {
+ throw new Error(
+ `Invalid aspect ratio format. Expected format: { "width:height": "decimal" }, got: {"${key}": "${ratio}"}`
+ );
+ }
+ }
+ return obj;
+ }, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
DEFAULT_VIDEO_CONFIG
was forgotten here