@3dsource/metabox-front-api 0.0.18 → 0.0.19-beta.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.
- package/README.md +218 -202
- package/dist/actions/CommandBase.d.ts +7 -0
- package/dist/actions/GetFastRender.d.ts +10 -14
- package/dist/actions/GetPdf.d.ts +8 -8
- package/dist/actions/SendCommandToUnreal.d.ts +4 -4
- package/dist/actions/SetEnvironment.d.ts +7 -9
- package/dist/actions/SetEnvironmentMaterial.d.ts +8 -11
- package/dist/actions/SetMaterial.d.ts +8 -11
- package/dist/actions/SetProduct.d.ts +8 -8
- package/dist/actions/ShowEmbeddedMenu.d.ts +7 -10
- package/dist/actions/ShowOverlayInterface.d.ts +7 -7
- package/dist/actions/WatchCallbacks.d.ts +3 -3
- package/dist/const/FromMetaboxApiAction.d.ts +52 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.esm.js +126 -236
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +126 -239
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +21 -73
- package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +7 -23
- package/dist/interfaces/UniversalConfigurator.d.ts +42 -2
- package/dist/interfaces/application-device-types.d.ts +1 -10
- package/dist/lib/{initializeCommunicator.d.ts → Communicator.d.ts} +7 -13
- package/dist/lib/EventDispatcher.d.ts +3 -3
- package/dist/lib/integrateMetaBox.d.ts +4 -3
- package/dist/lib/test/Communicator.spec.d.ts +1 -0
- package/dist/lib/test/integrateMetabox.spec.d.ts +9 -0
- package/package.json +51 -48
- package/dist/actions/ApiAction.d.ts +0 -26
package/dist/index.umd.js
CHANGED
|
@@ -5,69 +5,26 @@
|
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* **We strongly recommend using the option with npm and locking it to the latest version at the time of integration, as the option with cdn can change rapidly and may cause unexpected behavior in your existing code. See root documentation.**
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { integrateMetaBox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
14
|
-
*
|
|
15
|
-
* integrateMetaBox(
|
|
16
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
17
|
-
* 'embed3DSource'
|
|
18
|
-
* );
|
|
19
|
-
*
|
|
20
|
-
* // Set up the global API environment
|
|
21
|
-
* window.env3DSource = window.env3DSource || {};
|
|
22
|
-
*
|
|
23
|
-
* //Listen for the API ready event
|
|
24
|
-
* window.env3DSource.apiReady = (api) => {
|
|
25
|
-
* // Use the API actions here
|
|
26
|
-
* };
|
|
27
|
-
* ```
|
|
8
|
+
* Base class for commands sent to the MetaBox.
|
|
28
9
|
*/
|
|
29
|
-
class
|
|
30
|
-
constructor() {
|
|
31
|
-
this.api = window.env3DSource.api;
|
|
32
|
-
}
|
|
10
|
+
class CommandBase {
|
|
33
11
|
}
|
|
34
12
|
|
|
35
|
-
const ToMetaBoxApiAction = {
|
|
36
|
-
getPdf: 'getPdf',
|
|
37
|
-
loadLevel: 'loadLevel',
|
|
38
|
-
setProduct: 'setProduct',
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated, use 'watchCallbacks'"
|
|
41
|
-
* use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
42
|
-
* @hidden
|
|
43
|
-
*/
|
|
44
|
-
addResponse: 'addResponse',
|
|
45
|
-
getFastRender: 'getFastRender',
|
|
46
|
-
watchCallbacks: 'watchCallbacks',
|
|
47
|
-
setMaterialById: 'setMaterialById',
|
|
48
|
-
showEmbeddedMenu: 'showEmbeddedMenu',
|
|
49
|
-
forceSetDeviceType: 'forceSetDeviceType',
|
|
50
|
-
sendCommandToUnreal: 'sendCommandToUnreal',
|
|
51
|
-
showOverlayInterface: 'showOverlayInterface',
|
|
52
|
-
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
53
|
-
resetCamera: 'resetCamera',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
13
|
/**
|
|
57
|
-
* {@inheritDoc
|
|
14
|
+
* {@inheritDoc CommandBase}
|
|
58
15
|
*
|
|
59
|
-
* Represents
|
|
16
|
+
* Represents a command to toggle the Unreal Overlay Interface Menu.
|
|
60
17
|
*
|
|
61
18
|
* @remarks
|
|
62
19
|
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
63
20
|
*
|
|
64
21
|
* @example
|
|
65
|
-
* import { ShowOverlayInterface } from '
|
|
66
|
-
* window.env3DSource.apiReady = (api) => {
|
|
67
|
-
* new ShowOverlayInterface(true);
|
|
22
|
+
* import { ShowOverlayInterface,Communicator } from '@3dsource/metabox-front-api';
|
|
23
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
24
|
+
* api.setCommandToMetaBox(new ShowOverlayInterface(true));
|
|
68
25
|
* };
|
|
69
26
|
*/
|
|
70
|
-
class ShowOverlayInterface extends
|
|
27
|
+
class ShowOverlayInterface extends CommandBase {
|
|
71
28
|
/**
|
|
72
29
|
* Creates an instance of ShowOverlayInterface.
|
|
73
30
|
*
|
|
@@ -75,30 +32,27 @@
|
|
|
75
32
|
*/
|
|
76
33
|
constructor(visible) {
|
|
77
34
|
super();
|
|
78
|
-
this.
|
|
79
|
-
action:
|
|
35
|
+
this.data = {
|
|
36
|
+
action: 'showOverlayInterface',
|
|
80
37
|
payload: {
|
|
81
38
|
visible,
|
|
82
39
|
},
|
|
83
|
-
}
|
|
40
|
+
};
|
|
84
41
|
}
|
|
85
42
|
}
|
|
86
43
|
|
|
87
44
|
/**
|
|
88
|
-
* {@inheritDoc
|
|
89
|
-
*
|
|
90
|
-
* Represents an action to toggle the Embedded MetaBox Menu.
|
|
45
|
+
* {@inheritDoc CommandBase}
|
|
91
46
|
*
|
|
92
|
-
*
|
|
93
|
-
* This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
|
|
47
|
+
* Represents a command to toggle the Embedded MetaBox Menu.
|
|
94
48
|
*
|
|
95
49
|
* @example
|
|
96
|
-
* import { ShowEmbeddedMenu } from '
|
|
97
|
-
* window.env3DSource.apiReady = (api) => {
|
|
98
|
-
* new ShowEmbeddedMenu(true);
|
|
50
|
+
* import { ShowEmbeddedMenu,Communicator } from '@3dsource/metabox-front-api';
|
|
51
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
52
|
+
* api.setCommandToMetaBox(new ShowEmbeddedMenu(true));
|
|
99
53
|
* };
|
|
100
54
|
*/
|
|
101
|
-
class ShowEmbeddedMenu extends
|
|
55
|
+
class ShowEmbeddedMenu extends CommandBase {
|
|
102
56
|
/**
|
|
103
57
|
* Creates an instance of ShowEmbeddedMenu.
|
|
104
58
|
*
|
|
@@ -106,30 +60,28 @@
|
|
|
106
60
|
*/
|
|
107
61
|
constructor(visible) {
|
|
108
62
|
super();
|
|
109
|
-
this.
|
|
110
|
-
action:
|
|
63
|
+
this.data = {
|
|
64
|
+
action: 'showEmbeddedMenu',
|
|
111
65
|
payload: {
|
|
112
66
|
visible,
|
|
113
67
|
},
|
|
114
|
-
}
|
|
68
|
+
};
|
|
115
69
|
}
|
|
116
70
|
}
|
|
117
71
|
|
|
118
72
|
/**
|
|
119
|
-
* {@inheritDoc
|
|
73
|
+
* {@inheritDoc CommandBase}
|
|
120
74
|
*
|
|
121
|
-
* Represents
|
|
122
|
-
* @remarks
|
|
123
|
-
* This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
|
|
75
|
+
* Represents a command to set the environment by its ID.
|
|
124
76
|
*
|
|
125
77
|
* @example
|
|
126
|
-
* import { SetEnvironment } from '
|
|
127
|
-
* window.env3DSource.apiReady = (api) => {
|
|
78
|
+
* import { SetEnvironment,Communicator } from '@3dsource/metabox-front-api';
|
|
79
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
128
80
|
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
129
|
-
* new SetEnvironment('55555555-1234-1234-1234-01234567890');
|
|
81
|
+
* api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
130
82
|
* };
|
|
131
83
|
*/
|
|
132
|
-
class SetEnvironment extends
|
|
84
|
+
class SetEnvironment extends CommandBase {
|
|
133
85
|
/**
|
|
134
86
|
* Creates an instance of SetEnvironment.
|
|
135
87
|
*
|
|
@@ -137,32 +89,32 @@
|
|
|
137
89
|
*/
|
|
138
90
|
constructor(environmentId) {
|
|
139
91
|
super();
|
|
140
|
-
this.
|
|
92
|
+
this.data = {
|
|
141
93
|
payload: {
|
|
142
94
|
id: environmentId,
|
|
143
95
|
},
|
|
144
|
-
action:
|
|
145
|
-
}
|
|
96
|
+
action: 'loadLevel',
|
|
97
|
+
};
|
|
146
98
|
}
|
|
147
99
|
}
|
|
148
100
|
|
|
149
101
|
/**
|
|
150
|
-
* {@inheritDoc
|
|
102
|
+
* {@inheritDoc CommandBase}
|
|
151
103
|
*
|
|
152
|
-
* Represents
|
|
104
|
+
* Represents a command to set a product by its ID.
|
|
153
105
|
*
|
|
154
106
|
* @remarks
|
|
155
107
|
* This action sends a message to the MetaBox API to set a product using the provided product ID.
|
|
156
108
|
*
|
|
157
109
|
* @example
|
|
158
|
-
* import { SetProduct } from '
|
|
159
|
-
* window.env3DSource.apiReady = (api) => {
|
|
160
|
-
* new SetProduct(
|
|
110
|
+
* import { SetProduct,Communicator } from '@3dsource/metabox-front-api';
|
|
111
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
112
|
+
* api.setCommandToMetaBox(new SetProduct(
|
|
161
113
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
|
|
162
|
-
* );
|
|
114
|
+
* ));
|
|
163
115
|
* };
|
|
164
116
|
*/
|
|
165
|
-
class SetProduct extends
|
|
117
|
+
class SetProduct extends CommandBase {
|
|
166
118
|
/**
|
|
167
119
|
* Creates an instance of SetProduct.
|
|
168
120
|
*
|
|
@@ -170,32 +122,32 @@
|
|
|
170
122
|
*/
|
|
171
123
|
constructor(productId) {
|
|
172
124
|
super();
|
|
173
|
-
this.
|
|
125
|
+
this.data = {
|
|
174
126
|
payload: {
|
|
175
127
|
productId,
|
|
176
128
|
},
|
|
177
|
-
action:
|
|
178
|
-
}
|
|
129
|
+
action: 'setProduct',
|
|
130
|
+
};
|
|
179
131
|
}
|
|
180
132
|
}
|
|
181
133
|
|
|
182
134
|
/**
|
|
183
|
-
* {@inheritDoc
|
|
135
|
+
* {@inheritDoc CommandBase}
|
|
184
136
|
*
|
|
185
|
-
* Represents
|
|
137
|
+
* Represents a command to get a PDF from Metabox.
|
|
186
138
|
* @remarks
|
|
187
139
|
* This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
|
|
188
140
|
* This action does not require any parameters.
|
|
189
141
|
*
|
|
190
|
-
* **Important**: Invoking this
|
|
142
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
191
143
|
*
|
|
192
144
|
* @example
|
|
193
|
-
* import { GetPdf } from '
|
|
194
|
-
* window.env3DSource.apiReady = (api) => {
|
|
195
|
-
* new GetPdf();
|
|
145
|
+
* import { GetPdf,Communicator } from '@3dsource/metabox-front-api';
|
|
146
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
147
|
+
* api.sendCommandToMetaBox(new GetPdf());
|
|
196
148
|
* };
|
|
197
149
|
*/
|
|
198
|
-
class GetPdf extends
|
|
150
|
+
class GetPdf extends CommandBase {
|
|
199
151
|
/**
|
|
200
152
|
* Creates an instance of GetPdf.
|
|
201
153
|
*
|
|
@@ -204,31 +156,28 @@
|
|
|
204
156
|
*/
|
|
205
157
|
constructor() {
|
|
206
158
|
super();
|
|
207
|
-
this.
|
|
208
|
-
action:
|
|
209
|
-
}
|
|
159
|
+
this.data = {
|
|
160
|
+
action: 'getPdf',
|
|
161
|
+
};
|
|
210
162
|
}
|
|
211
163
|
}
|
|
212
164
|
|
|
213
165
|
/**
|
|
214
|
-
* {@inheritDoc
|
|
166
|
+
* {@inheritDoc CommandBase}
|
|
215
167
|
*
|
|
216
|
-
* Represents
|
|
217
|
-
*
|
|
218
|
-
* @remarks
|
|
219
|
-
* This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
|
|
168
|
+
* Represents a command to set a material by its ID.
|
|
220
169
|
*
|
|
221
170
|
* @example
|
|
222
|
-
* import { SetMaterial } from '
|
|
223
|
-
* window.env3DSource.apiReady = (api) => {
|
|
224
|
-
* new SetMaterial(
|
|
171
|
+
* import { SetMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
172
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
173
|
+
* api.sendCommandToMetaBox(new SetMaterial(
|
|
225
174
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
226
175
|
* 'carpaint',
|
|
227
176
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
228
|
-
* );
|
|
177
|
+
* ));
|
|
229
178
|
* };
|
|
230
179
|
*/
|
|
231
|
-
class SetMaterial extends
|
|
180
|
+
class SetMaterial extends CommandBase {
|
|
232
181
|
/**
|
|
233
182
|
* Creates an instance of SetMaterial.
|
|
234
183
|
*
|
|
@@ -238,36 +187,33 @@
|
|
|
238
187
|
*/
|
|
239
188
|
constructor(productId, slotId, materialId) {
|
|
240
189
|
super();
|
|
241
|
-
this.
|
|
190
|
+
this.data = {
|
|
242
191
|
payload: {
|
|
243
192
|
productId,
|
|
244
193
|
slotId,
|
|
245
194
|
materialId,
|
|
246
195
|
},
|
|
247
|
-
action:
|
|
248
|
-
}
|
|
196
|
+
action: 'setMaterialById',
|
|
197
|
+
};
|
|
249
198
|
}
|
|
250
199
|
}
|
|
251
200
|
|
|
252
201
|
/**
|
|
253
|
-
* {@inheritDoc
|
|
202
|
+
* {@inheritDoc CommandBase}
|
|
254
203
|
*
|
|
255
|
-
* Represents
|
|
256
|
-
*
|
|
257
|
-
* @remarks
|
|
258
|
-
* This action sends a message to the MetaBox API to update the material on a specific environment slot using the provided identifiers.
|
|
204
|
+
* Represents a command to set an environment material by its ID.
|
|
259
205
|
*
|
|
260
206
|
* @example
|
|
261
|
-
* import { SetEnvironmentMaterial } from '
|
|
262
|
-
* window.env3DSource.apiReady = (api) => {
|
|
263
|
-
* new SetEnvironmentMaterial(
|
|
207
|
+
* import { SetEnvironmentMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
208
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
209
|
+
* api.sendCommandToMetaBox(new SetEnvironmentMaterial(
|
|
264
210
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
265
211
|
* 'carpaint',
|
|
266
212
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
267
|
-
* );
|
|
213
|
+
* ));
|
|
268
214
|
* };
|
|
269
215
|
*/
|
|
270
|
-
class SetEnvironmentMaterial extends
|
|
216
|
+
class SetEnvironmentMaterial extends CommandBase {
|
|
271
217
|
/**
|
|
272
218
|
* Creates an instance of SetEnvironmentMaterial.
|
|
273
219
|
*
|
|
@@ -277,40 +223,36 @@
|
|
|
277
223
|
*/
|
|
278
224
|
constructor(productId, slotId, materialId) {
|
|
279
225
|
super();
|
|
280
|
-
this.
|
|
226
|
+
this.data = {
|
|
281
227
|
payload: {
|
|
282
228
|
productId,
|
|
283
229
|
slotId,
|
|
284
230
|
materialId,
|
|
285
231
|
},
|
|
286
|
-
action:
|
|
287
|
-
}
|
|
232
|
+
action: 'setEnvironmentMaterialById',
|
|
233
|
+
};
|
|
288
234
|
}
|
|
289
235
|
}
|
|
290
236
|
|
|
291
237
|
/**
|
|
292
|
-
* {@inheritDoc
|
|
238
|
+
* {@inheritDoc CommandBase}
|
|
293
239
|
*
|
|
294
|
-
* Represents a fast render
|
|
295
|
-
* @remarks
|
|
296
|
-
* This class sends a message to the MetaBox API to obtain a fast render based on the provided format and optional size.
|
|
240
|
+
* Represents a command to get fast render.
|
|
297
241
|
*
|
|
298
|
-
* **Important**: Invoking this
|
|
242
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
299
243
|
*
|
|
300
244
|
* @example
|
|
301
|
-
* import { GetFastRender,saveImage } from '
|
|
302
|
-
* window.env3DSource.apiReady = (api) => {
|
|
245
|
+
* import { GetFastRender,Communicator,saveImage } from '@3dsource/metabox-front-api';
|
|
246
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
303
247
|
* // Listen for events from the MetaBox API
|
|
304
|
-
* api.addEventListener('
|
|
248
|
+
* api.addEventListener('fastRender', (data) => {
|
|
305
249
|
* // Process the fast render response
|
|
306
|
-
*
|
|
307
|
-
* saveImage(data.payload, 'Render.png');
|
|
308
|
-
* }
|
|
250
|
+
* saveImage(data, 'Render.png');
|
|
309
251
|
* });
|
|
310
|
-
* new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
252
|
+
* api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
|
|
311
253
|
* };
|
|
312
254
|
*/
|
|
313
|
-
class GetFastRender extends
|
|
255
|
+
class GetFastRender extends CommandBase {
|
|
314
256
|
/**
|
|
315
257
|
* Constructs an instance of GetFastRender.
|
|
316
258
|
* @param mimeType - The output format.
|
|
@@ -318,29 +260,29 @@
|
|
|
318
260
|
*/
|
|
319
261
|
constructor(mimeType, size) {
|
|
320
262
|
super();
|
|
321
|
-
this.
|
|
263
|
+
this.data = {
|
|
322
264
|
payload: {
|
|
323
265
|
format: mimeType,
|
|
324
266
|
size,
|
|
325
267
|
},
|
|
326
|
-
action:
|
|
327
|
-
}
|
|
268
|
+
action: 'getFastRender',
|
|
269
|
+
};
|
|
328
270
|
}
|
|
329
271
|
}
|
|
330
272
|
|
|
331
273
|
/**
|
|
332
|
-
* {@inheritDoc
|
|
274
|
+
* {@inheritDoc CommandBase}
|
|
333
275
|
* @internal
|
|
334
276
|
* @hidden
|
|
335
|
-
* Represents
|
|
277
|
+
* Represents a command to send Unreal command.
|
|
336
278
|
*/
|
|
337
|
-
class SendCommandToUnreal extends
|
|
279
|
+
class SendCommandToUnreal extends CommandBase {
|
|
338
280
|
constructor(payload) {
|
|
339
281
|
super();
|
|
340
|
-
this.
|
|
282
|
+
this.data = {
|
|
341
283
|
payload,
|
|
342
|
-
action:
|
|
343
|
-
}
|
|
284
|
+
action: 'sendCommandToUnreal',
|
|
285
|
+
};
|
|
344
286
|
}
|
|
345
287
|
}
|
|
346
288
|
|
|
@@ -349,10 +291,10 @@
|
|
|
349
291
|
* @internal
|
|
350
292
|
* @hidden
|
|
351
293
|
* @remarks
|
|
352
|
-
* Represents
|
|
294
|
+
* Represents a command to watch Unreal callbacks from Unreal engine.
|
|
353
295
|
* Can be useful for custom solutions.
|
|
354
296
|
*/
|
|
355
|
-
class WatchCallbacks extends
|
|
297
|
+
class WatchCallbacks extends CommandBase {
|
|
356
298
|
/**
|
|
357
299
|
* Creates an instance of WatchCallbacks.
|
|
358
300
|
*
|
|
@@ -361,9 +303,9 @@
|
|
|
361
303
|
*/
|
|
362
304
|
constructor() {
|
|
363
305
|
super();
|
|
364
|
-
this.
|
|
365
|
-
action:
|
|
366
|
-
}
|
|
306
|
+
this.data = {
|
|
307
|
+
action: 'watchCallbacks',
|
|
308
|
+
};
|
|
367
309
|
}
|
|
368
310
|
}
|
|
369
311
|
|
|
@@ -388,6 +330,7 @@
|
|
|
388
330
|
*/
|
|
389
331
|
addEventListener(messageType, callback) {
|
|
390
332
|
this.listeners.push({ messageType, callback });
|
|
333
|
+
return this;
|
|
391
334
|
}
|
|
392
335
|
/**
|
|
393
336
|
* Dispatches an event to all listeners of a specific message type.
|
|
@@ -399,6 +342,7 @@
|
|
|
399
342
|
this.listeners
|
|
400
343
|
.filter((listener) => listener.messageType === messageType)
|
|
401
344
|
.forEach((listener) => listener.callback(data));
|
|
345
|
+
return this;
|
|
402
346
|
}
|
|
403
347
|
/**
|
|
404
348
|
* Removes an event listener for a specific type of message.
|
|
@@ -408,10 +352,10 @@
|
|
|
408
352
|
*/
|
|
409
353
|
removeEventListener(messageType, callback) {
|
|
410
354
|
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
355
|
+
return this;
|
|
411
356
|
}
|
|
412
357
|
}
|
|
413
358
|
|
|
414
|
-
const binderMessageType = 'metaboxData';
|
|
415
359
|
/**
|
|
416
360
|
* API class to handle communication with the embedded content.
|
|
417
361
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -435,7 +379,7 @@
|
|
|
435
379
|
/**
|
|
436
380
|
* Binder function for handling incoming messages.
|
|
437
381
|
*/
|
|
438
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
382
|
+
this.binder = this.handleMessageReceived.bind(this, 'metaboxData');
|
|
439
383
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
440
384
|
Communicator.instance = this;
|
|
441
385
|
window.addEventListener('message', this.binder);
|
|
@@ -449,12 +393,16 @@
|
|
|
449
393
|
}
|
|
450
394
|
/**
|
|
451
395
|
* Sends a message to the embedded content (MetaBox).
|
|
452
|
-
*
|
|
453
|
-
* @param data - The data to send.
|
|
396
|
+
* @param command
|
|
454
397
|
*/
|
|
455
|
-
|
|
398
|
+
sendCommandToMetaBox(command) {
|
|
456
399
|
var _a;
|
|
400
|
+
const data = command.data;
|
|
457
401
|
const iframe = document.getElementById('embeddedContent');
|
|
402
|
+
if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
|
|
403
|
+
console.warn('Iframe not found or not ready');
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
458
406
|
const dataToSend = {
|
|
459
407
|
host: 'metaBoxHost',
|
|
460
408
|
payload: Object.assign({}, data),
|
|
@@ -486,19 +434,23 @@
|
|
|
486
434
|
* @remarks
|
|
487
435
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
488
436
|
*/
|
|
489
|
-
static createInstance() {
|
|
490
|
-
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
437
|
+
static createInstance(apiReadyCallback) {
|
|
491
438
|
const startHandler = (event) => {
|
|
492
|
-
var _a
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
window.env3DSource.apiReady(window.env3DSource.api);
|
|
439
|
+
var _a;
|
|
440
|
+
const message = event.data;
|
|
441
|
+
if (((_a = message === null || message === void 0 ? void 0 : message.payload) === null || _a === void 0 ? void 0 : _a.action) === 'appLoaded') {
|
|
442
|
+
apiReadyCallback(new Communicator());
|
|
497
443
|
window.removeEventListener('message', startHandler);
|
|
498
444
|
}
|
|
499
445
|
};
|
|
500
446
|
window.addEventListener('message', startHandler);
|
|
501
447
|
}
|
|
448
|
+
addEventListener(eventName, callback) {
|
|
449
|
+
return super.addEventListener(eventName, callback);
|
|
450
|
+
}
|
|
451
|
+
dispatchEvent(eventType, data) {
|
|
452
|
+
return super.dispatchEvent(eventType, data);
|
|
453
|
+
}
|
|
502
454
|
}
|
|
503
455
|
/**
|
|
504
456
|
* The singleton instance of the communicator.
|
|
@@ -521,33 +473,33 @@
|
|
|
521
473
|
* i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
|
|
522
474
|
*
|
|
523
475
|
* @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
|
|
524
|
-
*
|
|
476
|
+
* @param apiReadyCallback
|
|
525
477
|
* @throws Error if the container element with the specified ID is not found.
|
|
526
478
|
*
|
|
527
479
|
* @example
|
|
528
480
|
* import {
|
|
529
481
|
* integrateMetaBox,
|
|
530
|
-
* } from '
|
|
482
|
+
* } from '@3dsource/metabox-front-api';
|
|
531
483
|
*
|
|
532
484
|
* integrateMetaBox(
|
|
533
485
|
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
534
486
|
* 'embed3DSource'
|
|
535
487
|
* );
|
|
536
488
|
*/
|
|
537
|
-
function integrateMetaBox(iframeSrc, containerId = 'embed3DSource') {
|
|
489
|
+
function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCallback) {
|
|
538
490
|
const container = document.getElementById(containerId);
|
|
539
491
|
if (!container) {
|
|
540
492
|
throw new Error(`Container element with id ${containerId} not found`);
|
|
541
493
|
}
|
|
542
|
-
Communicator.createInstance();
|
|
494
|
+
Communicator.createInstance(apiReadyCallback);
|
|
543
495
|
const style = document.createElement('style');
|
|
544
|
-
style.innerHTML = `
|
|
545
|
-
#${containerId} {
|
|
546
|
-
width: 100%;
|
|
547
|
-
height: 100%;
|
|
548
|
-
overflow: hidden;
|
|
549
|
-
position: relative;
|
|
550
|
-
}
|
|
496
|
+
style.innerHTML = `
|
|
497
|
+
#${containerId} {
|
|
498
|
+
width: 100%;
|
|
499
|
+
height: 100%;
|
|
500
|
+
overflow: hidden;
|
|
501
|
+
position: relative;
|
|
502
|
+
}
|
|
551
503
|
`;
|
|
552
504
|
document.head.appendChild(style);
|
|
553
505
|
const iframe = document.createElement('iframe');
|
|
@@ -626,72 +578,8 @@
|
|
|
626
578
|
return selections;
|
|
627
579
|
}
|
|
628
580
|
|
|
629
|
-
|
|
630
|
-
bridge: 'bridge',
|
|
631
|
-
appLoaded: 'appLoaded',
|
|
632
|
-
/**
|
|
633
|
-
* @hidden
|
|
634
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealFeature"
|
|
635
|
-
*/
|
|
636
|
-
unrealFeatureBridge: 'unrealFeatureBridge',
|
|
637
|
-
/**
|
|
638
|
-
* @hidden
|
|
639
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealCallback"
|
|
640
|
-
*/
|
|
641
|
-
unrealCallback: 'unrealCallback',
|
|
642
|
-
/**
|
|
643
|
-
* @hidden
|
|
644
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
645
|
-
*/
|
|
646
|
-
configuratorDataWithStateBridge: 'configuratorDataWithStateBridge',
|
|
647
|
-
/**
|
|
648
|
-
* @hidden
|
|
649
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
650
|
-
*/
|
|
651
|
-
configuratorDataBridge: 'configuratorDataBridge',
|
|
652
|
-
/**
|
|
653
|
-
* @hidden
|
|
654
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
655
|
-
*/
|
|
656
|
-
menuDataBridge: 'menuDataBridge',
|
|
657
|
-
/**
|
|
658
|
-
* @hidden
|
|
659
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
660
|
-
*/
|
|
661
|
-
flatMenuDataBridge: 'flatMenuDataBridge',
|
|
662
|
-
/**
|
|
663
|
-
* @hidden
|
|
664
|
-
* @deprecated, use Bridge with isFullscreen
|
|
665
|
-
*/
|
|
666
|
-
fullScreenBridge: 'fullScreenBridge',
|
|
667
|
-
/**
|
|
668
|
-
* @hidden
|
|
669
|
-
* @deprecated, use Bridge with streamResolution
|
|
670
|
-
*/
|
|
671
|
-
videoSize: 'videoSize',
|
|
672
|
-
/**
|
|
673
|
-
* @hidden
|
|
674
|
-
* Used in a platform, must be removed in future
|
|
675
|
-
* @deprecated
|
|
676
|
-
*/
|
|
677
|
-
unrealResponse: 'unrealResponse',
|
|
678
|
-
/**
|
|
679
|
-
* @hidden
|
|
680
|
-
* @deprecated\
|
|
681
|
-
*/
|
|
682
|
-
getFastRender: 'getFastRender',
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
const APPLICATION_DEVICE_TYPES = {
|
|
686
|
-
deviceTypeAuto: 'deviceTypeAuto',
|
|
687
|
-
deviceTypeMobile: 'deviceTypeMobile',
|
|
688
|
-
deviceTypeDesktop: 'deviceTypeDesktop',
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
exports.APPLICATION_DEVICE_TYPES = APPLICATION_DEVICE_TYPES;
|
|
692
|
-
exports.ApiAction = ApiAction;
|
|
581
|
+
exports.CommandBase = CommandBase;
|
|
693
582
|
exports.Communicator = Communicator;
|
|
694
|
-
exports.FromMetaboxApiAction = FromMetaboxApiAction;
|
|
695
583
|
exports.GetFastRender = GetFastRender;
|
|
696
584
|
exports.GetPdf = GetPdf;
|
|
697
585
|
exports.SendCommandToUnreal = SendCommandToUnreal;
|
|
@@ -701,7 +589,6 @@
|
|
|
701
589
|
exports.SetProduct = SetProduct;
|
|
702
590
|
exports.ShowEmbeddedMenu = ShowEmbeddedMenu;
|
|
703
591
|
exports.ShowOverlayInterface = ShowOverlayInterface;
|
|
704
|
-
exports.ToMetaBoxApiAction = ToMetaBoxApiAction;
|
|
705
592
|
exports.WatchCallbacks = WatchCallbacks;
|
|
706
593
|
exports.getUrlParams = getUrlParams;
|
|
707
594
|
exports.integrateMetaBox = integrateMetaBox;
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|