@capgo/camera-preview 8.13.3 → 8.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +40 -39
  2. package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +15 -0
  3. package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +21 -0
  4. package/android/src/main/java/app/capgo/capacitor/camera/preview/VideoRecordingOptions.java +53 -0
  5. package/android/src/main/java/app/capgo/capacitor/camera/preview/model/CameraSessionConfiguration.java +9 -0
  6. package/android/src/test/java/app/capgo/capacitor/camera/preview/VideoRecordingOptionsTest.java +65 -0
  7. package/dist/docs.json +21 -1
  8. package/dist/esm/definitions.d.ts +9 -1
  9. package/dist/esm/definitions.js.map +1 -1
  10. package/dist/esm/web-capture-scaling.d.ts +11 -0
  11. package/dist/esm/web-capture-scaling.js +14 -0
  12. package/dist/esm/web-capture-scaling.js.map +1 -0
  13. package/dist/esm/web.d.ts +3 -0
  14. package/dist/esm/web.js +26 -5
  15. package/dist/esm/web.js.map +1 -1
  16. package/dist/plugin.cjs.js +39 -4
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +39 -4
  19. package/dist/plugin.js.map +1 -1
  20. package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +125 -17
  21. package/ios/Sources/CapgoCameraPreviewPlugin/CaptureImageExifEncoder.swift +4 -20
  22. package/ios/Sources/CapgoCameraPreviewPlugin/CaptureLifecycleCoordination.swift +43 -0
  23. package/ios/Sources/CapgoCameraPreviewPlugin/ExifGpsMetadata.swift +44 -0
  24. package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +63 -4
  25. package/ios/Sources/CapgoCameraPreviewPlugin/VideoRecordingOptions.swift +56 -0
  26. package/ios/Tests/CameraPreviewPluginTests/CaptureImageExifEncoderTests.swift +121 -0
  27. package/ios/Tests/CameraPreviewPluginTests/CaptureLifecycleCoordinationTests.swift +62 -0
  28. package/ios/Tests/CameraPreviewPluginTests/ExifGpsMetadataTests.swift +187 -0
  29. package/ios/Tests/CameraPreviewPluginTests/VideoRecordingOptionsTests.swift +58 -0
  30. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -39,6 +39,20 @@ var capacitorCapacitorCameraView = (function (exports, core) {
39
39
  return !!success;
40
40
  }
41
41
 
42
+ /** Source and destination rects for scaling a video frame into the capture canvas. */
43
+ function getWebCaptureImageDrawRects(videoWidth, videoHeight, captureWidth, captureHeight) {
44
+ return {
45
+ sx: 0,
46
+ sy: 0,
47
+ sWidth: videoWidth,
48
+ sHeight: videoHeight,
49
+ dx: 0,
50
+ dy: 0,
51
+ dWidth: captureWidth,
52
+ dHeight: captureHeight,
53
+ };
54
+ }
55
+
42
56
  const DEFAULT_VIDEO_ID = 'capgo_video';
43
57
  class CameraPreviewWeb extends core.WebPlugin {
44
58
  constructor() {
@@ -54,6 +68,7 @@ var capacitorCapacitorCameraView = (function (exports, core) {
54
68
  this.orientationListenerBound = false;
55
69
  this.mediaRecorder = null;
56
70
  this.recordedChunks = [];
71
+ this.startVideoBitrate = null;
57
72
  this.currentAspectRatio = '4:3';
58
73
  this.barcodeDetector = null;
59
74
  this.barcodeScannerTimer = null;
@@ -242,6 +257,7 @@ var capacitorCapacitorCameraView = (function (exports, core) {
242
257
  if (this.isStarted && options.force) {
243
258
  await this.stop({ force: true });
244
259
  }
260
+ this.startVideoBitrate = this.parseVideoBitrate(options === null || options === void 0 ? void 0 : options.videoBitrate);
245
261
  this.isBackCamera = true;
246
262
  this.isStarted = false;
247
263
  const parent = document.getElementById((options === null || options === void 0 ? void 0 : options.parent) || '');
@@ -601,6 +617,20 @@ var capacitorCapacitorCameraView = (function (exports, core) {
601
617
  track.stop();
602
618
  }
603
619
  }
620
+ parseVideoBitrate(value) {
621
+ if (value != null && Number.isFinite(value) && Number.isInteger(value) && value > 0 && value <= 0xffffffff) {
622
+ return value;
623
+ }
624
+ return null;
625
+ }
626
+ resolveRecordingVideoBitrate(options) {
627
+ var _a;
628
+ const perCall = this.parseVideoBitrate((_a = options === null || options === void 0 ? void 0 : options.videoBitrate) !== null && _a !== void 0 ? _a : null);
629
+ if (perCall != null) {
630
+ return perCall;
631
+ }
632
+ return this.startVideoBitrate;
633
+ }
604
634
  async stop(_options) {
605
635
  await this.stopBarcodeScanner();
606
636
  const video = this.videoElement;
@@ -613,6 +643,7 @@ var capacitorCapacitorCameraView = (function (exports, core) {
613
643
  }
614
644
  this.videoElement = null;
615
645
  this.isStarted = false;
646
+ this.startVideoBitrate = null;
616
647
  // Remove grid overlay if it exists
617
648
  const gridOverlay = document.getElementById('camera-grid-overlay');
618
649
  gridOverlay === null || gridOverlay === void 0 ? void 0 : gridOverlay.remove();
@@ -632,8 +663,6 @@ var capacitorCapacitorCameraView = (function (exports, core) {
632
663
  // Calculate capture dimensions
633
664
  let captureWidth = video.videoWidth;
634
665
  let captureHeight = video.videoHeight;
635
- const sourceX = 0;
636
- const sourceY = 0;
637
666
  // If width or height is specified, resize to fit within both maximums while maintaining aspect ratio
638
667
  if (options.width || options.height) {
639
668
  const originalAspectRatio = video.videoWidth / video.videoHeight;
@@ -672,7 +701,8 @@ var capacitorCapacitorCameraView = (function (exports, core) {
672
701
  context === null || context === void 0 ? void 0 : context.translate(captureWidth, 0);
673
702
  context === null || context === void 0 ? void 0 : context.scale(-1, 1);
674
703
  }
675
- context === null || context === void 0 ? void 0 : context.drawImage(video, sourceX, sourceY, captureWidth, captureHeight, 0, 0, captureWidth, captureHeight);
704
+ const { sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight } = getWebCaptureImageDrawRects(video.videoWidth, video.videoHeight, captureWidth, captureHeight);
705
+ context === null || context === void 0 ? void 0 : context.drawImage(video, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
676
706
  if (options.saveToGallery) ;
677
707
  if (options.withExifLocation) ;
678
708
  if ((options.format || 'jpeg') === 'jpeg') {
@@ -851,7 +881,12 @@ var capacitorCapacitorCameraView = (function (exports, core) {
851
881
  ? 'video/webm;codecs=vp8'
852
882
  : 'video/webm';
853
883
  this.recordedChunks = [];
854
- this.mediaRecorder = new MediaRecorder(stream, { mimeType });
884
+ const recorderOptions = { mimeType };
885
+ const videoBitrate = this.resolveRecordingVideoBitrate(options);
886
+ if (videoBitrate != null) {
887
+ recorderOptions.videoBitsPerSecond = videoBitrate;
888
+ }
889
+ this.mediaRecorder = new MediaRecorder(stream, recorderOptions);
855
890
  this.mediaRecorder.ondataavailable = (event) => {
856
891
  if (event.data && event.data.size > 0) {
857
892
  this.recordedChunks.push(event.data);