Skip to content

Commit

Permalink
Upgrade demo to support frame return display
Browse files Browse the repository at this point in the history
  • Loading branch information
willmorgan committed Jan 14, 2022
1 parent c6379bf commit 49938eb
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 50 deletions.
6 changes: 4 additions & 2 deletions demo/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"private": true,
"type": "module",
"dependencies": {
"@hapi/hapi": "^20.0.3",
"@hapi/inert": "^6.0.3",
"@hapi/basic": "^6.0.0",
"@hapi/hapi": "^20.2.1",
"@hapi/inert": "^6.0.4",
"dotenv": "^8.2.0",
"prettier": "^2.2.1",
"superagent": "^6.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export class PlatformAPI {
.set(this.withHeaders())
.send(
this.withJsonAuth({
user_id: userId,
token,
ip: "127.0.0.1", // @todo: change when IPv6 is fully supported
client: "superagent",
user_id: userId,
})
)
)
Expand Down
6 changes: 3 additions & 3 deletions demo/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ async function init() {
server.route({
method: "GET",
path: "/{param*}",
options: { cors: { origin: ["*"] } },
handler: {
directory: {
path: resolve(__dirname, "static"),
index: "index.html",
}
}
},
},
})

server.route({
Expand All @@ -55,7 +56,6 @@ async function init() {

console.log("iProov tokens will be created on %s with API_KEY %s", BASE_URL, API_KEY)
console.log("Web SDK example available at %s", "http://localhost:" + EXAMPLE_SERVER_PORT)

}

process.on("unhandledRejection", (err) => {
Expand Down
11 changes: 9 additions & 2 deletions demo/src/static/js/iproov-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ export const IPROOV_EVENTS = [
"unsupported",
]

export function createSDK(logger, token, base_url) {
export function createSDK(logger, token, base_url, { onResult }) {
const template = document.querySelector("#iproov_template").content.cloneNode(true)
const iProov = document.createElement("iproov-me")
iProov.setAttribute("token", token)
iProov.setAttribute("base_url", base_url)
iProov.setAttribute("assets_url", "/node_modules/@iproov/web/")
iProov.setAttribute("debug", "true")
iProov.addEventListener("progress", (event) => {
const { progress, message } = event.detail
document.querySelector(".progress__inner").style.width = progress + '%'
document.querySelector(".progress__inner").style.width = progress + "%"
document.querySelector(".progress__text").innerText = message
})
;["passed", "failed"].forEach((resultEvent) => {
iProov.addEventListener(resultEvent, () => {
onResult(resultEvent)
})
})
iProov.append(template)
IPROOV_EVENTS.forEach((eventName) => {
iProov.addEventListener(eventName, (event) => {
Expand Down
35 changes: 33 additions & 2 deletions demo/src/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createSDK } from "./iproov-integration.js"
* Initialize a new SDK instance or handle any errors.
*/
async function submitTokenRequest() {
document.querySelector("button[type=submit]").textContent = "Loading..."
const formData = new FormData(document.querySelector("#token_config"))
const payload = {}
for (let [field, value] of formData.entries()) {
Expand Down Expand Up @@ -89,7 +90,7 @@ function createSupportChecker() {
*/
async function initializeSDK(body) {
const { token, base_url } = body
const iProov = createSDK(console, token, base_url)
const iProov = createSDK(console, token, base_url, { onResult: renderFrame })
const container = document.querySelector("#iproovme_container")
container.innerHTML = ""
container.appendChild(iProov)
Expand All @@ -99,11 +100,41 @@ async function initializeSDK(body) {
}
const wrapper = document.querySelector("#iproov_wrapper")
wrapper.classList.remove("hidden")

document.querySelector("#token_config").classList.add("collapsed")
document.querySelector("button[type=submit]").textContent = "Create token"

iProov.addEventListener("ready", () => {
iProov.querySelector("[slot=button] button").focus()
wrapper.scrollIntoView({ behavior: "smooth", block: "end" })
})
document.querySelector("#token_config").classList.add("collapsed")

async function renderFrame() {
const formData = new FormData(document.querySelector("#token_config"))
const payload = { token }
for (let [field, value] of formData.entries()) {
payload[field] = value
}

const res = await fetch(`/api/claim/${payload.mode}/validate`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(payload),
})

const body = await res.json()
if (body.error) {
return handleError(body)
}

if (body.frame_available) {
const img = document.createElement("img")
img.id = "frame"
img.src = "data:image/png;base64," + body.frame
container.appendChild(img)
img.scrollIntoView({ behavior: "smooth", block: "start" })
}
}
}

initializeSDK.imported = false
Expand Down
100 changes: 60 additions & 40 deletions demo/src/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@
dependencies:
"@hapi/hoek" "9.x.x"

"@hapi/basic@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@hapi/basic/-/basic-6.0.0.tgz#d8372a8eea9583f7077c60b8d55eb5f3a447d4ef"
integrity sha512-nWWSXNCq3WptnP3To2c8kfQiRFDUnd9FQOcMS0B85y1x/m12c0hhp+VdmK60BMe44k6WIog1n6g8f9gZOagqBg==
dependencies:
"@hapi/boom" "9.x.x"
"@hapi/hoek" "9.x.x"

"@hapi/[email protected]":
version "9.1.1"
resolved "https://registry.yarnpkg.com/@hapi/boom/-/boom-9.1.1.tgz#89e6f0e01637c2a4228da0d113e8157c93677b04"
integrity sha512-VNR8eDbBrOxBgbkddRYIe7+8DZ+vSbV6qlmaN2x7eWjsUjy2VmQgChkOKcVZIeupEZYj+I0dqNg430OhwzagjA==
dependencies:
"@hapi/hoek" "9.x.x"

"@hapi/[email protected]":
"@hapi/boom@^9.1.0":
version "9.1.4"
resolved "https://registry.yarnpkg.com/@hapi/boom/-/boom-9.1.4.tgz#1f9dad367c6a7da9f8def24b4a986fc5a7bd9db6"
integrity sha512-Ls1oH8jaN1vNsqcaHVYJrKmgMcKsC1wcp8bujvXrHaAqD2iDYq3HoOwsxwo09Cuda5R5nC0o0IxlrlTuvPuzSw==
dependencies:
"@hapi/hoek" "9.x.x"

"@hapi/[email protected]", "@hapi/bounce@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@hapi/bounce/-/bounce-2.0.0.tgz#e6ef56991c366b1e2738b2cd83b01354d938cf3d"
integrity sha512-JesW92uyzOOyuzJKjoLHM1ThiOvHPOLDHw01YV8yh5nCso7sDwJho1h0Ad2N+E62bZyz46TG3xhAi/78Gsct6A==
Expand All @@ -44,18 +59,18 @@
resolved "https://registry.yarnpkg.com/@hapi/bourne/-/bourne-2.0.0.tgz#5bb2193eb685c0007540ca61d166d4e1edaf918d"
integrity sha512-WEezM1FWztfbzqIUbsDzFRVMxSoLy3HugVcux6KDDtTqzPsLE8NDRHfXvev66aH1i2oOKKar3/XDjbvh/OUBdg==

"@hapi/call@8.x.x":
"@hapi/call@^8.0.0":
version "8.0.1"
resolved "https://registry.yarnpkg.com/@hapi/call/-/call-8.0.1.tgz#9e64cd8ba6128eb5be6e432caaa572b1ed8cd7c0"
integrity sha512-bOff6GTdOnoe5b8oXRV3lwkQSb/LAWylvDMae6RgEWWntd0SHtkYbQukDHKlfaYtVnSAgIavJ0kqszF/AIBb6g==
dependencies:
"@hapi/boom" "9.x.x"
"@hapi/hoek" "9.x.x"

"@hapi/catbox-memory@5.x.x":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@hapi/catbox-memory/-/catbox-memory-5.0.0.tgz#6c18dad1a80737480d1c33bfbefd5d028deec86d"
integrity sha512-ByuxVJPHNaXwLzbBv4GdTr6ccpe1nG+AfYt+8ftDWEJY7EWBWzD+Klhy5oPTDGzU26pNUh1e7fcYI1ILZRxAXQ==
"@hapi/catbox-memory@^5.0.0":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@hapi/catbox-memory/-/catbox-memory-5.0.1.tgz#cb63fca0ded01d445a2573b38eb2688df67f70ac"
integrity sha512-QWw9nOYJq5PlvChLWV8i6hQHJYfvdqiXdvTupJFh0eqLZ64Xir7mKNi96d5/ZMUAqXPursfNDIDxjFgoEDUqeQ==
dependencies:
"@hapi/boom" "9.x.x"
"@hapi/hoek" "9.x.x"
Expand Down Expand Up @@ -89,29 +104,29 @@
resolved "https://registry.yarnpkg.com/@hapi/file/-/file-2.0.0.tgz#2ecda37d1ae9d3078a67c13b7da86e8c3237dfb9"
integrity sha512-WSrlgpvEqgPWkI18kkGELEZfXr0bYLtr16iIN4Krh9sRnzBZN6nnWxHFxtsnP684wueEySBbXPDg/WfA9xJdBQ==

"@hapi/hapi@^20.0.3":
version "20.0.3"
resolved "https://registry.yarnpkg.com/@hapi/hapi/-/hapi-20.0.3.tgz#e72cad460394e6d2c15f9c57abb5d3332dea27e3"
integrity sha512-aqJVHVjoY3phiZsgsGjDRG15CoUNIs1azScqLZDOCZUSKYGTbzPi+K0QP+RUjUJ0m8L9dRuTZ27c8HKxG3wEhA==
"@hapi/hapi@^20.2.1":
version "20.2.1"
resolved "https://registry.yarnpkg.com/@hapi/hapi/-/hapi-20.2.1.tgz#7482bc28757cb4671623a61bdb5ce920bffc8a2f"
integrity sha512-OXAU+yWLwkMfPFic+KITo+XPp6Oxpgc9WUH+pxXWcTIuvWbgco5TC/jS8UDvz+NFF5IzRgF2CL6UV/KLdQYUSQ==
dependencies:
"@hapi/accept" "^5.0.1"
"@hapi/ammo" "^5.0.1"
"@hapi/boom" "9.x.x"
"@hapi/bounce" "2.x.x"
"@hapi/call" "8.x.x"
"@hapi/boom" "^9.1.0"
"@hapi/bounce" "^2.0.0"
"@hapi/call" "^8.0.0"
"@hapi/catbox" "^11.1.1"
"@hapi/catbox-memory" "5.x.x"
"@hapi/catbox-memory" "^5.0.0"
"@hapi/heavy" "^7.0.1"
"@hapi/hoek" "9.x.x"
"@hapi/mimos" "5.x.x"
"@hapi/hoek" "^9.0.4"
"@hapi/mimos" "^6.0.0"
"@hapi/podium" "^4.1.1"
"@hapi/shot" "^5.0.1"
"@hapi/somever" "3.x.x"
"@hapi/shot" "^5.0.5"
"@hapi/somever" "^3.0.0"
"@hapi/statehood" "^7.0.3"
"@hapi/subtext" "^7.0.3"
"@hapi/teamwork" "5.x.x"
"@hapi/topo" "5.x.x"
"@hapi/validate" "^1.1.0"
"@hapi/teamwork" "^5.1.0"
"@hapi/topo" "^5.0.0"
"@hapi/validate" "^1.1.1"

"@hapi/heavy@^7.0.1":
version "7.0.1"
Expand All @@ -127,10 +142,10 @@
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.1.tgz#9daf5745156fd84b8e9889a2dc721f0c58e894aa"
integrity sha512-CAEbWH7OIur6jEOzaai83jq3FmKmv4PmX1JYfs9IrYcGEVI/lyL1EXJGCj7eFVJ0bg5QR8LMxBlEtA+xKiLpFw==

"@hapi/inert@^6.0.3":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@hapi/inert/-/inert-6.0.3.tgz#57af5d912893fabcb57eb4b956f84f6cd8020fe1"
integrity sha512-Z6Pi0Wsn2pJex5CmBaq+Dky9q40LGzXLUIUFrYpDtReuMkmfy9UuUeYc4064jQ1Xe9uuw7kbwE6Fq6rqKAdjAg==
"@hapi/inert@^6.0.4":
version "6.0.4"
resolved "https://registry.yarnpkg.com/@hapi/inert/-/inert-6.0.4.tgz#0544221eabc457110a426818358d006e70ff1f41"
integrity sha512-tpmNqtCCAd+5Ts07bJmMaA79+ZUIf0zSWnQMaWtbcO4nGrO/yXB2AzoslfzFX2JEV9vGeF3FfL8mYw0pHl8VGg==
dependencies:
"@hapi/ammo" "5.x.x"
"@hapi/boom" "9.x.x"
Expand All @@ -150,10 +165,10 @@
"@hapi/cryptiles" "5.x.x"
"@hapi/hoek" "9.x.x"

"@hapi/mimos@5.x.x":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@hapi/mimos/-/mimos-5.0.0.tgz#245c6c98b1cc2c13395755c730321b913de074eb"
integrity sha512-EVS6wJYeE73InTlPWt+2e3Izn319iIvffDreci3qDNT+t3lA5ylJ0/SoTaID8e0TPNUkHUSsgJZXEmLHvoYzrA==
"@hapi/mimos@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@hapi/mimos/-/mimos-6.0.0.tgz#daa523d9c07222c7e8860cb7c9c5501fd6506484"
integrity sha512-Op/67tr1I+JafN3R3XN5DucVSxKRT/Tc+tUszDwENoNpolxeXkhrJ2Czt6B6AAqrespHoivhgZBWYSuANN9QXg==
dependencies:
"@hapi/hoek" "9.x.x"
mime-db "1.x.x"
Expand Down Expand Up @@ -186,18 +201,18 @@
"@hapi/teamwork" "5.x.x"
"@hapi/validate" "1.x.x"

"@hapi/shot@^5.0.1":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@hapi/shot/-/shot-5.0.4.tgz#6c978314f21a054c041f4becc50095dd78d3d775"
integrity sha512-PcEz0WJgFDA3xNSMeONgQmothFr7jhbbRRSAKaDh7chN7zOXBlhl13bvKZW6CMb2xVfJUmt34CW3e/oExMgBhQ==
"@hapi/shot@^5.0.5":
version "5.0.5"
resolved "https://registry.yarnpkg.com/@hapi/shot/-/shot-5.0.5.tgz#a25c23d18973bec93c7969c51bf9579632a5bebd"
integrity sha512-x5AMSZ5+j+Paa8KdfCoKh+klB78otxF+vcJR/IoN91Vo2e5ulXIW6HUsFTCU+4W6P/Etaip9nmdAx2zWDimB2A==
dependencies:
"@hapi/hoek" "9.x.x"
"@hapi/validate" "1.x.x"

"@hapi/somever@3.x.x":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@hapi/somever/-/somever-3.0.0.tgz#f4e9b16a948415b926b4dd898013602b0cb45758"
integrity sha512-Upw/kmKotC9iEmK4y047HMYe4LDKsE5NWfjgX41XNKmFvxsQL7OiaCWVhuyyhU0ShDGBfIAnCH8jZr49z/JzZA==
"@hapi/somever@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@hapi/somever/-/somever-3.0.1.tgz#9961cd5bdbeb5bb1edc0b2acdd0bb424066aadcc"
integrity sha512-4ZTSN3YAHtgpY/M4GOtHUXgi6uZtG9nEZfNI6QrArhK0XN/RDVgijlb9kOmXwCR5VclDSkBul9FBvhSuKXx9+w==
dependencies:
"@hapi/bounce" "2.x.x"
"@hapi/hoek" "9.x.x"
Expand Down Expand Up @@ -228,19 +243,19 @@
"@hapi/pez" "^5.0.1"
"@hapi/wreck" "17.x.x"

"@hapi/[email protected]":
"@hapi/[email protected]", "@hapi/teamwork@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@hapi/teamwork/-/teamwork-5.1.0.tgz#7801a61fc727f702fd2196ef7625eb4e389f4124"
integrity sha512-llqoQTrAJDTXxG3c4Kz/uzhBS1TsmSBa/XG5SPcVXgmffHE1nFtyLIK0hNJHCB3EuBKT84adzd1hZNY9GJLWtg==

"@hapi/topo@5.x.x", "@hapi/topo@^5.0.0":
"@hapi/topo@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.0.0.tgz#c19af8577fa393a06e9c77b60995af959be721e7"
integrity sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw==
dependencies:
"@hapi/hoek" "^9.0.0"

"@hapi/[email protected]", "@hapi/validate@^1.1.0":
"@hapi/[email protected]", "@hapi/validate@^1.1.1":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@hapi/validate/-/validate-1.1.3.tgz#f750a07283929e09b51aa16be34affb44e1931ad"
integrity sha512-/XMR0N0wjw0Twzq2pQOzPBZlDzkekGcoCtzO314BpIEsbXdYGthQUbxgkGDf4nhk1+IPDAsXqWjMohRQYO06UA==
Expand Down Expand Up @@ -298,6 +313,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

fast-safe-stringify@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
Expand Down

0 comments on commit 49938eb

Please sign in to comment.