@plattar/plattar-ar-adapter 1.118.3 → 1.121.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { LauncherAR } from "./launcher-ar";
2
+ /**
3
+ * Performs AT Functionality using Plattar FileModel types
4
+ */
5
+ export declare class ModelAR extends LauncherAR {
6
+ private _analytics;
7
+ private readonly _modelID;
8
+ private _ar;
9
+ constructor(modelID?: string | undefined | null);
10
+ get modelID(): string;
11
+ private _SetupAnalytics;
12
+ /**
13
+ * Initialise the ModelAR instance. This returns a Promise that resolves
14
+ * successfully if initialisation is successful, otherwise it will fail.
15
+ *
16
+ * filure can occur for a number of reasons but it generally means that AR
17
+ * cannot be performed.
18
+ */
19
+ init(): Promise<LauncherAR>;
20
+ /**
21
+ * Initialise and launch with a single function call. this is mostly for convenience.
22
+ * Use .init() and .start() separately for fine-grained control
23
+ */
24
+ launch(): Promise<void>;
25
+ /**
26
+ * Launches the internal AR instance using an appropriate version of AR Viewers
27
+ */
28
+ start(): void;
29
+ canQuicklook(): boolean;
30
+ canRealityViewer(): boolean;
31
+ canSceneViewer(): boolean;
32
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ModelAR = void 0;
7
+ const plattar_api_1 = require("@plattar/plattar-api");
8
+ const plattar_analytics_1 = require("@plattar/plattar-analytics");
9
+ const util_1 = require("../util/util");
10
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
11
+ const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
12
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
13
+ const launcher_ar_1 = require("./launcher-ar");
14
+ /**
15
+ * Performs AT Functionality using Plattar FileModel types
16
+ */
17
+ class ModelAR extends launcher_ar_1.LauncherAR {
18
+ constructor(modelID = null) {
19
+ super();
20
+ // analytics instance
21
+ this._analytics = null;
22
+ if (!modelID) {
23
+ throw new Error("ModelAR.constructor(modelID) - modelID must be defined");
24
+ }
25
+ this._modelID = modelID;
26
+ this._ar = null;
27
+ }
28
+ get modelID() {
29
+ return this._modelID;
30
+ }
31
+ _SetupAnalytics(model) {
32
+ let analytics = null;
33
+ const project = model.relationships.find(plattar_api_1.Project);
34
+ // setup scene stuff (if any)
35
+ if (project) {
36
+ analytics = new plattar_analytics_1.Analytics(project.id);
37
+ analytics.origin = plattar_api_1.Server.location().type;
38
+ analytics.data.push("applicationId", project.id);
39
+ analytics.data.push("applicationTitle", project.attributes.title);
40
+ analytics.data.push("modelId", model.id);
41
+ analytics.data.push("modelTitle", model.attributes.title);
42
+ this._analytics = analytics;
43
+ }
44
+ }
45
+ /**
46
+ * Initialise the ModelAR instance. This returns a Promise that resolves
47
+ * successfully if initialisation is successful, otherwise it will fail.
48
+ *
49
+ * filure can occur for a number of reasons but it generally means that AR
50
+ * cannot be performed.
51
+ */
52
+ init() {
53
+ return new Promise((accept, reject) => {
54
+ if (!util_1.Util.canAugment()) {
55
+ return reject(new Error("ModelAR.init() - cannot proceed as AR not available in context"));
56
+ }
57
+ const model = new plattar_api_1.FileModel(this.modelID);
58
+ model.include(plattar_api_1.Project);
59
+ model.get().then((model) => {
60
+ // setup the analytics data
61
+ this._SetupAnalytics(model);
62
+ // we need to define our AR module here
63
+ // we are in Safari/Quicklook mode here
64
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
65
+ // model needs to have either USDZ or REALITY files defined
66
+ // we load REALITY stuff first if available
67
+ if (model.attributes.reality_filename && util_1.Util.canRealityViewer()) {
68
+ this._ar = new reality_viewer_1.default();
69
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.reality_filename;
70
+ return accept(this);
71
+ }
72
+ // otherwise, load the USDZ stuff second if available
73
+ if (model.attributes.usdz_filename && util_1.Util.canQuicklook()) {
74
+ this._ar = new quicklook_viewer_1.default();
75
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.usdz_filename;
76
+ return accept(this);
77
+ }
78
+ return reject(new Error("ModelAR.init() - cannot proceed as ModelFile does not have a defined .usdz or .reality file"));
79
+ }
80
+ // check android
81
+ if (util_1.Util.canSceneViewer()) {
82
+ this._ar = new scene_viewer_1.default();
83
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
84
+ return accept(this);
85
+ }
86
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
87
+ // earlier in the process
88
+ return reject(new Error("ModelAR.init() - could not initialise AR correctly, check values"));
89
+ }).catch(reject);
90
+ });
91
+ }
92
+ /**
93
+ * Initialise and launch with a single function call. this is mostly for convenience.
94
+ * Use .init() and .start() separately for fine-grained control
95
+ */
96
+ launch() {
97
+ return new Promise((accept, reject) => {
98
+ this.init().then((value) => {
99
+ value.start();
100
+ return accept();
101
+ }).catch(reject);
102
+ });
103
+ }
104
+ /**
105
+ * Launches the internal AR instance using an appropriate version of AR Viewers
106
+ */
107
+ start() {
108
+ if (!this._ar) {
109
+ throw new Error("ModelAR.start() - cannot proceed as AR instance is null");
110
+ }
111
+ const analytics = this._analytics;
112
+ if (analytics) {
113
+ analytics.data.push("device", this._ar.device);
114
+ analytics.data.push("eventCategory", this._ar.nodeType);
115
+ analytics.data.push("eventAction", "Start Model Augment");
116
+ analytics.write();
117
+ analytics.startRecordEngagement();
118
+ }
119
+ // this was initialised via the init() function
120
+ this._ar.start();
121
+ }
122
+ canQuicklook() {
123
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
124
+ }
125
+ canRealityViewer() {
126
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
127
+ }
128
+ canSceneViewer() {
129
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
130
+ }
131
+ }
132
+ exports.ModelAR = ModelAR;
@@ -103,7 +103,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
103
103
  this._setupAnalytics(product, variation);
104
104
  // we need to define our AR module here
105
105
  // we are in Safari/Quicklook mode here
106
- if (util_1.Util.isSafari()) {
106
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
107
107
  // model needs to have either USDZ or REALITY files defined
108
108
  // we load REALITY stuff first if available
109
109
  if (model.attributes.reality_filename && util_1.Util.canRealityViewer()) {
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * as version from "./version";
4
4
  export { ConfiguratorAR } from "./ar/configurator-ar";
5
5
  export { ProductAR } from "./ar/product-ar";
6
6
  export { SceneAR } from "./ar/scene-ar";
7
+ export { ModelAR } from "./ar/model-ar";
7
8
  export { Util } from "./util/util";
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Util = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.Util = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
26
26
  exports.PlattarWeb = __importStar(require("@plattar/plattar-web"));
27
27
  exports.PlattarQRCode = __importStar(require("@plattar/plattar-qrcode"));
28
28
  exports.version = __importStar(require("./version"));
@@ -32,11 +32,15 @@ var product_ar_1 = require("./ar/product-ar");
32
32
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
33
33
  var scene_ar_1 = require("./ar/scene-ar");
34
34
  Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
35
+ var model_ar_1 = require("./ar/model-ar");
36
+ Object.defineProperty(exports, "ModelAR", { enumerable: true, get: function () { return model_ar_1.ModelAR; } });
35
37
  var util_1 = require("./util/util");
36
38
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
37
39
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
38
40
  const version_1 = __importDefault(require("./version"));
39
41
  if (customElements) {
40
- customElements.define("plattar-embed", plattar_embed_1.default);
42
+ if (customElements.get("plattar-embed") === undefined) {
43
+ customElements.define("plattar-embed", plattar_embed_1.default);
44
+ }
41
45
  }
42
46
  console.log("using @plattar/plattar-ar-adapter v" + version_1.default);
@@ -7,6 +7,7 @@ export declare class Util {
7
7
  static canSceneViewer(): boolean;
8
8
  static canRealityViewer(): boolean;
9
9
  static isSafari(): boolean;
10
+ static isChromeOnIOS(): boolean;
10
11
  static getIOSVersion(): number[];
11
12
  static getChromeVersion(): number;
12
13
  }
package/dist/util/util.js CHANGED
@@ -6,18 +6,20 @@ exports.Util = void 0;
6
6
  */
7
7
  class Util {
8
8
  static canAugment() {
9
- if (/Macintosh|iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
9
+ const userAgent = navigator.userAgent;
10
+ // test google chrome on IOS and standard IOS test
11
+ if ((/CriOS/i.test(userAgent) || /Macintosh|iPad|iPhone|iPod/.test(userAgent)) && !window.MSStream) {
10
12
  // inside facebook browser
11
- if (/\bFB[\w_]+\//.test(navigator.userAgent)) {
13
+ if (/\bFB[\w_]+\//.test(userAgent)) {
12
14
  return false;
13
15
  }
14
16
  // inside instagram browser
15
- if (/\bInstagram/i.test(navigator.userAgent)) {
17
+ if (/\bInstagram/i.test(userAgent)) {
16
18
  return false;
17
19
  }
18
20
  return Util.canQuicklook();
19
21
  }
20
- else if (/android/i.test(navigator.userAgent)) {
22
+ else if (/android/i.test(userAgent)) {
21
23
  return true;
22
24
  }
23
25
  return false;
@@ -50,6 +52,13 @@ class Util {
50
52
  }
51
53
  return false;
52
54
  }
55
+ static isChromeOnIOS() {
56
+ const userAgent = navigator.userAgent;
57
+ if (userAgent) {
58
+ return Util.canAugment() && /CriOS/i.test(userAgent);
59
+ }
60
+ return false;
61
+ }
53
62
  static getIOSVersion() {
54
63
  if (/iP(hone|od|ad)/.test(navigator.platform)) {
55
64
  const v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.118.3";
1
+ declare const _default: "1.121.1";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "1.118.3";
3
+ exports.default = "1.121.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.118.3",
3
+ "version": "1.121.1",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -38,16 +38,16 @@
38
38
  "homepage": "https://www.plattar.com",
39
39
  "dependencies": {
40
40
  "@plattar/plattar-analytics": "^1.117.2",
41
- "@plattar/plattar-api": "^1.116.3",
42
- "@plattar/plattar-qrcode": "1.118.1",
41
+ "@plattar/plattar-api": "^1.120.1",
42
+ "@plattar/plattar-qrcode": "1.120.3",
43
43
  "@plattar/plattar-web": "^1.117.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/cli": "^7.15.7",
47
- "@babel/core": "^7.15.8",
48
- "@babel/preset-env": "^7.15.8",
46
+ "@babel/cli": "^7.16.0",
47
+ "@babel/core": "^7.16.0",
48
+ "@babel/preset-env": "^7.16.4",
49
49
  "browserify": "^17.0.0",
50
- "typescript": "^4.4.4",
50
+ "typescript": "^4.5.2",
51
51
  "uglify-es": "^3.3.9"
52
52
  },
53
53
  "publishConfig": {