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