Skip to content

Commit 966a68c

Browse files
Merge branch 'main' of https://github.com/Dynamsoft/capture-vision-javascript-samples into playwright-test
2 parents 1885d50 + 0607f5e commit 966a68c

File tree

7 files changed

+142
-47
lines changed

7 files changed

+142
-47
lines changed

.github/workflows/preview.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy PR previews
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- closed
12+
13+
jobs:
14+
deploy-preview:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Deploy PR Preview
19+
uses: rossjrw/pr-preview-action@v1.4.3
20+
with:
21+
token: ${{ secrets.PREVIEW_TOKEN }}
22+
preview-branch: gh-pages
23+
source-dir: .
24+
umbrella-dir: pr-preview
25+
action: auto

README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,82 @@ Execute playwright code coverage test by simply run
2222
npm test
2323
```
2424

25-
## License
25+
## Request a Trial License
26+
27+
The key "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" used in this solution (found in the js/init.js file) is a test license valid for 24 hours for any newly authorized browser. If you wish to test the SDK further, you can request a 30-day free trial license through the <a href="https://www.dynamsoft.com/customer/license/trialLicense?product=mrz&utm_source=docs&package=js" target="_blank">Request a Trial License</a> link.
28+
29+
## Project Structure
30+
31+
```text
32+
Sample Project
33+
├── assets
34+
│ ├── ...
35+
│ ├── ...
36+
│ └── ...
37+
├── css
38+
│ └── index.css
39+
├── font
40+
│ ├── ...
41+
│ ├── ...
42+
│ └── ...
43+
├── js
44+
│ ├── const.js
45+
│ ├── index.js
46+
│ ├── init.js
47+
│ └── util.js
48+
├── index.html
49+
└── template.json
50+
```
51+
52+
* `/assets` : This directory contains all the static files such as images, icons, etc. that are used in the project.
53+
* `/css` : This directory contains the CSS file(s) used for styling the project.
54+
* `/font` : This directory contains the font files used in the project.
55+
* `/js` : This directory contains all the JavaScript files used in the project.
56+
* `const.js` : This file contains definitions of certain constants or variables used across the project.
57+
* `index.js`: This is the main JavaScript file where the core logic of the project is implemented.
58+
* `init.js` : This file is used for initialization purposes, such as initializing license, load resources, etc.
59+
* `util.js` : This file contains utility functions that are used across the project.
60+
* `index.html` : This is the main HTML file that represents the homepage of the project.
61+
* `template.json` : This file contains predefined templates used in the project.
62+
* `minimum-elements.html` : This HTML file includes the sample project with minimal elements and limited CSS, all contained within a single page.
63+
64+
## System Requirements
65+
66+
This project requires the following features to work:
67+
68+
- Secure context (HTTPS deployment)
69+
70+
When deploying your application / website for production, make sure to serve it via a secure HTTPS connection. This is required for two reasons
71+
72+
- Access to the camera video stream is only granted in a security context. Most browsers impose this restriction.
73+
> Some browsers like Chrome may grant the access for `http://127.0.0.1` and `http://localhost` or even for pages opened directly from the local disk (`file:///...`). This can be helpful for temporary development and test.
74+
75+
- Dynamsoft License requires a secure context to work.
76+
77+
- `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`
78+
79+
The above four features are required for the SDK to work.
80+
81+
- `MediaDevices`/`getUserMedia`
82+
83+
This API is required for in-browser video streaming.
84+
85+
- `getSettings`
86+
87+
This API inspects the video input which is a `MediaStreamTrack` object about its constrainable properties.
88+
89+
The following table is a list of supported browsers based on the above requirements:
90+
91+
| Browser Name | Version |
92+
| :----------: | :--------------: |
93+
| Chrome | v78+<sup>1</sup> |
94+
| Firefox | v63+<sup>1</sup> |
95+
| Edge | v79+ |
96+
| Safari | v14+ |
97+
98+
<sup>1</sup> devices running iOS needs to be on iOS 14.3+ for camera video streaming to work in Chrome, Firefox or other Apps using webviews.
2699

27-
You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense/?product=cvs&utm_source=github&package=js) link.
100+
Apart from the browsers, the operating systems may impose some limitations of their own that could restrict the use of the SDK. Browser compatibility ultimately depends on whether the browser on that particular operating system supports the features listed above.
28101

29102
## Testing
30103

VINScanner/css/index.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,13 @@ img {
368368
justify-content: center;
369369
align-items: center;
370370
border-radius: 8px;
371-
opacity: 0.8;
372371
background-color: rgb(34, 34, 34);
373372
}
374373

375374
.scan-orientation-btn .scan-orientation-icon {
376375
width: 24px;
377376
height: 24px;
378-
filter: invert(0.4);
377+
filter: invert(1);
379378
}
380379

381380
#notification {

VINScanner/js/index.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,49 @@ import {
1414
SCAN_MODES.forEach((mode) =>
1515
document.querySelector(`#scan-${mode}-btn`).addEventListener("click", async () => {
1616
try {
17-
(async () => {
18-
homePage.style.display = "none";
19-
scannerContainer.style.display = "block";
17+
homePage.style.display = "none";
18+
scannerContainer.style.display = "block";
2019

21-
pInit = pInit || (await init);
20+
pInit = pInit || (await init);
2221

23-
// Starts streaming the video
24-
if (cameraEnhancer.isOpen()) {
25-
await cvRouter.stopCapturing();
26-
await cameraView.clearAllInnerDrawingItems();
27-
} else {
28-
await cameraEnhancer.open();
29-
}
22+
// Starts streaming the video
23+
if (cameraEnhancer.isOpen()) {
24+
await cvRouter.stopCapturing();
25+
await cameraView.clearAllInnerDrawingItems();
26+
} else {
27+
await cameraEnhancer.open();
28+
}
3029

31-
// Highlight the selected camera in the camera list container
32-
const currentCamera = cameraEnhancer.getSelectedCamera();
30+
// Highlight the selected camera in the camera list container
31+
const currentCamera = cameraEnhancer.getSelectedCamera();
3332

34-
const currentResolution = judgeCurResolution(cameraEnhancer.getResolution());
35-
cameraListContainer.childNodes.forEach((child) => {
36-
if (currentCamera.deviceId === child.deviceId && currentResolution === child.resolution) {
37-
child.className = "camera-item camera-selected";
38-
}
39-
});
33+
const currentResolution = judgeCurResolution(cameraEnhancer.getResolution());
34+
cameraListContainer.childNodes.forEach((child) => {
35+
if (currentCamera.deviceId === child.deviceId && currentResolution === child.resolution) {
36+
child.className = "camera-item camera-selected";
37+
}
38+
});
4039

41-
// Start capturing based on the selected scan mode template
42-
await cvRouter.startCapturing(SCAN_TEMPLATES[mode]);
43-
// By default, cameraEnhancer captures grayscale images to optimize performance.
44-
// To capture RGB Images, we set the Pixel Format to EnumImagePixelFormat.IPF_ABGR_8888
45-
cameraEnhancer.setPixelFormat(Dynamsoft.Core.EnumImagePixelFormat.IPF_ABGR_8888);
40+
// Start capturing based on the selected scan mode template
41+
await cvRouter.startCapturing(SCAN_TEMPLATES[mode]);
42+
// By default, cameraEnhancer captures grayscale images to optimize performance.
43+
// To capture RGB Images, we set the Pixel Format to EnumImagePixelFormat.IPF_ABGR_8888
44+
cameraEnhancer.setPixelFormat(Dynamsoft.Core.EnumImagePixelFormat.IPF_ABGR_8888);
4645

47-
// Update button styles to show selected scan mode
48-
document.querySelectorAll(".scan-option-btn").forEach((button) => {
49-
button.classList.remove("selected");
50-
});
51-
document.querySelector(`#scan-${mode}-btn`).classList.add("selected");
52-
showNotification(`Scan mode switched successfully`, "banner-success");
46+
// Update button styles to show selected scan mode
47+
document.querySelectorAll(".scan-option-btn").forEach((button) => {
48+
button.classList.remove("selected");
49+
});
50+
document.querySelector(`#scan-${mode}-btn`).classList.add("selected");
51+
showNotification(`Scan mode switched successfully`, "banner-success");
5352

54-
// Update the current mode to the newly selected mode and set scan orientation based on current mode
55-
currentMode = mode;
56-
configureScanOrientation();
57-
})();
53+
// Update the current mode to the newly selected mode and set scan orientation based on current mode
54+
currentMode = mode;
55+
configureScanOrientation();
5856
} catch (ex) {
5957
let errMsg = ex.message || ex;
60-
console.error(errMsg);
61-
alert(errMsg);
58+
console.error(`An error occurred: ${errMsg}`);
59+
alert(`An error occurred: ${errMsg}`);
6260
}
6361
})
6462
);
@@ -197,8 +195,8 @@ copyResultBtn.addEventListener("click", () => {
197195
})
198196
.catch((ex) => {
199197
let errMsg = ex.message || ex;
200-
console.error(errMsg);
201-
alert(errMsg);
198+
console.error(`An error occured: ${errMsg}`);
199+
alert(`An error occured: ${errMsg}`);
202200
});
203201
});
204202

@@ -243,7 +241,7 @@ function updateScanOrientationStyles() {
243241
scanHelpMsg.style.display = "none"; // Hide the scan help message in portrait orientation
244242
} else {
245243
scanOrientationBtn.style.backgroundColor = "rgb(34,34,34)";
246-
scanOrientationIcon.style.filter = "invert(0.4)";
244+
scanOrientationIcon.style.filter = "invert(1)";
247245
scanHelpMsg.style.display = "block"; // Show the scan help message in landscape orientation
248246
}
249247
}

VINScanner/js/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function initDCE() {
8383
let init = (async function initCVR() {
8484
await initDCE();
8585
cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
86-
await cvRouter.initSettings("./VIN_Template.json");
86+
await cvRouter.initSettings("./template.json");
8787
cvRouter.setInput(cameraEnhancer);
8888

8989
/* Filter out unchecked and duplicate results. */

VINScanner/minimum-elements.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h3 id="scan-title"></h3>
6767

6868
cvRouter.setInput(cameraEnhancer);
6969
// Set parameters to read VIN through DLR, DBR, and DCP
70-
await cvRouter.initSettings("./VIN_Template.json");
70+
await cvRouter.initSettings("./template.json");
7171

7272
// Filter out unchecked and duplicate results.
7373
const filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
@@ -164,8 +164,8 @@ <h3 id="scan-title"></h3>
164164
cameraEnhancer.setPixelFormat(Dynamsoft.Core.EnumImagePixelFormat.IPF_ABGR_8888);
165165
} catch (ex) {
166166
let errMsg = ex.message || ex;
167-
console.error(errMsg);
168-
alert(errMsg);
167+
console.error(`An error occurred: ${errMsg}`);
168+
alert(`An error occurred: ${errMsg}`);
169169
}
170170
})
171171
);
File renamed without changes.

0 commit comments

Comments
 (0)