Initially, you'll see this instruction screen, guiding the user on best practices for good sefie capture:
After granting access, the capture screen appears prompting the user to present their face and take a selfie:
Upon capturing a selfie, you'll be presented with the review screen:
Document Capture
If the capture-id attribute is used, you will be presented with additional screens for document capture (front, back (optional by adding hide-back-of-id attribute), review):
Capture front of document only
<!-- Example: Capture front of document only --><document-capture-screenshide-back-of-id></document-capture-screens>
<!-- Example: Capture selfie and front of document only --><smart-camera-webcapture-idhide-back-of-id></smart-camera-web>
Handle the smart-camera-web.publish event:
When the user approves the captured image, an smart-camera-web.publish event is dispatched. The event returns a CustomEvent payload in e.detail.
Here's a script example to handle the event and send data to a backend endpoint:
Note: when using the selfie-capture-screens listen to selfie-capture-screens.publish event to get the selfie and liveness images.
For document-capture-screens listen to the document-capture-screens.publish event for the document image.
More details here
The provided backend endpoint uses the NodeJS Server to Server library and ExpressJS:
constexpress=require("express");const { v4: UUID } =require("uuid");if (process.env.NODE_ENV==="development") {constdotenv=require("dotenv");dotenv.config();}constSIDCore=require("smile-identity-core");constSIDSignature=SIDCore.Signature;constSIDWebAPI=SIDCore.WebApi;constapp=express();app.use(express.json({ limit:"500kb" }));app.use(express.static("public"));app.post("/",async (req, res, next) => {try {const { PARTNER_ID,API_KEY,SID_SERVER } =process.env;constconnection=newSIDWebAPI(PARTNER_ID,"/callback",API_KEY,SID_SERVER, );constpartner_params_from_server= { user_id:`user-${UUID()}`, job_id:`job-${UUID()}`, job_type:4,// job_type is the simplest job we have which enrolls a user using their selfie };const {images, partner_params: { libraryVersion }, } =req.body;constoptions= { return_job_status:true, };constpartner_params=Object.assign({}, partner_params_from_server, { libraryVersion, });constresult=awaitconnection.submit_job( partner_params, images, {}, options, );res.json(result); } catch (e) {console.error(e); }});// NOTE: This can be used to process responses. don't forget to add it as a callback option in the `connection` config on L22// https://docs.usesmileid.com/further-reading/faqs/how-do-i-setup-a-callbackapp.post("/callback", (req, res, next) => {});app.listen(process.env.PORT||4000);
To receive the images after they have been captured, you can listen to the custom event selfie-capture-screens.publish. The data posted to this event has the structure:
{"detail": {"images": [{ "image":"base64 image","image_type_id":"" }],"meta": {"version":"version of the library in use" } }}
SmartCameraWeb is compatible with most JavaScript frameworks and libraries. For integration with ReactJS, refer to this tutorial due to React-WebComponents compatibility issues.
Support
Tested on the latest versions of Chrome, Edge, Firefox, and Safari. If compatibility issues arise on certain browsers, please notify us.