-
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.
Also renames oink to @bsdavidson/oink to avoid an npm conflict. KT-15 #done KT-21 #done
- Loading branch information
1 parent
9e82695
commit 0f5b311
Showing
18 changed files
with
225 additions
and
3,456 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/.vscode | ||
/.nyc_output | ||
/coverage | ||
/lib | ||
/node_modules | ||
.vscode | ||
node_modules | ||
yarn-error.log | ||
/coverage | ||
/.nyc_output | ||
yarn.lock |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Brian Davidson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,82 @@ | ||
# Oink | ||
|
||
[![Build Status](https://travis-ci.org/bsdavidson/oink.svg?branch=master)](https://travis-ci.org/bsdavidson/oink) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/bsdavidson/oink/blob/master/LICENSE) | ||
|
||
Oink is a Node library for controlling Onkyo receivers. This was inspired by the | ||
Python [onkyo-eiscp] library. Oink also makes use of a customized version of | ||
onkyo-eiscp's YAML file for code generation. | ||
|
||
Oink provides: | ||
|
||
- A device class to communicate with receivers, and the ability to automatically | ||
discover receivers on a local network. | ||
- An HTTP handler to provide a REST API to communicate with a device. | ||
- A generated module of [helper functions] to make it easier | ||
to send commands to a device. | ||
|
||
[onkyo-eiscp]: https://github.com/miracle2k/onkyo-eiscp | ||
[helper functions]: https://github.com/bsdavidson/oink/tree/master/src/commands | ||
|
||
## Installation | ||
|
||
```bash | ||
yarn add @bsdavidson/oink | ||
``` | ||
|
||
## Example | ||
|
||
```javascript | ||
const http = require("http"); | ||
const {createDeviceHandler, discover} = require("oink"); | ||
|
||
async function main() { | ||
// Oink's discover method will search for devices on the network and return | ||
// an array of DiscoveredDevice objects. | ||
let discovered; | ||
do { | ||
discovered = await discover({deviceLimit: 1}); | ||
} while (!discovered.length); | ||
|
||
// If you already know the host and port of your reciever, | ||
// you can call new Device() to create a Device instance | ||
// manually, rather than use discovery. For example: | ||
// | ||
// const device = new Device("10.0.0.120", 60128, "1"); | ||
// | ||
// But in this case, since we used discovery, you can call toDevice() on a | ||
// DiscoveredDevice instance to create a Device instance that can be used to | ||
// communicate with the receiver. | ||
const device = discovered[0].toDevice(); | ||
|
||
// Device instances emit a data event for packets from the receiver. | ||
// Each incoming packet is a Packet instance containing the | ||
// command (e.g. PWR, MVL, ...), a parameter (e.g. "01", "somestring", ...), | ||
// and the device type (typically "1") | ||
device.on("data", packet => { | ||
console.log(packet); | ||
}); | ||
|
||
// Call connect on a device to establish a persistant connection. | ||
await device.connect(); | ||
|
||
// Send a command to a device by creating a command packet and passing it to | ||
// the send() method. | ||
// | ||
// Send an UP command to the Main Volume Level (MVL) | ||
const response = await device.sendCommand("MVL", "UP"); | ||
console.log(response); // Packet { command: 'MVL', parameter: '1F', deviceType: '1' } | ||
|
||
// Oink also provides a way to create a standard HTTP handler which provides a | ||
// simple REST API to send and recieve commands to a device. For example, | ||
// to query the current master volume level (MVL), make a GET request like the | ||
// following: | ||
// | ||
// $ curl http://127.0.0.1:3000/MVL | ||
// {"command":"MVL","parameter":"1F","deviceType":"1"} | ||
http.createServer(createDeviceHandler(device)).listen(3000); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
[Oink.](http://gph.is/1OoF29s) |
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
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,51 @@ | ||
const http = require("http"); | ||
const {createDeviceHandler, discover} = require("@bsdavidson/oink"); | ||
|
||
async function main() { | ||
// Oink's discover method will search for devices on the network and return | ||
// an array of DiscoveredDevice objects. | ||
let discovered; | ||
do { | ||
discovered = await discover({deviceLimit: 1}); | ||
} while (!discovered.length); | ||
|
||
// If you already know the host and port of your reciever, | ||
// you can call new Device() to create a Device instance | ||
// manually, rather than use discovery. For example: | ||
// | ||
// const device = new Device("10.0.0.120", 60128, "1"); | ||
// | ||
// But in this case, since we used discovery, you can call toDevice() on a | ||
// DiscoveredDevice instance to create a Device instance that can be used to | ||
// communicate with the receiver. | ||
const device = discovered[0].toDevice(); | ||
|
||
// Device instances emit a data event for packets from the receiver. | ||
// Each incoming packet is a Packet instance containing the | ||
// command (e.g. PWR, MVL, ...), a parameter (e.g. "01", "somestring", ...), | ||
// and the device type (typically "1") | ||
device.on("data", packet => { | ||
console.log(packet); | ||
}); | ||
|
||
// Call connect on a device to establish a persistant connection. | ||
await device.connect(); | ||
|
||
// Send a command to a device by creating a command packet and passing it to | ||
// the send() method. | ||
// | ||
// Send an UP command to the Main Volume Level (MVL) | ||
const response = await device.sendCommand("MVL", "UP"); | ||
console.log(response); // Packet { command: 'MVL', parameter: '1F', deviceType: '1' } | ||
|
||
// Oink also provides a way to create a standard HTTP handler which provides a | ||
// simple REST API to send and recieve commands to a device. For example, | ||
// to query the current master volume level (MVL), make a GET request like the | ||
// following: | ||
// | ||
// $ curl http://127.0.0.1:3000/MVL | ||
// {"command":"MVL","parameter":"1F","deviceType":"1"} | ||
http.createServer(createDeviceHandler(device)).listen(3000); | ||
} | ||
|
||
main(); |
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,10 @@ | ||
{ | ||
"name": "oink-example", | ||
"version": "1.0.0", | ||
"description": "An example app using Oink", | ||
"main": "main.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@bsdavidson/oink": "^0.0.0" | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export {Packet} from "./protocol"; | ||
export {createDeviceHandler} from "./api"; | ||
export {Device, discover, DiscoveredDevice} from "./device"; | ||
export {Packet} from "./protocol"; | ||
|
||
import * as commands from "./commands"; | ||
export {commands}; |
Oops, something went wrong.