This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring changes from master to gh-packages branch (#174)
* Downgrade ts-jest and jest to support older Node version (#168) * Downgrade ts-jest and jest to support older Node version * bumbed ts-jest to 27.1.5 (latest 27.x.y) * Bump lib-pixelstreamingfrontend to 0.3.0 Signed-off-by: Luke Bermingham <1215582+lukehb@users.noreply.github.com> * Bump lib-pixelstreamingfrontend-ui to 0.2.0 update dep versions Signed-off-by: Luke Bermingham <1215582+lukehb@users.noreply.github.com> * Bump versions in package-lock.json for ui-library * Bump ui-library to 0.2.0 and force NPM publish * Update UE version printed when Cirrus starts Signed-off-by: Luke Bermingham <1215582+lukehb@users.noreply.github.com> * Bump Github release of 5.2 infra to 0.4.0 Signed-off-by: Luke Bermingham <1215582+lukehb@users.noreply.github.com> * Fix: sfu player would try subscribing when sfu disconnected * Updating the Frontend Docs (#152) --------- Signed-off-by: Luke Bermingham <1215582+lukehb@users.noreply.github.com> Co-authored-by: hmuurine <hmuurine@users.noreply.github.com> Co-authored-by: William Belcher <william.belcher@xa.epicgames.com> Co-authored-by: Michael Stopa <michael.stopa@xa.epicgames.com>
- Loading branch information
1 parent
344e338
commit 146e4c5
Showing
25 changed files
with
1,604 additions
and
1,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 44 additions & 28 deletions
72
Frontend/Docs/Communicating from the Player Page to UE5.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,85 @@ | ||
**TO DO**: Update this information to match the new front end. | ||
|
||
## Communicating from the Player Page to UE5 | ||
|
||
The `app.js` file provides two JavaScript functions that you can call in your HTML player page to allow the user to send events and commands from the browser to the Unreal Engine application: | ||
The frontend provides three functions that you can call in your HTML player page to allow the user to pass events and commands from the browser to your Unreal Engine application: | ||
|
||
* `emitCommand` Allows sending arbitrary commands to the game in the form of JSON objects. | ||
* You can use `emitConsoleCommand` to send console commands back to Unreal Engine. For example, `stat fps` to show the frame rate. See [Using the emitCommand Function below](#using-the-emitcommand-function). | ||
* `emitUIInteraction` sends any arbitrary string or object to the game. Use this function to send your own custom commands from your player UI, which you can respond to in your gameplay logic to produce any effect you need in your application. See [Using the emitUIInteraction Function below](#using-the-emituiinteraction-function). | ||
|
||
* You can use `emitCommand` to send console commands back to Unreal Engine. For example, `stat fps` to show the frame rate. See [Using the emitCommand Function below](#using-the-emitcommand-function). | ||
* `emitUIInteraction` sends any arbitrary string or JavaScript object to the game. Use this function to send your own custom commands from your player UI, which you can respond to in your gameplay logic to produce any effect you need in your application. See [Using the emitUIInteraction Function below](#using-the-emituiinteraction-function). | ||
|
||
### Using the emitCommand Function | ||
|
||
When you call the `emitCommand` function, you must pass it a JavaScript object. This object must contain a key that matches one of the following strings: | ||
When you call the `emitCommand` function, you pass it an object which then gets converted to JSON and sent onward to the game. This can then be used for implementing any sort of custom functionality you may require. | ||
|
||
#### Reserved Keywords | ||
|
||
Though you are given free reign to organize commands how you see fit, if the object contains a key with one of the following reserved keywords it will be interpreted by the PixelStreaming module instead: | ||
|
||
* `ConsoleCommand` \- Use this key to execute a console command on the remote Unreal Engine application. The value of this key should be a string that contains the command you want to run, along with any parameters it needs. For example: | ||
|
||
let descriptor = { | ||
ConsoleCommand: 'stat fps' | ||
} | ||
emitCommand(descriptor); | ||
```typescript | ||
let descriptor = { | ||
ConsoleCommand: 'stat fps' | ||
} | ||
emitCommand(descriptor); | ||
``` | ||
|
||
**_NOTE:_** | ||
Due to the power of the Unreal Engine console commands, the `emitCommand` function can present a security risk. In order for this function to work, you also need to provide the `-AllowPixelStreamingCommands` parameter on the command line when you launch your Unreal Engine application or start it from the Unreal Editor using the Standalone Game option. | ||
Due to the power of the Unreal Engine console commands, the `emitConsoleCommand` function can present a security risk. In order for this function to work, you also need to provide the `-AllowPixelStreamingCommands` parameter on the command line when you launch your Unreal Engine application or start it from the Unreal Editor using the Standalone Game option. | ||
|
||
|
||
### Using the emitConsoleCommand Function | ||
|
||
You may also use `emitConsoleCommand` to pass Unreal Engine console commands as a string. Like passing commands via `emitCommand`, you must provide `-AllowPixelStreamingCommands` on the command line when you launch your Unreal Engine application in order for these commands to be fielded. | ||
|
||
|
||
### Using the emitUIInteraction Function | ||
|
||
When you call the `emitUIInteraction` function, you can pass it a single string or JavaScript object. For example: | ||
When you call the `emitUIInteraction` function, you can pass it a single string or object. For example: | ||
|
||
emitUIInteraction("MyCustomCommand"); | ||
```typescript | ||
emitUIInteraction("MyCustomCommand"); | ||
``` | ||
|
||
or | ||
|
||
let descriptor = { | ||
LoadLevel: "/Game/Maps/Level_2" | ||
PlayerCharacter: { | ||
Name: "Shinbi" | ||
Skin: "Dynasty" | ||
} | ||
} | ||
emitUIInteraction(descriptor); | ||
```typescript | ||
const descriptor = { | ||
LoadLevel: "/Game/Maps/Level_2", | ||
PlayerCharacter: { | ||
Name: "Shinobi", | ||
Skin: "Dynasty", | ||
}, | ||
}; | ||
this.stream.emitUIInteraction(descriptor); | ||
``` | ||
|
||
If you pass a JavaScript object, the `emitUIInteraction` function converts it to a JSON string internally. It then passes the resulting string back to the Pixel Streaming Plugin in your Unreal Engine application, which raises an event on the input controller. In your application's gameplay logic, you bind your own custom event to handle these inputs, using the **Bind Event to OnPixelStreamingInputEvent** node. For example: | ||
If you pass an object, the `emitUIInteraction` function converts it to a JSON string internally. It then passes the resulting string back to the Pixel Streaming Plugin in your Unreal Engine application, which raises an event on the input controller. In your application's gameplay logic, you bind your own custom event to handle these inputs, using the **Pixel Streaming Input > Bind Event to On Input Event** node. For example: | ||
|
||
<p align="center"> | ||
<img src="Resources\Images\pixelstreaming-uiinteractionrespond.JPG" alt="Bind Event to OnPixelStreamingInputEvent"> | ||
<img src="Resources/Images/pixelstreaming-ui-interaction-event.png" alt="Bind Event to On Input Event"> | ||
</p> | ||
|
||
You need to bind this event once, typically at the start of your game. Each time any player HTML page connected to an instance of your Unreal Engine application calls the `emitUIInteraction`function, your custom event is automatically invoked, regardless of the input passed to `emitUIInteraction`. | ||
You need to bind this event once, typically at the start of your game. Each time any player HTML page connected to an instance of your Unreal Engine application calls the `emitUIInteraction` function, your custom event is automatically invoked, regardless of the input passed to `emitUIInteraction`. | ||
|
||
The custom event you assign (for example, the **UI Interaction** node in the image above) has an output named **Descriptor**, which you can use to retrieve the string that was sent to your Unreal Engine application by the `emitUIInteraction` function. You can use that value to determine how your gameplay code needs to respond each time `emitUIInteraction` is called. | ||
|
||
For example, the following Blueprint tests to see whether the input given to `emitUIInteraction` contains the string "MyCustomCommand", and calls a custom function to handle the event: | ||
|
||
|
||
<p align="center"> | ||
<img src="Resources\Images\pixelstreaming-respond-searchsubstring.JPG" alt="Search for substring"> | ||
<img src="Resources/Images/pixelstreaming-ui-interaction-search-substring.png" alt="Search for substring"> | ||
</p> | ||
|
||
If you originally passed a JavaScript object to `emitUIInteraction`, you can retrieve the value of any key from that JSON object using the **Pixel Streaming > Get Json String Value** node. For example, the following Blueprint tests for a key named LoadLevel. If that key is present, it calls a custom function to handle the event: | ||
|
||
|
||
<p align="center"> | ||
<img src="Resources\Images\pixelstreaming-respond-json.JPG" alt="Get a JSON field value"> | ||
<img src="Resources/Images/pixelstreaming-ui-interaction-extract-json.png" alt="Get a JSON field value"> | ||
</p> | ||
|
||
|
||
**_Tip:_** | ||
If you need to retrieve a nested key, use the dot notation common in JavaScript for your key. | ||
For example, `PlayerCharacter.Name` or `PlayerCharacter.Skin`. | ||
If you need to retrieve a nested key, use the dot notation common in TypeScript for your key. | ||
For example, `PlayerCharacter.Name` or `PlayerCharacter.Skin`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.