@digipair/skill-web-interact 0.25.1 → 0.25.2

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/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let DomService = class DomService {
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let WebInteractService = class WebInteractService {
6
6
  async setAttribute(params, _pinsSettingsList, _context) {
7
7
  const { selector, attribute, value } = params;
8
8
  const element = document.querySelector(selector);
@@ -88,19 +88,55 @@ Object.defineProperty(exports, '__esModule', { value: true });
88
88
  });
89
89
  return result;
90
90
  }
91
+ async capture(params, _pinsSettingsList, _context) {
92
+ const { deviceId, width = 4096, height = 2160, facingMode = 'environment' } = params;
93
+ const constraints = {
94
+ audio: false,
95
+ video: {
96
+ width: {
97
+ ideal: width
98
+ },
99
+ height: {
100
+ ideal: height
101
+ },
102
+ facingMode,
103
+ deviceId
104
+ }
105
+ };
106
+ const video = document.createElement('video');
107
+ video.autoplay = true;
108
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
109
+ video.srcObject = stream;
110
+ await new Promise((resolve)=>video.onloadedmetadata = resolve);
111
+ const canvas = document.createElement('canvas');
112
+ canvas.width = video.videoWidth;
113
+ canvas.height = video.videoHeight;
114
+ const ctx = canvas.getContext('2d');
115
+ ctx == null ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
116
+ const image = canvas.toDataURL('image/jpeg');
117
+ stream.getTracks().forEach((track)=>track.stop());
118
+ return image;
119
+ }
120
+ async getMediaDevices(_params, _pinsSettingsList, _context) {
121
+ return navigator.mediaDevices.enumerateDevices();
122
+ }
91
123
  };
92
- const setAttribute = (params, pinsSettingsList, context)=>new DomService().setAttribute(params, pinsSettingsList, context);
93
- const getAttribute = (params, pinsSettingsList, context)=>new DomService().getAttribute(params, pinsSettingsList, context);
94
- const dispatchEvent = (params, pinsSettingsList, context)=>new DomService().dispatchEvent(params, pinsSettingsList, context);
95
- const execute = (params, pinsSettingsList, context)=>new DomService().execute(params, pinsSettingsList, context);
96
- const goTo = (params, pinsSettingsList, context)=>new DomService().goTo(params, pinsSettingsList, context);
97
- const reload = (params, pinsSettingsList, context)=>new DomService().reload(params, pinsSettingsList, context);
98
- const upload = (params, pinsSettingsList, context)=>new DomService().upload(params, pinsSettingsList, context);
99
- const uploadText = (params, pinsSettingsList, context)=>new DomService().uploadText(params, pinsSettingsList, context);
124
+ const setAttribute = (params, pinsSettingsList, context)=>new WebInteractService().setAttribute(params, pinsSettingsList, context);
125
+ const getAttribute = (params, pinsSettingsList, context)=>new WebInteractService().getAttribute(params, pinsSettingsList, context);
126
+ const dispatchEvent = (params, pinsSettingsList, context)=>new WebInteractService().dispatchEvent(params, pinsSettingsList, context);
127
+ const execute = (params, pinsSettingsList, context)=>new WebInteractService().execute(params, pinsSettingsList, context);
128
+ const goTo = (params, pinsSettingsList, context)=>new WebInteractService().goTo(params, pinsSettingsList, context);
129
+ const reload = (params, pinsSettingsList, context)=>new WebInteractService().reload(params, pinsSettingsList, context);
130
+ const upload = (params, pinsSettingsList, context)=>new WebInteractService().upload(params, pinsSettingsList, context);
131
+ const uploadText = (params, pinsSettingsList, context)=>new WebInteractService().uploadText(params, pinsSettingsList, context);
132
+ const capture = (params, pinsSettingsList, context)=>new WebInteractService().capture(params, pinsSettingsList, context);
133
+ const getMediaDevices = (params, pinsSettingsList, context)=>new WebInteractService().getMediaDevices(params, pinsSettingsList, context);
100
134
 
135
+ exports.capture = capture;
101
136
  exports.dispatchEvent = dispatchEvent;
102
137
  exports.execute = execute;
103
138
  exports.getAttribute = getAttribute;
139
+ exports.getMediaDevices = getMediaDevices;
104
140
  exports.goTo = goTo;
105
141
  exports.reload = reload;
106
142
  exports.setAttribute = setAttribute;
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let DomService = class DomService {
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let WebInteractService = class WebInteractService {
2
2
  async setAttribute(params, _pinsSettingsList, _context) {
3
3
  const { selector, attribute, value } = params;
4
4
  const element = document.querySelector(selector);
@@ -84,14 +84,48 @@
84
84
  });
85
85
  return result;
86
86
  }
87
+ async capture(params, _pinsSettingsList, _context) {
88
+ const { deviceId, width = 4096, height = 2160, facingMode = 'environment' } = params;
89
+ const constraints = {
90
+ audio: false,
91
+ video: {
92
+ width: {
93
+ ideal: width
94
+ },
95
+ height: {
96
+ ideal: height
97
+ },
98
+ facingMode,
99
+ deviceId
100
+ }
101
+ };
102
+ const video = document.createElement('video');
103
+ video.autoplay = true;
104
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
105
+ video.srcObject = stream;
106
+ await new Promise((resolve)=>video.onloadedmetadata = resolve);
107
+ const canvas = document.createElement('canvas');
108
+ canvas.width = video.videoWidth;
109
+ canvas.height = video.videoHeight;
110
+ const ctx = canvas.getContext('2d');
111
+ ctx == null ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
112
+ const image = canvas.toDataURL('image/jpeg');
113
+ stream.getTracks().forEach((track)=>track.stop());
114
+ return image;
115
+ }
116
+ async getMediaDevices(_params, _pinsSettingsList, _context) {
117
+ return navigator.mediaDevices.enumerateDevices();
118
+ }
87
119
  };
88
- const setAttribute = (params, pinsSettingsList, context)=>new DomService().setAttribute(params, pinsSettingsList, context);
89
- const getAttribute = (params, pinsSettingsList, context)=>new DomService().getAttribute(params, pinsSettingsList, context);
90
- const dispatchEvent = (params, pinsSettingsList, context)=>new DomService().dispatchEvent(params, pinsSettingsList, context);
91
- const execute = (params, pinsSettingsList, context)=>new DomService().execute(params, pinsSettingsList, context);
92
- const goTo = (params, pinsSettingsList, context)=>new DomService().goTo(params, pinsSettingsList, context);
93
- const reload = (params, pinsSettingsList, context)=>new DomService().reload(params, pinsSettingsList, context);
94
- const upload = (params, pinsSettingsList, context)=>new DomService().upload(params, pinsSettingsList, context);
95
- const uploadText = (params, pinsSettingsList, context)=>new DomService().uploadText(params, pinsSettingsList, context);
120
+ const setAttribute = (params, pinsSettingsList, context)=>new WebInteractService().setAttribute(params, pinsSettingsList, context);
121
+ const getAttribute = (params, pinsSettingsList, context)=>new WebInteractService().getAttribute(params, pinsSettingsList, context);
122
+ const dispatchEvent = (params, pinsSettingsList, context)=>new WebInteractService().dispatchEvent(params, pinsSettingsList, context);
123
+ const execute = (params, pinsSettingsList, context)=>new WebInteractService().execute(params, pinsSettingsList, context);
124
+ const goTo = (params, pinsSettingsList, context)=>new WebInteractService().goTo(params, pinsSettingsList, context);
125
+ const reload = (params, pinsSettingsList, context)=>new WebInteractService().reload(params, pinsSettingsList, context);
126
+ const upload = (params, pinsSettingsList, context)=>new WebInteractService().upload(params, pinsSettingsList, context);
127
+ const uploadText = (params, pinsSettingsList, context)=>new WebInteractService().uploadText(params, pinsSettingsList, context);
128
+ const capture = (params, pinsSettingsList, context)=>new WebInteractService().capture(params, pinsSettingsList, context);
129
+ const getMediaDevices = (params, pinsSettingsList, context)=>new WebInteractService().getMediaDevices(params, pinsSettingsList, context);
96
130
 
97
- export { dispatchEvent, execute, getAttribute, goTo, reload, setAttribute, upload, uploadText };
131
+ export { capture, dispatchEvent, execute, getAttribute, getMediaDevices, goTo, reload, setAttribute, upload, uploadText };
@@ -7,3 +7,5 @@ export declare const goTo: (params: any, pinsSettingsList: PinsSettings[], conte
7
7
  export declare const reload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
8
8
  export declare const upload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
9
9
  export declare const uploadText: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
10
+ export declare const capture: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
11
+ export declare const getMediaDevices: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-interact",
3
- "version": "0.25.1",
3
+ "version": "0.25.2",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js"
package/schema.json CHANGED
@@ -224,6 +224,61 @@
224
224
  ],
225
225
  "x-events": []
226
226
  }
227
+ },
228
+ "/capture": {
229
+ "post": {
230
+ "tags": ["web"],
231
+ "summary": "Capture une image de la webcam",
232
+ "description": "Permet de capturer une image de la webcam",
233
+ "parameters": [
234
+ {
235
+ "name": "deviceId",
236
+ "summary": "Identifiant du périphérique",
237
+ "required": false,
238
+ "description": "Identifiant du périphérique de capture",
239
+ "schema": {
240
+ "type": "string"
241
+ }
242
+ },
243
+ {
244
+ "name": "width",
245
+ "summary": "Largeur de l'image",
246
+ "required": false,
247
+ "description": "Largeur de l'image capturée",
248
+ "schema": {
249
+ "type": "number"
250
+ }
251
+ },
252
+ {
253
+ "name": "height",
254
+ "summary": "Hauteur de l'image",
255
+ "required": false,
256
+ "description": "Hauteur de l'image capturée",
257
+ "schema": {
258
+ "type": "number"
259
+ }
260
+ },
261
+ {
262
+ "name": "facingMode",
263
+ "summary": "Mode de capture",
264
+ "required": false,
265
+ "description": "Mode de capture de l'image",
266
+ "schema": {
267
+ "type": "string"
268
+ }
269
+ }
270
+ ],
271
+ "x-events": []
272
+ }
273
+ },
274
+ "/getMediaDevices": {
275
+ "post": {
276
+ "tags": ["web"],
277
+ "summary": "Liste des périphériques",
278
+ "description": "Liste les périphériques de capture disponibles",
279
+ "parameters": [],
280
+ "x-events": []
281
+ }
227
282
  }
228
283
  },
229
284
  "components": {