Skip to content

Commit f7afa69

Browse files
committed
Bump DeepAR version, use previewElement container instead of canvas
1 parent 87b93c8 commit f7afa69

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# quickstart-web-npm-js
22

3+
This is a quickstart project for DeepAR Web SDK. It is a minimal example of how to use the SDK.
4+
5+
## View the demo
6+
7+
[https://demo.deepar.ai/quickstart-web-js-npm/](https://demo.deepar.ai/quickstart-web-js-npm/)
8+
9+
## How to run the project
10+
311
- Go to https://developer.deepar.ai
412
- Sign up
513
- Create a project and a Web app
@@ -9,3 +17,10 @@
917
- Run `npm install`
1018
- Run `npm run dev`
1119
- If the browser doesn't open automatically, open http://localhost:8888
20+
21+
## How to build the project
22+
23+
- Open the terminal in the root of the project
24+
- Run `npm install`
25+
- Run `npm run build`
26+
- The build will be in the `dist` folder

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"webpack-dev-server": "^4.11.0"
1616
},
1717
"dependencies": {
18-
"deepar": "^5.2.0"
18+
"deepar": "^5.4.1"
1919
}
2020
}

public/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<img
2626
id="initial-loading-logo"
2727
style="max-width: 200px"
28-
src="/images/crystal.png"
28+
src="./images/crystal.png"
2929
class="animate-bounce"
3030
/>
3131
<div
@@ -43,7 +43,7 @@
4343
<img
4444
id="initial-loading-text"
4545
style="max-width: 140px; margin-top: 30px"
46-
src="/images/powered-by.svg"
46+
src="./images/powered-by.svg"
4747
/>
4848
</div>
4949
</div>
@@ -69,8 +69,8 @@
6969
</div>
7070

7171
<!-- AR screen -->
72-
<div id="ar-screen" style="display: none">
73-
<canvas class="deepar" id="deepar-canvas"></canvas>
72+
<div class="fixed-fullscreen screen" id="ar-screen" style="display: none">
73+
<!-- <canvas class="deepar" id="deepar-canvas"></canvas> -->
7474

7575
<div class="carousel" id="carousel">
7676
<div class="carousel-center" id="carousel-center">

public/style.css

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ body {
1818
#permission-denied-screen,
1919
#permission-denied-background {
2020
background-color: rgb(17 24 39 / 1);
21-
background-image: url("/images/gradient.svg"), url("/images/bg-grid-dark.svg");
21+
background-image: url("./images/gradient.svg"), url("./images/bg-grid-dark.svg");
2222
background-repeat: no-repeat, repeat;
2323
display: flex;
2424
align-items: center;
2525
justify-content: center;
26-
height: 100vh;
26+
}
27+
28+
.fixed-fullscreen {
29+
position: fixed;
30+
top: 0;
31+
left: 0;
2732
width: 100vw;
33+
height: 100vh;
2834
}
2935

3036
/* Carousel */

src/index.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ console.log("Deepar version: " + deepar.version);
77
// Top-level await is not supported.
88
// So we wrap the whole code in an async function that is called immediatly.
99
(async function () {
10-
// Resize the canvas according to screen size and pixel ratio.
11-
const canvas = document.getElementById("deepar-canvas");
12-
const dpr = window.devicePixelRatio || 1;
13-
canvas.width = Math.floor(window.innerWidth * dpr);
14-
canvas.height = Math.floor(window.innerHeight * dpr);
10+
// Get the element you want to place DeepAR into. DeepAR will inherit its width and height from this and fill it.
11+
const previewElement = document.getElementById("ar-screen");
1512

1613
// trigger loading progress bar animation
1714
const loadingProgressBar = document.getElementById("loading-progress-bar");
@@ -43,12 +40,17 @@ console.log("Deepar version: " + deepar.version);
4340
try {
4441
deepAR = await deepar.initialize({
4542
licenseKey: "your_license_key_goes_here",
46-
canvas,
43+
previewElement,
4744
effect: effectList[0],
4845
// Removing the rootPath option will make DeepAR load the resources from the JSdelivr CDN,
4946
// which is fine for development but is not recommended for production since it's not optimized for performance and can be unstable.
5047
// More info here: https://docs.deepar.ai/deepar-sdk/deep-ar-sdk-for-web/download-optimizations#custom-deployment-of-deepar-web-resources
5148
rootPath: "./deepar-resources",
49+
additionalOptions: {
50+
cameraConfig: {
51+
// facingMode: 'environment' // uncomment this line to use the rear camera
52+
},
53+
},
5254
});
5355
} catch (error) {
5456
console.error(error);
@@ -57,15 +59,6 @@ console.log("Deepar version: " + deepar.version);
5759
return;
5860
}
5961

60-
var resizeCanvas = function () {
61-
const canvas = document.getElementById("deepar-canvas");
62-
const dpr = window.devicePixelRatio || 1;
63-
canvas.width = Math.floor(window.innerWidth * dpr);
64-
canvas.height = Math.floor(window.innerHeight * dpr);
65-
};
66-
67-
window.addEventListener("resize", resizeCanvas);
68-
6962
// Hide the loading screen.
7063
document.getElementById("loading-screen").style.display = "none";
7164
document.getElementById("ar-screen").style.display = "block";

0 commit comments

Comments
 (0)