Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdadams committed Dec 27, 2024
1 parent 596bcfe commit aef63a6
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 532 deletions.
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,8 +24,9 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. MacOS, Windows]
- Version [e.g. 22]

- OS: [e.g. MacOS, Windows]
- Version [e.g. 22]

** Beacon devices in use:**
blink(1), luxafor-flag, etc.
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: 'Feature Request: '
labels: enhancement
assignees: josephdadams

---

**Is your feature request related to a problem? Please describe.**
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"printWidth": 120,
"semi": false,
"singleQuote": true,
"useTabs": true,
"endOfLine": "lf"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Built with [Electron](https://electronjs.org).
```
$ npm install
$ npm start
```
```
122 changes: 61 additions & 61 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
const express = require('express');
const http = require('http');
const socketio = require('socket.io');
const express = require('express')
const http = require('http')
const socketio = require('socket.io')

const util = require('./util.js');
const config = require('./config.js');
const util = require('./util.js')
const config = require('./config.js')

const package_json = require('./package.json');
const VERSION = package_json.version;
const package_json = require('./package.json')
const VERSION = package_json.version

var server = null;
var httpServer = null;
var io = null;
var server = null
var httpServer = null
var io = null

class API {
static start(port) {
//starts the REST API
server = express();
server = express()

httpServer = new http.Server(server);
io = new socketio.Server(httpServer, { allowEIO3: true });
httpServer = new http.Server(server)
io = new socketio.Server(httpServer, { allowEIO3: true })

server.use(express.json()); //parse json in body
server.use(express.json()) //parse json in body

server.get('/version', function (req, res) {
res.send({version: VERSION});
});
res.send({ version: VERSION })
})

server.get('/control_status', function (req, res) {
res.send({control_status: config.get('allowControl')});
});
res.send({ control_status: config.get('allowControl') })
})

server.get('/devices', function (req, res) {
res.send({devices: util.getDevices()});
});
res.send({ devices: util.getDevices() })
})

server.get('/colors', function (req, res) {
res.send({colors: util.getColors()});
});
res.send({ colors: util.getColors() })
})

server.get('/sounds', function (req, res) {
res.send({sounds: util.getSounds()});
});
res.send({ sounds: util.getSounds() })
})

server.post('/beacon', function (req, res) {
let beaconObj = req.body;
let beaconObj = req.body
if (beaconObj) {
util.showNotification(beaconObj);
util.engageBeacon(beaconObj);
util.playSound(beaconObj);
util.showNotification(beaconObj)
util.engageBeacon(beaconObj)
util.playSound(beaconObj)
}

res.send({control_status: config.get('allowControl')});
});
res.send({ control_status: config.get('allowControl') })
})

server.use(function (req, res) {
res.status(404).send({error: true, url: req.originalUrl + ' not found.'});
});
res.status(404).send({ error: true, url: req.originalUrl + ' not found.' })
})

io.sockets.on('connection', (socket) => {
let ipAddr = socket.handshake.address;
socket.emit('control_status', config.get('allowControl'));
let ipAddr = socket.handshake.address
socket.emit('control_status', config.get('allowControl'))

socket.on('version', function() {
socket.emit('version', VERSION);
});
socket.on('version', function () {
socket.emit('version', VERSION)
})

socket.on('control_status', function() {
socket.emit('control_status', config.get('allowControl'));
});
socket.on('control_status', function () {
socket.emit('control_status', config.get('allowControl'))
})

socket.on('devices', function() {
socket.emit('devices', util.getDevices());
});
socket.on('devices', function () {
socket.emit('devices', util.getDevices())
})

socket.on('colors', function() {
socket.emit('colors', util.getColors());
});
socket.on('colors', function () {
socket.emit('colors', util.getColors())
})

socket.on('sounds', function() {
socket.emit('sounds', util.getSounds());
});
socket.on('sounds', function () {
socket.emit('sounds', util.getSounds())
})

socket.on('beacon', function(beaconObj) {
socket.on('beacon', function (beaconObj) {
if (beaconObj) {
util.showNotification(beaconObj);
util.engageBeacon(beaconObj);
util.playSound(beaconObj);
util.showNotification(beaconObj)
util.engageBeacon(beaconObj)
util.playSound(beaconObj)
}
});
});
})
})

httpServer.listen(port);
console.log('REST/Socket.io API server started on: ' + port);
httpServer.listen(port)
console.log('REST/Socket.io API server started on: ' + port)

util.startUp();
util.startUp()
}

static sendControlStatus() {
io.sockets.emit('control_status', config.get('allowControl'));
io.sockets.emit('control_status', config.get('allowControl'))
}
}

module.exports = API;
module.exports = API
23 changes: 20 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
beacon has both a REST-based API as well as a socket.io API. Both run on Port `8802`.

## REST API

It is possible to disable remote control within the context menu of the beacon application. If this is done, you will receive this response when using the REST API:

```javascript
{ control_status: false }
{
control_status: false
}
```

## socket.io API
Expand All @@ -15,30 +19,39 @@ Upon connection, the server will emit the `control_status` event to let the clie
## Available Methods

### REST: `/version`: GET

### socket.io: 'version'

Returns the version of beacon currently running.

```javascript
{version: 0.1.0}
```

### REST: `/control_status`: GET

### socket.io: 'control_status'

Returns whether remote control is currently enabled or not in beacon

```javascript
{control_status: true}
{
control_status: true
}
```

### REST: `/devices`: GET

### socket.io: 'devices'

Returns a list of devices/beacons available.

### REST: `/colors`: GET

### socket.io: 'colors'

Returns a list of available colors that beacon can use.

```javascript
{ id: 'red', label: 'Red', r: 255, g: 0, b: 0 },
{ id: 'green', label: 'Green', r: 0, g: 255, b: 0 },
Expand All @@ -51,19 +64,23 @@ Returns a list of available colors that beacon can use.
```

### REST: `/sounds`: GET

### socket.io: 'sounds'

Returns a list of available sounds/tones that beacon can use.

```javascript
{ id: 'single', label: '*' },
{ id: 'triple', label: '* * *' },
{ id: 'hey', label: 'Hey' },
```

### REST: `/beacon`: POST

### socket.io: 'beacon'

Send a beacon object via `application/json` in a POST request to control beacon.

```javascript
{
device: `deviceId` or 'all',
Expand All @@ -80,4 +97,4 @@ Send a beacon object via `application/json` in a POST request to control beacon.

### socket.io: `error`:

Emitted whenever there is an error. Contains the error message as a string.
Emitted whenever there is an error. Contains the error message as a string.
10 changes: 5 additions & 5 deletions config.js

Large diffs are not rendered by default.

Loading

0 comments on commit aef63a6

Please sign in to comment.