<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [ExpressEnvironment](#expressenvironment)
-   [CommandStdoutDetector](#commandstdoutdetector)
-   [RequestDetector](#requestdetector)
-   [Start](#start)
-   [Reset](#reset)

## ExpressEnvironment

**Extends ext.SystemEnvironment**

Wraps an Express web-server, which will allow viewing all the Motion Detectors and
Notifiers in the system. See more in
<https://expressjs.com/en/api.html>
Acts like a Singleton, in the sense that the wrapped express app is a single instance

**Parameters**

-   `port` **integer** is the port of the web-app, if not provided, will default to 8080.
-   `static_addr` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** , is the relative URL of the static resources, it defaults to the 
    module's internal public folder
-   `command`   (optional, default `"pwd"`)
-   `interval`   (optional, default `10000`)
-   `maxAttempts`   (optional, default `10`)

**Examples**

```javascript
let web = require("t-motion-detector-cli");
let config = new web._.Config('./config.js');
web._.StartWithConfig(config, (e,d,n,f)=>{
console.log("Good to go!");
});
//Example of a config file which creates the routes necessary

profiles = {
default: {
ExpressEnvironment: {
port: 8777
},
RequestDetector: [{
name: "My Detectors Route",
route: "/config/detectors",
callback: "GetMotionDetectors"
},
{
name: "My Notifiers Route",
route: "/config/notifiers",
callback: "GetNotifiers"
},
{
name: "Activate route",
route: "/config/detector/activate",
callback: "ActivateDetector;name",
verb: "POST"
},
{
name: "Deactivate route",
route: "/config/detector/deactivate",
callback: "DeactivateDetector;name",
verb: "POST"
}]
}
}
exports.profiles = profiles;
exports.default = profiles.default;
```

## CommandStdoutDetector

**Extends ent.MotionDetector**

A Detector which takes a line command and will send a change if detects the pattern given on stdout

**Parameters**

-   `name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** is a friendly name for reference for this route, will be the detector name.
-   `command` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** will be executed by the command line
-   `args` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** is an array of arguments for the command to execute (optional, default `[]`)
-   `pattern` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** is a pattern which the detector will attempt to find in the log (optional, default `""`)

## RequestDetector

**Extends ent.MotionDetector**

A Web Request Detector which implements an URL route to some known available serve-moethod.

**Parameters**

-   `name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** is a friendly name for reference for this route, will be the detector name.
-   `route` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** an URL route
-   `handler` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** is the name of the method / function to call when this route is used, the function's return contents are displayed as a Web Response.
-   `verb` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** is the HTTP Verb to be used, if ommited defaults to "GET". (optional, default `"GET"`)

**Examples**

```javascript
new RequestDetector("Get Notifiers route", "/config/notifiers", "GetNotifiers");
//GET route which calls the GetNotifiers function
new RequestDetector("Deactivate Detectors route", "/config/detectors/deactivate", "DeactivateDetector;name", "POST");
//POST request route. in this case expects in the query string a "name" argument which should refer the name of the detector to deactivate e.g.
///config/detectors/deactivate?name=MyDetectorToDeactivate
```

## Start

Called when t-motion-detector is started. Called when StartWithConfig is called.
Adds default detector routes needed for the t-motion-detector-cli web-app

Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True the plugin was successfully added.

## Reset

Called when t-motion-detector is reset. Called when Reset is called.
Emits also a "reset" event which can be used for performing additional tasks

Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True the plugin was successfully added.
