Skip to content

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

sh
npm i @nhtio/adonis-rtu-server
sh
pnpm add @nhtio/adonis-rtu-server
sh
yarn add @nhtio/adonis-rtu-server

Configuration

Use the Adonis built-in configuration utility to automatically create the relevant configuration files:

shell
node ace configure @nhtio/adonis-rtu-server

It will create the following files:

FileUsage
config/adonis_rtu_policy.tsDefine the function which checks if a user can read information about a model instance
config/adonis_rtu_server.tsDefine 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

typescript
import rtu from '@nhtio/adonis-rtu-server/services/main'
typescript
import { main as rtu } from '@nhtio/adonis-rtu-server/services'

2. As an Attribute of the Application

typescript
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

typescript
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:trace
  • rtu:debug
  • rtu:info
  • rtu:warn
  • rtu:error
  • rtu:fatal