@3dsource/metabox-front-api 0.0.14 → 0.0.16
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 +15 -2
- package/dist/actions/ShowOverlayInterface.d.ts +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +94 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +94 -43
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +4 -0
- package/dist/lib/EventDispatcher.d.ts +39 -0
- package/dist/lib/initializeCommunicator.d.ts +2 -26
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImag
|
|
|
17
17
|
**OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download package and use it locally):
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
|
-
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest
|
|
20
|
+
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
**We strongly recommend using the first option with npm and locking it to the latest version at the time of integration, as the second option can change rapidly and may cause unexpected behavior in your existing code.**
|
|
@@ -45,8 +45,10 @@ Insert this code into your HTML file just before the closing `</body>` tag:
|
|
|
45
45
|
|
|
46
46
|
```html
|
|
47
47
|
<script type="module">
|
|
48
|
-
import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from '
|
|
48
|
+
import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
49
|
+
import { ShowOverlayInterface } from './ShowOverlayInterface';
|
|
49
50
|
// Expose API
|
|
51
|
+
window.env3DSource = { ...window.env3DSource };
|
|
50
52
|
window.env3DSource.apiReady = (api) => {
|
|
51
53
|
api.addEventListener('metaboxData', (data) => {
|
|
52
54
|
const { action, payload, eventType } = data;
|
|
@@ -97,6 +99,9 @@ Insert this code into your HTML file just before the closing `</body>` tag:
|
|
|
97
99
|
// Toggle embedded menu
|
|
98
100
|
new ShowEmbeddedMenu(false);
|
|
99
101
|
|
|
102
|
+
// Toggle overlay interface
|
|
103
|
+
new ShowOverlayInterface(false);
|
|
104
|
+
|
|
100
105
|
//Request Pdf, Will execute as stream is ready, will be auto-downloaded
|
|
101
106
|
new GetPdf();
|
|
102
107
|
|
|
@@ -165,6 +170,14 @@ Insert this code into your HTML file just before the closing `</body>` tag:
|
|
|
165
170
|
new ShowEmbeddedMenu(visible: boolean);
|
|
166
171
|
```
|
|
167
172
|
|
|
173
|
+
### `ShowOverlayInterface`
|
|
174
|
+
|
|
175
|
+
- **Description**: Toggles the overlay interface over Unreal viewport.
|
|
176
|
+
- **Constructor**:
|
|
177
|
+
```typescript
|
|
178
|
+
new ShowOverlayInterface(visible: boolean);
|
|
179
|
+
```
|
|
180
|
+
|
|
168
181
|
### `GetFastRender`
|
|
169
182
|
|
|
170
183
|
- **Description**: Retrieves a fast render of the current view.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ApiAction } from './ApiAction';
|
|
2
|
+
/**
|
|
3
|
+
* {@inheritDoc ApiAction}
|
|
4
|
+
*
|
|
5
|
+
* Represents an action to toggle the Unreal Overlay Interface Menu.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { ShowOverlayInterface } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
|
+
* window.env3DSource.apiReady = (api) => {
|
|
13
|
+
* new ShowOverlayInterface(true);
|
|
14
|
+
* };
|
|
15
|
+
*/
|
|
16
|
+
export declare class ShowOverlayInterface extends ApiAction {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of ShowOverlayInterface.
|
|
19
|
+
*
|
|
20
|
+
* @param visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
21
|
+
*/
|
|
22
|
+
constructor(visible: boolean);
|
|
23
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -52,9 +52,46 @@ const ToMetaBoxApiAction = {
|
|
|
52
52
|
showEmbeddedMenu: 'showEmbeddedMenu',
|
|
53
53
|
forceSetDeviceType: 'forceSetDeviceType',
|
|
54
54
|
sendCommandToUnreal: 'sendCommandToUnreal',
|
|
55
|
+
showOverlayInterface: 'showOverlayInterface',
|
|
55
56
|
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
56
57
|
};
|
|
57
58
|
|
|
59
|
+
/*
|
|
60
|
+
* Copyright (c) 2025.
|
|
61
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
62
|
+
* All Rights Reserved
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritDoc ApiAction}
|
|
66
|
+
*
|
|
67
|
+
* Represents an action to toggle the Unreal Overlay Interface Menu.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import { ShowOverlayInterface } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
74
|
+
* window.env3DSource.apiReady = (api) => {
|
|
75
|
+
* new ShowOverlayInterface(true);
|
|
76
|
+
* };
|
|
77
|
+
*/
|
|
78
|
+
class ShowOverlayInterface extends ApiAction {
|
|
79
|
+
/**
|
|
80
|
+
* Creates an instance of ShowOverlayInterface.
|
|
81
|
+
*
|
|
82
|
+
* @param visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
83
|
+
*/
|
|
84
|
+
constructor(visible) {
|
|
85
|
+
super();
|
|
86
|
+
this.api.sendMessageToMetaBox({
|
|
87
|
+
action: ToMetaBoxApiAction.showOverlayInterface,
|
|
88
|
+
payload: {
|
|
89
|
+
visible,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
58
95
|
/*
|
|
59
96
|
* Copyright (c) 2025.
|
|
60
97
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
@@ -388,7 +425,56 @@ class WatchCallbacks extends ApiAction {
|
|
|
388
425
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
389
426
|
* All Rights Reserved
|
|
390
427
|
*/
|
|
391
|
-
|
|
428
|
+
/**
|
|
429
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
430
|
+
*/
|
|
431
|
+
class EventDispatcher {
|
|
432
|
+
constructor() {
|
|
433
|
+
/**
|
|
434
|
+
* Storage for callback listeners by message type.
|
|
435
|
+
*/
|
|
436
|
+
this.listeners = [];
|
|
437
|
+
}
|
|
438
|
+
destroy() {
|
|
439
|
+
this.listeners = [];
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Adds an event listener for receiving specific types of messages.
|
|
443
|
+
*
|
|
444
|
+
* @param messageType - The message type to listen for.
|
|
445
|
+
* @param callback - The callback function to execute when a message is received.
|
|
446
|
+
*/
|
|
447
|
+
addEventListener(messageType, callback) {
|
|
448
|
+
this.listeners.push({ messageType, callback });
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
452
|
+
*
|
|
453
|
+
* @param messageType - The message type.
|
|
454
|
+
* @param data - The data associated with the event.
|
|
455
|
+
*/
|
|
456
|
+
dispatchEvent(messageType, data) {
|
|
457
|
+
this.listeners
|
|
458
|
+
.filter((listener) => listener.messageType === messageType)
|
|
459
|
+
.forEach((listener) => listener.callback(data));
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Removes an event listener for a specific type of message.
|
|
463
|
+
*
|
|
464
|
+
* @param messageType - The message type.
|
|
465
|
+
* @param callback - The callback function to remove.
|
|
466
|
+
*/
|
|
467
|
+
removeEventListener(messageType, callback) {
|
|
468
|
+
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/*
|
|
473
|
+
* Copyright (c) 2025.
|
|
474
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
475
|
+
* All Rights Reserved
|
|
476
|
+
*/
|
|
477
|
+
const binderMessageType = 'metaboxData';
|
|
392
478
|
/**
|
|
393
479
|
* API class to handle communication with the embedded content.
|
|
394
480
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -398,7 +484,7 @@ const messageType = 'metaboxData';
|
|
|
398
484
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
399
485
|
* @hidden
|
|
400
486
|
*/
|
|
401
|
-
class Communicator {
|
|
487
|
+
class Communicator extends EventDispatcher {
|
|
402
488
|
/**
|
|
403
489
|
* Creates an instance of Communicator.
|
|
404
490
|
* @internal
|
|
@@ -408,14 +494,11 @@ class Communicator {
|
|
|
408
494
|
*/
|
|
409
495
|
constructor() {
|
|
410
496
|
var _a;
|
|
411
|
-
|
|
412
|
-
* Storage for callback listeners by message type.
|
|
413
|
-
*/
|
|
414
|
-
this.listeners = [];
|
|
497
|
+
super();
|
|
415
498
|
/**
|
|
416
499
|
* Binder function for handling incoming messages.
|
|
417
500
|
*/
|
|
418
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
501
|
+
this.binder = this.handleMessageReceived.bind(this, binderMessageType);
|
|
419
502
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
420
503
|
Communicator.instance = this;
|
|
421
504
|
window.addEventListener('message', this.binder);
|
|
@@ -424,7 +507,7 @@ class Communicator {
|
|
|
424
507
|
* Destroys the communicator instance by clearing listeners and removing event listeners.
|
|
425
508
|
*/
|
|
426
509
|
destroy() {
|
|
427
|
-
|
|
510
|
+
super.destroy();
|
|
428
511
|
window.removeEventListener('message', this.binder);
|
|
429
512
|
}
|
|
430
513
|
/**
|
|
@@ -442,26 +525,6 @@ class Communicator {
|
|
|
442
525
|
// In production, replace "*" with the actual origin for added security.
|
|
443
526
|
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
|
|
444
527
|
}
|
|
445
|
-
/**
|
|
446
|
-
* Adds an event listener for receiving specific types of messages.
|
|
447
|
-
*
|
|
448
|
-
* @param messageType - The message type to listen for.
|
|
449
|
-
* @param callback - The callback function to execute when a message is received.
|
|
450
|
-
*/
|
|
451
|
-
addEventListener(messageType, callback) {
|
|
452
|
-
this.listeners.push({ messageType, callback });
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
456
|
-
*
|
|
457
|
-
* @param messageType - The message type.
|
|
458
|
-
* @param data - The data associated with the event.
|
|
459
|
-
*/
|
|
460
|
-
dispatchEvent(messageType, data) {
|
|
461
|
-
this.listeners
|
|
462
|
-
.filter((listener) => listener.messageType === messageType)
|
|
463
|
-
.forEach((listener) => listener.callback(data));
|
|
464
|
-
}
|
|
465
528
|
/**
|
|
466
529
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
467
530
|
*
|
|
@@ -478,20 +541,7 @@ class Communicator {
|
|
|
478
541
|
if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
479
542
|
return;
|
|
480
543
|
}
|
|
481
|
-
this.
|
|
482
|
-
.filter((listener) => listener.messageType === messageType)
|
|
483
|
-
.forEach((listener) => {
|
|
484
|
-
listener.callback(event.data.payload);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Removes an event listener for a specific type of message.
|
|
489
|
-
*
|
|
490
|
-
* @param messageType - The message type.
|
|
491
|
-
* @param callback - The callback function to remove.
|
|
492
|
-
*/
|
|
493
|
-
removeEventListener(messageType, callback) {
|
|
494
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
544
|
+
this.dispatchEvent(messageType, event.data.payload);
|
|
495
545
|
}
|
|
496
546
|
/**
|
|
497
547
|
* Initializes the communicator when the embedded content is ready.
|
|
@@ -500,7 +550,7 @@ class Communicator {
|
|
|
500
550
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
501
551
|
*/
|
|
502
552
|
static createInstance() {
|
|
503
|
-
window.env3DSource = window.env3DSource
|
|
553
|
+
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
504
554
|
const startHandler = (event) => {
|
|
505
555
|
var _a, _b;
|
|
506
556
|
if (((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.action) === 'appLoaded' &&
|
|
@@ -731,5 +781,5 @@ const APPLICATION_DEVICE_TYPES = {
|
|
|
731
781
|
deviceTypeDesktop: 'deviceTypeDesktop',
|
|
732
782
|
};
|
|
733
783
|
|
|
734
|
-
export { APPLICATION_DEVICE_TYPES, ApiAction, Communicator, FromMetaboxApiAction, GetFastRender, GetPdf, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ToMetaBoxApiAction, WatchCallbacks, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
784
|
+
export { APPLICATION_DEVICE_TYPES, ApiAction, Communicator, FromMetaboxApiAction, GetFastRender, GetPdf, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, ToMetaBoxApiAction, WatchCallbacks, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
735
785
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -58,9 +58,46 @@
|
|
|
58
58
|
showEmbeddedMenu: 'showEmbeddedMenu',
|
|
59
59
|
forceSetDeviceType: 'forceSetDeviceType',
|
|
60
60
|
sendCommandToUnreal: 'sendCommandToUnreal',
|
|
61
|
+
showOverlayInterface: 'showOverlayInterface',
|
|
61
62
|
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
/*
|
|
66
|
+
* Copyright (c) 2025.
|
|
67
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
68
|
+
* All Rights Reserved
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* {@inheritDoc ApiAction}
|
|
72
|
+
*
|
|
73
|
+
* Represents an action to toggle the Unreal Overlay Interface Menu.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* import { ShowOverlayInterface } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
80
|
+
* window.env3DSource.apiReady = (api) => {
|
|
81
|
+
* new ShowOverlayInterface(true);
|
|
82
|
+
* };
|
|
83
|
+
*/
|
|
84
|
+
class ShowOverlayInterface extends ApiAction {
|
|
85
|
+
/**
|
|
86
|
+
* Creates an instance of ShowOverlayInterface.
|
|
87
|
+
*
|
|
88
|
+
* @param visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
89
|
+
*/
|
|
90
|
+
constructor(visible) {
|
|
91
|
+
super();
|
|
92
|
+
this.api.sendMessageToMetaBox({
|
|
93
|
+
action: ToMetaBoxApiAction.showOverlayInterface,
|
|
94
|
+
payload: {
|
|
95
|
+
visible,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
64
101
|
/*
|
|
65
102
|
* Copyright (c) 2025.
|
|
66
103
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
@@ -394,7 +431,56 @@
|
|
|
394
431
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
395
432
|
* All Rights Reserved
|
|
396
433
|
*/
|
|
397
|
-
|
|
434
|
+
/**
|
|
435
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
436
|
+
*/
|
|
437
|
+
class EventDispatcher {
|
|
438
|
+
constructor() {
|
|
439
|
+
/**
|
|
440
|
+
* Storage for callback listeners by message type.
|
|
441
|
+
*/
|
|
442
|
+
this.listeners = [];
|
|
443
|
+
}
|
|
444
|
+
destroy() {
|
|
445
|
+
this.listeners = [];
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Adds an event listener for receiving specific types of messages.
|
|
449
|
+
*
|
|
450
|
+
* @param messageType - The message type to listen for.
|
|
451
|
+
* @param callback - The callback function to execute when a message is received.
|
|
452
|
+
*/
|
|
453
|
+
addEventListener(messageType, callback) {
|
|
454
|
+
this.listeners.push({ messageType, callback });
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
458
|
+
*
|
|
459
|
+
* @param messageType - The message type.
|
|
460
|
+
* @param data - The data associated with the event.
|
|
461
|
+
*/
|
|
462
|
+
dispatchEvent(messageType, data) {
|
|
463
|
+
this.listeners
|
|
464
|
+
.filter((listener) => listener.messageType === messageType)
|
|
465
|
+
.forEach((listener) => listener.callback(data));
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Removes an event listener for a specific type of message.
|
|
469
|
+
*
|
|
470
|
+
* @param messageType - The message type.
|
|
471
|
+
* @param callback - The callback function to remove.
|
|
472
|
+
*/
|
|
473
|
+
removeEventListener(messageType, callback) {
|
|
474
|
+
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/*
|
|
479
|
+
* Copyright (c) 2025.
|
|
480
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
481
|
+
* All Rights Reserved
|
|
482
|
+
*/
|
|
483
|
+
const binderMessageType = 'metaboxData';
|
|
398
484
|
/**
|
|
399
485
|
* API class to handle communication with the embedded content.
|
|
400
486
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -404,7 +490,7 @@
|
|
|
404
490
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
405
491
|
* @hidden
|
|
406
492
|
*/
|
|
407
|
-
class Communicator {
|
|
493
|
+
class Communicator extends EventDispatcher {
|
|
408
494
|
/**
|
|
409
495
|
* Creates an instance of Communicator.
|
|
410
496
|
* @internal
|
|
@@ -414,14 +500,11 @@
|
|
|
414
500
|
*/
|
|
415
501
|
constructor() {
|
|
416
502
|
var _a;
|
|
417
|
-
|
|
418
|
-
* Storage for callback listeners by message type.
|
|
419
|
-
*/
|
|
420
|
-
this.listeners = [];
|
|
503
|
+
super();
|
|
421
504
|
/**
|
|
422
505
|
* Binder function for handling incoming messages.
|
|
423
506
|
*/
|
|
424
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
507
|
+
this.binder = this.handleMessageReceived.bind(this, binderMessageType);
|
|
425
508
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
426
509
|
Communicator.instance = this;
|
|
427
510
|
window.addEventListener('message', this.binder);
|
|
@@ -430,7 +513,7 @@
|
|
|
430
513
|
* Destroys the communicator instance by clearing listeners and removing event listeners.
|
|
431
514
|
*/
|
|
432
515
|
destroy() {
|
|
433
|
-
|
|
516
|
+
super.destroy();
|
|
434
517
|
window.removeEventListener('message', this.binder);
|
|
435
518
|
}
|
|
436
519
|
/**
|
|
@@ -448,26 +531,6 @@
|
|
|
448
531
|
// In production, replace "*" with the actual origin for added security.
|
|
449
532
|
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
|
|
450
533
|
}
|
|
451
|
-
/**
|
|
452
|
-
* Adds an event listener for receiving specific types of messages.
|
|
453
|
-
*
|
|
454
|
-
* @param messageType - The message type to listen for.
|
|
455
|
-
* @param callback - The callback function to execute when a message is received.
|
|
456
|
-
*/
|
|
457
|
-
addEventListener(messageType, callback) {
|
|
458
|
-
this.listeners.push({ messageType, callback });
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
462
|
-
*
|
|
463
|
-
* @param messageType - The message type.
|
|
464
|
-
* @param data - The data associated with the event.
|
|
465
|
-
*/
|
|
466
|
-
dispatchEvent(messageType, data) {
|
|
467
|
-
this.listeners
|
|
468
|
-
.filter((listener) => listener.messageType === messageType)
|
|
469
|
-
.forEach((listener) => listener.callback(data));
|
|
470
|
-
}
|
|
471
534
|
/**
|
|
472
535
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
473
536
|
*
|
|
@@ -484,20 +547,7 @@
|
|
|
484
547
|
if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
485
548
|
return;
|
|
486
549
|
}
|
|
487
|
-
this.
|
|
488
|
-
.filter((listener) => listener.messageType === messageType)
|
|
489
|
-
.forEach((listener) => {
|
|
490
|
-
listener.callback(event.data.payload);
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Removes an event listener for a specific type of message.
|
|
495
|
-
*
|
|
496
|
-
* @param messageType - The message type.
|
|
497
|
-
* @param callback - The callback function to remove.
|
|
498
|
-
*/
|
|
499
|
-
removeEventListener(messageType, callback) {
|
|
500
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
550
|
+
this.dispatchEvent(messageType, event.data.payload);
|
|
501
551
|
}
|
|
502
552
|
/**
|
|
503
553
|
* Initializes the communicator when the embedded content is ready.
|
|
@@ -506,7 +556,7 @@
|
|
|
506
556
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
507
557
|
*/
|
|
508
558
|
static createInstance() {
|
|
509
|
-
window.env3DSource = window.env3DSource
|
|
559
|
+
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
510
560
|
const startHandler = (event) => {
|
|
511
561
|
var _a, _b;
|
|
512
562
|
if (((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.action) === 'appLoaded' &&
|
|
@@ -749,6 +799,7 @@
|
|
|
749
799
|
exports.SetMaterial = SetMaterial;
|
|
750
800
|
exports.SetProduct = SetProduct;
|
|
751
801
|
exports.ShowEmbeddedMenu = ShowEmbeddedMenu;
|
|
802
|
+
exports.ShowOverlayInterface = ShowOverlayInterface;
|
|
752
803
|
exports.ToMetaBoxApiAction = ToMetaBoxApiAction;
|
|
753
804
|
exports.WatchCallbacks = WatchCallbacks;
|
|
754
805
|
exports.getUrlParams = getUrlParams;
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -16,6 +16,7 @@ export declare const ToMetaBoxApiAction: {
|
|
|
16
16
|
readonly showEmbeddedMenu: "showEmbeddedMenu";
|
|
17
17
|
readonly forceSetDeviceType: "forceSetDeviceType";
|
|
18
18
|
readonly sendCommandToUnreal: "sendCommandToUnreal";
|
|
19
|
+
readonly showOverlayInterface: "showOverlayInterface";
|
|
19
20
|
readonly setEnvironmentMaterialById: "setEnvironmentMaterialById";
|
|
20
21
|
};
|
|
21
22
|
export type ToMetaBoxActions = (typeof ToMetaBoxApiAction)[keyof typeof ToMetaBoxApiAction];
|
|
@@ -58,6 +59,9 @@ export interface ToMetaboxMessagePayloads {
|
|
|
58
59
|
showEmbeddedMenu: {
|
|
59
60
|
visible: boolean;
|
|
60
61
|
};
|
|
62
|
+
showOverlayInterface: {
|
|
63
|
+
visible: boolean;
|
|
64
|
+
};
|
|
61
65
|
forceSetDeviceType: {
|
|
62
66
|
deviceType: ApplicationDeviceType;
|
|
63
67
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a callback listener for specific message types.
|
|
3
|
+
*/
|
|
4
|
+
interface Listener {
|
|
5
|
+
messageType: string;
|
|
6
|
+
callback: (data: unknown) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EventDispatcher {
|
|
12
|
+
/**
|
|
13
|
+
* Storage for callback listeners by message type.
|
|
14
|
+
*/
|
|
15
|
+
listeners: Listener[];
|
|
16
|
+
destroy(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an event listener for receiving specific types of messages.
|
|
19
|
+
*
|
|
20
|
+
* @param messageType - The message type to listen for.
|
|
21
|
+
* @param callback - The callback function to execute when a message is received.
|
|
22
|
+
*/
|
|
23
|
+
addEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
24
|
+
/**
|
|
25
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
26
|
+
*
|
|
27
|
+
* @param messageType - The message type.
|
|
28
|
+
* @param data - The data associated with the event.
|
|
29
|
+
*/
|
|
30
|
+
dispatchEvent(messageType: string, data: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Removes an event listener for a specific type of message.
|
|
33
|
+
*
|
|
34
|
+
* @param messageType - The message type.
|
|
35
|
+
* @param callback - The callback function to remove.
|
|
36
|
+
*/
|
|
37
|
+
removeEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToMetaBoxMessageEnvelope } from '../interfaces/ToMetaboxMessagePayloads';
|
|
2
|
+
import { EventDispatcher } from './EventDispatcher';
|
|
2
3
|
declare global {
|
|
3
4
|
interface Window {
|
|
4
5
|
env3DSource: {
|
|
@@ -16,11 +17,7 @@ declare global {
|
|
|
16
17
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
17
18
|
* @hidden
|
|
18
19
|
*/
|
|
19
|
-
export declare class Communicator {
|
|
20
|
-
/**
|
|
21
|
-
* Storage for callback listeners by message type.
|
|
22
|
-
*/
|
|
23
|
-
private listeners;
|
|
20
|
+
export declare class Communicator extends EventDispatcher {
|
|
24
21
|
/**
|
|
25
22
|
* Binder function for handling incoming messages.
|
|
26
23
|
*/
|
|
@@ -47,20 +44,6 @@ export declare class Communicator {
|
|
|
47
44
|
* @param data - The data to send.
|
|
48
45
|
*/
|
|
49
46
|
sendMessageToMetaBox(data: ToMetaBoxMessageEnvelope): void;
|
|
50
|
-
/**
|
|
51
|
-
* Adds an event listener for receiving specific types of messages.
|
|
52
|
-
*
|
|
53
|
-
* @param messageType - The message type to listen for.
|
|
54
|
-
* @param callback - The callback function to execute when a message is received.
|
|
55
|
-
*/
|
|
56
|
-
addEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
57
|
-
/**
|
|
58
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
59
|
-
*
|
|
60
|
-
* @param messageType - The message type.
|
|
61
|
-
* @param data - The data associated with the event.
|
|
62
|
-
*/
|
|
63
|
-
dispatchEvent(messageType: string, data: unknown): void;
|
|
64
47
|
/**
|
|
65
48
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
66
49
|
*
|
|
@@ -71,13 +54,6 @@ export declare class Communicator {
|
|
|
71
54
|
* Optionally, you can perform an origin check for added security.
|
|
72
55
|
*/
|
|
73
56
|
private handleMessageReceived;
|
|
74
|
-
/**
|
|
75
|
-
* Removes an event listener for a specific type of message.
|
|
76
|
-
*
|
|
77
|
-
* @param messageType - The message type.
|
|
78
|
-
* @param callback - The callback function to remove.
|
|
79
|
-
*/
|
|
80
|
-
removeEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
81
57
|
/**
|
|
82
58
|
* Initializes the communicator when the embedded content is ready.
|
|
83
59
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3dsource/metabox-front-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "API for MetaBox BASIC configurator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"metabox",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
20
|
"require": "./dist/index.umd.js",
|
|
21
|
-
"
|
|
21
|
+
"import": "./dist/index.esm.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"main": "dist/index.umd.js",
|