Quickstart
Getting started with Adonis RTU Server is quick and easy. Just follow the steps below and you'll be up and running in no time.
Installation
You can install @nhtio/adonis-rtu-server directly from your preferred package manager
npm i @nhtio/adonis-rtu-serverpnpm add @nhtio/adonis-rtu-serveryarn add @nhtio/adonis-rtu-serverConfiguration
Use the Adonis built-in configuration utility to automatically create the relevant configuration files:
node ace configure @nhtio/adonis-rtu-serverIt will create the following files:
| File | Usage |
|---|---|
config/adonis_rtu_policy.ts | Define the function which checks if a user can read information about a model instance |
config/adonis_rtu_server.ts | Define the configuration for the underlying socket.io server |
Usage
Update the config/adonis_rtu_policy.ts file to match your desired functionality. Then you can just run your application and the plugin handles the rest "auto-magically".
Advanced Usage
The plugin binds an instance of the RTUInterface to the Adonis IoC Container under the name rtu. You can access it through one of the following methods:
1. As an importable service
import rtu from '@nhtio/adonis-rtu-server/services/main'import { main as rtu } from '@nhtio/adonis-rtu-server/services'2. As an Attribute of the Application
import { default as app } from "@adonisjs/core/services/app";
app.rtu // the Adonis RTU Interface instance is accessible as `app.rtu`3. Using Container Services
import { default as app } from "@adonisjs/core/services/app";
// Resolve the Adonis RTU Interface instance from the IoC container
const rtu = await app.container.make('rtu');Debugging
The Adonis RTU Server plugin will automatically hook into the applications Logger. Additionally, you can also use the DEBUG environmental variable with the rtu prefix to have debug information output to the console independantly of the Adonis logger. The following namepaces are available:
rtu:tracertu:debugrtu:infortu:warnrtu:errorrtu:fatal