Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-ons support #6468

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
eccb840
Initial add-ons API commit
keianhzo Jan 29, 2024
4e69cb6
Try to get some more info about the build error
keianhzo Feb 15, 2024
1b48d6e
Do not install dev dependencies in production
keianhzo Feb 15, 2024
3cc6d09
Revert tests
keianhzo Feb 15, 2024
f3d84cc
organize types
keianhzo Feb 15, 2024
4ff2d0e
Test
keianhzo Feb 22, 2024
460930f
Omit dev packages when installing deps in production
keianhzo Apr 10, 2024
3726836
Package lock update
keianhzo Apr 10, 2024
2781f1f
Increase log level
keianhzo Apr 10, 2024
ca5a91e
Try --legacy-peer-deps
keianhzo Apr 10, 2024
4a432f9
Use webpack in addons instead of tsup
keianhzo Apr 17, 2024
f0da86a
Revert docker image changes
keianhzo Apr 17, 2024
174c6fa
Remove portals addon
keianhzo Apr 17, 2024
56f6567
Update addon version
keianhzo Apr 18, 2024
f3d12c4
Update addons
keianhzo Apr 24, 2024
2240897
BGs initial support
keianhzo May 8, 2024
0956082
Packages updates
keianhzo May 8, 2024
5920ae4
Better handle of bitECS/addons state
keianhzo May 9, 2024
fe03f9c
Add lost trigger collision group
keianhzo May 10, 2024
4f4f186
Skip homepage when creating a new room
keianhzo May 10, 2024
5beeac1
Update BGs add-on
keianhzo May 10, 2024
b16f757
Add-ons docs
keianhzo May 13, 2024
e03ce8b
Fix format
keianhzo May 13, 2024
672c680
Fix image size
keianhzo May 13, 2024
644d101
Restore dockerfile
keianhzo May 13, 2024
d616838
Add add-on preferences update support
keianhzo May 21, 2024
129b460
Add post-processing addon
keianhzo May 23, 2024
7c20ad5
Use legacy peers for storybook
keianhzo May 23, 2024
905abd9
Pin addons versions
keianhzo May 24, 2024
c02bb8d
remove unnecessary legacy-peer-deps
keianhzo Jun 3, 2024
5b9ce83
Fix admin store access
keianhzo Jun 3, 2024
bccf94d
Update admin store ref
keianhzo Jun 3, 2024
064441a
Fix addon configuration
keianhzo Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Then visit https://hubs.local:8080 (note: HTTPS is required, you'll need to acce

> Note: When running the Hubs client locally, you will still connect to the development versions of our [Janus WebRTC](https://github.com/mozilla/janus-plugin-sfu) and [reticulum](https://github.com/mozilla/reticulum) servers. These servers do not allow being accessed outside of localhost. If you want to host your own Hubs servers, please check out [Hubs Cloud](https://hubs.mozilla.com/docs/hubs-cloud-intro.html).

## Add-ons

Hubs client add-ons are pluggable libraries that are installed as part of the client and loaded at runtime. Add-ons allow functionality to the Hubs core and allow easy Hubs client extensibility while maintaining the Hubs client core lean and minimal.

You can read more about add-ons installation and development [here](doc/add-ons.md).

## Documentation

The Hubs documentation can be found [here](https://hubs.mozilla.com/docs).
Expand All @@ -59,18 +65,16 @@ Contributors are expected to abide by the project's [Code of Conduct](./CODE_OF_

## Additional Resources

* [Reticulum](https://github.com/mozilla/reticulum) - Phoenix-based backend for managing state and presence.
* [NAF Janus Adapter](https://github.com/mozilla/naf-janus-adapter) - A [Networked A-Frame](https://github.com/networked-aframe) adapter for the Janus SFU service.
* [Janus Gateway](https://github.com/meetecho/janus-gateway) - A WebRTC proxy used for centralizing network traffic in this client.
* [Janus SFU Plugin](https://github.com/mozilla/janus-plugin-sfu) - Plugins for Janus which enables it to act as a SFU.
* [Hubs-Ops](https://github.com/mozilla/hubs-ops) - Infrastructure as code + management tools for running necessary backend services on AWS.
- [Reticulum](https://github.com/mozilla/reticulum) - Phoenix-based backend for managing state and presence.
- [NAF Janus Adapter](https://github.com/mozilla/naf-janus-adapter) - A [Networked A-Frame](https://github.com/networked-aframe) adapter for the Janus SFU service.
- [Janus Gateway](https://github.com/meetecho/janus-gateway) - A WebRTC proxy used for centralizing network traffic in this client.
- [Janus SFU Plugin](https://github.com/mozilla/janus-plugin-sfu) - Plugins for Janus which enables it to act as a SFU.
- [Hubs-Ops](https://github.com/mozilla/hubs-ops) - Infrastructure as code + management tools for running necessary backend services on AWS.

## Privacy

Mozilla and Hubs believe that privacy is fundamental to a healthy internet. Read our [privacy policy](https://www.mozilla.org/en-US/privacy/hubs/) for more info.


## License

Hubs is licensed with the [Mozilla Public License 2.0](./LICENSE)

8 changes: 8 additions & 0 deletions addons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"addons": [
"hubs-duck-addon",
"hubs-portals-addon",
"hubs-behavior-graphs-addon",
"hubs-postprocessing-addon"
]
}
48 changes: 28 additions & 20 deletions admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions admin/src/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { AutoEndSessionDialog } from "./react-components/auto-end-session-dialog
import registerTelemetry from "hubs/src/telemetry";
import { createMuiTheme, withStyles } from "@material-ui/core/styles";
import { UnauthorizedPage } from "./react-components/unauthorized";
import { store } from "hubs/src/utils/store-instance";
import { getStore } from "hubs/src/utils/store-instance";

const qs = new URLSearchParams(location.hash.split("?")[1]);

window.APP = { store };
window.APP = { store: getStore() };

registerTelemetry("/admin", "Hubs Admin");

Expand Down Expand Up @@ -185,6 +185,7 @@ const mountUI = async (retPhxChannel, customRoutes, layout) => {

let permsTokenRefreshInterval;

const store = APP.store;
if (configs.POSTGREST_SERVER) {
dataProvider = postgrestClient(configs.POSTGREST_SERVER);
authProvider = postgrestAuthenticatior.createAuthProvider(retPhxChannel);
Expand Down Expand Up @@ -234,6 +235,7 @@ const HiddenAppBar = withStyles({
document.addEventListener("DOMContentLoaded", async () => {
const socket = await connectToReticulum();

const store = APP.store;
if (store.state && store.state.credentials && store.state.credentials.token) {
setItaAuthToken(store.state.credentials.token);
try {
Expand Down
3 changes: 2 additions & 1 deletion admin/src/react-components/service-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import LinearProgress from "@material-ui/core/LinearProgress";
import clsx from "classnames";
import { Title } from "react-admin";
import theme from "../utils/sample-theme";
import { store } from "hubs/src/utils/store-instance";
import { getStore } from "hubs/src/utils/store-instance";
import withCommonStyles from "../utils/with-common-styles";
import {
getEditableConfig,
Expand Down Expand Up @@ -649,6 +649,7 @@ const AppConfigEditor = withStyles(styles)(
class AppConfigEditor extends ConfigurationEditor {
constructor(props) {
super(props);
const store = getStore();
if (store.state && store.state.credentials && store.state.credentials.token) {
AppConfigUtils.setAuthToken(store.state.credentials.token);
}
Expand Down
104 changes: 104 additions & 0 deletions doc/add-ons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Hubs client Add-ons

Hubs client add-ons are pluggable libraries that are installed as part of the client and loaded at runtime. Add-ons allow functionality to the Hubs core and allow easy Hubs client extensibility while maintaining the Hubs client core lean and minimal.

## Installation

Installing an addon in your Hubs client is a two step process:

1. You'll need to install the add-on package in your client. You can do that using the `npm install` as with any other npm package.
For example if we would want to install the portals add-on we would need to do:

```
npm i https://github.com/MozillaReality/hubs-portals-addon.git
```

2. After the add-on is installed you'll need to add it to the addons array inside the `addons.json` file at the root of the Hubs client source.

```
{
"addons": [
...
"hubs-portals-addon",
...
]
}
```

Now you can build your client and run it as usual.

## Configuration

To configure your add-ons you need to update the add-on configuration JSON in the Admin console. Open your admin console and go to `App Settings -> Features`.

**Important Note**: Add-on require the bitECS based loader so you'll need to enable it for add-ons to work.

Update the add-ons JSON config with your add-ons configuration:

<p align="center">
<img src="img/addons-admin-config.png" width="420"/>
</p>

There are currently two properties supported in the add-ons configuration:

- **enabled**: Determines if the add-on is enabled by default in the instance rooms.
- **config**: A free form JSON containing the add-on configuration. This JSON will be passed as is to the add-on during the add-on initialization. See each add-on docs to know what JSON properties the add-on supports if any.

Once your configuration is saved, you can create or open a room in your instance and you should see add-ons running for that room.

### Room add-ons configuration

Add-ons can also be enabled/disabled per room independently from the instance configuration. To override the instance configuration you can go to your room settings and change the add-ons enabled/disabled configuration there. The room add-ons configuration will take precedence over the instance configuration if it has been changed at least once.

<p align="center">
<img src="img/addons-room-config.png" width="420"/>
</p>

## Add-on development

You can develop Hubs add-ons using Javascript or Typescript.

If you are developing using Typescript you can use the add-on template as a starting point. You can get the Add-on template from [here](https://github.com/MozillaReality/hubs-template-addon).

The add-on template has the basic dependencies already configured to get started with development as fast as possible.

The easiest way of iterating over an add-on development is by linking the add-on package source from the client.

1. Create a global link for the add-on. Go to the add-ons source folder and do:

`npm link`

Other related commands:

- To see all the global package links:

`npm ls --link --global`

- To remove a global linked package:

`npm unlink -g`

2. Go to the Hubs client root and add a link to the add-on package:

`npm link [package-id]`

Other related commands:

- You can see the currently linked packages with:

`npm ls --link`

- To remove a linked package:

`npm unlink --no-save [package-id]`

Now you can build the client and the add-on should be bundled as part of the client code.

There is a typings library available for Typescript development: [Hubs Client TS Types](https://github.com/MozillaReality/hubs-ts-types)

## Currently available add-ons

- [Template add-on](https://github.com/MozillaReality/hubs-template-addon). This add-on serves as a foundation for add-on development.
- [Duck add-on](https://github.com/MozillaReality/hubs-duck-addon): Replaces the existing `/duck` chat command and refactors it into a Hubs add-on.
- [Portals add-on](https://github.com/MozillaReality/hubs-portals-addon): Simple portals implementation as an add-on that lets you spawn portals using the `/portal`. It also show how to add key bindings.
- [Behavior Graphs add-on](https://github.com/MozillaReality/hubs-behavior-graphs-addon/): Initial Behavior Graphs implementation as an add-on
Binary file added doc/img/addons-admin-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/addons-room-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading