diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index ca2a01cb..a90d9397 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -61,6 +61,10 @@ jobs: run: yarn run lint working-directory: "front" + - name: "Pretty" + run: yarn run pretty + working-directory: "front" + - name: "Jasmine" run: yarn test working-directory: "front" diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d23f4b9..c0bd7335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## Version develop +### Updates +- New scripting API features : + - Use `WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions): Menu` to add a custom menu or an iframe to the menu. +- New `jitsiWidth` parameter to set the width of Jitsi +- Refactored the way videos are displayed to better cope for vertical videos (on mobile) +- Fixing reconnection issues after 5 minutes of an inactive tab on Google Chrome + +## Version 1.4.14 + ### Updates - New scripting API features : - Use `WA.room.loadTileset(url: string) : Promise` to load a tileset from a JSON file. diff --git a/README.md b/README.md index 322f06ba..ba9e70ce 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ Note: on some OSes, you will need to add this line to your `/etc/hosts` file: 127.0.0.1 workadventure.localhost ``` +Note: If on the first run you get a page with "network error". Try to ``docker-compose stop`` , then ``docker-compose start``. +Note 2: If you are still getting "network error". Make sure you are authorizing the self-signed certificate by entering https://pusher.workadventure.testing and accepting them. + ### MacOS developers, your environment with Vagrant If you are using MacOS, you can increase Docker performance using Vagrant. If you want more explanations, you can read [this medium article](https://medium.com/better-programming/vagrant-to-increase-docker-performance-with-macos-25b354b0c65c). diff --git a/back/package.json b/back/package.json index 8a1e445e..bb54d624 100644 --- a/back/package.json +++ b/back/package.json @@ -40,7 +40,7 @@ }, "homepage": "https://github.com/thecodingmachine/workadventure#readme", "dependencies": { - "@workadventure/tiled-map-type-guard": "^1.0.0", + "@workadventure/tiled-map-type-guard": "^1.0.2", "axios": "^0.21.1", "busboy": "^0.3.1", "circular-json": "^0.5.9", @@ -54,7 +54,6 @@ "prom-client": "^12.0.0", "query-string": "^6.13.3", "redis": "^3.1.2", - "systeminformation": "^4.31.1", "uWebSockets.js": "uNetworking/uWebSockets.js#v18.5.0", "uuidv4": "^6.0.7" }, diff --git a/back/src/Enum/EnvironmentVariable.ts b/back/src/Enum/EnvironmentVariable.ts index 92f62b0b..493f97a2 100644 --- a/back/src/Enum/EnvironmentVariable.ts +++ b/back/src/Enum/EnvironmentVariable.ts @@ -9,7 +9,6 @@ const JITSI_ISS = process.env.JITSI_ISS || ""; const SECRET_JITSI_KEY = process.env.SECRET_JITSI_KEY || ""; const HTTP_PORT = parseInt(process.env.HTTP_PORT || "8080") || 8080; const GRPC_PORT = parseInt(process.env.GRPC_PORT || "50051") || 50051; -export const SOCKET_IDLE_TIMER = parseInt(process.env.SOCKET_IDLE_TIMER as string) || 30; // maximum time (in second) without activity before a socket is closed export const TURN_STATIC_AUTH_SECRET = process.env.TURN_STATIC_AUTH_SECRET || ""; export const MAX_PER_GROUP = parseInt(process.env.MAX_PER_GROUP || "4"); export const REDIS_HOST = process.env.REDIS_HOST || undefined; diff --git a/back/src/Services/VariablesManager.ts b/back/src/Services/VariablesManager.ts index e8aaef25..915c6c05 100644 --- a/back/src/Services/VariablesManager.ts +++ b/back/src/Services/VariablesManager.ts @@ -1,7 +1,12 @@ /** * Handles variables shared between the scripting API and the server. */ -import { ITiledMap, ITiledMapObject, ITiledMapObjectLayer } from "@workadventure/tiled-map-type-guard/dist"; +import { + ITiledMap, + ITiledMapLayer, + ITiledMapObject, + ITiledMapObjectLayer, +} from "@workadventure/tiled-map-type-guard/dist"; import { User } from "_Model/User"; import { variablesRepository } from "./Repository/VariablesRepository"; import { redisClient } from "./RedisClient"; @@ -83,25 +88,33 @@ export class VariablesManager { private static findVariablesInMap(map: ITiledMap): Map { const objects = new Map(); for (const layer of map.layers) { - if (layer.type === "objectgroup") { - for (const object of (layer as ITiledMapObjectLayer).objects) { - if (object.type === "variable") { - if (object.template) { - console.warn( - 'Warning, a variable object is using a Tiled "template". WorkAdventure does not support objects generated from Tiled templates.' - ); - continue; - } - - // We store a copy of the object (to make it immutable) - objects.set(object.name, this.iTiledObjectToVariable(object)); - } - } - } + this.recursiveFindVariablesInLayer(layer, objects); } return objects; } + private static recursiveFindVariablesInLayer(layer: ITiledMapLayer, objects: Map): void { + if (layer.type === "objectgroup") { + for (const object of layer.objects) { + if (object.type === "variable") { + if (object.template) { + console.warn( + 'Warning, a variable object is using a Tiled "template". WorkAdventure does not support objects generated from Tiled templates.' + ); + continue; + } + + // We store a copy of the object (to make it immutable) + objects.set(object.name, this.iTiledObjectToVariable(object)); + } + } + } else if (layer.type === "group") { + for (const innerLayer of layer.layers) { + this.recursiveFindVariablesInLayer(innerLayer, objects); + } + } + } + private static iTiledObjectToVariable(object: ITiledMapObject): Variable { const variable: Variable = {}; diff --git a/back/yarn.lock b/back/yarn.lock index 98d675ee..64dcb9ce 100644 --- a/back/yarn.lock +++ b/back/yarn.lock @@ -194,10 +194,10 @@ semver "^7.3.2" tsutils "^3.17.1" -"@workadventure/tiled-map-type-guard@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@workadventure/tiled-map-type-guard/-/tiled-map-type-guard-1.0.0.tgz#02524602ee8b2688429a1f56df1d04da3fc171ba" - integrity sha512-Mc0SE128otQnYlScQWVaQVyu1+CkailU/FTBh09UTrVnBAhyMO+jIn9vT9+Dv244xq+uzgQDpXmiVdjgrYFQ+A== +"@workadventure/tiled-map-type-guard@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@workadventure/tiled-map-type-guard/-/tiled-map-type-guard-1.0.2.tgz#4171550f6cd71be19791faef48360d65d698bcb0" + integrity sha512-RCtygGV5y9cb7QoyGMINBE9arM5pyXjkxvXgA5uXEv4GDbXKorhFim/rHgwbVR+eFnVF3rDgWbRnk3DIaHt+lQ== dependencies: generic-type-guard "^3.4.1" @@ -554,7 +554,7 @@ chokidar@^3.4.0: optionalDependencies: fsevents "~2.1.2" -chownr@^1.1.1: +chownr@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg== @@ -1159,7 +1159,7 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" -fs-minipass@^1.2.5: +fs-minipass@^1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.7.tgz#ccff8570841e7fe4265693da88936c55aed7f7c7" integrity sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA== @@ -1969,7 +1969,7 @@ minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== -minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: +minipass@^2.6.0, minipass@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" integrity sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg== @@ -1977,7 +1977,7 @@ minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: safe-buffer "^5.1.2" yallist "^3.0.0" -minizlib@^1.2.1: +minizlib@^1.3.3: version "1.3.3" resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.3.tgz#2290de96818a34c29551c8a8d301216bd65a861d" integrity sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q== @@ -1992,7 +1992,7 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" -mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3: +mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.5: version "0.5.5" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== @@ -2290,9 +2290,9 @@ path-key@^3.0.0, path-key@^3.1.0: integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== path-type@^1.0.0: version "1.1.0" @@ -2578,7 +2578,7 @@ rxjs@^6.6.7: dependencies: tslib "^1.9.0" -safe-buffer@^5.0.1, safe-buffer@^5.1.2: +safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== @@ -2962,11 +2962,6 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" -systeminformation@^4.31.1: - version "4.31.1" - resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-4.31.1.tgz#2e02c26987494d4b6a4d2d83138724593bc98d50" - integrity sha512-dVCDWNMN8ncMZo5vbMCA5dpAdMgzafK2ucuJy5LFmGtp1cG6farnPg8QNvoOSky9SkFoEX1Aw0XhcOFV6TnLYA== - table@^5.2.3: version "5.4.6" resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" @@ -2978,17 +2973,17 @@ table@^5.2.3: string-width "^3.0.0" tar@^4.4.2: - version "4.4.13" - resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" - integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA== + version "4.4.19" + resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.19.tgz#2e4d7263df26f2b914dee10c825ab132123742f3" + integrity sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA== dependencies: - chownr "^1.1.1" - fs-minipass "^1.2.5" - minipass "^2.8.6" - minizlib "^1.2.1" - mkdirp "^0.5.0" - safe-buffer "^5.1.2" - yallist "^3.0.3" + chownr "^1.1.4" + fs-minipass "^1.2.7" + minipass "^2.9.0" + minizlib "^1.3.3" + mkdirp "^0.5.5" + safe-buffer "^5.2.1" + yallist "^3.1.1" tdigest@^0.1.1: version "0.1.1" @@ -3282,7 +3277,7 @@ y18n@^3.2.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.2.tgz#85c901bd6470ce71fc4bb723ad209b70f7f28696" integrity sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ== -yallist@^3.0.0, yallist@^3.0.3: +yallist@^3.0.0, yallist@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== diff --git a/benchmark/package-lock.json b/benchmark/package-lock.json index 2d25c58a..5d9ef0c6 100644 --- a/benchmark/package-lock.json +++ b/benchmark/package-lock.json @@ -429,9 +429,9 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-type": { "version": "1.1.0", diff --git a/benchmark/yarn.lock b/benchmark/yarn.lock index 8dcffe52..92541451 100644 --- a/benchmark/yarn.lock +++ b/benchmark/yarn.lock @@ -315,8 +315,8 @@ path-is-absolute@^1.0.0: resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" path-type@^1.0.0: version "1.1.0" diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 494c72b8..75a4de8c 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -75,6 +75,9 @@ "UPLOADER_URL": "//uploader-"+url, "ADMIN_URL": "//"+url, "JITSI_URL": env.JITSI_URL, + #POSTHOG + "POSTHOG_API_KEY": if namespace == "master" then env.POSTHOG_API_KEY else "", + "POSTHOG_URL": if namespace == "master" then env.POSTHOG_URL else "", "SECRET_JITSI_KEY": env.SECRET_JITSI_KEY, "TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443", "JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false", @@ -101,6 +104,7 @@ }, "redis": { "image": "redis:6", + "ports": [6379] } }, "config": { diff --git a/docs/maps/api-deprecated.md b/docs/maps/api-deprecated.md index 930caebe..f2b582a5 100644 --- a/docs/maps/api-deprecated.md +++ b/docs/maps/api-deprecated.md @@ -18,3 +18,4 @@ The list of functions below is **deprecated**. You should not use those but. use - Method `WA.onChatMessage` is deprecated. It has been renamed to `WA.chat.onChatMessage`. - Method `WA.onEnterZone` is deprecated. It has been renamed to `WA.room.onEnterZone`. - Method `WA.onLeaveZone` is deprecated. It has been renamed to `WA.room.onLeaveZone`. +- Method `WA.ui.registerMenuCommand` parameter `callback` is deprecated. Use `WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions)`. \ No newline at end of file diff --git a/docs/maps/api-state.md b/docs/maps/api-state.md index 634b47e1..a8ee5589 100644 --- a/docs/maps/api-state.md +++ b/docs/maps/api-state.md @@ -9,11 +9,12 @@ Moreover, `WA.state` functions can be used to persist this state across reloads. ``` WA.state.saveVariable(key : string, data : unknown): void WA.state.loadVariable(key : string) : unknown +WA.state.hasVariable(key : string) : boolean WA.state.onVariableChange(key : string).subscribe((data: unknown) => {}) : Subscription WA.state.[any property]: unknown ``` -These methods and properties can be used to save, load and track changes in variables related to the current room. +These methods and properties can be used to save, load and track changes in [variables related to the current room](variables.md). Variables stored in `WA.state` can be any value that is serializable in JSON. @@ -62,44 +63,11 @@ that you get the expected type). For security reasons, the list of variables you are allowed to access and modify is **restricted** (otherwise, anyone on your map could set any data). Variables storage is subject to an authorization process. Read below to learn more. -### Declaring allowed keys +## Defining a variable -In order to declare allowed keys related to a room, you need to add **objects** in an "object layer" of the map. - -Each object will represent a variable. - -
-
- -
-
- -The name of the variable is the name of the object. -The object **type** MUST be **variable**. - -You can set a default value for the object in the `default` property. - -### Persisting variables state - -Use the `persist` property to save the state of the variable in database. If `persist` is false, the variable will stay -in the memory of the WorkAdventure servers but will be wiped out of the memory as soon as the room is empty (or if the -server restarts). - -{.alert.alert-info} -Do not use `persist` for highly dynamic values that have a short life spawn. - -### Managing access rights to variables - -With `readableBy` and `writableBy`, you control who can read of write in this variable. The property accepts a string -representing a "tag". Anyone having this "tag" can read/write in the variable. - -{.alert.alert-warning} -`readableBy` and `writableBy` are specific to the "online" version of WorkAdventure because the notion of tags -is not available unless you have an "admin" server (that is not part of the self-hosted version of WorkAdventure). - -Finally, the `jsonSchema` property can contain [a complete JSON schema](https://json-schema.org/) to validate the content of the variable. -Trying to set a variable to a value that is not compatible with the schema will fail. +Out of the box, you cannot edit *any* variable. Variables MUST be declared in the map. +Check the [dedicated variables page](variables.md) to learn how to declare a variable in a map. ## Tracking variables changes diff --git a/docs/maps/api-ui.md b/docs/maps/api-ui.md index e4b9425d..dc701500 100644 --- a/docs/maps/api-ui.md +++ b/docs/maps/api-ui.md @@ -68,25 +68,53 @@ WA.room.onLeaveZone('myZone', () => { ### Add custom menu -```typescript -WA.ui.registerMenuCommand(menuCommand: string, callback: (menuCommand: string) => void): void ``` -Add a custom menu item containing the text `commandDescriptor` in the main menu. A click on the menu will trigger the `callback`. +WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions): Menu +``` +Add a custom menu item containing the text `commandDescriptor` in the navbar of the menu. +`options` attribute accepts an object with three properties : +- `callback : (commandDescriptor: string) => void` : A click on the custom menu will trigger the `callback`. +- `iframe: string` : A click on the custom menu will open the `iframe` inside the menu. +- `allowApi?: boolean` : Allow the iframe of the custom menu to use the Scripting API. + +Important : `options` accepts only `callback` or `iframe` not both. + Custom menu exist only until the map is unloaded, or you leave the iframe zone of the script. -Example: +
+
+ +
+
+ +
+
+Example: ```javascript +const menu = WA.ui.registerMenuCommand('menu test', + { + callback: () => { + WA.chat.sendChatMessage('test'); + } + }) -WA.ui.registerMenuCommand("test", () => { - WA.chat.sendChatMessage("test clicked", "menu cmd") -}) - +// Some time later, if you want to remove the menu: +menu.remove(); ``` -
- -
+Please note that `registerMenuCommand` returns an object of the `Menu` class. + +The `Menu` class contains a single method: `remove(): void`. This will obviously remove the menu when called. + +```javascript +class Menu { + /** + * Remove the menu + */ + remove() {}; +} +``` diff --git a/docs/maps/entry-exit.md b/docs/maps/entry-exit.md new file mode 100644 index 00000000..bd194138 --- /dev/null +++ b/docs/maps/entry-exit.md @@ -0,0 +1,67 @@ +{.section-title.accent.text-primary} +# Entries and exits + +https://www.youtube.com/watch?v=MuhVgu8H7U0 + +## Defining a default entry point + +In order to define a default start position, you MUST create a layer named "`start`" on your map. This layer MUST contain at least one tile. The players will start on the tile of this layer. If the layer contains many tiles, the players will start randomly on one of those tiles. + +![Start layer screenshot](images/start_layer.png) + +In the screenshot above, the start layer is made of the 2 white tiles. These tiles are not visible to the end user because they are hidden below the "bottom" layer that displays the floor of the map. + +{.alert.alert-info} +**Pro tip**: if you expect many people to connect to your map at the same time (for instance, if you are organizing a big event), consider making a large start zone. This way, users will not all appear at the same position and will not pop randomly in a chat with someone connecting at the same moment. + +## Defining exits + +In order to place an exit on your scene that leads to another scene: + +* You must create a specific layer. When a character reaches ANY tile of that layer, it will exit the scene. +* In layer properties, you MUST add "`exitUrl`" property. It represents the URL of the next scene. You can put relative or absolute URLs. +* If you want to have multiple exits, you can create many layers. Each layer has a different key `exitUrl` and has tiles that represent exits to another scene. + +![](images/exit_layer_map.png) + +{.alert.alert-warning} +**Note:** in older releases of WorkAdventure, you could link to a map file directly using properties `exitSceneUrl` and `exitInstance`. Those properties are now **deprecated**. Use "`exitUrl`" instead. + +## Understanding map URLs in WorkAdventure + +There are 2 kinds of URLs in WorkAdventure: + +* Public URLs are in the form `https://play.workadventu.re/_/[instance]/[server]/[path to map]` +* Private URLs (used in paid accounts) are in the form `https://play.workadventu.re/@/[organization]/[world]/[map]` + +Assuming your JSON map is hosted at "`https://example.com/my/map.json`", then you can browse your map at "`https://play.workadventu.re/_/global/example.com/my/map.json`". Here, "global" is a name of an "instance" of your map. You can put anything instead of "global" here. People on the same instance of the map can see each others. If 2 users use 2 different instances, they are on the same map, but in 2 parallel universes. They cannot see each other. + +## Defining several entry points + +Often your map will have several exits, and therefore, several entry points. For instance, if there is an exit by a door that leads to the garden map, when you come back from the garden you expect to come back by the same door. Therefore, a map can have several entry points. Those entry points are "named" (they have a name). + +In order to create a named entry point: + +You can create a new layer for your entry point or use an existing layer with named tiles. + +* If you don't use the layer named "`start`", you MUST add a boolean "`startLayer`" property to the layer properties. It MUST be set to true. +* If you use this method, when a character enters the map by this entry point, it will enter randomly on ANY tile of that layer. The name of the entry point is the name of that layer. + +![](images/layer-entry-point.png) + +You can also use the tiles properties to create entry point. + +* To do that, you will need to have a layer named "`start`" or with the "`startLayer`" property. Then you MUST add a string "`start`" property to a tile than you use in that layer. The name of the entry point is the value that property. +* If you use this method, when a character enters the map by this entry point, it will enter on ANY tile of the same kind in that layer. + +![](images/tile-entry-point.png) + +Notes : + +* Two tiles with a string "start" property with different value can be in the same layer of entries. +* A tile with a string "start" property that is not in a layer of entries won't usable as an entry point. + +How to use entry point : + +* To enter via this entry point, simply add a hash with the entry point name to the URL ("#[_entryPointName_]"). For instance: "`https://workadventu.re/_/global/mymap.com/path/map.json#my-entry-point`". +* You can of course use the "#" notation in an exit scene URL (so an exit scene URL will point to a given entry scene URL) diff --git a/docs/maps/hosting.md b/docs/maps/hosting.md new file mode 100644 index 00000000..cd3d310d --- /dev/null +++ b/docs/maps/hosting.md @@ -0,0 +1,25 @@ +{.section-title.accent.text-primary} +# Hosting your map + +The [Getting Started](.) page proposes to use a "starter kit" that is relying on GitHub pages for hosting the map. This is a fairly good solution as GitHub pages offers a free and performant hosting. + +But using GitHub pages is not necessary. You can host your maps on any webserver. + +{.alert.alert-warning} +If you decide to host your maps on your own webserver, you must **configure CORS headers** in your browser to allow access from WorkAdventure. + +## Configuring CORS headers + +CORS headers ([Cross Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)) are useful when a website want to make some resources accessible to another website. This is exactly what we want to do. We want the map you are designing to be accessible from the WorkAdventure domain (`play.workadventu.re`). + +### Enabling CORS for Apache + +In order to enable CORS in your Apache configuration, you will need to ensure the `headers` module is enabled. + +In your Apache configuration file, simply add the following line inside either the ``, ``, `` or `` sections, or within a `.htaccess` file. + + Header set Access-Control-Allow-Origin "*" + +### Enabling CORS on another webserver + +Check out [enable-cors.org](https://enable-cors.org/server.html) which has detailed instructions on how to enable CORS on many different webservers. diff --git a/docs/maps/images/click_space_jitsi.png b/docs/maps/images/click_space_jitsi.png new file mode 100644 index 00000000..ec7d7198 Binary files /dev/null and b/docs/maps/images/click_space_jitsi.png differ diff --git a/docs/maps/images/click_space_open_website.png b/docs/maps/images/click_space_open_website.png new file mode 100644 index 00000000..09d0daa2 Binary files /dev/null and b/docs/maps/images/click_space_open_website.png differ diff --git a/docs/maps/images/create_repo.png b/docs/maps/images/create_repo.png new file mode 100644 index 00000000..38083edd Binary files /dev/null and b/docs/maps/images/create_repo.png differ diff --git a/docs/maps/images/custom-menu-iframe.png b/docs/maps/images/custom-menu-iframe.png new file mode 100644 index 00000000..9df2aa5f Binary files /dev/null and b/docs/maps/images/custom-menu-iframe.png differ diff --git a/docs/maps/images/custom-menu-navbar.png b/docs/maps/images/custom-menu-navbar.png new file mode 100644 index 00000000..c2440956 Binary files /dev/null and b/docs/maps/images/custom-menu-navbar.png differ diff --git a/docs/maps/images/exit_layer_map.png b/docs/maps/images/exit_layer_map.png new file mode 100644 index 00000000..dd3e32f1 Binary files /dev/null and b/docs/maps/images/exit_layer_map.png differ diff --git a/docs/maps/images/github_pages.png b/docs/maps/images/github_pages.png new file mode 100644 index 00000000..7b66c24c Binary files /dev/null and b/docs/maps/images/github_pages.png differ diff --git a/docs/maps/images/layer-entry-point.png b/docs/maps/images/layer-entry-point.png new file mode 100644 index 00000000..52345800 Binary files /dev/null and b/docs/maps/images/layer-entry-point.png differ diff --git a/docs/maps/images/open_website.png b/docs/maps/images/open_website.png new file mode 100644 index 00000000..75023a4e Binary files /dev/null and b/docs/maps/images/open_website.png differ diff --git a/docs/maps/images/open_website_policy.png b/docs/maps/images/open_website_policy.png new file mode 100644 index 00000000..d72e3472 Binary files /dev/null and b/docs/maps/images/open_website_policy.png differ diff --git a/docs/maps/images/start_kit_start_screen.png b/docs/maps/images/start_kit_start_screen.png new file mode 100644 index 00000000..fd1a63f2 Binary files /dev/null and b/docs/maps/images/start_kit_start_screen.png differ diff --git a/docs/maps/images/start_layer.png b/docs/maps/images/start_layer.png new file mode 100644 index 00000000..07a80dab Binary files /dev/null and b/docs/maps/images/start_layer.png differ diff --git a/docs/maps/images/tile-entry-point.png b/docs/maps/images/tile-entry-point.png new file mode 100644 index 00000000..45c36d2d Binary files /dev/null and b/docs/maps/images/tile-entry-point.png differ diff --git a/docs/maps/images/use_this_template.png b/docs/maps/images/use_this_template.png new file mode 100644 index 00000000..6ed83ab9 Binary files /dev/null and b/docs/maps/images/use_this_template.png differ diff --git a/docs/maps/images/website_address.png b/docs/maps/images/website_address.png new file mode 100644 index 00000000..d994e9f5 Binary files /dev/null and b/docs/maps/images/website_address.png differ diff --git a/docs/maps/images/youtube.jpg b/docs/maps/images/youtube.jpg new file mode 100644 index 00000000..3dc6c15b Binary files /dev/null and b/docs/maps/images/youtube.jpg differ diff --git a/docs/maps/index.md b/docs/maps/index.md new file mode 100644 index 00000000..7f5e7867 --- /dev/null +++ b/docs/maps/index.md @@ -0,0 +1,128 @@ +{.section-title.accent.text-primary} +# Create your map + +## Tools you will need + +In order to build your own map for WorkAdventure, you need: + +* the [Tiled editor](https://www.mapeditor.org/) software +* "tiles" (i.e. images) to create your map +* a web-server to serve your map + +WorkAdventure comes with a "map starter kit" that we recommend using to start designing your map quickly. It contains **a good default tileset** for building an office and it proposes to **use Github static pages as a web-server** which is both free and performant. It also comes with a local webserver for testing purpose and with Typescript support (if you are looking to use the [map scripting API]({{url('/map-building/scripting')}}). + +{.alert.alert-info} +If you are looking to host your maps on your own webserver, be sure to read the [Self-hosting your map](hosting.md) guide. + +[](https://www.youtube.com/watch?v=lu1IZgBJJD4) + +## Getting started + +Start by [creating a GitHub account](https://github.com/join) if you don't already have one. + +Then, go to the [Github map starter kit repository page](https://github.com/thecodingmachine/workadventure-map-starter-kit) and click the **"Use this template"** button. + +
+ +
The "Use this template" button
+
+ +You will be prompted to enter a repository name for your map. + +
+ +
The "create a new repository" page
+
+ +**Make sure to check the "Include all branches" checkbox, otherwise the Github Pages deployment process will not be setup automatically.** + +If you miss that step, don't worry, you can always fix that by clicking on the **Settings tab** of your repository and scroll down to the **GitHub Pages** section. Then select the **gh-pages** branch. It might already be selected, but please be sure to click on it nonetheless (otherwise GitHub will not enable GitHub pages). + +{.alert.alert-info} +If you only see a "master" branch and if the **gh-pages** branch does not appear here, simply wait a few minutes and refresh your page. When you created the project, Github Actions triggered a job that is in charge of creating the **gh-pages** branch. Maybe the job is not finished yet. + +
+ +
The GitHub pages configuration section
+
+ +Wait a few minutes... Github will deploy a new website with the content of the repository. The address of the website is visible in the "GitHub Pages" section. + +
+ +
Your website is ready!
+
+ +Click on the link. You should be redirected directly to WorkAdventure, on your map! + +## Customizing your map + +Your map is now up and online, but this is still the demo map from the starter kit. You need to customize it. + +### Cloning the map + +Start by cloning the map. If you are used to Git and GitHub, simply clone the map to your computer using your preferred tool and [jump to the next chapter](#loading-the-map-in-tiled). + +If you are new to Git, cloning the map means downloading the map to your computer. To do this, you will need Git, or a Git compatible tool. Our advice is to use [GitHub Desktop](https://desktop.github.com/). We recommend you take some time mastering the notion of pull / commit / push as this will make uploading your maps really easier. + +As an (easier) alternative, you can simply use the "Export" button to download the code of the map in a big Zip file. When you want to upload your work again, you will simply drag'n'drop your files in the GitHub website. + +### Loading the map in Tiled + +The sample map is in the file `map.json`. You can load this file in [Tiled](https://www.mapeditor.org/). + +Now, it's up to you to edit the map and write your own map. + +Some resources regarding Tiled: + +* [Tiled documentation](https://doc.mapeditor.org/en/stable/manual/introduction/) +* [Tiled video tutorials](https://www.gamefromscratch.com/post/2015/10/14/Tiled-Map-Editor-Tutorial-Series.aspx) + +### Testing your map locally + +In order to test your map, you need a webserver to host your map. The "map starter kit" comes with a local webserver that you can use to test your map. + +In order to start the webserver, you will need [Node.JS](https://nodejs.org/en/). When it is downloaded, open your command line and from the directory of the map, run this command: + + $ npm install + +This will install the local webserver. + + $ npm run start + +This command will start the webserver and open the welcome page. You should see a page looking like this: + +
+ +
The welcome page of the "map start kit"
+
+ +From here, you simply need to click the "Test this map" button to test your map in WorkAdventure. + +{.alert.alert-warning} +The local web server can only be used to test your map locally. In particular, the link will only work on your computer. You cannot share it with other people. + +### Pushing the map + +When your changes are ready, you need to "commit" and "push" (i.e. "upload") the changes back to GitHub. Just wait a few minutes, and your map will be propagated automatically to the GitHub pages web-server. + +## Testing your map + +To test your map, you need to find its URL. There are 2 kinds of URLs in WorkAdventure: + +* Test URLs are in the form `https://play.workadventu.re/_/[instance]/[server]/[path to map]` +* Registered URLs are in the form `https://play.workadventu.re/@/[organization]/[world]/[map]` + +Assuming your JSON map is hosted at "`https://myuser.github.io/myrepo/map.json`", then you can browse your map at "`https://play.workadventu.re/_/global/myuser.github.io/myrepo/map.json`". Here, "global" is a name of an "instance" of your map. You can put anything instead of "global" here. People on the same instance of the map can see each others. If 2 users use 2 different instances, they are on the same map, but in 2 parallel universes. They cannot see each other. + +This will connect you to a "public" instance. Anyone can come and connect to a public instance. If you want to manage invitations, or to perform some moderation, you will need to create a "private" instance. Private instances are available in "pro" accounts. + +
+
+

Need some help?

+

WorkAdventure is a constantly evolving project and there is plenty of room for improvement regarding map editing.

+

If you are facing any troubles, do not hesitate to open an "issue" in the + GitHub WorkAdventure account. +

+
+
diff --git a/docs/maps/meeting-rooms.md b/docs/maps/meeting-rooms.md new file mode 100644 index 00000000..719e0630 --- /dev/null +++ b/docs/maps/meeting-rooms.md @@ -0,0 +1,82 @@ +{.section-title.accent.text-primary} +# Meeting rooms + +https://www.youtube.com/watch?v=cN9VMWHN0eo + +## Opening a Jitsi meet when walking on the map + +On your map, you can define special zones (meeting rooms) that will trigger the opening of a Jitsi meet. When a player will pass over these zones, a Jitsi meet will open (as an iframe on the right side of the screen) + +In order to create Jitsi meet zones: + +* You must create a specific layer. +* In layer properties, you MUST add a "`jitsiRoom`" property (of type "`string`"). The value of the property is the name of the room in Jitsi. Note: the name of the room will be "slugified" and prepended with the name of the instance of the map (so that different instances of the map have different rooms) +* You may also use "jitsiWidth" property (of type "number" between 0 and 100) to control the width of the iframe containing the meeting room. + +## Triggering of the "Jitsi meet" action + +By default, Jitsi meet will open when a user enters the zone defined on the map. + +It is however possible to trigger Jitsi only on user action. You can do this with the `jitsiTrigger` property. + +If you set `jitsiTrigger: onaction`, when the user walks on the layer, an alert message will be displayed at the bottom of the screen: + +
+ +
Jitsi meet will only open if the user clicks Space
+
+ +If you set `jitsiTriggerMessage: your message action` you can edit alert message displayed. If is not defined, the default message displayed is 'Press on SPACE to enter in jitsi meet room'. + +## Customizing your "Jitsi meet" + +Your Jitsi meet experience can be customized using Jitsi specific config options. The `jitsiConfig` and `jitsiInterfaceConfig` properties can be used on the Jitsi layer to change the way Jitsi looks and behaves. Those 2 properties are accepting a JSON string. + +For instance, use `jitsiConfig: { "startWithAudioMuted": true }` to automatically mute the microphone when someone enters a room. Or use `jitsiInterfaceConfig: { "DEFAULT_BACKGROUND": "#77ee77" }` to change the background color of Jitsi. + +The `jitsiConfig` property will override the Jitsi [config.js](https://github.com/jitsi/jitsi-meet/blob/master/config.js) file + +The `jitsiInterfaceConfig` property will override the Jitsi [interface_config.js](https://github.com/jitsi/jitsi-meet/blob/master/interface_config.js) file + +
If your customizations are not working: +
    +
  • First, check that the JSON you are entering is valid. Take a look at the console in your browser. If the JSON string is invalid, you should see a warning.
  • +
  • Then, check that the JSON you are using is matching the version of Jitsi used.
  • +
+
+ +## Granting moderator controls in Jitsi + +{.alert.alert-info} +Moderator controls are linked to member tags. You need a pro account to edit member tags. + +You can grant moderator rights to some of your members. Jitsi moderators can: + +* Publish a Jitsi meeting on Youtube Live (you will need a Youtube Live account) +* Record a meeting to Dropbox (you will need a Dropbox account) +* Mute someone +* Mute everybody expect one speaker +* Kick users out of the meeting + +In order to grant moderator rights to a given user, you can add a `jitsiRoomAdminTag` property to your Jitsi layer. For instance, if you write a property: + + jitsiRoomAdminTag: speaker + +then, any of your member with the `speaker` tag will be automatically granted moderator rights over this Jitsi instance. + +You can read more about [managing member tags in the admin documentation](/admin-guide/manage-members). + +## Using another Jitsi server + +WorkAdventure usually comes with a default Jitsi meet installation. If you are using the online version at `workadventu.re`, we are handling a Jitsi meet cluster for you. If you are running the self-hosted version of WorkAdventure, the administrator probably set up a Jitsi meet instance too. + +You have the possibility, in your map, to override the Jitsi meet instance that will be used by default. This can be useful for regulatory reasons. Maybe your company wants to keep control on the video streams and therefore, wants to self-host a Jitsi instance? Or maybe you want to use a very special configuration or very special version of Jitsi? + +Use the `jitsiUrl` property to in the Jitsi layer to specify the Jitsi instance that should be used. Beware, `jitsiUrl` takes in parameter a **domain name**, without the protocol. So you should use: +`jitsiUrl: meet.jit.si` +and not +`jitsiUrl: https://meet.jit.si` + +{.alert.alert-info} +When you use `jitsiUrl`, the targeted Jitsi instance must be public. You cannot use moderation features or the JWT +tokens authentication with maps configured using the `jitsiUrl` property. diff --git a/docs/maps/menu.php b/docs/maps/menu.php new file mode 100644 index 00000000..9fb3428f --- /dev/null +++ b/docs/maps/menu.php @@ -0,0 +1,133 @@ + 'Getting started', + 'url' => '/map-building', + 'markdown' => 'maps.index' + ], + [ + 'title' => 'WorkAdventure maps', + 'url' => '/map-building/wa-maps', + 'markdown' => 'maps.wa-maps' + ], + [ + 'title' => 'Entries and exits', + 'url' => '/map-building/entry-exit.md', + 'markdown' => 'maps.entry-exit' + ], + [ + 'title' => 'Opening a website', + 'url' => '/map-building/opening-a-website.md', + 'markdown' => 'maps.opening-a-website' + ], + [ + 'title' => 'Meeting rooms', + 'url' => '/map-building/meeting-rooms.md', + 'markdown' => 'maps.meeting-rooms' + ], + [ + 'title' => 'Special zones', + 'url' => '/map-building/special-zones.md', + 'markdown' => 'maps.special-zones' + ], + [ + 'title' => 'Animations', + 'url' => '/map-building/animations.md', + 'markdown' => 'maps.animations' + ], + [ + 'title' => 'Integrated websites', + 'url' => '/map-building/website-in-map.md', + 'markdown' => 'maps.website-in-map' + ], + [ + 'title' => 'Variables', + 'url' => '/map-building/variables.md', + 'markdown' => 'maps.variables' + ], + [ + 'title' => 'Self-hosting your map', + 'url' => '/map-building/hosting.md', + 'markdown' => 'maps.hosting' + ], + $extraMenu, + [ + 'title' => 'Scripting maps', + 'url' => '/map-building/scripting', + 'markdown' => 'maps.scripting', + 'children' => [ + [ + 'title' => 'Using Typescript', + 'url' => '/map-building/using-typescript.md', + 'markdown' => 'maps.using-typescript' + ], + [ + 'title' => 'API Reference', + 'url' => '/map-building/api-reference', + 'markdown' => 'maps.api-reference', + 'collapse' => true, + 'children' => [ + [ + 'title' => 'Initialization', + 'url' => '/map-building/api-start.md', + 'markdown' => 'maps.api-start', + ], + [ + 'title' => 'Navigation', + 'url' => '/map-building/api-nav.md', + 'markdown' => 'maps.api-nav', + ], + [ + 'title' => 'Chat', + 'url' => '/map-building/api-chat.md', + 'markdown' => 'maps.api-chat', + ], + [ + 'title' => 'Room', + 'url' => '/map-building/api-room.md', + 'markdown' => 'maps.api-room', + ], + [ + 'title' => 'State', + 'url' => '/map-building/api-state.md', + 'markdown' => 'maps.api-state', + ], + [ + 'title' => 'Player', + 'url' => '/map-building/api-player.md', + 'markdown' => 'maps.api-player', + ], + [ + 'title' => 'UI', + 'url' => '/map-building/api-ui.md', + 'markdown' => 'maps.api-ui', + ], + [ + 'title' => 'Sound', + 'url' => '/map-building/api-sound.md', + 'markdown' => 'maps.api-sound', + ], + [ + 'title' => 'Controls', + 'url' => '/map-building/api-controls.md', + 'markdown' => 'maps.api-controls', + ], + [ + 'title' => 'Deprecated', + 'url' => '/map-building/api-deprecated.md', + 'markdown' => 'maps.api-deprecated', + ], + ] + ], + $extraUtilsMenu + ] + ], + [ + 'title' => 'Troubleshooting', + 'url' => '/map-building/troubleshooting', + 'view' => 'content.map.troubleshooting' + ], +]; diff --git a/docs/maps/opening-a-website.md b/docs/maps/opening-a-website.md new file mode 100644 index 00000000..2ca54281 --- /dev/null +++ b/docs/maps/opening-a-website.md @@ -0,0 +1,66 @@ +{.section-title.accent.text-primary} +# Opening a website when walking on the map + +https://www.youtube.com/watch?v=Me8cu5lLN3A + +## The openWebsite property + +On your map, you can define special zones. When a player will pass over these zones, a website will open (as an iframe +on the right side of the screen) + +In order to create a zone that opens websites: + +* You must create a specific layer. +* In layer properties, you MUST add a "`openWebsite`" property (of type "`string`"). The value of the property is the URL of the website to open (the URL must start with "https://") +* You may also use "`openWebsiteWidth`" property (of type "`int`" or "`float`" between 0 and 100) to control the width of the iframe. +* You may also use "`openTab`" property (of type "`string`") to open in a new tab instead. + +{.alert.alert-warning} +A website can explicitly forbid another website from loading it in an iFrame using +the [X-Frame-Options HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options). + +## Integrating a Youtube video + +A common use case is to use `openWebsite` to open a Youtube video. + +The global Youtube page cannot be embedded into an iFrame (it has the `X-Frame-Options` HTTP header). + +To embed a Youtube video, be sure to **use the "embed" link**. You can get this link be clicking "Share > Embed" in Youtube. + +
+ +
Find the URL of your video in the "embed Video" HTML snippet on Youtube
+
+ +
+ +
Put this URL in the "openWebsite" property
+
+ +### Triggering of the "open website" action + +By default, the iFrame will open when a user enters the zone defined on the map. + +It is however possible to trigger the iFrame only on user action. You can do this with the `openWebsiteTrigger` property. + +If you set `openWebsiteTrigger: onaction`, when the user walks on the layer, an alert message will be displayed at the bottom of the screen: + +
+ +
The iFrame will only open if the user clicks Space
+
+ +If you set `openWebsiteTriggerMessage: your message action` you can edit alert message displayed. If is not defined, the default message displayed is 'Press on SPACE to open the web site'. + +### Setting the iFrame "allow" attribute + +By default, iFrames have limited rights in browsers. For instance, they cannot put their content in fullscreen, they cannot start your webcam, etc... + +If you want to grant additional access rights to your iFrame, you should use the `openWebsitePolicy` property. The value of this property will be directly used for the [`allow` atttribute of your iFrame](https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy/Using_Feature_Policy#the_iframe_allow_attribute). + +For instance, if you want an iFrame to be able to go in fullscreen, you will use the property `openWebsitePolicy: fullscreen` + +
+ +
The generated iFrame will have the allow attribute set to: <iframe allow="fullscreen">
+
diff --git a/docs/maps/special-zones.md b/docs/maps/special-zones.md new file mode 100644 index 00000000..fff4e730 --- /dev/null +++ b/docs/maps/special-zones.md @@ -0,0 +1,27 @@ +{.section-title.accent.text-primary} +# Other special zones + +## Making a "silent" zone + +https://www.youtube.com/watch?v=z7XLo06o-ow + +On your map, you can define special silent zones where nobody is allowed to talk. In these zones, users will not speak to each others, even if they are next to each others. + +In order to create a silent zone: + +* You must create a specific layer. +* In layer properties, you MUST add a boolean "`silent`" property. If the silent property is checked, the users are entering the silent zone when they walk on any tile of the layer. + +## Playing sounds or background music + +Your map can define special zones where a sound or background music will automatically be played. + +In order to create a zone that triggers sounds/music: + +* You must create a specific layer. +* In layer properties, you MUST add a "`playAudio`" property. The value of the property is a URL to an MP3 file that will be played. The URL can be relative to the URL of the map. +* You may use the boolean property "`audioLoop`" to make the sound loop (thanks captain obvious). +* If the "`audioVolume`" property is set, the audio player uses either the value of the property or the last volume set by the user - whichever is smaller. This property is a float from 0 to 1.0 + +{.alert.alert-info} +"`playAudioLoop`" is deprecated and should not be used anymore. diff --git a/docs/maps/using-typescript.md b/docs/maps/using-typescript.md new file mode 100644 index 00000000..04fcc171 --- /dev/null +++ b/docs/maps/using-typescript.md @@ -0,0 +1,183 @@ +{.section-title.accent.text-primary} +# Using Typescript with the scripting API + +{.alert.alert-info} +The easiest way to get started with writing scripts in Typescript is to use the +[Github map starter kit repository](https://github.com/thecodingmachine/workadventure-map-starter-kit). It comes with +Typescript enabled. If you are **not** using the "map starter kit", this page explains how to add Typescript to your +own scripts. + +## The short story + +In this page, we will assume you already know Typescript and know how to set it up with Webpack. + +To work with the scripting API in Typescript, you will need the typings of the `WA` object. These typings can be downloaded from the `@workadventure/iframe-api-typings` package. + +```console +$ npm install --save-dev @workadventure/iframe-api-typings +``` + +Furthermore, you need to make the global `WA` object available. To do this, edit the entry point of your project (usually, it is a file called `index.ts` in the root directory). + +Add this line at the top of the file: + +**index.ts** +```typescript +/// +``` + +From there, you should be able to use Typescript in your project. + +## The long story + +Below is a step by step guide explaining how to set up Typescript + Webpack along your WorkAdventure map. + +In your map directory, start by adding a `package.json` file. This file will contain dependencies on Webpack, Typescript and the Workadventure typings: + +**package.json** +```json +{ + "devDependencies": { + "@workadventure/iframe-api-typings": "^1.2.1", + "eslint": "^7.24.0", + "html-webpack-plugin": "^5.3.1", + "ts-loader": "^8.1.0", + "ts-node": "^9.1.1", + "typescript": "^4.2.4", + "webpack": "^5.31.2", + "webpack-cli": "^4.6.0", + "webpack-dev-server": "^3.11.2", + "webpack-merge": "^5.7.3" + }, + "scripts": { + "start": "webpack serve --open", + "build": "webpack --config webpack.prod.js", + } +} +``` + +You can now install the dependencies: + +```console +$ npm install +``` + +We now need to add a Webpack configuration file (for development mode). This Webpack file will: + +* Start a local webserver that will be in charge of serving the map +* Compile Typescript into Javascript and serve it automatically + +**webpack.config.js** +```js +const path = require('path'); +const webpack = require('webpack'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); + +module.exports = { + mode: 'development', + entry: './src/index.ts', + devtool: 'inline-source-map', + devServer: { + // The test webserver serves static files from the root directory. + // It comes with CORS enabled (important for WorkAdventure to be able to load the map) + static: { + directory: ".", + serveIndex: true, + watch: true, + }, + host: 'localhost', + allowedHosts: "all", + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS", + "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization" + } + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: [ '.tsx', '.ts', '.js' ], + }, + output: { + filename: 'script.js', + path: path.resolve(__dirname, 'dist'), + publicPath: '/' + } +}; +``` + +We need to configure Typescript, using a `tsconfig.json` file. + +**tsconfig.json** +```json +{ + "compilerOptions": { + "outDir": "./dist/", + "sourceMap": true, + "moduleResolution": "node", + "module": "CommonJS", + "target": "ES2015", + "declaration": false, + "downlevelIteration": true, + "jsx": "react", + "allowJs": true, + "strict": true + } +} +``` + +Create your entry point (the Typescript file at the root of your project). + +**src/index.ts** +```typescript +/// + +console.log('Hello world!'); +``` + +The first comment line is important in order to get `WA` typings. + +Now, you can start Webpack in dev mode! + +```console +$ npm run start +``` + +This will automatically compile Typescript, and serve it (along the map) on your local webserver (so at `http://localhost:8080/script.js`). Please note that the `script.js` file is never written to the disk. So do not worry if you don't see it appearing, you need to "build" it to actually write it to the disk. + +Final step, you must reference the script inside your map, by adding a `script` property at the root of your map: + +
+ +
The script property
+
+ +### Building the final script + +We now have a correct development setup. But we still need to be able to build the production script from Typescript files. We are not going to use the development server in production. To do this, we will add an additional `webpack.prod.js` file. + +**webpack.prod.js** +```javascript +const { merge } = require('webpack-merge'); +const common = require('./webpack.config.js'); + +module.exports = merge(common, { + mode: 'production', + devtool: 'source-map' +}); +``` + +This file will simply switch the Webpack config file in "production" mode. You can simply run: + +```console +$ npm run build +``` + +and the `script.js` file will be generated in the `dist/` folder. Beware, you will need to move it at the root of map for it to be read by the map. diff --git a/docs/maps/variables.md b/docs/maps/variables.md new file mode 100644 index 00000000..17e803d9 --- /dev/null +++ b/docs/maps/variables.md @@ -0,0 +1,59 @@ +{.section-title.accent.text-primary} +# Variables + +Maps can contain **variables**. Variables are piece of information that store some data. In computer science, we like +to say variables are storing the "state" of the room. + +- Variables are shared amongst all players in a given room. When the value of a variable changes for one player, it changes + for everyone. +- Variables are **invisible**. There are plenty of ways they can act on the room, but by default, you don't see them. + +## Declaring a variable + +In order to declare allowed variables in a room, you need to add **objects** in an "object layer" of the map. + +Each object will represent a variable. + +
+
+ +
+
+ +The name of the variable is the name of the object. +The object **type** MUST be **variable**. + +You can set a default value for the object in the `default` property. + +## Persisting variables state + +Use the `persist` property to save the state of the variable in database. If `persist` is false, the variable will stay +in the memory of the WorkAdventure servers but will be wiped out of the memory as soon as the room is empty (or if the +server restarts). + +{.alert.alert-info} +Do not use `persist` for highly dynamic values that have a short life spawn. + +## Managing access rights to variables + +With `readableBy` and `writableBy`, you control who can read of write in this variable. The property accepts a string +representing a "tag". Anyone having this "tag" can read/write in the variable. + +{.alert.alert-warning} +`readableBy` and `writableBy` are specific to the "online" version of WorkAdventure because the notion of tags +is not available unless you have an "admin" server (that is not part of the self-hosted version of WorkAdventure). + +In a future release, the `jsonSchema` property will contain [a complete JSON schema](https://json-schema.org/) to validate the content of the variable. +Trying to set a variable to a value that is not compatible with the schema will fail. + +## Using variables + +There are plenty of ways to use variables in WorkAdventure: + +- Using the [scripting API](api-state.md), you can read, edit or track the content of variables. +- Using the [Action zones](https://workadventu.re/map-building-extra/generic-action-zones.md), you can set the value of a variable when someone is entering or leaving a zone +- By [binding variable values to properties in the map](https://workadventu.re/map-building-extra/variable-to-property-binding.md) +- By [using automatically generated configuration screens](https://workadventu.re/map-building-extra/automatic-configuration.md) to create forms to edit the value of variables + +In general, variables can be used by third party libraries that you can embed in your map to add extra features. +A good example of such a library is the ["Scripting API Extra" library](https://workadventu.re/map-building-extra/about.md) diff --git a/front/Dockerfile b/front/Dockerfile index ef724e0f..6fef9dc8 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -1,13 +1,13 @@ -FROM thecodingmachine/workadventure-back-base:latest as builder -WORKDIR /var/www/messages -COPY --chown=docker:docker messages . +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder +WORKDIR /usr/src +COPY messages . RUN yarn install && yarn proto # we are rebuilding on each deploy to cope with the PUSHER_URL environment URL FROM thecodingmachine/nodejs:14-apache COPY --chown=docker:docker front . -COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/html/src/Messages/generated +COPY --from=builder --chown=docker:docker /usr/src/generated /var/www/html/src/Messages/generated # Removing the iframe.html file from the final image as this adds a XSS attack. # iframe.html is only in dev mode to circumvent a limitation diff --git a/front/dist/.htaccess b/front/dist/.htaccess index 72c4d724..522fc2af 100644 --- a/front/dist/.htaccess +++ b/front/dist/.htaccess @@ -22,3 +22,5 @@ RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule "^[_@]/" "/index.html" [L] RewriteRule "^register/" "/index.html" [L] +RewriteRule "^login" "/index.html" [L] +RewriteRule "^jwt/" "/index.html" [L] diff --git a/front/dist/index.tmpl.html b/front/dist/index.tmpl.html index 187e513a..0c89b611 100644 --- a/front/dist/index.tmpl.html +++ b/front/dist/index.tmpl.html @@ -34,7 +34,6 @@ WorkAdventure -
@@ -62,31 +61,6 @@
- -
diff --git a/front/dist/resources/html/gameMenu.html b/front/dist/resources/html/gameMenu.html index 73c62918..e69de29b 100644 --- a/front/dist/resources/html/gameMenu.html +++ b/front/dist/resources/html/gameMenu.html @@ -1,78 +0,0 @@ - - - diff --git a/front/dist/resources/html/gameMenuIcon.html b/front/dist/resources/html/gameMenuIcon.html deleted file mode 100644 index 22fe9867..00000000 --- a/front/dist/resources/html/gameMenuIcon.html +++ /dev/null @@ -1,28 +0,0 @@ - -
-
- -
-
\ No newline at end of file diff --git a/front/dist/resources/html/gameQualityMenu.html b/front/dist/resources/html/gameQualityMenu.html deleted file mode 100644 index babb3f0e..00000000 --- a/front/dist/resources/html/gameQualityMenu.html +++ /dev/null @@ -1,81 +0,0 @@ - - - diff --git a/front/dist/resources/html/gameReport.html b/front/dist/resources/html/gameReport.html deleted file mode 100644 index d35ae556..00000000 --- a/front/dist/resources/html/gameReport.html +++ /dev/null @@ -1,115 +0,0 @@ - - -
-
- -

Moderate

-

What action do you want to take?

-
-
-

Block:

-

Block any communication from and to this user. This can be reverted.

-
- -
-
-
-

Report:

-

Send a report message to the administrators of this room. They may later ban this user.

-
-
-
Your message:
- -

-
-
- -
-
-
-
- diff --git a/front/dist/resources/html/gameShare.html b/front/dist/resources/html/gameShare.html deleted file mode 100644 index 404c8680..00000000 --- a/front/dist/resources/html/gameShare.html +++ /dev/null @@ -1,96 +0,0 @@ - - - diff --git a/front/dist/resources/logos/tcm_full.png b/front/dist/resources/logos/tcm_full.png new file mode 100644 index 00000000..3ea27990 Binary files /dev/null and b/front/dist/resources/logos/tcm_full.png differ diff --git a/front/dist/resources/logos/tcm_short.png b/front/dist/resources/logos/tcm_short.png new file mode 100644 index 00000000..ed55c836 Binary files /dev/null and b/front/dist/resources/logos/tcm_short.png differ diff --git a/front/dist/resources/logos/logo-WA-min.png b/front/dist/static/images/logo-WA-min.png similarity index 100% rename from front/dist/resources/logos/logo-WA-min.png rename to front/dist/static/images/logo-WA-min.png diff --git a/front/package.json b/front/package.json index d60b6fa6..38c0570f 100644 --- a/front/package.json +++ b/front/package.json @@ -49,6 +49,7 @@ "phaser": "^3.54.0", "phaser-animated-tiles": "workadventure/phaser-animated-tiles#da68bbededd605925621dd4f03bd27e69284b254", "phaser3-rex-plugins": "^1.1.42", + "posthog-js": "^1.13.12", "queue-typescript": "^1.0.1", "quill": "1.3.6", "quill-delta-to-html": "^0.12.0", diff --git a/front/src/Administration/AnalyticsClient.ts b/front/src/Administration/AnalyticsClient.ts new file mode 100644 index 00000000..f3cde793 --- /dev/null +++ b/front/src/Administration/AnalyticsClient.ts @@ -0,0 +1,61 @@ +import {POSTHOG_API_KEY, POSTHOG_URL} from "../Enum/EnvironmentVariable"; + +class AnalyticsClient { + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private posthogPromise: Promise; + + constructor() { + if (POSTHOG_API_KEY && POSTHOG_URL) { + this.posthogPromise = import('posthog-js').then(({default: posthog}) => { + posthog.init(POSTHOG_API_KEY, { api_host: POSTHOG_URL, disable_cookie: true }); + return posthog; + }); + } else { + this.posthogPromise = Promise.reject(); + } + } + + identifyUser(uuid: string) { + this.posthogPromise.then(posthog => { + posthog.identify(uuid, { uuid, wa: true }); + }).catch(); + } + + loggedWithSso() { + this.posthogPromise.then(posthog => { + posthog.capture('wa-logged-sso'); + }).catch(); + } + + loggedWithToken() { + this.posthogPromise.then(posthog => { + posthog.capture('wa-logged-token'); + }).catch(); + } + + enteredRoom(roomId: string) { + this.posthogPromise.then(posthog => { + posthog.capture('$pageView', {roomId}); + }).catch(); + } + + openedMenu() { + this.posthogPromise.then(posthog => { + posthog.capture('wa-opened-menu'); + }).catch(); + } + + launchEmote(emote: string) { + this.posthogPromise.then(posthog => { + posthog.capture('wa-emote-launch', {emote}); + }).catch(); + } + + enteredJitsi(roomName: string, roomId: string) { + this.posthogPromise.then(posthog => { + posthog.capture('wa-entered-jitsi', {roomName, roomId}); + }).catch(); + } +} +export const analyticsClient = new AnalyticsClient(); diff --git a/front/src/Api/Events/ButtonClickedEvent.ts b/front/src/Api/Events/ButtonClickedEvent.ts index de807037..26a8aceb 100644 --- a/front/src/Api/Events/ButtonClickedEvent.ts +++ b/front/src/Api/Events/ButtonClickedEvent.ts @@ -1,10 +1,11 @@ import * as tg from "generic-type-guard"; -export const isButtonClickedEvent = - new tg.IsInterface().withProperties({ +export const isButtonClickedEvent = new tg.IsInterface() + .withProperties({ popupId: tg.isNumber, buttonId: tg.isNumber, - }).get(); + }) + .get(); /** * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. */ diff --git a/front/src/Api/Events/ChatEvent.ts b/front/src/Api/Events/ChatEvent.ts index 5729a120..984859e8 100644 --- a/front/src/Api/Events/ChatEvent.ts +++ b/front/src/Api/Events/ChatEvent.ts @@ -1,10 +1,11 @@ import * as tg from "generic-type-guard"; -export const isChatEvent = - new tg.IsInterface().withProperties({ +export const isChatEvent = new tg.IsInterface() + .withProperties({ message: tg.isString, author: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. */ diff --git a/front/src/Api/Events/ClosePopupEvent.ts b/front/src/Api/Events/ClosePopupEvent.ts index 83b09c96..f604a404 100644 --- a/front/src/Api/Events/ClosePopupEvent.ts +++ b/front/src/Api/Events/ClosePopupEvent.ts @@ -1,9 +1,10 @@ import * as tg from "generic-type-guard"; -export const isClosePopupEvent = - new tg.IsInterface().withProperties({ +export const isClosePopupEvent = new tg.IsInterface() + .withProperties({ popupId: tg.isNumber, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/EnterLeaveEvent.ts b/front/src/Api/Events/EnterLeaveEvent.ts index 0c0cb4ff..ca68136e 100644 --- a/front/src/Api/Events/EnterLeaveEvent.ts +++ b/front/src/Api/Events/EnterLeaveEvent.ts @@ -1,9 +1,10 @@ import * as tg from "generic-type-guard"; -export const isEnterLeaveEvent = - new tg.IsInterface().withProperties({ +export const isEnterLeaveEvent = new tg.IsInterface() + .withProperties({ name: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. */ diff --git a/front/src/Api/Events/GoToPageEvent.ts b/front/src/Api/Events/GoToPageEvent.ts index cb258b03..d8d6467d 100644 --- a/front/src/Api/Events/GoToPageEvent.ts +++ b/front/src/Api/Events/GoToPageEvent.ts @@ -1,11 +1,10 @@ import * as tg from "generic-type-guard"; - - -export const isGoToPageEvent = - new tg.IsInterface().withProperties({ +export const isGoToPageEvent = new tg.IsInterface() + .withProperties({ url: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/IframeEvent.ts b/front/src/Api/Events/IframeEvent.ts index ed723241..861acc22 100644 --- a/front/src/Api/Events/IframeEvent.ts +++ b/front/src/Api/Events/IframeEvent.ts @@ -15,7 +15,6 @@ import type { SetPropertyEvent } from "./setPropertyEvent"; import type { LoadSoundEvent } from "./LoadSoundEvent"; import type { PlaySoundEvent } from "./PlaySoundEvent"; import type { MenuItemClickedEvent } from "./ui/MenuItemClickedEvent"; -import type { MenuItemRegisterEvent } from "./ui/MenuItemRegisterEvent"; import type { HasPlayerMovedEvent } from "./HasPlayerMovedEvent"; import type { SetTilesEvent } from "./SetTilesEvent"; import type { SetVariableEvent } from "./SetVariableEvent"; @@ -33,6 +32,7 @@ import type { TriggerActionMessageEvent, } from "./ui/TriggerActionMessageEvent"; import { isMessageReferenceEvent, isTriggerActionMessageEvent } from "./ui/TriggerActionMessageEvent"; +import type { MenuRegisterEvent, UnregisterMenuEvent } from "./ui/MenuRegisterEvent"; export interface TypedMessageEvent extends MessageEvent { data: T; @@ -63,7 +63,8 @@ export type IframeEventMap = { stopSound: null; getState: undefined; loadTileset: LoadTilesetEvent; - registerMenuCommand: MenuItemRegisterEvent; + registerMenu: MenuRegisterEvent; + unregisterMenu: UnregisterMenuEvent; setTiles: SetTilesEvent; modifyEmbeddedWebsite: Partial; // Note: name should be compulsory in fact }; diff --git a/front/src/Api/Events/LoadSoundEvent.ts b/front/src/Api/Events/LoadSoundEvent.ts index 19b4b8e1..f48f202f 100644 --- a/front/src/Api/Events/LoadSoundEvent.ts +++ b/front/src/Api/Events/LoadSoundEvent.ts @@ -1,9 +1,10 @@ import * as tg from "generic-type-guard"; -export const isLoadSoundEvent = - new tg.IsInterface().withProperties({ +export const isLoadSoundEvent = new tg.IsInterface() + .withProperties({ url: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/OpenPopupEvent.ts b/front/src/Api/Events/OpenPopupEvent.ts index 094ba555..c1070bbe 100644 --- a/front/src/Api/Events/OpenPopupEvent.ts +++ b/front/src/Api/Events/OpenPopupEvent.ts @@ -1,18 +1,20 @@ import * as tg from "generic-type-guard"; -const isButtonDescriptor = - new tg.IsInterface().withProperties({ +const isButtonDescriptor = new tg.IsInterface() + .withProperties({ label: tg.isString, - className: tg.isOptional(tg.isString) - }).get(); + className: tg.isOptional(tg.isString), + }) + .get(); -export const isOpenPopupEvent = - new tg.IsInterface().withProperties({ +export const isOpenPopupEvent = new tg.IsInterface() + .withProperties({ popupId: tg.isNumber, targetObject: tg.isString, message: tg.isString, - buttons: tg.isArray(isButtonDescriptor) - }).get(); + buttons: tg.isArray(isButtonDescriptor), + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/OpenTabEvent.ts b/front/src/Api/Events/OpenTabEvent.ts index e510f8b6..6fe6ec21 100644 --- a/front/src/Api/Events/OpenTabEvent.ts +++ b/front/src/Api/Events/OpenTabEvent.ts @@ -1,11 +1,10 @@ import * as tg from "generic-type-guard"; - - -export const isOpenTabEvent = - new tg.IsInterface().withProperties({ +export const isOpenTabEvent = new tg.IsInterface() + .withProperties({ url: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/PlaySoundEvent.ts b/front/src/Api/Events/PlaySoundEvent.ts index 33ca1ff4..6fe56746 100644 --- a/front/src/Api/Events/PlaySoundEvent.ts +++ b/front/src/Api/Events/PlaySoundEvent.ts @@ -1,22 +1,23 @@ import * as tg from "generic-type-guard"; - -const isSoundConfig = - new tg.IsInterface().withProperties({ +const isSoundConfig = new tg.IsInterface() + .withProperties({ volume: tg.isOptional(tg.isNumber), loop: tg.isOptional(tg.isBoolean), mute: tg.isOptional(tg.isBoolean), rate: tg.isOptional(tg.isNumber), detune: tg.isOptional(tg.isNumber), seek: tg.isOptional(tg.isNumber), - delay: tg.isOptional(tg.isNumber) - }).get(); + delay: tg.isOptional(tg.isNumber), + }) + .get(); -export const isPlaySoundEvent = - new tg.IsInterface().withProperties({ +export const isPlaySoundEvent = new tg.IsInterface() + .withProperties({ url: tg.isString, - config : tg.isOptional(isSoundConfig), - }).get(); + config: tg.isOptional(isSoundConfig), + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/SetVariableEvent.ts b/front/src/Api/Events/SetVariableEvent.ts index 3b4e9c85..3e2303b3 100644 --- a/front/src/Api/Events/SetVariableEvent.ts +++ b/front/src/Api/Events/SetVariableEvent.ts @@ -1,5 +1,4 @@ import * as tg from "generic-type-guard"; -import { isMenuItemRegisterEvent } from "./ui/MenuItemRegisterEvent"; export const isSetVariableEvent = new tg.IsInterface() .withProperties({ diff --git a/front/src/Api/Events/StopSoundEvent.ts b/front/src/Api/Events/StopSoundEvent.ts index 6d12516d..cdfe43ca 100644 --- a/front/src/Api/Events/StopSoundEvent.ts +++ b/front/src/Api/Events/StopSoundEvent.ts @@ -1,9 +1,10 @@ import * as tg from "generic-type-guard"; -export const isStopSoundEvent = - new tg.IsInterface().withProperties({ +export const isStopSoundEvent = new tg.IsInterface() + .withProperties({ url: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the iFrame to the game to add a message in the chat. diff --git a/front/src/Api/Events/UserInputChatEvent.ts b/front/src/Api/Events/UserInputChatEvent.ts index de21ff6e..9de41327 100644 --- a/front/src/Api/Events/UserInputChatEvent.ts +++ b/front/src/Api/Events/UserInputChatEvent.ts @@ -1,9 +1,10 @@ import * as tg from "generic-type-guard"; -export const isUserInputChatEvent = - new tg.IsInterface().withProperties({ +export const isUserInputChatEvent = new tg.IsInterface() + .withProperties({ message: tg.isString, - }).get(); + }) + .get(); /** * A message sent from the game to the iFrame when a user types a message in the chat. */ diff --git a/front/src/Api/Events/ui/MenuItemRegisterEvent.ts b/front/src/Api/Events/ui/MenuItemRegisterEvent.ts deleted file mode 100644 index 404bdb13..00000000 --- a/front/src/Api/Events/ui/MenuItemRegisterEvent.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as tg from "generic-type-guard"; -import { Subject } from "rxjs"; - -export const isMenuItemRegisterEvent = new tg.IsInterface() - .withProperties({ - menutItem: tg.isString, - }) - .get(); -/** - * A message sent from the iFrame to the game to add a new menu item. - */ -export type MenuItemRegisterEvent = tg.GuardedType; - -export const isMenuItemRegisterIframeEvent = new tg.IsInterface() - .withProperties({ - type: tg.isSingletonString("registerMenuCommand"), - data: isMenuItemRegisterEvent, - }) - .get(); - -const _registerMenuCommandStream: Subject = new Subject(); -export const registerMenuCommandStream = _registerMenuCommandStream.asObservable(); - -export function handleMenuItemRegistrationEvent(event: MenuItemRegisterEvent) { - _registerMenuCommandStream.next(event.menutItem); -} diff --git a/front/src/Api/Events/ui/MenuRegisterEvent.ts b/front/src/Api/Events/ui/MenuRegisterEvent.ts new file mode 100644 index 00000000..f620745f --- /dev/null +++ b/front/src/Api/Events/ui/MenuRegisterEvent.ts @@ -0,0 +1,31 @@ +import * as tg from "generic-type-guard"; + +/** + * A message sent from a script to the game to remove a custom menu from the menu + */ +export const isUnregisterMenuEvent = new tg.IsInterface() + .withProperties({ + name: tg.isString, + }) + .get(); + +export type UnregisterMenuEvent = tg.GuardedType; + +export const isMenuRegisterOptions = new tg.IsInterface() + .withProperties({ + allowApi: tg.isBoolean, + }) + .get(); + +/** + * A message sent from a script to the game to add a custom menu from the menu + */ +export const isMenuRegisterEvent = new tg.IsInterface() + .withProperties({ + name: tg.isString, + iframe: tg.isUnion(tg.isString, tg.isUndefined), + options: isMenuRegisterOptions, + }) + .get(); + +export type MenuRegisterEvent = tg.GuardedType; diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 4dde1b7d..5a9aca85 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -29,11 +29,12 @@ import { isSetPropertyEvent, SetPropertyEvent } from "./Events/setPropertyEvent" import { isLayerEvent, LayerEvent } from "./Events/LayerEvent"; import type { HasPlayerMovedEvent } from "./Events/HasPlayerMovedEvent"; import { isLoadPageEvent } from "./Events/LoadPageEvent"; -import { handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent } from "./Events/ui/MenuItemRegisterEvent"; +import { isMenuRegisterEvent, isUnregisterMenuEvent } from "./Events/ui/MenuRegisterEvent"; import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent"; import type { SetVariableEvent } from "./Events/SetVariableEvent"; import { ModifyEmbeddedWebsiteEvent, isEmbeddedWebsiteEvent } from "./Events/EmbeddedWebsiteEvent"; import { EmbeddedWebsite } from "./iframe/Room/EmbeddedWebsite"; +import { handleMenuRegistrationEvent, handleMenuUnregisterEvent } from "../Stores/MenuStore"; type AnswererCallback = ( query: IframeQueryMap[T]["query"], @@ -45,30 +46,18 @@ type AnswererCallback = ( * Also allows to send messages to those iframes. */ class IframeListener { - private readonly _readyStream: Subject = new Subject(); - public readonly readyStream = this._readyStream.asObservable(); - - private readonly _chatStream: Subject = new Subject(); - public readonly chatStream = this._chatStream.asObservable(); - private readonly _openPopupStream: Subject = new Subject(); public readonly openPopupStream = this._openPopupStream.asObservable(); private readonly _openTabStream: Subject = new Subject(); public readonly openTabStream = this._openTabStream.asObservable(); - private readonly _goToPageStream: Subject = new Subject(); - public readonly goToPageStream = this._goToPageStream.asObservable(); - private readonly _loadPageStream: Subject = new Subject(); public readonly loadPageStream = this._loadPageStream.asObservable(); private readonly _openCoWebSiteStream: Subject = new Subject(); public readonly openCoWebSiteStream = this._openCoWebSiteStream.asObservable(); - private readonly _closeCoWebSiteStream: Subject = new Subject(); - public readonly closeCoWebSiteStream = this._closeCoWebSiteStream.asObservable(); - private readonly _disablePlayerControlStream: Subject = new Subject(); public readonly disablePlayerControlStream = this._disablePlayerControlStream.asObservable(); @@ -93,12 +82,6 @@ class IframeListener { private readonly _setPropertyStream: Subject = new Subject(); public readonly setPropertyStream = this._setPropertyStream.asObservable(); - private readonly _registerMenuCommandStream: Subject = new Subject(); - public readonly registerMenuCommandStream = this._registerMenuCommandStream.asObservable(); - - private readonly _unregisterMenuCommandStream: Subject = new Subject(); - public readonly unregisterMenuCommandStream = this._unregisterMenuCommandStream.asObservable(); - private readonly _playSoundStream: Subject = new Subject(); public readonly playSoundStream = this._playSoundStream.asObservable(); @@ -224,7 +207,7 @@ class IframeListener { } else if (payload.type === "setProperty" && isSetPropertyEvent(payload.data)) { this._setPropertyStream.next(payload.data); } else if (payload.type === "chat" && isChatEvent(payload.data)) { - this._chatStream.next(payload.data); + scriptUtils.sendAnonymousChat(payload.data); } else if (payload.type === "openPopup" && isOpenPopupEvent(payload.data)) { this._openPopupStream.next(payload.data); } else if (payload.type === "closePopup" && isClosePopupEvent(payload.data)) { @@ -260,17 +243,23 @@ class IframeListener { this._removeBubbleStream.next(); } else if (payload.type == "onPlayerMove") { this.sendPlayerMove = true; - } else if (isMenuItemRegisterIframeEvent(payload)) { - const data = payload.data.menutItem; - // @ts-ignore - this.iframeCloseCallbacks.get(iframe).push(() => { - this._unregisterMenuCommandStream.next(data); - }); - handleMenuItemRegistrationEvent(payload.data); } else if (payload.type == "setTiles" && isSetTilesEvent(payload.data)) { this._setTilesStream.next(payload.data); } else if (payload.type == "modifyEmbeddedWebsite" && isEmbeddedWebsiteEvent(payload.data)) { this._modifyEmbeddedWebsiteStream.next(payload.data); + } else if (payload.type == "registerMenu" && isMenuRegisterEvent(payload.data)) { + const dataName = payload.data.name; + this.iframeCloseCallbacks.get(iframe)?.push(() => { + handleMenuUnregisterEvent(dataName); + }); + handleMenuRegistrationEvent( + payload.data.name, + payload.data.iframe, + foundSrc, + payload.data.options + ); + } else if (payload.type == "unregisterMenu" && isUnregisterMenuEvent(payload.data)) { + handleMenuUnregisterEvent(payload.data.name); } } }, @@ -293,57 +282,67 @@ class IframeListener { this.iframes.delete(iframe); } - registerScript(scriptUrl: string): void { - console.log("Loading map related script at ", scriptUrl); + registerScript(scriptUrl: string): Promise { + return new Promise((resolve, reject) => { + console.log("Loading map related script at ", scriptUrl); - if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { - // Using external iframe mode ( - const iframe = document.createElement("iframe"); - iframe.id = IframeListener.getIFrameId(scriptUrl); - iframe.style.display = "none"; - iframe.src = "/iframe.html?script=" + encodeURIComponent(scriptUrl); + if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { + // Using external iframe mode ( + const iframe = document.createElement("iframe"); + iframe.id = IframeListener.getIFrameId(scriptUrl); + iframe.style.display = "none"; + iframe.src = "/iframe.html?script=" + encodeURIComponent(scriptUrl); - // We are putting a sandbox on this script because it will run in the same domain as the main website. - iframe.sandbox.add("allow-scripts"); - iframe.sandbox.add("allow-top-navigation-by-user-activation"); + // We are putting a sandbox on this script because it will run in the same domain as the main website. + iframe.sandbox.add("allow-scripts"); + iframe.sandbox.add("allow-top-navigation-by-user-activation"); - document.body.prepend(iframe); + iframe.addEventListener("load", () => { + resolve(); + }); - this.scripts.set(scriptUrl, iframe); - this.registerIframe(iframe); - } else { - // production code - const iframe = document.createElement("iframe"); - iframe.id = IframeListener.getIFrameId(scriptUrl); - iframe.style.display = "none"; + document.body.prepend(iframe); - // We are putting a sandbox on this script because it will run in the same domain as the main website. - iframe.sandbox.add("allow-scripts"); - iframe.sandbox.add("allow-top-navigation-by-user-activation"); + this.scripts.set(scriptUrl, iframe); + this.registerIframe(iframe); + } else { + // production code + const iframe = document.createElement("iframe"); + iframe.id = IframeListener.getIFrameId(scriptUrl); + iframe.style.display = "none"; - //iframe.src = "data:text/html;charset=utf-8," + escape(html); - iframe.srcdoc = - "\n" + - "\n" + - '\n' + - "\n" + - '\n' + - '\n' + - "\n" + - "\n" + - "\n"; + // We are putting a sandbox on this script because it will run in the same domain as the main website. + iframe.sandbox.add("allow-scripts"); + iframe.sandbox.add("allow-top-navigation-by-user-activation"); - document.body.prepend(iframe); + //iframe.src = "data:text/html;charset=utf-8," + escape(html); + iframe.srcdoc = + "\n" + + "\n" + + '\n' + + "\n" + + '\n' + + '\n' + + "\n" + + "\n" + + "\n"; - this.scripts.set(scriptUrl, iframe); - this.registerIframe(iframe); - } + iframe.addEventListener("load", () => { + resolve(); + }); + + document.body.prepend(iframe); + + this.scripts.set(scriptUrl, iframe); + this.registerIframe(iframe); + } + }); } private getBaseUrl(src: string, source: MessageEventSource | null): string { diff --git a/front/src/Api/ScriptUtils.ts b/front/src/Api/ScriptUtils.ts index 0dbe40fe..ad6dcc0f 100644 --- a/front/src/Api/ScriptUtils.ts +++ b/front/src/Api/ScriptUtils.ts @@ -1,4 +1,7 @@ import { coWebsiteManager } from "../WebRtc/CoWebsiteManager"; +import { playersStore } from "../Stores/PlayersStore"; +import { chatMessagesStore } from "../Stores/ChatStore"; +import type { ChatEvent } from "./Events/ChatEvent"; class ScriptUtils { public openTab(url: string) { @@ -16,6 +19,11 @@ class ScriptUtils { public closeCoWebSite() { coWebsiteManager.closeCoWebsite(); } + + public sendAnonymousChat(chatEvent: ChatEvent) { + const userId = playersStore.addFacticePlayer(chatEvent.author); + chatMessagesStore.addExternalMessage(userId, chatEvent.message); + } } export const scriptUtils = new ScriptUtils(); diff --git a/front/src/Api/iframe/Sound/Sound.ts b/front/src/Api/iframe/Sound/Sound.ts index 3bb3251a..132176c2 100644 --- a/front/src/Api/iframe/Sound/Sound.ts +++ b/front/src/Api/iframe/Sound/Sound.ts @@ -1,38 +1,35 @@ -import {sendToWorkadventure} from "../IframeApiContribution"; -import type {LoadSoundEvent} from "../../Events/LoadSoundEvent"; -import type {PlaySoundEvent} from "../../Events/PlaySoundEvent"; -import type {StopSoundEvent} from "../../Events/StopSoundEvent"; +import { sendToWorkadventure } from "../IframeApiContribution"; +import type { LoadSoundEvent } from "../../Events/LoadSoundEvent"; +import type { PlaySoundEvent } from "../../Events/PlaySoundEvent"; +import type { StopSoundEvent } from "../../Events/StopSoundEvent"; import SoundConfig = Phaser.Types.Sound.SoundConfig; export class Sound { constructor(private url: string) { sendToWorkadventure({ - "type": 'loadSound', - "data": { + type: "loadSound", + data: { url: this.url, - } as LoadSoundEvent - + } as LoadSoundEvent, }); } - public play(config: SoundConfig) { + public play(config: SoundConfig | undefined) { sendToWorkadventure({ - "type": 'playSound', - "data": { + type: "playSound", + data: { url: this.url, - config - } as PlaySoundEvent - + config, + } as PlaySoundEvent, }); return this.url; } public stop() { sendToWorkadventure({ - "type": 'stopSound', - "data": { + type: "stopSound", + data: { url: this.url, - } as StopSoundEvent - + } as StopSoundEvent, }); return this.url; } diff --git a/front/src/Api/iframe/Ui/ButtonDescriptor.ts b/front/src/Api/iframe/Ui/ButtonDescriptor.ts index 119daf5c..9cf1688a 100644 --- a/front/src/Api/iframe/Ui/ButtonDescriptor.ts +++ b/front/src/Api/iframe/Ui/ButtonDescriptor.ts @@ -1,4 +1,4 @@ -import type {Popup} from "./Popup"; +import type { Popup } from "./Popup"; export type ButtonClickedCallback = (popup: Popup) => void; @@ -6,13 +6,13 @@ export interface ButtonDescriptor { /** * The label of the button */ - label: string, + label: string; /** * The type of the button. Can be one of "normal", "primary", "success", "warning", "error", "disabled" */ - className?: "normal" | "primary" | "success" | "warning" | "error" | "disabled", + className?: "normal" | "primary" | "success" | "warning" | "error" | "disabled"; /** * Callback called if the button is pressed */ - callback: ButtonClickedCallback, + callback: ButtonClickedCallback; } diff --git a/front/src/Api/iframe/Ui/Menu.ts b/front/src/Api/iframe/Ui/Menu.ts new file mode 100644 index 00000000..c0fe772e --- /dev/null +++ b/front/src/Api/iframe/Ui/Menu.ts @@ -0,0 +1,17 @@ +import { sendToWorkadventure } from "../IframeApiContribution"; + +export class Menu { + constructor(private menuName: string) {} + + /** + * remove the menu + */ + public remove() { + sendToWorkadventure({ + type: "unregisterMenu", + data: { + name: this.menuName, + }, + }); + } +} diff --git a/front/src/Api/iframe/Ui/Popup.ts b/front/src/Api/iframe/Ui/Popup.ts index 37dea922..085fdc2c 100644 --- a/front/src/Api/iframe/Ui/Popup.ts +++ b/front/src/Api/iframe/Ui/Popup.ts @@ -1,19 +1,18 @@ -import {sendToWorkadventure} from "../IframeApiContribution"; -import type {ClosePopupEvent} from "../../Events/ClosePopupEvent"; +import { sendToWorkadventure } from "../IframeApiContribution"; +import type { ClosePopupEvent } from "../../Events/ClosePopupEvent"; export class Popup { - constructor(private id: number) { - } + constructor(private id: number) {} /** * Closes the popup */ public close(): void { sendToWorkadventure({ - 'type': 'closePopup', - 'data': { - 'popupId': this.id, - } as ClosePopupEvent + type: "closePopup", + data: { + popupId: this.id, + } as ClosePopupEvent, }); } } diff --git a/front/src/Api/iframe/registeredCallbacks.ts b/front/src/Api/iframe/registeredCallbacks.ts index 5d6f784d..3b6ee6c7 100644 --- a/front/src/Api/iframe/registeredCallbacks.ts +++ b/front/src/Api/iframe/registeredCallbacks.ts @@ -1,16 +1,18 @@ -import type {IframeResponseEventMap} from "../../Api/Events/IframeEvent"; -import type {IframeCallback} from "../../Api/iframe/IframeApiContribution"; -import type {IframeCallbackContribution} from "../../Api/iframe/IframeApiContribution"; +import type { IframeResponseEventMap } from "../../Api/Events/IframeEvent"; +import type { IframeCallback } from "../../Api/iframe/IframeApiContribution"; +import type { IframeCallbackContribution } from "../../Api/iframe/IframeApiContribution"; -export const registeredCallbacks: { [K in keyof IframeResponseEventMap]?: IframeCallback } = {} +export const registeredCallbacks: { [K in keyof IframeResponseEventMap]?: IframeCallback } = {}; -export function apiCallback(callbackData: IframeCallbackContribution): IframeCallbackContribution { +export function apiCallback( + callbackData: IframeCallbackContribution +): IframeCallbackContribution { const iframeCallback = { typeChecker: callbackData.typeChecker, - callback: callbackData.callback + callback: callbackData.callback, } as IframeCallback; const newCallback = { [callbackData.type]: iframeCallback }; - Object.assign(registeredCallbacks, newCallback) + Object.assign(registeredCallbacks, newCallback); return callbackData as unknown as IframeCallbackContribution; } diff --git a/front/src/Api/iframe/state.ts b/front/src/Api/iframe/state.ts index 3b551864..a875f3e0 100644 --- a/front/src/Api/iframe/state.ts +++ b/front/src/Api/iframe/state.ts @@ -62,6 +62,10 @@ export class WorkadventureStateCommands extends IframeApiContribution { let subject = variableSubscribers.get(key); if (subject === undefined) { @@ -85,6 +89,12 @@ const proxyCommand = new Proxy(new WorkadventureStateCommands(), { target.saveVariable(p.toString(), value); return true; }, + has(target: WorkadventureStateCommands, p: PropertyKey): boolean { + if (p in target) { + return true; + } + return target.hasVariable(p.toString()); + }, }) as WorkadventureStateCommands & { [key: string]: unknown }; export default proxyCommand; diff --git a/front/src/Api/iframe/ui.ts b/front/src/Api/iframe/ui.ts index ab5b2007..c4d40d16 100644 --- a/front/src/Api/iframe/ui.ts +++ b/front/src/Api/iframe/ui.ts @@ -6,6 +6,8 @@ import type { ButtonClickedCallback, ButtonDescriptor } from "./Ui/ButtonDescrip import { Popup } from "./Ui/Popup"; import { ActionMessage } from "./Ui/ActionMessage"; import { isMessageReferenceEvent } from "../Events/ui/TriggerActionMessageEvent"; +import { Menu } from "./Ui/Menu"; +import type { RequireOnlyOne } from "../types"; let popupId = 0; const popups: Map = new Map(); @@ -14,9 +16,18 @@ const popupCallbacks: Map> = new Map< Map >(); +const menus: Map = new Map(); const menuCallbacks: Map void> = new Map(); const actionMessages = new Map(); +interface MenuDescriptor { + callback?: (commandDescriptor: string) => void; + iframe?: string; + allowApi?: boolean; +} + +export type MenuOptions = RequireOnlyOne; + interface ZonedPopupOptions { zone: string; objectLayerName?: string; @@ -52,6 +63,10 @@ export class WorkAdventureUiCommands extends IframeApiContribution { const callback = menuCallbacks.get(event.menuItem); + const menu = menus.get(event.menuItem); + if (menu === undefined) { + throw new Error('Could not find menu named "' + event.menuItem + '"'); + } if (callback) { callback(event.menuItem); } @@ -104,14 +119,53 @@ export class WorkAdventureUiCommands extends IframeApiContribution void) { - menuCallbacks.set(commandDescriptor, callback); - sendToWorkadventure({ - type: "registerMenuCommand", - data: { - menutItem: commandDescriptor, - }, - }); + registerMenuCommand(commandDescriptor: string, options: MenuOptions | ((commandDescriptor: string) => void)): Menu { + const menu = new Menu(commandDescriptor); + + if (typeof options === "function") { + menuCallbacks.set(commandDescriptor, options); + sendToWorkadventure({ + type: "registerMenu", + data: { + name: commandDescriptor, + options: { + allowApi: false, + }, + }, + }); + } else { + options.allowApi = options.allowApi === undefined ? options.iframe !== undefined : options.allowApi; + + if (options.iframe !== undefined) { + sendToWorkadventure({ + type: "registerMenu", + data: { + name: commandDescriptor, + iframe: options.iframe, + options: { + allowApi: options.allowApi, + }, + }, + }); + } else if (options.callback !== undefined) { + menuCallbacks.set(commandDescriptor, options.callback); + sendToWorkadventure({ + type: "registerMenu", + data: { + name: commandDescriptor, + options: { + allowApi: options.allowApi, + }, + }, + }); + } else { + throw new Error( + "When adding a menu with WA.ui.registerMenuCommand, you must pass either an iframe or a callback" + ); + } + } + menus.set(commandDescriptor, menu); + return menu; } displayBubble(): void { diff --git a/front/src/Api/types.ts b/front/src/Api/types.ts new file mode 100644 index 00000000..7d1a2107 --- /dev/null +++ b/front/src/Api/types.ts @@ -0,0 +1,4 @@ +export type RequireOnlyOne = Pick> & + { + [K in keys]-?: Required> & Partial, undefined>>; + }[keys]; diff --git a/front/src/Components/App.svelte b/front/src/Components/App.svelte index d65f699e..8b033e5f 100644 --- a/front/src/Components/App.svelte +++ b/front/src/Components/App.svelte @@ -1,4 +1,6 @@
@@ -55,22 +62,22 @@ Switch to presentation mode {/if}
-
- {#if $requestedScreenSharingState} +
+ {#if $requestedScreenSharingState && !isSilent} Start screen sharing {:else} Stop screen sharing {/if}
-
- {#if $requestedCameraState} +
+ {#if $requestedCameraState && !isSilent} Turn on webcam {:else} Turn off webcam {/if}
-
- {#if $requestedMicrophoneState} +
+ {#if $requestedMicrophoneState && !isSilent} Turn on microphone {:else} Turn off microphone diff --git a/front/src/Components/Chat/Chat.svelte b/front/src/Components/Chat/Chat.svelte index a636205b..fd394781 100644 --- a/front/src/Components/Chat/Chat.svelte +++ b/front/src/Components/Chat/Chat.svelte @@ -3,7 +3,7 @@ import { chatMessagesStore, chatVisibilityStore } from "../../Stores/ChatStore"; import ChatMessageForm from './ChatMessageForm.svelte'; import ChatElement from './ChatElement.svelte'; - import {afterUpdate, beforeUpdate} from "svelte"; + import {afterUpdate, beforeUpdate, onMount} from "svelte"; import {HtmlUtils} from "../../WebRtc/HtmlUtils"; let listDom: HTMLElement; @@ -15,6 +15,10 @@ autoscroll = listDom && (listDom.offsetHeight + listDom.scrollTop) > (listDom.scrollHeight - 20); }); + onMount(() => { + listDom.scrollTo(0, listDom.scrollHeight); + }) + afterUpdate(() => { if (autoscroll) listDom.scrollTo(0, listDom.scrollHeight); }); diff --git a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte b/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte deleted file mode 100644 index c1811650..00000000 --- a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte +++ /dev/null @@ -1,152 +0,0 @@ - - - - -
- -
-
-

Global Message

- -
-
- {#if inputSendTextActive} - - {/if} - {#if uploadMusicActive} - - {/if} -
- -
-
- - - - diff --git a/front/src/Components/HelpCameraSettings/HelpCameraSettingsPopup.svelte b/front/src/Components/HelpCameraSettings/HelpCameraSettingsPopup.svelte index 8f4de785..ed4a84ca 100644 --- a/front/src/Components/HelpCameraSettings/HelpCameraSettingsPopup.svelte +++ b/front/src/Components/HelpCameraSettings/HelpCameraSettingsPopup.svelte @@ -3,10 +3,11 @@ import {helpCameraSettingsVisibleStore} from "../../Stores/HelpCameraSettingsStore"; import firefoxImg from "./images/help-setting-camera-permission-firefox.png"; import chromeImg from "./images/help-setting-camera-permission-chrome.png"; + import {getNavigatorType, isAndroid as isAndroidFct, NavigatorType} from "../../WebRtc/DeviceUtils"; - let isAndroid = window.navigator.userAgent.includes('Android'); - let isFirefox = window.navigator.userAgent.includes('Firefox'); - let isChrome = window.navigator.userAgent.includes('Chrome'); + let isAndroid = isAndroidFct(); + let isFirefox = getNavigatorType() === NavigatorType.firefox; + let isChrome = getNavigatorType() === NavigatorType.chrome; function refresh() { window.location.reload(); diff --git a/front/src/Components/Menu/AboutRoomSubMenu.svelte b/front/src/Components/Menu/AboutRoomSubMenu.svelte new file mode 100644 index 00000000..3ccc9669 --- /dev/null +++ b/front/src/Components/Menu/AboutRoomSubMenu.svelte @@ -0,0 +1,147 @@ + + +
+ +
+

Share the link of the room !

+ +
+

Information on the map

+
+

{mapName}

+

{mapDescription}

+

expandedMapCopyright = !expandedMapCopyright}>Copyrights of the map

+ +

expandedTilesetCopyright = !expandedTilesetCopyright}>Copyrights of the tilesets

+ +
+
+ + + \ No newline at end of file diff --git a/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte b/front/src/Components/Menu/AudioGlobalMessage.svelte similarity index 81% rename from front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte rename to front/src/Components/Menu/AudioGlobalMessage.svelte index 91f462c8..1704e732 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte +++ b/front/src/Components/Menu/AudioGlobalMessage.svelte @@ -1,20 +1,15 @@ @@ -105,24 +94,17 @@ img { flex: 1 1 auto; - max-height: 80%; margin-bottom: 20px; } - p { - flex: 1 1 auto; - margin-bottom: 5px; - color: whitesmoke; font-size: 1rem; - &.err { color: #ce372b; } } - input { display: none; } diff --git a/front/src/Components/Menu/ContactSubMenu.svelte b/front/src/Components/Menu/ContactSubMenu.svelte new file mode 100644 index 00000000..6cca0609 --- /dev/null +++ b/front/src/Components/Menu/ContactSubMenu.svelte @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/front/src/Components/Menu/CreateMapSubMenu.svelte b/front/src/Components/Menu/CreateMapSubMenu.svelte new file mode 100644 index 00000000..6cce71ac --- /dev/null +++ b/front/src/Components/Menu/CreateMapSubMenu.svelte @@ -0,0 +1,51 @@ + + +
+
+
+

Getting started

+

+ WorkAdventure allows you to create an online space to communicate spontaneously with others. + And it all starts with creating your own space. Choose from a large selection of prefabricated maps by our team. +

+ +
+
+

Create your map

+

You can also create your own custom map by following the step of the documentation.

+ +
+
+
+ + \ No newline at end of file diff --git a/front/src/Components/Menu/CustomSubMenu.svelte b/front/src/Components/Menu/CustomSubMenu.svelte new file mode 100644 index 00000000..f85499c3 --- /dev/null +++ b/front/src/Components/Menu/CustomSubMenu.svelte @@ -0,0 +1,33 @@ + + + + + + \ No newline at end of file diff --git a/front/src/Components/Menu/GlobalMessagesSubMenu.svelte b/front/src/Components/Menu/GlobalMessagesSubMenu.svelte new file mode 100644 index 00000000..8ec66de9 --- /dev/null +++ b/front/src/Components/Menu/GlobalMessagesSubMenu.svelte @@ -0,0 +1,118 @@ + + +
+
+
+ +
+
+ +
+
+
+ {#if inputSendTextActive} + + {/if} + {#if uploadAudioActive} + + {/if} +
+ +
+ + + + + \ No newline at end of file diff --git a/front/src/Components/Menu/Menu.svelte b/front/src/Components/Menu/Menu.svelte new file mode 100644 index 00000000..6cbef9c1 --- /dev/null +++ b/front/src/Components/Menu/Menu.svelte @@ -0,0 +1,181 @@ + + + + + + + + \ No newline at end of file diff --git a/front/src/Components/Menu/MenuIcon.svelte b/front/src/Components/Menu/MenuIcon.svelte index 241bf45f..92a52ba3 100644 --- a/front/src/Components/Menu/MenuIcon.svelte +++ b/front/src/Components/Menu/MenuIcon.svelte @@ -1,33 +1,40 @@ + +
-
- -
+ open menu
diff --git a/front/src/Components/Menu/ProfileSubMenu.svelte b/front/src/Components/Menu/ProfileSubMenu.svelte new file mode 100644 index 00000000..83ec329c --- /dev/null +++ b/front/src/Components/Menu/ProfileSubMenu.svelte @@ -0,0 +1,109 @@ + + +
+ {#if $userIsConnected} +
+ {#if PROFILE_URL != undefined} + + {/if} +
+
+ +
+ {:else} +
+ Sign in +
+ {/if} +
+ + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/front/src/Components/Menu/SettingsSubMenu.svelte b/front/src/Components/Menu/SettingsSubMenu.svelte new file mode 100644 index 00000000..38544639 --- /dev/null +++ b/front/src/Components/Menu/SettingsSubMenu.svelte @@ -0,0 +1,142 @@ + + +
+
+

Game quality

+
+ +
+
+
+

Video quality

+
+ +
+
+
+

(Saving these settings will restart the game)

+ +
+
+ + +
+
+ + \ No newline at end of file diff --git a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte b/front/src/Components/Menu/TextGlobalMessage.svelte similarity index 69% rename from front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte rename to front/src/Components/Menu/TextGlobalMessage.svelte index 7baa8226..1749ba7d 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte +++ b/front/src/Components/Menu/TextGlobalMessage.svelte @@ -1,8 +1,7 @@
-
+
diff --git a/front/src/Components/MyCamera.svelte b/front/src/Components/MyCamera.svelte index ed4154a9..67826859 100644 --- a/front/src/Components/MyCamera.svelte +++ b/front/src/Components/MyCamera.svelte @@ -1,27 +1,11 @@
-
- {#if $localStreamStore.type === "success" && $localStreamStore.stream } - +
+ {#if $localStreamStore.type === "success" && $localStreamStore.stream} + {/if}
+
+ Silent zone +
diff --git a/front/src/Components/ReportMenu/BlockSubMenu.svelte b/front/src/Components/ReportMenu/BlockSubMenu.svelte new file mode 100644 index 00000000..0ec04abc --- /dev/null +++ b/front/src/Components/ReportMenu/BlockSubMenu.svelte @@ -0,0 +1,44 @@ + + +
+

Block

+

Block any communication from and to {userName}. This can be reverted.

+ +
+ + + \ No newline at end of file diff --git a/front/src/Components/ReportMenu/ReportMenu.svelte b/front/src/Components/ReportMenu/ReportMenu.svelte new file mode 100644 index 00000000..7594b1c9 --- /dev/null +++ b/front/src/Components/ReportMenu/ReportMenu.svelte @@ -0,0 +1,141 @@ + + + + +
+
+

Moderate {userName}

+
+ +
+
+
+
+ +
+
+ +
+
+
+ {#if blockActive} + + {:else if reportActive} + + {:else } +

ERROR : There is no action selected.

+ {/if} +
+
+ + \ No newline at end of file diff --git a/front/src/Components/ReportMenu/ReportSubMenu.svelte b/front/src/Components/ReportMenu/ReportSubMenu.svelte new file mode 100644 index 00000000..45167cc0 --- /dev/null +++ b/front/src/Components/ReportMenu/ReportSubMenu.svelte @@ -0,0 +1,55 @@ + + +
+

Report

+

Send a report message to the administrators of this room. They may later ban this user.

+
+
+ + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/front/src/Components/Video/PresentationLayout.svelte b/front/src/Components/Video/PresentationLayout.svelte index f68dd2f1..65a229f4 100644 --- a/front/src/Components/Video/PresentationLayout.svelte +++ b/front/src/Components/Video/PresentationLayout.svelte @@ -12,7 +12,9 @@
{#if $videoFocusStore } - + {#key $videoFocusStore.uniqueId} + + {/key} {/if}