1.0.0 • Published 3 years ago

glamar-sdk v1.0.0

Weekly downloads
13
License
ISC
Repository
-
Last release
3 years ago

GlamAR Web SDK

GlamAR Web SDK provides a set of APIs that enable real time virtual makeup try-on on a web page.

Installation

Via script tags:

<script src="https://unpkg.com/glamar-sdk@1.0.0/dist/glamar-sdk.umd.js"></script>

Via npm:

Using npm:

npm install glamar-sdk

Using yarn:

yarn install glamar-sdk

Usage

If you are using via npm, first add:

import * as GlamAR from "glamar-sdk";

Then:

// Pass in the id of a container and your API key
GlamAR.init("GlamAR-module", <<YOUR_API_KEY>>);
GlamAR.addEventListener('opened', () =>
  GlamAR.applyMakeupBySku(<<SKU_ID>>)
);

also call applyMakeupBySku on any event to apply the makeup

<button onclick="GlamAR.applyMakeupBySku(<<SKU_ID>>)">Apply Lip Color</button>

API Reference

Methods

MethodsDescription
GlamAR.initGlamAR.init(containerId, apiKey, openLiveMakeup)
Parameters: containerId: string, id of the div to mount the widget apiKey: string, api key openLiveMakeup: boolean, whether to open widget in live mode.
Return Value: None
Initializes the widget
GlamAR.applyMakeupBySkuGlamAR.applyMakeupBySku(skuId, callback)
Parameters: skuId: number, a sku IDcallback(optional): function, fires after the makeup effect is applied
Return Value: None
Changes the makeup effect by the given sku ID, you could retrieve your sku information from admin panel.
GlamAR.addEventListenerGlamAR.addEventListener(eventName, handlerFunction)
Parameters: eventName: string, a named eventhandlerFunction: function, a handler
Return Value: None
Adds the listener to the given event name.
GlamAR.removeEventListenerGlamAR.removeEventListener(eventName, handlerFunction)
Parameters:eventName: string, a named eventhandlerFunction: function, a handler
Return Value: None
Removes the given listener for the event name.
GlamAR.getAllSKUsGlamAR.getAllSKUs()
Parameters: None
Return Value: Promise that resolves to an array of SKUs available for the given API key.
Returns an array of available SKUs for the given API key.
GlamAR.resetGlamAR.reset()
Parameters: None
Return Value: None
Removes all the makeup effects from the canvas.
GlamAR.closeGlamAR.close()
Parameters: None
Return Value: None
Closes canvas and back to main widget page.
GlamAR.snapshotGlamAR.snapshot(contentType, callback)
Parameters:contentType: string, valid value: base64 or blob
Return Value: image in base64 or blob
Takes a snapshot of current result window.
GlamAR.isLoadedGlamAR.isLoaded()
Parameters: None
Return Value: true if the module is loaded else false
Returns status of module loading.
GlamAR.isLoadingGlamAR.isLoading()
Parameters: None
Return Value: true if the module is loading else false
Returns status of module loading.

Events

EventsDescription
loadedPayload: NoneThis event is fired when GlamAR module is loaded
openedPayload: NoneThis event is fired when the GlamAR module is opened.
closedPayload: NoneThis event is fired when the canvas is closed and user returns to main widget page.
camera-openedPayload: NoneThis event is fired when the camera is opened.
camera-closedPayload: NoneThis event is fired when the camera is closed.
camera-failedPayload: NoneThis event is fired when the camera failed. Either user refuses to grant permission or the app is unable to retrieve video stream normally.
photo-loadedPayload: NoneThis event is fired when a given photo loaded on the canvas.
sku-appliedPayload: NoneThis event is fired when a given sku effects are applied.
sku-failedPayload: NoneThis event is fired when a given sku is not applied successfully.
resetPayload: NoneThis event is fired when all the effects are reset.
errorPayload: ErrorThis event is fired anytime an error occurs.

Sample WebAR SDK app

See the Glamar SDK quickstart sample on Gitlab for an example of this SDK in use.