UNPKG

@plattar/plattar-ar-adapter

Version:

Plattar AR Adapter for interfacing with Google & Apple WebAR

50 lines (49 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SceneProductAR = void 0; const product_ar_1 = require("./product-ar"); const plattar_api_1 = require("@plattar/plattar-api"); const util_1 = require("../util/util"); /** * Allows launching Product AR by providing a SceneProduct ID instead. * SceneProducts are much more convenient to grab from the Plattar CMS */ class SceneProductAR extends product_ar_1.ProductAR { constructor(options) { //super(sceneProductID, variationID, variationSKU); super(options); // this is evaluated in the init() function this._attachedProductID = null; if (!options.productID) { throw new Error("SceneProductAR.constructor(sceneProductID, variationID) - sceneProductID must be defined"); } this._sceneProductID = options.productID; } get sceneProductID() { return this._sceneProductID; } get productID() { if (!this._attachedProductID) { throw new Error("SceneProductAR.productID() - product id was not defined, did you call init()?"); } return this._attachedProductID; } init() { return new Promise((accept, reject) => { if (!util_1.Util.canAugment()) { return reject(new Error("SceneProductAR.init() - cannot proceed as AR not available in context")); } const sceneProduct = new plattar_api_1.SceneProduct(this.sceneProductID); sceneProduct.get().then((sceneProduct) => { const productID = sceneProduct.attributes.product_id; if (!productID) { return reject("SceneProductAR.init() - Scene Product does not have an attached Product instance"); } this._attachedProductID = productID; // execute the standard Product AR functionality return super.init().then(accept).catch(reject); }).catch(reject); }); } } exports.SceneProductAR = SceneProductAR;