diff --git a/docs/maps/api-chat.md b/docs/maps/api-chat.md new file mode 100644 index 00000000..49a40f97 --- /dev/null +++ b/docs/maps/api-chat.md @@ -0,0 +1,37 @@ +{.section-title.accent.text-primary} +# API Chat functions reference + +### Sending a message in the chat + +``` +WA.chat.sendChatMessage(message: string, author: string): void +``` + +Sends a message in the chat. The message is only visible in the browser of the current user. + +* **message**: the message to be displayed in the chat +* **author**: the name displayed for the author of the message. It does not have to be a real user. + +Example: + +```javascript +WA.chat.sendChatMessage('Hello world', 'Mr Robot'); +``` + +### Listening to messages from the chat + +```javascript +WA.chat.onChatMessage(callback: (message: string) => void): void +``` + +Listens to messages typed by the current user and calls the callback. Messages from other users in the chat cannot be listened to. + +* **callback**: the function that will be called when a message is received. It contains the message typed by the user. + +Example: + +```javascript +WA.chat.onChatMessage((message => { + console.log('The user typed a message', message); +})); +``` diff --git a/docs/maps/api-nav.md b/docs/maps/api-nav.md new file mode 100644 index 00000000..29323632 --- /dev/null +++ b/docs/maps/api-nav.md @@ -0,0 +1,68 @@ +{.section-title.accent.text-primary} +# API Navigation functions reference + +### Opening a web page in a new tab + +``` +WA.nav.openTab(url: string): void +``` + +Opens the webpage at "url" in your browser, in a new tab. + +Example: + +```javascript +WA.nav.openTab('https://www.wikipedia.org/'); +``` + +### Opening a web page in the current tab + +``` +WA.nav.goToPage(url: string): void +``` + +Opens the webpage at "url" in your browser in place of WorkAdventure. WorkAdventure will be completely unloaded. + +Example: + +```javascript +WA.nav.goToPage('https://www.wikipedia.org/'); +``` + +### Going to a different map from the script + +``` + +WA.nav.goToRoom(url: string): void +``` + +Load the map at url without unloading workadventure + +relative urls: "../subFolder/map.json[#start-layer-name]" +global urls: "/_/global/domain/path/map.json[#start-layer-name]" + +Example: + +```javascript +WA.nav.goToRoom("/@/tcm/workadventure/floor0") // workadventure urls +WA.nav.goToRoom('../otherMap/map.json'); +WA.nav.goToRoom("/_/global/.json#start-layer-2") +``` + +### Opening/closing a web page in an iFrame + +``` +WA.nav.openCoWebSite(url: string): void +WA.nav.closeCoWebSite(): void +``` + +Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. + +Example: + +```javascript +WA.nav.openCoWebSite('https://www.wikipedia.org/'); +// ... +WA.nav.closeCoWebSite(); +``` + diff --git a/docs/maps/api-reference.md b/docs/maps/api-reference.md index b9525d3c..2c73e6a9 100644 --- a/docs/maps/api-reference.md +++ b/docs/maps/api-reference.md @@ -1,40 +1,8 @@ {.section-title.accent.text-primary} # API Reference -### Sending a message in the chat - -``` -sendChatMessage(message: string, author: string): void -``` - -Sends a message in the chat. The message is only visible in the browser of the current user. - -* **message**: the message to be displayed in the chat -* **author**: the name displayed for the author of the message. It does not have to be a real user. - -Example: - -```javascript -WA.sendChatMessage('Hello world', 'Mr Robot'); -``` - -### Listening to messages from the chat - -```javascript -onChatMessage(callback: (message: string) => void): void -``` - -Listens to messages typed by the current user and calls the callback. Messages from other users in the chat cannot be listened to. - -* **callback**: the function that will be called when a message is received. It contains the message typed by the user. - -Example: - -```javascript -WA.onChatMessage((message => { - console.log('The user typed a message', message); -})); -``` +- [Navigation functions](api-nav.md) +- [Chat functions](api-chat.md) ### Detecting when the user enters/leaves a zone @@ -159,71 +127,6 @@ WA.onEnterZone('myZone', () => { }); ``` -### Opening a web page in a new tab - -``` -openTab(url: string): void -``` - -Opens the webpage at "url" in your browser, in a new tab. - -Example: - -```javascript -WA.openTab('https://www.wikipedia.org/'); -``` - -### Opening a web page in the current tab - -``` -goToPage(url: string): void -``` - -Opens the webpage at "url" in your browser in place of WorkAdventure. WorkAdventure will be completely unloaded. - -Example: - -```javascript -WA.goToPage('https://www.wikipedia.org/'); -``` - -### Going to a different map from the script - -``` - -goToRoom(url: string): void -``` - -Load the map at url without unloading workadventure - -relative urls: "../subFolder/map.json[#start-layer-name]" -global urls: "/_/global/domain/path/map.json[#start-layer-name]" - -Example: - -```javascript -WA.goToRoom("/@/tcm/workadventure/floor0") // workadventure urls -WA.goToRoom('../otherMap/map.json'); -WA.goToRoom("/_/global/.json#start-layer-2") -``` - -### Opening/closing a web page in an iFrame - -``` -openCoWebSite(url: string): void -closeCoWebSite(): void -``` - -Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. - -Example: - -```javascript -WA.openCoWebSite('https://www.wikipedia.org/'); -// ... -WA.closeCoWebSite(); -``` - ### Load a sound from an url ```