@capgo/camera-preview 6.2.31 → 6.3.5

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.
package/dist/plugin.js CHANGED
@@ -1,16 +1,21 @@
1
- var capacitorApp = (function (exports, core) {
1
+ var capacitorCapacitorCameraView = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
- const CameraPreview = core.registerPlugin('CameraPreview', {
5
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CameraPreviewWeb()),
4
+ const CameraPreview = core.registerPlugin("CameraPreview", {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CameraPreviewWeb()),
6
6
  });
7
7
 
8
8
  class CameraPreviewWeb extends core.WebPlugin {
9
9
  constructor() {
10
10
  super({
11
- name: 'CameraPreview',
12
- platforms: ['web'],
11
+ name: "CameraPreview",
12
+ platforms: ["web"],
13
13
  });
14
+ /**
15
+ * track which camera is used based on start options
16
+ * used in capture
17
+ */
18
+ this.isBackCamera = false;
14
19
  }
15
20
  async start(options) {
16
21
  var _a;
@@ -21,32 +26,32 @@ var capacitorApp = (function (exports, core) {
21
26
  })
22
27
  .then((stream) => {
23
28
  // Stop any existing stream so we can request media with different constraints based on user input
24
- stream.getTracks().forEach(track => track.stop());
29
+ stream.getTracks().forEach((track) => track.stop());
25
30
  })
26
31
  .catch((error) => {
27
32
  Promise.reject(error);
28
33
  });
29
- const video = document.getElementById('video');
30
- const parent = document.getElementById(options.parent);
34
+ const video = document.getElementById("video");
35
+ const parent = document.getElementById((options === null || options === void 0 ? void 0 : options.parent) || "");
31
36
  if (!video) {
32
- const videoElement = document.createElement('video');
33
- videoElement.id = 'video';
34
- videoElement.setAttribute('class', options.className || '');
37
+ const videoElement = document.createElement("video");
38
+ videoElement.id = "video";
39
+ videoElement.setAttribute("class", (options === null || options === void 0 ? void 0 : options.className) || "");
35
40
  // Don't flip video feed if camera is rear facing
36
- if (options.position !== 'rear') {
37
- videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');
41
+ if (options.position !== "rear") {
42
+ videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);");
38
43
  }
39
44
  const userAgent = navigator.userAgent.toLowerCase();
40
- const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');
45
+ const isSafari = userAgent.includes("safari") && !userAgent.includes("chrome");
41
46
  // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
42
47
  // Without these attributes videoElement.play() will throw a NotAllowedError
43
48
  // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
44
49
  if (isSafari) {
45
- videoElement.setAttribute('autoplay', 'true');
46
- videoElement.setAttribute('muted', 'true');
47
- videoElement.setAttribute('playsinline', 'true');
50
+ videoElement.setAttribute("autoplay", "true");
51
+ videoElement.setAttribute("muted", "true");
52
+ videoElement.setAttribute("playsinline", "true");
48
53
  }
49
- parent.appendChild(videoElement);
54
+ parent === null || parent === void 0 ? void 0 : parent.appendChild(videoElement);
50
55
  if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
51
56
  const constraints = {
52
57
  video: {
@@ -54,18 +59,17 @@ var capacitorApp = (function (exports, core) {
54
59
  height: { ideal: options.height },
55
60
  },
56
61
  };
57
- if (options.position === 'rear') {
58
- constraints.video.facingMode
59
- = 'environment';
62
+ if (options.position === "rear") {
63
+ constraints.video.facingMode =
64
+ "environment";
60
65
  this.isBackCamera = true;
61
66
  }
62
67
  else {
63
68
  this.isBackCamera = false;
64
69
  }
65
- // eslint-disable-next-line ts/no-this-alias
66
70
  const self = this;
67
71
  await navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
68
- if (document.getElementById('video')) {
72
+ if (document.getElementById("video")) {
69
73
  // video.src = window.URL.createObjectURL(stream);
70
74
  videoElement.srcObject = stream;
71
75
  videoElement.play();
@@ -73,7 +77,7 @@ var capacitorApp = (function (exports, core) {
73
77
  }
74
78
  else {
75
79
  self.stopStream(stream);
76
- Promise.reject(new Error('camera already stopped'));
80
+ Promise.reject(new Error("camera already stopped"));
77
81
  }
78
82
  }, (err) => {
79
83
  Promise.reject(new Error(err));
@@ -81,7 +85,7 @@ var capacitorApp = (function (exports, core) {
81
85
  }
82
86
  }
83
87
  else {
84
- Promise.reject(new Error('camera already started'));
88
+ Promise.reject(new Error("camera already started"));
85
89
  }
86
90
  }
87
91
  stopStream(stream) {
@@ -92,7 +96,7 @@ var capacitorApp = (function (exports, core) {
92
96
  }
93
97
  }
94
98
  async stop() {
95
- const video = document.getElementById('video');
99
+ const video = document.getElementById("video");
96
100
  if (video) {
97
101
  video.pause();
98
102
  this.stopStream(video.srcObject);
@@ -101,33 +105,33 @@ var capacitorApp = (function (exports, core) {
101
105
  }
102
106
  async capture(options) {
103
107
  return new Promise((resolve, reject) => {
104
- const video = document.getElementById('video');
108
+ const video = document.getElementById("video");
105
109
  if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
106
- reject(new Error('camera is not running'));
110
+ reject(new Error("camera is not running"));
107
111
  return;
108
112
  }
109
113
  // video.width = video.offsetWidth;
110
114
  let base64EncodedImage;
111
115
  if (video && video.videoWidth > 0 && video.videoHeight > 0) {
112
- const canvas = document.createElement('canvas');
113
- const context = canvas.getContext('2d');
116
+ const canvas = document.createElement("canvas");
117
+ const context = canvas.getContext("2d");
114
118
  canvas.width = video.videoWidth;
115
119
  canvas.height = video.videoHeight;
116
120
  // flip horizontally back camera isn't used
117
121
  if (!this.isBackCamera) {
118
- context.translate(video.videoWidth, 0);
119
- context.scale(-1, 1);
122
+ context === null || context === void 0 ? void 0 : context.translate(video.videoWidth, 0);
123
+ context === null || context === void 0 ? void 0 : context.scale(-1, 1);
120
124
  }
121
- context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
122
- if ((options.format || 'jpeg') === 'jpeg') {
125
+ context === null || context === void 0 ? void 0 : context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
126
+ if ((options.format || "jpeg") === "jpeg") {
123
127
  base64EncodedImage = canvas
124
- .toDataURL('image/jpeg', (options.quality || 85) / 100.0)
125
- .replace('data:image/jpeg;base64,', '');
128
+ .toDataURL("image/jpeg", (options.quality || 85) / 100.0)
129
+ .replace("data:image/jpeg;base64,", "");
126
130
  }
127
131
  else {
128
132
  base64EncodedImage = canvas
129
- .toDataURL('image/png')
130
- .replace('data:image/png;base64,', '');
133
+ .toDataURL("image/png")
134
+ .replace("data:image/png;base64,", "");
131
135
  }
132
136
  }
133
137
  resolve({
@@ -139,27 +143,28 @@ var capacitorApp = (function (exports, core) {
139
143
  return this.capture(_options);
140
144
  }
141
145
  async stopRecordVideo() {
142
- throw new Error('stopRecordVideo not supported under the web platform');
146
+ throw new Error("stopRecordVideo not supported under the web platform");
143
147
  }
144
148
  async startRecordVideo(_options) {
145
- throw new Error('startRecordVideo not supported under the web platform');
149
+ console.log("startRecordVideo", _options);
150
+ throw new Error("startRecordVideo not supported under the web platform");
146
151
  }
147
152
  async getSupportedFlashModes() {
148
- throw new Error('getSupportedFlashModes not supported under the web platform');
153
+ throw new Error("getSupportedFlashModes not supported under the web platform");
149
154
  }
150
155
  async getHorizontalFov() {
151
- throw new Error('getHorizontalFov not supported under the web platform');
156
+ throw new Error("getHorizontalFov not supported under the web platform");
152
157
  }
153
158
  async setFlashMode(_options) {
154
159
  throw new Error(`setFlashMode not supported under the web platform${_options}`);
155
160
  }
156
161
  async flip() {
157
- throw new Error('flip not supported under the web platform');
162
+ throw new Error("flip not supported under the web platform");
158
163
  }
159
164
  async setOpacity(_options) {
160
- const video = document.getElementById('video');
165
+ const video = document.getElementById("video");
161
166
  if (!!video && !!_options.opacity)
162
- video.style.setProperty('opacity', _options.opacity.toString());
167
+ video.style.setProperty("opacity", _options.opacity.toString());
163
168
  }
164
169
  }
165
170
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then(m => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach(track => track.stop());\n })\n .catch((error) => {\n Promise.reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode\n = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n // eslint-disable-next-line ts/no-this-alias\n const self = this;\n await navigator.mediaDevices.getUserMedia(constraints).then((stream) => {\n if (document.getElementById('video')) {\n // video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n Promise.resolve({});\n }\n else {\n self.stopStream(stream);\n Promise.reject(new Error('camera already stopped'));\n }\n }, (err) => {\n Promise.reject(new Error(err));\n });\n }\n }\n else {\n Promise.reject(new Error('camera already started'));\n }\n }\n stopStream(stream) {\n if (stream) {\n const tracks = stream.getTracks();\n for (const track of tracks)\n track.stop();\n }\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n this.stopStream(video.srcObject);\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, reject) => {\n const video = document.getElementById('video');\n if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {\n reject(new Error('camera is not running'));\n return;\n }\n // video.width = video.offsetWidth;\n let base64EncodedImage;\n if (video && video.videoWidth > 0 && video.videoHeight > 0) {\n const canvas = document.createElement('canvas');\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n if ((options.format || 'jpeg') === 'jpeg') {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', (options.quality || 85) / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas\n .toDataURL('image/png')\n .replace('data:image/png;base64,', '');\n }\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async stopRecordVideo() {\n throw new Error('stopRecordVideo not supported under the web platform');\n }\n async startRecordVideo(_options) {\n throw new Error('startRecordVideo not supported under the web platform');\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async getHorizontalFov() {\n throw new Error('getHorizontalFov not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error(`setFlashMode not supported under the web platform${_options}`);\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options.opacity)\n video.style.setProperty('opacity', _options.opacity.toString());\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAClE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC;IACd,YAAY,IAAI,EAAE,eAAe;IACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;IAC9B,SAAS,CAAC,CAAC;IACX,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE,CAAC;IACf,QAAQ,MAAM,SAAS,CAAC,YAAY;IACpC,aAAa,YAAY,CAAC;IAC1B,YAAY,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;IACxC,YAAY,KAAK,EAAE,IAAI;IACvB,SAAS,CAAC;IACV,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK;IAC9B;IACA,YAAY,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,SAAS,CAAC;IACV,aAAa,KAAK,CAAC,CAAC,KAAK,KAAK;IAC9B,YAAY,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,SAAS,CAAC,CAAC;IACX,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,QAAQ,IAAI,CAAC,KAAK,E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,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAChF,KAAK;IACL,IAAI,MAAM,gBAAgB,CAAC,QAAQ,EAAE;IACrC,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IACjF,KAAK;IACL,IAAI,MAAM,sBAAsB,GAAG;IACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACvF,KAAK;IACL,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IACjF,KAAK;IACL,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,iDAAiD,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxF,KAAK;IACL,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACrE,KAAK;IACL,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;IAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO;IACzC,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5E,KAAK;IACL;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst CameraPreview = registerPlugin(\"CameraPreview\", {\n web: () => import(\"./web\").then((m) => new m.CameraPreviewWeb()),\n});\nexport * from \"./definitions\";\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: \"CameraPreview\",\n platforms: [\"web\"],\n });\n /**\n * track which camera is used based on start options\n * used in capture\n */\n this.isBackCamera = false;\n }\n async start(options) {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n Promise.reject(error);\n });\n const video = document.getElementById(\"video\");\n const parent = document.getElementById((options === null || options === void 0 ? void 0 : options.parent) || \"\");\n if (!video) {\n const videoElement = document.createElement(\"video\");\n videoElement.id = \"video\";\n videoElement.setAttribute(\"class\", (options === null || options === void 0 ? void 0 : options.className) || \"\");\n // Don't flip video feed if camera is rear facing\n if (options.position !== \"rear\") {\n videoElement.setAttribute(\"style\", \"-webkit-transform: scaleX(-1); transform: scaleX(-1);\");\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes(\"safari\") && !userAgent.includes(\"chrome\");\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute(\"autoplay\", \"true\");\n videoElement.setAttribute(\"muted\", \"true\");\n videoElement.setAttribute(\"playsinline\", \"true\");\n }\n parent === null || parent === void 0 ? void 0 : parent.appendChild(videoElement);\n if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === \"rear\") {\n constraints.video.facingMode =\n \"environment\";\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n const self = this;\n await navigator.mediaDevices.getUserMedia(constraints).then((stream) => {\n if (document.getElementById(\"video\")) {\n // video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n Promise.resolve({});\n }\n else {\n self.stopStream(stream);\n Promise.reject(new Error(\"camera already stopped\"));\n }\n }, (err) => {\n Promise.reject(new Error(err));\n });\n }\n }\n else {\n Promise.reject(new Error(\"camera already started\"));\n }\n }\n stopStream(stream) {\n if (stream) {\n const tracks = stream.getTracks();\n for (const track of tracks)\n track.stop();\n }\n }\n async stop() {\n const video = document.getElementById(\"video\");\n if (video) {\n video.pause();\n this.stopStream(video.srcObject);\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, reject) => {\n const video = document.getElementById(\"video\");\n if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {\n reject(new Error(\"camera is not running\"));\n return;\n }\n // video.width = video.offsetWidth;\n let base64EncodedImage;\n if (video && video.videoWidth > 0 && video.videoHeight > 0) {\n const canvas = document.createElement(\"canvas\");\n const context = canvas.getContext(\"2d\");\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context === null || context === void 0 ? void 0 : context.translate(video.videoWidth, 0);\n context === null || context === void 0 ? void 0 : context.scale(-1, 1);\n }\n context === null || context === void 0 ? void 0 : context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n if ((options.format || \"jpeg\") === \"jpeg\") {\n base64EncodedImage = canvas\n .toDataURL(\"image/jpeg\", (options.quality || 85) / 100.0)\n .replace(\"data:image/jpeg;base64,\", \"\");\n }\n else {\n base64EncodedImage = canvas\n .toDataURL(\"image/png\")\n .replace(\"data:image/png;base64,\", \"\");\n }\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async stopRecordVideo() {\n throw new Error(\"stopRecordVideo not supported under the web platform\");\n }\n async startRecordVideo(_options) {\n console.log(\"startRecordVideo\", _options);\n throw new Error(\"startRecordVideo not supported under the web platform\");\n }\n async getSupportedFlashModes() {\n throw new Error(\"getSupportedFlashModes not supported under the web platform\");\n }\n async getHorizontalFov() {\n throw new Error(\"getHorizontalFov not supported under the web platform\");\n }\n async setFlashMode(_options) {\n throw new Error(`setFlashMode not supported under the web platform${_options}`);\n }\n async flip() {\n throw new Error(\"flip not supported under the web platform\");\n }\n async setOpacity(_options) {\n const video = document.getElementById(\"video\");\n if (!!video && !!_options.opacity)\n video.style.setProperty(\"opacity\", _options.opacity.toString());\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC;IACd,YAAY,IAAI,EAAE,eAAe;IACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;IAC9B,SAAS,CAAC,CAAC;IACX;IACA;IACA;IACA;IACA,QAAQ,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAClC,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE,CAAC;IACf,QAAQ,MAAM,SAAS,CAAC,YAAY;IACpC,aAAa,YAAY,CAAC;IAC1B,YAAY,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;IACxC,YAAY,KAAK,EAAE,IAAI;IACvB,SAAS,CAAC;IACV,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK;IAC9B;IACA,YAAY,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,SAAS,CAAC;IACV,aAAa,KAAK,CAAC,CAAC,KAAK,KAAK;IAC9B,YAAY,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,SAAS,CAAC,CAAC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AAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACrE,KAAK;IACL,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;IAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO;IACzC,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5E,KAAK;IACL;;;;;;;;;;;;;;;"}
@@ -23,6 +23,8 @@ class CameraController: NSObject {
23
23
  var rearCamera: AVCaptureDevice?
24
24
  var rearCameraInput: AVCaptureDeviceInput?
25
25
 
26
+ var fileVideoOutput: AVCaptureMovieFileOutput?
27
+
26
28
  var previewLayer: AVCaptureVideoPreviewLayer?
27
29
 
28
30
  var flashMode = AVCaptureDevice.FlashMode.off
@@ -119,6 +121,12 @@ extension CameraController {
119
121
  self.photoOutput!.setPreparedPhotoSettingsArray([AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])], completionHandler: nil)
120
122
  self.photoOutput?.isHighResolutionCaptureEnabled = self.highResolutionOutput
121
123
  if captureSession.canAddOutput(self.photoOutput!) { captureSession.addOutput(self.photoOutput!) }
124
+
125
+ let fileVideoOutput = AVCaptureMovieFileOutput()
126
+ if captureSession.canAddOutput(fileVideoOutput) {
127
+ captureSession.addOutput(fileVideoOutput)
128
+ self.fileVideoOutput = fileVideoOutput
129
+ }
122
130
  captureSession.startRunning()
123
131
  }
124
132
 
@@ -427,17 +435,41 @@ extension CameraController {
427
435
  guard let captureSession = self.captureSession, captureSession.isRunning else {
428
436
  throw CameraControllerError.captureSessionIsMissing
429
437
  }
430
- let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
438
+ guard let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
439
+ throw CameraControllerError.cannotFindDocumentsDirectory
440
+ }
441
+
442
+ guard let fileVideoOutput = self.fileVideoOutput else {
443
+ throw CameraControllerError.fileVideoOutputNotFound
444
+ }
445
+
446
+ // cpcp_video_A6C01203 - portrait
447
+ //
448
+ if let connection = fileVideoOutput.connection(with: .video) {
449
+ switch UIDevice.current.orientation {
450
+ case .landscapeRight:
451
+ connection.videoOrientation = .landscapeLeft
452
+ case .landscapeLeft:
453
+ connection.videoOrientation = .landscapeRight
454
+ case .portrait:
455
+ connection.videoOrientation = .portrait
456
+ case .portraitUpsideDown:
457
+ connection.videoOrientation = .portraitUpsideDown
458
+ default:
459
+ connection.videoOrientation = .portrait
460
+ }
461
+ }
462
+
431
463
  let identifier = UUID()
432
464
  let randomIdentifier = identifier.uuidString.replacingOccurrences(of: "-", with: "")
433
465
  let finalIdentifier = String(randomIdentifier.prefix(8))
434
466
  let fileName="cpcp_video_"+finalIdentifier+".mp4"
435
467
 
436
- let fileUrl = path.appendingPathComponent(fileName)
468
+ let fileUrl = documentsDirectory.appendingPathComponent(fileName)
437
469
  try? FileManager.default.removeItem(at: fileUrl)
438
470
 
439
471
  // Start recording video
440
- // ...
472
+ fileVideoOutput.startRecording(to: fileUrl, recordingDelegate: self)
441
473
 
442
474
  // Save the file URL for later use
443
475
  self.videoFileURL = fileUrl
@@ -448,8 +480,13 @@ extension CameraController {
448
480
  completion(nil, CameraControllerError.captureSessionIsMissing)
449
481
  return
450
482
  }
483
+ guard let fileVideoOutput = self.fileVideoOutput else {
484
+ completion(nil, CameraControllerError.fileVideoOutputNotFound)
485
+ return
486
+ }
487
+
451
488
  // Stop recording video
452
- // ...
489
+ fileVideoOutput.stopRecording()
453
490
 
454
491
  // Return the video file URL in the completion handler
455
492
  completion(self.videoFileURL, nil)
@@ -579,6 +616,8 @@ enum CameraControllerError: Swift.Error {
579
616
  case inputsAreInvalid
580
617
  case invalidOperation
581
618
  case noCamerasAvailable
619
+ case cannotFindDocumentsDirectory
620
+ case fileVideoOutputNotFound
582
621
  case unknown
583
622
  }
584
623
 
@@ -602,7 +641,10 @@ extension CameraControllerError: LocalizedError {
602
641
  return NSLocalizedString("Failed to access device camera(s)", comment: "No Cameras Available")
603
642
  case .unknown:
604
643
  return NSLocalizedString("Unknown", comment: "Unknown")
605
-
644
+ case .cannotFindDocumentsDirectory:
645
+ return NSLocalizedString("Cannot find documents directory", comment: "This should never happen")
646
+ case .fileVideoOutputNotFound:
647
+ return NSLocalizedString("Cannot find fileVideoOutput", comment: "Perhaps you are running IOS < 17 or you are not recording?")
606
648
  }
607
649
  }
608
650
  }
@@ -634,17 +676,14 @@ extension UIImage {
634
676
  transform = transform.translatedBy(x: size.width, y: size.height)
635
677
  transform = transform.rotated(by: CGFloat.pi)
636
678
  print("down")
637
- break
638
- case .left, .leftMirrored:
679
+ case .left, .leftMirrored:
639
680
  transform = transform.translatedBy(x: size.width, y: 0)
640
681
  transform = transform.rotated(by: CGFloat.pi / 2.0)
641
682
  print("left")
642
- break
643
- case .right, .rightMirrored:
683
+ case .right, .rightMirrored:
644
684
  transform = transform.translatedBy(x: 0, y: size.height)
645
685
  transform = transform.rotated(by: CGFloat.pi / -2.0)
646
686
  print("right")
647
- break
648
687
  case .up, .upMirrored:
649
688
  break
650
689
  }
@@ -654,7 +693,6 @@ extension UIImage {
654
693
  case .upMirrored, .downMirrored:
655
694
  transform.translatedBy(x: size.width, y: 0)
656
695
  transform.scaledBy(x: -1, y: 1)
657
- break
658
696
  case .leftMirrored, .rightMirrored:
659
697
  transform.translatedBy(x: size.height, y: 0)
660
698
  transform.scaledBy(x: -1, y: 1)
@@ -667,9 +705,8 @@ extension UIImage {
667
705
  switch imageOrientation {
668
706
  case .left, .leftMirrored, .right, .rightMirrored:
669
707
  ctx.draw(self.cgImage!, in: CGRect(x: 0, y: 0, width: size.height, height: size.width))
670
- default:
708
+ default:
671
709
  ctx.draw(self.cgImage!, in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
672
- break
673
710
  }
674
711
  guard let newCGImage = ctx.makeImage() else { return nil }
675
712
  return UIImage.init(cgImage: newCGImage, scale: 1, orientation: .up)
@@ -678,10 +715,11 @@ extension UIImage {
678
715
 
679
716
  extension CameraController: AVCaptureFileOutputRecordingDelegate {
680
717
  func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
681
- /*if error == nil {
682
- self.videoRecordCompletionBlock?(outputFileURL, nil)
683
- } else {
684
- self.videoRecordCompletionBlock?(nil, error)
685
- }*/
718
+ if let error = error {
719
+ print("Error recording movie: \(error.localizedDescription)")
720
+ } else {
721
+ print("Movie recorded successfully: \(outputFileURL)")
722
+ // You can save the file to the library, upload it, etc.
723
+ }
686
724
  }
687
725
  }
@@ -64,6 +64,21 @@ public class CameraPreview: CAPPlugin {
64
64
  self.cameraController.previewLayer?.frame = self.previewView.frame
65
65
  }
66
66
 
67
+ if let connection = self.cameraController.fileVideoOutput?.connection(with: .video) {
68
+ switch UIDevice.current.orientation {
69
+ case .landscapeRight:
70
+ connection.videoOrientation = .landscapeLeft
71
+ case .landscapeLeft:
72
+ connection.videoOrientation = .landscapeRight
73
+ case .portrait:
74
+ connection.videoOrientation = .portrait
75
+ case .portraitUpsideDown:
76
+ connection.videoOrientation = .portraitUpsideDown
77
+ default:
78
+ connection.videoOrientation = .portrait
79
+ }
80
+ }
81
+
67
82
  cameraController.updateVideoOrientation()
68
83
  }
69
84
 
@@ -294,6 +309,9 @@ public class CameraPreview: CAPPlugin {
294
309
  }
295
310
 
296
311
  @objc func startRecordVideo(_ call: CAPPluginCall) {
312
+ if #unavailable(iOS 17) {
313
+ call.reject("You cannot record video on IOS < 17")
314
+ }
297
315
  DispatchQueue.main.async {
298
316
  do {
299
317
  try self.cameraController.captureVideo()
@@ -317,7 +335,7 @@ public class CameraPreview: CAPPlugin {
317
335
  return
318
336
  }
319
337
 
320
- call.resolve(["videoUrl": fileURL.absoluteString])
338
+ call.resolve(["videoFilePath": fileURL.absoluteString])
321
339
  }
322
340
  }
323
341
  }
package/ios/Podfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  PODS:
2
- - Capacitor (6.0.0):
2
+ - Capacitor (6.1.0):
3
3
  - CapacitorCordova
4
4
  - CapacitorCordova (2.0.1)
5
5
 
@@ -15,7 +15,7 @@ EXTERNAL SOURCES:
15
15
  :path: "../node_modules/@capacitor/ios"
16
16
 
17
17
  SPEC CHECKSUMS:
18
- Capacitor: 559d073c4ca6c27f8e7002c807eea94c3ba435a9
18
+ Capacitor: 187bd7847b6f71467015a20200a1a071be3e5f14
19
19
  CapacitorCordova: 9fee2eb6780331b6ff09710d6a7d1f2e4707f1b9
20
20
 
21
21
  PODFILE CHECKSUM: e80ffb7ef3a0ac7d0d6143f3e64f287d4d027c84
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "6.2.31",
3
+ "version": "6.3.5",
4
4
  "description": "Camera preview",
5
5
  "author": "Martin Donadieu <martindonadieu@gmail.com>",
6
6
  "license": "MIT",
@@ -31,38 +31,46 @@
31
31
  "verify:web": "npm run build",
32
32
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
33
33
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
34
- "eslint": "eslint .",
35
- "prettier": "prettier --config .prettierrc.js \"**/*.java\"",
34
+ "eslint": "eslint . --ext .ts",
35
+ "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
36
36
  "swiftlint": "node-swiftlint",
37
+ "docgen": "docgen --api CameraPreviewPlugin --output-readme README.md --output-json dist/docs.json",
37
38
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
38
39
  "clean": "rimraf ./dist",
39
40
  "watch": "tsc --watch",
40
- "docgen": "docgen --api CameraPreviewPlugin --output-readme README.md --output-json dist/docs.json",
41
- "prepublishOnly": "npm run build",
42
- "prepare": "husky install"
43
- },
44
- "peerDependencies": {
45
- "@capacitor/core": "^6.0.0"
41
+ "prepublishOnly": "npm run build"
46
42
  },
47
- "dependencies": {},
48
43
  "devDependencies": {
49
- "@antfu/eslint-config": "^2.16.1",
50
44
  "@capacitor/android": "^6.0.0",
51
45
  "@capacitor/cli": "^6.0.0",
52
46
  "@capacitor/core": "^6.0.0",
53
47
  "@capacitor/docgen": "^0.2.2",
54
48
  "@capacitor/ios": "^6.0.0",
49
+ "@ionic/eslint-config": "^0.4.0",
55
50
  "@ionic/prettier-config": "^4.0.0",
56
51
  "@ionic/swiftlint-config": "^1.1.2",
57
- "eslint": "^9.1.1",
58
- "husky": "^9.0.11",
52
+ "@types/node": "^20.12.12",
53
+ "@typescript-eslint/eslint-plugin": "^7.11.0",
54
+ "@typescript-eslint/parser": "^7.11.0",
55
+ "eslint": "^8.57.0",
56
+ "eslint-plugin-import": "^2.29.1",
59
57
  "prettier": "^3.2.5",
60
58
  "prettier-plugin-java": "^2.6.0",
61
- "rimraf": "^5.0.5",
62
- "rollup": "^4.17.1",
59
+ "rimraf": "^5.0.7",
60
+ "rollup": "^4.18.0",
63
61
  "swiftlint": "^1.0.2",
64
62
  "typescript": "^5.4.5"
65
63
  },
64
+ "peerDependencies": {
65
+ "@capacitor/core": "^6.0.0"
66
+ },
67
+ "prettier": "@ionic/prettier-config",
68
+ "eslintConfig": {
69
+ "extends": "@ionic/eslint-config/recommended",
70
+ "rules": {
71
+ "@typescript-eslint/prefer-optional-chain": "off"
72
+ }
73
+ },
66
74
  "capacitor": {
67
75
  "ios": {
68
76
  "src": "ios"
@@ -71,5 +79,5 @@
71
79
  "src": "android"
72
80
  }
73
81
  },
74
- "prettier": "@ionic/prettier-config"
82
+ "packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
75
83
  }