The ClientApi object is used for interacting with everything related to the Dragonroll client. It is passed to the `Main` function at the entrypoint defined in the [plugin.json](/plugin/plugin.json) file
### createView
Creates a [ClientView](#clientview) object from a Vue view defined inside the `client/views` folder
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``path`` | String | yes | The path relative from `client/views` to the Vue view without the `.vue` extension |
### Returns
| Type | Description |
| ---- | ----------- |
| [ClientView](#clientview) | The new created view |
#### Example
```js
// Supposing that we have /your-plugin-root/client/views/Calculator.vue
let calculatorView = Api.createView('Calculator');
```
### createModule
Creates a [ClientModule](#clientmodule). The module needs to be later registered with the [registerModule](#registermodule) method to be loaded by Dragonroll. See [creating a module]()
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``id`` | String | yes | The identifier of the new module |
#### Returns
| Type | Description |
| ---- | ----------- |
| [ClientModule](#clientmodule) | The new ClientModule |
This method instances a new window from an already registered one. You can also pass custom parameters inside this method and then read them from your view.
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``type`` | String ([WindowType]()) | yes | The type of the new window |
| ``data`` | Object ([WindowData]()) | no | Aditional data for the created window |
#### Example
```js
let databaseWindow = Api.registerWindow('database', Api.createView('Database'));
// Opens the database window
Api.createWindow(databaseWindow, {
id: 'my-database-window',
title: "My Database",
custom: [
{
data: "This is custom data"
}
]
})
```
### clearWindow
Clears the window with the specified id
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``id`` | String | yes | The id of the window to clear |
#### Example
```js
Api.createWindow(databaseWindow, {
id: 'my-database-window',
title: "My Database",
close: () => {
// When the close button is pressed, clear the window
Api.clearWindow('my-database-window');
}
})
```
### registerModule
Registers an already created [module](#clientmodule) to Dragonroll
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``module`` | [ClientModule](#clientmodule) | yes | The module to register |
#### Example
```js
let dndModule = Api.createModule('dnd-5e');
...
api.registerModule(dndModule);
```
### registerWindow
Registers a new window to Dragonroll and returns the registered id
#### Parameters
| Property | Type | Required | Description |
| -------- | ---- | -------- | ----------- |
| ``name`` | String | yes | The name of the new window |
| ``view`` | [ClientView](#clientview) | yes | The view that contains the window |
#### Returns
| Type | Description |
| ---- | ----------- |
| String ([WindowType](#windowpath)) | The registered type of window |
#### Example
```js
let databaseWindow = Api.registerWindow('database', Api.createView('Database'));
Gets the [ClientRouter](#clientrouter) associated with that module. The paths of this router can be easily catched by the same BackendRouter associated with the module with the same id.
#### Returns
| Type | Description |
| ---- | ----------- |
| [ClientRouter](#clientrouter) | The router associated with the module |
### socket
Gets the [ClientSocket](#clientsocket) object associated with the Module.
#### Returns
| Type | Description |
| ---- | ----------- |
| [ClientSocket](#clientsocket) | The module socket |
### baseSocket
Gets the [ClientSocket](#clientsocket) pointing to the root of the application. Use it only for calling internal socket.io events of Dragonroll.
#### Returns
| Type | Description |
| ---- | ----------- |
| [ClientSocket](#clientsocket) | The socket object |
The `ClientRouter` class is used to make http requests between the Dragonroll client and the Dragonroll backend. To make the routing process easier, Dragonroll provides different instances of the `ClientRouter` class depending on the context. For example, you can have a ClientRouter for registering routes for an specific module inside your plugin, and another for registering more general routes that you may want to create within the backend part of your plugin. It is also possible to make http requests
to the internal Dragonroll routes using the `baseRouter`