Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 61526ee

Browse files
authored
Merge pull request #4 from Dynamsoft/_dev
Dev
2 parents fb69733 + 5f77841 commit 61526ee

35 files changed

+873
-1298
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ yarn.lock
4040
/*.txt
4141
/.gitattributes
4242
/.*ignore
43-
/DCE-*
43+
/dynamsoft-camera-enhancer-js-*
4444
/sampleFromGithub
4545
/src
46+
/doc
4647
/Web.config
47-
/samples.url
4848
/samples
4949
/temp
5050
/public
51-
/doc/api reference
5251
/README.html
5352

53+
!/legal.txt
5454
!/package.json
5555
!/LICENSE
5656

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[InternetShortcut]
2-
URL=https://www.dynamsoft.com/camera-enhancer/docs/programming/javascript/api-reference/?ver=latest
2+
URL=https://www.dynamsoft.com/camera-enhancer/docs/programming/javascript/api-reference/?ver=3.0.0

README.md

Lines changed: 99 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,89 @@ Allow your website to easily control cameras on desktop and mobile devices.
44

55
Once integrated, your users can open your website in a browser, access their cameras to stream live video and acquire realtime frames.
66

7-
In this guide, you will learn step by step on how to integrate this library into your website.
7+
In this guide, you will learn step by step on how to integrate this SDK into your website.
88

99
**Table of Contents**
1010

1111
* [Getting Started](#getting-started)
12-
+ [Include the library](#include-the-library)
13-
+ [Interact with the library](#interact-with-the-library)
14-
* [Hosting the Library](#hosting-the-library)
12+
* [Include the SDK](#include-the-sdk)
13+
* [Interact with the SDK](#interact-with-the-sdk)
14+
* [Hosting the SDK](#hosting-the-sdk)
1515
* [FAQ](#faq)
1616

17-
**Example Usage**
18-
19-
Read the user guide of Dynamsoft Label Recognizer on how DCE helps the SDK achieve video recognition:
20-
21-
* [Dynamsoft Label Recognizer User Guide](https://www.dynamsoft.com/label-recognition/programming/javascript/user-guide.html?ver=latest&utm_source=dceguide)
17+
> **Example Usage**
18+
>
19+
> Read the user guide of Dynamsoft Label Recognizer on how DCE helps the SDK achieve video recognition:
20+
>
21+
> * [Dynamsoft Label Recognizer User Guide](https://www.dynamsoft.com/label-recognition/programming/javascript/user-guide.html?ver=latest&utm_source=dceguide)
2222
2323
## Getting Started
2424

25-
### Include the library
25+
### Include the SDK
2626

2727
#### Use a CDN
2828

29-
The simplest way to include the library is to use either the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN.
29+
The simplest way to include the SDK is to use either the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN.
3030

3131
* jsDelivr
3232

33-
```html
34-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.3.2/dist/dce.js"></script>
35-
```
33+
```html
34+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@3.0.0/dist/dce.js"></script>
35+
```
3636

3737
* UNPKG
3838

39-
```html
40-
<script src="https://unpkg.com/dynamsoft-camera-enhancer@2.3.2/dist/dce.js"></script>
41-
```
39+
```html
40+
<script src="https://unpkg.com/dynamsoft-camera-enhancer@3.0.0/dist/dce.js"></script>
41+
```
4242

43-
#### Host the library yourself (recommended)
43+
#### Host the SDK yourself
4444

45-
Besides using the CDN, you can also download the library and host it locally.
45+
Besides using the CDN, you can also download the SDK and host it locally.
4646

47-
The following shows a few ways to download the library.
47+
The following shows a few ways to download the SDK.
4848

4949
* From the website
5050

5151
[Download the JavaScript Package](https://www.dynamsoft.com/camera-enhancer/downloads/1000021-confirmation/?utm_source=github)
5252

5353
* yarn
5454

55-
```cmd
56-
$ yarn add dynamsoft-camera-enhancer
57-
```
55+
```cmd
56+
yarn add dynamsoft-camera-enhancer
57+
```
5858

5959
* npm
6060

61-
```
62-
$ npm install dynamsoft-camera-enhancer --save
63-
```
61+
```cmd
62+
npm install dynamsoft-camera-enhancer --save
63+
```
6464

65-
Depending on how you downloaded the library and where you put it. You can typically include it like this:
65+
Depending on how you downloaded the SDK and where you put it. You can typically include it like this:
6666

6767
```html
68-
<script src="/dce-js-2.3.2/dist/dce.js"></script>
68+
<script src="/dce-js-3.0.0/dist/dce.js"></script>
69+
```
6970

7071
or
7172

7273
```html
7374
<script src="/node_modules/dynamsoft-camera-enhancer/dist/dce.js"></script>
7475
```
7576

76-
Read more on [how to host the library](#hosting-the-library).
77+
or
78+
79+
```typescript
80+
import { CameraEnhancer } from 'dynamsoft-camera-enhancer';
81+
```
82+
83+
Read more on [how to host the SDK](#hosting-the-sdk).
7784

78-
### Interact with the library
85+
### Interact with the SDK
7986

8087
#### Create a `CameraEnhancer` object
8188

82-
To use the library, we need to create a `CameraEnhancer` object first.
89+
To use the SDK, we need to create a `CameraEnhancer` object first.
8390

8491
```javascript
8592
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
@@ -93,19 +100,19 @@ As shown in the code snippet below, before opening the video stream, we need to
93100
<!-- Define an element to hold the UI element -->
94101
<div id="enhancerUIContainer" style="width:100%;height:500px;"></div>
95102
<script>
96-
(async () => {
97-
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
98-
document.getElementById("enhancerUIContainer").appendChild(enhancer.getUIElement());
99-
await enhancer.open(true);
100-
})();
103+
(async () => {
104+
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
105+
await enhancer.open();
106+
document.getElementById("enhancerUIContainer").appendChild(enhancer.getUIElement());
107+
})();
101108
</script>
102109
```
103110

104111
#### Customize the UI
105112

106113
The built-in UI of the `CameraEnhancer` object is defined in the file `dist/dce.ui.html` . There are a few ways to customize it:
107114

108-
* Modify the file `dist/dce.ui.html` directly.
115+
* Modify the file `dist/dce.ui.html` directly.
109116

110117
This option is only possible when you host this file on your own web server instead of using a CDN.
111118

@@ -117,101 +124,102 @@ Dynamsoft.DCE.CameraEnhancer.defaultUIElementURL = "THE-URL-TO-THE-FILE";
117124

118125
> You must set `defaultUIElementURL` before you call `createInstance()` .
119126
120-
* Append the default UI element to your page as shown in [Configure the CameraEnhancer object](#configure-the-cameraenhancer-object), customize it before showing it.
127+
* Append the default UI element to your page as shown in [Configure the CameraEnhancer object](#configure-the-cameraenhancer-object), customize it if necessary.
121128

122129
```html
123130
<!-- Define an element to hold the UI element -->
124131
<div id="enhancerUIContainer" style="width:100%;height:500px;"></div>
125132
<script>
126-
(async () => {
127-
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
128-
document.getElementById("enhancerUIContainer").appendChild(enhancer.getUIElement());
129-
// The following line hides the close button
130-
document.getElementsByClassName("dce-btn-close")[0].style.display = "none";
131-
await enhancer.open(true);
132-
})();
133+
(async () => {
134+
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
135+
// In order to get the UIElement to put on the page, call open() first.
136+
await enhancer.open();
137+
// Gets the internally built UI element and bind it to an element on the page.
138+
document.getElementById("enhancerUIContainer").appendChild(enhancer.getUIElement());
139+
// The following line hides the close button
140+
document.getElementsByClassName("dce-btn-close")[0].style.display = "none";
141+
})();
133142
</script>
134143
```
135144

136145
* Build the UI element into your own web page and specify it with the API `setUIElement(HTMLElement)`.
137146

138-
+ Embed only the video
139-
140-
```html
141-
<div id="enhancerUIContainer" style="width:100%;height:100%;">
142-
<div class="dce-video-container" style="position:relative;width:100%;height:500px;"></div>
143-
</div>
144-
<script>
145-
(async () => {
146-
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
147-
await enhancer.setUIElement(document.getElementById("enhancerUIContainer"));
148-
await enhancer.open(true);
149-
})();
150-
</script>
151-
```
147+
* Embed only the video
148+
149+
```html
150+
<div id="enhancerUIContainer" style="width:100%;height:100%;">
151+
<div class="dce-video-container" style="position:relative;width:100%;height:500px;"></div>
152+
</div>
153+
<script>
154+
(async () => {
155+
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
156+
await enhancer.setUIElement(document.getElementById("enhancerUIContainer"));
157+
await enhancer.open();
158+
})();
159+
</script>
160+
```
152161

153162
> The video element will be created and appended to the DIV element with the class `dce-video-container`, make sure the class name is the same. Besides, the CSS property `position` of the DIV element must be either `relative`, `absolute`, `fixed`, or `sticky`.
154163
155-
+ Add the camera list and resolution list. If the class names for these lists match the default ones, `dce-sel-camera` and `dce-sel-resolution` , the library will automatically populate the lists and handle the camera/resolution switching.
164+
* Add the camera list and resolution list. If the class names for these lists match the default ones, `dce-sel-camera` and `dce-sel-resolution` , the SDK will automatically populate the lists and handle the camera/resolution switching.
156165

157-
```html
158-
<select class="dce-sel-camera"></select>
159-
```
166+
```html
167+
<select class="dce-sel-camera"></select>
168+
```
160169

161-
```html
162-
<select class="dce-sel-resolution"></select>
163-
```
170+
```html
171+
<select class="dce-sel-resolution"></select>
172+
```
164173

165-
> By default, only 3 hard-coded resolutions (1920 x 1080, 1280 x 720, 640 x 480), are populated as options. You can show a customized set of options by hardcoding them.
174+
> By default, only 4 hard-coded resolutions (3840 x 2160, 1920 x 1080, 1280 x 720, 640 x 480), are populated as options. You can show a customized set of options by hardcoding them.
166175
167-
```html
168-
<select class="dce-sel-resolution">
169-
<option class="dce-opt-gotResolution" value="got"></option>
170-
<option data-width="1280" data-height="720">1280x720</option>
171-
<option data-width="800" data-height="600">800x600</option>
172-
<option data-width="640" data-height="480">640x480</option>
173-
</select>
174-
```
176+
```html
177+
<select class="dce-sel-resolution">
178+
<option class="dce-opt-gotResolution" value="got"></option>
179+
<option data-width="1280" data-height="720">1280x720</option>
180+
<option data-width="1920" data-height="1080">1920x1080</option>
181+
</select>
182+
```
175183

176-
> Generally, you need to provide a resolution that the camera supports. However, in case a camera does not support the specified resolution, it usually uses the cloest supported resolution. As a result, the selected resolution may not be the actual resolution. In this case, add an option with the class name `dce-opt-gotResolution` (as shown above) and the library will then use it to show the **actual resolution**.
184+
> Generally, you need to provide a resolution that the camera supports. However, in case a camera does not support the specified resolution, it usually uses the cloest supported resolution. As a result, the selected resolution may not be the actual resolution. In this case, add an option with the class name `dce-opt-gotResolution` (as shown above) and the SDK will then use it to show the **actual resolution**.
177185
178-
## Hosting the library
186+
## Hosting the SDK
179187

180188
### Step One: Deploy the dist folder
181189

182-
Once you have downloaded the library, you can locate the "dist" directory and copy it to your project (usually as part of your website / web application). The following shows some of the files in this directory:
190+
Once you have downloaded the SDK, you can locate the "dist" directory and copy it to your project (usually as part of your website / web application). The following shows some of the files in this directory:
183191

184-
* `dce.js` // The main library file
185-
* `dce.mjs` // For using the library as a module (`<script type="module">`)
192+
* `dce.js` // The main SDK file
193+
* `dce.mjs` // For using the SDK as a module (`<script type="module">`)
186194
* `dce.ui.html` // Defines the default enhancer UI
187195

188196
### Step Two: Configure the Server
189197

190198
* Enable HTTPS
191199

192-
To use the library, you must access your website / web application via a secure HTTPS connection. This is due to browser security restrictions which only grant camera video streaming access to a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).
200+
To use the SDK, you must access your website / web application via a secure HTTPS connection. This is due to browser security restrictions which only grant camera video streaming access to a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).
193201

194-
> For convenience, self-signed certificates are allowed during development and testing.
202+
> For convenience, self-signed certificates are allowed during development and testing. Or use "http://localhost".
195203
196-
### Step Three: Include the library from the server
204+
### Step Three: Include the SDK from the server
197205

198-
Now that the library is hosted on your server, you can include it accordingly.
206+
Now that the SDK is hosted on your server, you can include it accordingly.
199207

200208
```html
201-
<script src="https://www.yourwebsite.com/dynamsoft-camera-enhancer/dist/dce.js"></script>
209+
<script src="https://www.yourwebsite.com/PATH-TO-THE-SDK/dynamsoft-camera-enhancer/dist/dce.js"></script>
202210
```
203211

204212
## FAQ
205213

206214
### Can I open the web page directly from the hard drive?
207215

208-
Yes, for simple testing purposes, it's perfectly fine to open the file directly from the hard drive. However, you might encounter some issues in doing so (like unable to access the camera, etc.). The recommendation is to deploy this page to your web server and run it over **HTTPS**. If you don't have a ready-to-use web server but have a package manager like *npm* or *yarn*, you can set up a simple HTTP server in minutes. Check out [ `http-server` on npm](https://www.npmjs.com/package/http-server) or [yarn](https://yarnpkg.com/package/http-server).
216+
Yes, for simple testing purposes, it's perfectly fine to open the file directly from the hard drive. However, you might encounter some issues in doing so (like unable to access the camera, etc.). The recommendation is to deploy this page to your web server and run it over **HTTPS**. If you don't have a ready-to-use web server but have a package manager like *npm* or *yarn*, you can set up a simple HTTP server in minutes. Check out [`http-server` on npm](https://www.npmjs.com/package/http-server) or [yarn](https://yarnpkg.com/package/http-server).
209217

210218
### Why can't I use my camera?
211219

212220
If you open the web page as `http://` , the camera may not work and you see the following error in the browser console:
213221

214-
> [Deprecation] getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
222+
> [Deprecation] getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See [https://goo.gl/rStTGz](https://goo.gl/rStTGz) for more details.
215223
216224
* In Safari 12 the equivalent error is:
217225

@@ -221,7 +229,7 @@ You get this error because the API [getUserMedia](https://developer.mozilla.org/
221229

222230
To make sure your web application can access the camera, please configure your web server to support HTTPS. The following links may help.
223231

224-
+ NGINX: [Configuring HTTPS servers](https://nginx.org/en/docs/http/configuring_https_servers.html)
225-
+ IIS: [Create a Self Signed Certificate in IIS](https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/)
226-
+ Tomcat: [Setting Up SSL on Tomcat in 5 minutes](https://dzone.com/articles/setting-ssl-tomcat-5-minutes)
227-
+ Node.js: [npm tls](https://nodejs.org/docs/v0.4.1/api/tls.html)
232+
* NGINX: [Configuring HTTPS servers](https://nginx.org/en/docs/http/configuring_https_servers.html)
233+
* IIS: [Create a Self Signed Certificate in IIS](https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/)
234+
* Tomcat: [Setting Up SSL on Tomcat in 5 minutes](https://dzone.com/articles/setting-ssl-tomcat-5-minutes)
235+
* Node.js: [npm tls](https://nodejs.org/docs/v0.4.1/api/tls.html)

0 commit comments

Comments
 (0)