-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates MotionApi class and related README
- Loading branch information
Showing
6 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Motion API | ||
|
||
This library aims to expose a simplistic API for the https://motion-project.github.io/ project. | ||
|
||
# Installation | ||
|
||
``` | ||
npm i motion-project-api | ||
``` | ||
|
||
# Usage | ||
|
||
Example creating a snapshot with the camera 1. | ||
|
||
```typescript | ||
let motionApi = new MotionApi("http://localhost:7999"); // URL of the motion web server | ||
motionApi.getCamera(1).createSnapshot(); // creates a snapshot for the camera 1 | ||
``` | ||
|
||
## API | ||
|
||
### Class MotionApi | ||
|
||
**MotionApi(apiUrl)** | ||
|
||
+ apiUrl - (_string_) The motion web server url. | ||
|
||
**getCamera(idCamera): Camera** | ||
|
||
+ idCamera - (_number_) The camera number to control. | ||
|
||
Returns an instance of `Camera`. | ||
|
||
### Class Camera | ||
|
||
**Camera(id)** | ||
|
||
+ id - (_number_) The camera number to control. | ||
|
||
**startMotionDetection(): Promise<void>** | ||
|
||
Start or resume motion detection. | ||
|
||
**pauseMotionDetection(): Promise<void>** | ||
|
||
Pause the motion detection. | ||
|
||
**createSnapshot(): Promise<void>** | ||
|
||
Create a snapshot | ||
|
||
**getCurrentStatus(): Promise<MotionDetectionStatus>** | ||
|
||
Return the current status of the camera. `MotionDetectionStatus.ENABLE` is enable or `MotionDetectionStatus.DISABLE` if disabled. | ||
|
||
**getConnectionStatus(): Promise<MotionConnectionStatus>** | ||
|
||
Return the connection status of the camera. `MotionConnectionStatus.OK` if well connected otherwise `MotionConnectionStatus.DISCONNECTED`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {WebControl} from "./WebControl"; | ||
import {Camera} from "./Camera"; | ||
|
||
const _ = require('lodash'); | ||
|
||
export class MotionApi { | ||
|
||
private cameras: Array<Camera> = []; | ||
|
||
/** | ||
* Creates MotionApi object | ||
* @param apiUrl The base url of the HTTP motion server | ||
*/ | ||
constructor(apiUrl: string) { | ||
WebControl.url = apiUrl; | ||
} | ||
|
||
/** | ||
* Returns an unique instance of the camera | ||
* @param idCamera | ||
*/ | ||
public getCamera(idCamera: number): Camera{ | ||
let camera = _.find(this.cameras, function (camera: Camera) { | ||
return camera.id === idCamera; | ||
}); | ||
if (camera !== undefined) { | ||
return camera; | ||
} else { | ||
let newCamera = new Camera(idCamera); | ||
this.cameras.push(newCamera); | ||
return newCamera; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters