51 lines
1.2 KiB
Markdown
51 lines
1.2 KiB
Markdown
|
# Plugins
|
||
|
Here is a brief specification of the plugin module itself.
|
||
|
All loadable plugin modules need to have an `init` method.
|
||
|
|
||
|
## Backend
|
||
|
Backend modules get two initialization parameters: `logger` and `LMathPluginAPI`.
|
||
|
Feel free to use these in any way you want. Below you'll find a simple example.
|
||
|
|
||
|
```js
|
||
|
let logger, api;
|
||
|
|
||
|
module.exports = {
|
||
|
init: (_logger, _api) => {
|
||
|
|
||
|
logger = _logger;
|
||
|
api = _api;
|
||
|
|
||
|
logger.info('Hewwo! It is me, the new plugin!');
|
||
|
|
||
|
api.messages.on('testMessage', (d) => {
|
||
|
logger.info('Someone sent me a message! ' + d);
|
||
|
});
|
||
|
|
||
|
}
|
||
|
};
|
||
|
```
|
||
|
|
||
|
## Frontend
|
||
|
Frontend modules also get two parameters: `window` (the actual window object) and `LMathPluginAPI` (frontend).
|
||
|
jQuery and other useful things can be found like presented below.
|
||
|
|
||
|
```js
|
||
|
let window, api, $, jQuery;
|
||
|
|
||
|
module.exports = {
|
||
|
init: (_window, _api) => {
|
||
|
|
||
|
window = _window;
|
||
|
api = _api;
|
||
|
|
||
|
$ = window.jQuery;
|
||
|
jQuery = window.jQuery;
|
||
|
|
||
|
console.log('Hewwo wowld! This is the frontend side!');
|
||
|
|
||
|
setInterval(() => api.messages.send('testMessage', Date.now()), 2000);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
```
|