unreal-toolkit 0.1.21 → 0.1.24

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 CHANGED
@@ -14,22 +14,25 @@ with your hosted Unreal Engine streaming web application.
14
14
  npm install unreal-toolkit
15
15
  ```
16
16
 
17
- * Default Toolkit Import Libraries
18
- ```javascript
17
+ * Unreal Toolkit Runtime Library
18
+ ```typescript
19
19
  import UnrealToolkit from 'unreal-toolkit';
20
- ```
21
20
 
22
- * Unreal Toolkit Event Bus Usage
23
- ```typescript
24
- // Post WM_HELLO message to Unreal Engine
25
- UnrealToolkit.EventBus.PostWindowMessage("WM_HELLO", ["Hello World!"]);
21
+ // Create cross origin isolated iframe window
22
+ const iframe = UnrealToolkit.Bridge.CreateWindow("game");
23
+ iframe.src = "your.unrealtoolkitproject.com";
26
24
 
27
- // Handle WM_MY_EVENT message from Unreal Engine
28
- UnrealToolkit.EventBus.OnWindowMessage("WM_MY_EVENT", (args:string[]) => {
25
+ // Handle message from Unreal Engine content
26
+ UnrealToolkit.Bridge.OnWindowMessage("WM_EVENT", (args:string[]) => {
29
27
  console.log("My Event Args: ", args);
30
28
  });
29
+
30
+ // Post message safely to Unreal Engine content
31
+ UnrealToolkit.Bridge.PostWindowMessage("WM_HELLO", ["Hello World!"]);
31
32
  ```
32
33
 
34
+ ## Additional Reference Information
35
+
33
36
  * Unreal Toolkit Content Frame Style
34
37
  ```css
35
38
  iframe {
@@ -43,12 +46,22 @@ iframe {
43
46
  }
44
47
  ```
45
48
 
46
- * Unreal Toolkit Content Frame Window
49
+ * Unreal Toolkit Content Frame Settings
47
50
  ```html
48
51
  <iframe
49
- src="your.unrealtoolkitproject.com"
50
52
  crossorigin="anonymous"
51
53
  allow="cross-origin-isolated"
52
54
  sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-pointer-lock">
53
55
  </iframe>
54
56
  ```
57
+
58
+ * Unreal Toolkit Required Response Headers
59
+ ```json
60
+ headers: {
61
+ 'Access-Control-Allow-Origin': '*',
62
+ 'Cross-Origin-Opener-Policy': 'same-origin',
63
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
64
+ 'Cross-Origin-Resource-Policy': 'cross-origin',
65
+ 'Permissions-Policy': 'cross-origin-isolated=*'
66
+ }
67
+ ```
package/dist/index.d.ts CHANGED
@@ -1,29 +1,36 @@
1
1
  /** UMD Type References */
2
2
  /**
3
- * Unreal Toolkit (Static Manager Pattern)
3
+ * Unreal Toolkit Runtime Library
4
4
  * @class UnrealToolkit - All rights reserved (c) 2024 Mackey Kinard
5
5
  */
6
6
  export declare class UnrealToolkit {
7
- private static _EventBus;
8
- /** Unreal Toolkit event message bus
7
+ private static _Bridge;
8
+ /** Unreal Toolkit Communication Bridge (Event Bus)
9
9
  * @example
10
- * ```typescript
11
- * // Post WM_HELLO message to Unreal Engine
12
- * UnrealToolkit.EventBus.PostWindowMessage("WM_HELLO", ["Hello World!"]);
10
+ * ```typescript
11
+ * import UnrealToolkit from 'unreal-toolkit';
13
12
  *
14
- * // Handle WM_MY_EVENT message from Unreal Engine
15
- * UnrealToolkit.EventBus.OnWindowMessage("WM_MY_EVENT", (args:string[]) => {
16
- * console.log("My Event Args: ", args);
17
- * });
18
- * ```
19
- */
20
- static get EventBus(): UnrealMessageBus;
13
+ * // Create cross origin isolated iframe window
14
+ * const iframe = UnrealToolkit.Bridge.CreateWindow("game");
15
+ * iframe.src = "your.unrealtoolkitproject.com";
16
+ *
17
+ * // Handle message from Unreal Engine content
18
+ * UnrealToolkit.Bridge.OnWindowMessage("WM_EVENT", (args:string[]) => {
19
+ * console.log("My Event Args: ", args);
20
+ * });
21
+ *
22
+ * // Post message safely to Unreal Engine content
23
+ * UnrealToolkit.Bridge.PostWindowMessage("WM_HELLO", ["Hello World!"]);
24
+ * ```
25
+ */
26
+ static get Bridge(): EventBus;
21
27
  }
22
28
  /**
23
- * Unreal Toolkit Message Bus (Asynchronous Post Message Communication)
24
- * @class UnrealMessageBus - All rights reserved (c) 2024 Mackey Kinard
29
+ * Unreal Toolkit Event Bus (Asynchronous Post Message Communication)
30
+ * @class EventBus - All rights reserved (c) 2024 Mackey Kinard
25
31
  */
26
- export declare class UnrealMessageBus {
32
+ export declare class EventBus {
33
+ static PostWindowID: string;
27
34
  static AllowedOrigin: string;
28
35
  static TargetOrigin: string;
29
36
  static ContentFrames: NodeListOf<HTMLIFrameElement>;
@@ -40,6 +47,11 @@ export declare class UnrealMessageBus {
40
47
  * @returns void
41
48
  */
42
49
  OnWindowMessage(name: string, handler: (args: string[]) => void): void;
50
+ /** Creates or attaches a game window iframe
51
+ * @param id The iframe id to create
52
+ * @returns HTMLIFrameElement
53
+ */
54
+ CreateWindow(id: string, display?: string): HTMLIFrameElement;
43
55
  /** Remove event bus message handler
44
56
  * @param message The message to remove
45
57
  * @param handler The handler to remove
@@ -50,14 +62,14 @@ export declare class UnrealMessageBus {
50
62
  * @returns void
51
63
  */
52
64
  ResetHandlers(): void;
53
- /** Dispose the unreal message bus
54
- * @returns void
55
- */
56
- Dispose(): void;
57
65
  /** Resets the content frame list
58
66
  * @returns void
59
67
  */
60
68
  ResetContentFrames(): void;
69
+ /** Dispose the unreal message bus
70
+ * @returns void
71
+ */
72
+ Dispose(): void;
61
73
  /** Handle window message event
62
74
  * @param event The message event to handle
63
75
  * @returns void
@@ -1,29 +1,36 @@
1
1
  /** UMD Type References */
2
2
  /**
3
- * Unreal Toolkit (Static Manager Pattern)
3
+ * Unreal Toolkit Runtime Library
4
4
  * @class UnrealToolkit - All rights reserved (c) 2024 Mackey Kinard
5
5
  */
6
6
  export declare class UnrealToolkit {
7
- private static _EventBus;
8
- /** Unreal Toolkit event message bus
7
+ private static _Bridge;
8
+ /** Unreal Toolkit Communication Bridge (Event Bus)
9
9
  * @example
10
- * ```typescript
11
- * // Post WM_HELLO message to Unreal Engine
12
- * UnrealToolkit.EventBus.PostWindowMessage("WM_HELLO", ["Hello World!"]);
10
+ * ```typescript
11
+ * import UnrealToolkit from 'unreal-toolkit';
13
12
  *
14
- * // Handle WM_MY_EVENT message from Unreal Engine
15
- * UnrealToolkit.EventBus.OnWindowMessage("WM_MY_EVENT", (args:string[]) => {
16
- * console.log("My Event Args: ", args);
17
- * });
18
- * ```
19
- */
20
- static get EventBus(): UnrealMessageBus;
13
+ * // Create cross origin isolated iframe window
14
+ * const iframe = UnrealToolkit.Bridge.CreateWindow("game");
15
+ * iframe.src = "your.unrealtoolkitproject.com";
16
+ *
17
+ * // Handle message from Unreal Engine content
18
+ * UnrealToolkit.Bridge.OnWindowMessage("WM_EVENT", (args:string[]) => {
19
+ * console.log("My Event Args: ", args);
20
+ * });
21
+ *
22
+ * // Post message safely to Unreal Engine content
23
+ * UnrealToolkit.Bridge.PostWindowMessage("WM_HELLO", ["Hello World!"]);
24
+ * ```
25
+ */
26
+ static get Bridge(): EventBus;
21
27
  }
22
28
  /**
23
- * Unreal Toolkit Message Bus (Asynchronous Post Message Communication)
24
- * @class UnrealMessageBus - All rights reserved (c) 2024 Mackey Kinard
29
+ * Unreal Toolkit Event Bus (Asynchronous Post Message Communication)
30
+ * @class EventBus - All rights reserved (c) 2024 Mackey Kinard
25
31
  */
26
- export declare class UnrealMessageBus {
32
+ export declare class EventBus {
33
+ static PostWindowID: string;
27
34
  static AllowedOrigin: string;
28
35
  static TargetOrigin: string;
29
36
  static ContentFrames: NodeListOf<HTMLIFrameElement>;
@@ -40,6 +47,11 @@ export declare class UnrealMessageBus {
40
47
  * @returns void
41
48
  */
42
49
  OnWindowMessage(name: string, handler: (args: string[]) => void): void;
50
+ /** Creates or attaches a game window iframe
51
+ * @param id The iframe id to create
52
+ * @returns HTMLIFrameElement
53
+ */
54
+ CreateWindow(id: string, display?: string): HTMLIFrameElement;
43
55
  /** Remove event bus message handler
44
56
  * @param message The message to remove
45
57
  * @param handler The handler to remove
@@ -50,14 +62,14 @@ export declare class UnrealMessageBus {
50
62
  * @returns void
51
63
  */
52
64
  ResetHandlers(): void;
53
- /** Dispose the unreal message bus
54
- * @returns void
55
- */
56
- Dispose(): void;
57
65
  /** Resets the content frame list
58
66
  * @returns void
59
67
  */
60
68
  ResetContentFrames(): void;
69
+ /** Dispose the unreal message bus
70
+ * @returns void
71
+ */
72
+ Dispose(): void;
61
73
  /** Handle window message event
62
74
  * @param event The message event to handle
63
75
  * @returns void
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.UnrealToolkit=n():e.UnrealToolkit=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var o in t)e.o(t,o)&&!e.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:t[o]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n)},n={};e.d(n,{default:()=>i});var t=function(){function e(){}return Object.defineProperty(e,"EventBus",{get:function(){return null==e._EventBus&&(e._EventBus=new o),e._EventBus},enumerable:!1,configurable:!0}),e._EventBus=null,e}(),o=function(){function e(){this.ListenerDictionary={},this.HandleWindowMessage=this.HandleWindowMessage.bind(this),window.addEventListener("message",this.HandleWindowMessage)}return e.prototype.PostWindowMessage=function(n,t){try{null==e.ContentFrames&&(e.ContentFrames=document.querySelectorAll("iframe")),null!=e.ContentFrames?e.ContentFrames.forEach((function(o){var i;try{null===(i=o.contentWindow)||void 0===i||i.postMessage({source:"unrealtoolkit",message:n,args:t},e.TargetOrigin)}catch(e){console.warn(e)}})):console.warn("UnrealMessageBus: No Content Frames Found!")}catch(e){console.warn(e)}},e.prototype.OnWindowMessage=function(e,n){var t;null==this.ListenerDictionary[e]?(t=[],this.ListenerDictionary[e]=t):t=this.ListenerDictionary[e],t.findIndex((function(e){return n==e}))<0&&t.push(n)},e.prototype.RemoveHandler=function(e,n){var t=this.ListenerDictionary[e];if(null!=t){var o=t.findIndex((function(e){return n==e}));o>=0&&t.splice(o,1)}},e.prototype.ResetHandlers=function(){this.ListenerDictionary={}},e.prototype.Dispose=function(){this.ResetHandlers(),window.removeEventListener("message",this.HandleWindowMessage)},e.prototype.ResetContentFrames=function(){e.ContentFrames=null},e.prototype.HandleWindowMessage=function(n){if(null!=n&&null!=n.origin&&null!=n.data)if(null==e.AllowedOrigin||""===e.AllowedOrigin||"*"===e.AllowedOrigin||n.origin===e.AllowedOrigin){var t=null,o=null;null!=n.data.type?"progress"===n.data.type?(t="WM_PROGRESS",o=null!=n.data.value?[n.data.value.toString()]:null):"loaded"===n.data.type?(t="WM_LOADED",o=null):"focus"===n.data.type?(t="WM_FOCUS",o=null):"blur"===n.data.type?(t="WM_BLUR",o=null):"pointer-lock-active"===n.data.type?(t="WM_POINTER_LOCK_ACTIVE",o=null):"pointer-lock-inactive"===n.data.type&&(t="WM_POINTER_LOCK_INACTIVE",o=null):null!=n.data.source&&"unrealtoolkit"===n.data.source&&null!=n.data.message&&(t=n.data.message,o=null!=n.data.args?n.data.args:null);try{null!=t&&this.OnDispatchMessage(t,o)}catch(e){console.warn(e)}}else console.warn("UnrealMessageBus: Invalid Origin: "+n.origin)},e.prototype.OnDispatchMessage=function(e,n){void 0===n&&(n=null);var t=this.ListenerDictionary[e];null!=t&&t.forEach((function(e){try{e&&e(n)}catch(e){console.warn(e)}}))},e.AllowedOrigin="*",e.TargetOrigin="*",e.ContentFrames=null,e}();console.log("Unreal Toolkit Runtime - Version 0.1.8");const i=t;return n.default})()));
1
+ !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.UnrealToolkit=n():e.UnrealToolkit=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var o in t)e.o(t,o)&&!e.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:t[o]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n)},n={};e.d(n,{default:()=>i});var t=function(){function e(){}return Object.defineProperty(e,"Bridge",{get:function(){return null==e._Bridge&&(e._Bridge=new o),e._Bridge},enumerable:!1,configurable:!0}),e._Bridge=null,e}(),o=function(){function e(){this.ListenerDictionary={},this.HandleWindowMessage=this.HandleWindowMessage.bind(this),window.addEventListener("message",this.HandleWindowMessage)}return e.prototype.PostWindowMessage=function(n,t){try{null==e.ContentFrames&&(e.ContentFrames=document.querySelectorAll("iframe")),null!=e.ContentFrames?e.ContentFrames.forEach((function(o){var i;try{null!=e.PostWindowID&&""!==e.PostWindowID&&o.id!==e.PostWindowID||null===(i=o.contentWindow)||void 0===i||i.postMessage({source:"unrealtoolkit",message:n,args:t},e.TargetOrigin)}catch(e){console.warn(e)}})):console.warn("EventBus: No Content Frames Found!")}catch(e){console.warn(e)}},e.prototype.OnWindowMessage=function(e,n){var t;null==this.ListenerDictionary[e]?(t=[],this.ListenerDictionary[e]=t):t=this.ListenerDictionary[e],t.findIndex((function(e){return n==e}))<0&&t.push(n)},e.prototype.CreateWindow=function(e,n){void 0===n&&(n="block");var t=document.getElementById(e);if(null!=t)return t;var o=document.createElement("iframe");return o.id=e||"game",o.allow="cross-origin-isolated",o.crossOrigin="anonymous",o.sandbox.add("allow-same-origin","allow-scripts","allow-popups","allow-forms","allow-pointer-lock"),o.style.position="absolute",o.style.width="100%",o.style.height="100%",o.style.minHeight="100vh",o.style.border="none",o.style.outline="none",o.style.zIndex="0",o.style.display=n||"block",document.body.insertBefore(o,document.body.firstChild),o},e.prototype.RemoveHandler=function(e,n){var t=this.ListenerDictionary[e];if(null!=t){var o=t.findIndex((function(e){return n==e}));o>=0&&t.splice(o,1)}},e.prototype.ResetHandlers=function(){this.ListenerDictionary={}},e.prototype.ResetContentFrames=function(){e.ContentFrames=null},e.prototype.Dispose=function(){this.ResetHandlers(),this.ResetContentFrames(),window.removeEventListener("message",this.HandleWindowMessage)},e.prototype.HandleWindowMessage=function(n){if(null!=n&&null!=n.origin&&null!=n.data)if(null==e.AllowedOrigin||""===e.AllowedOrigin||"*"===e.AllowedOrigin||n.origin===e.AllowedOrigin){var t=null,o=null;null!=n.data.type?"progress"===n.data.type?(t="WM_PROGRESS",o=null!=n.data.value?[n.data.value.toString()]:null):"loaded"===n.data.type?(t="WM_LOADED",o=null):"focus"===n.data.type?(t="WM_FOCUS",o=null):"blur"===n.data.type?(t="WM_BLUR",o=null):"pointer-lock-active"===n.data.type?(t="WM_POINTER_LOCK_ACTIVE",o=null):"pointer-lock-inactive"===n.data.type&&(t="WM_POINTER_LOCK_INACTIVE",o=null):null!=n.data.source&&"unrealtoolkit"===n.data.source&&null!=n.data.message&&(t=n.data.message,o=null!=n.data.args?n.data.args:null);try{null!=t&&this.OnDispatchMessage(t,o)}catch(e){console.warn(e)}}else console.warn("EventBus: Invalid Origin: "+n.origin)},e.prototype.OnDispatchMessage=function(e,n){void 0===n&&(n=null);var t=this.ListenerDictionary[e];null!=t&&t.forEach((function(e){try{e&&e(n)}catch(e){console.warn(e)}}))},e.PostWindowID=null,e.AllowedOrigin="*",e.TargetOrigin="*",e.ContentFrames=null,e}();console.log("Unreal Toolkit Runtime - Version 0.1.8");const i=t;return n.default})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unreal-toolkit",
3
- "version": "0.1.21",
3
+ "version": "0.1.24",
4
4
  "description": "Unreal Toolkit Runtime Library (UMD)",
5
5
  "main": "dist/unreal.toolkit.js",
6
6
  "types": "dist/index.d.ts",