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