Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdadams committed Dec 28, 2024
1 parent f8bfae3 commit e7d22be
Show file tree
Hide file tree
Showing 18 changed files with 2,398 additions and 2,325 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]

**Additional context**
Add any other context about the problem here.
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
189 changes: 94 additions & 95 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,161 +1,160 @@
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 notifications = require('./notifications.js');
const path = require('path');
const util = require('./util.js')
const config = require('./config.js')
const notifications = require('./notifications.js')
const path = require('path')

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.use(express.static(path.join(__dirname, 'static')));
server.use(express.static(path.join(__dirname, 'static')))

server.get('/', function (req, res) {
res.sendFile('index.html', { root: __dirname });
});
res.sendFile('index.html', { root: __dirname })
})

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('/midi_outputs', function (req, res) {
res.send(util.getMIDIOutputs());
});
res.send(util.getMIDIOutputs())
})

server.get('/refresh', function (req, res) {
util.refreshPorts();
res.send({result: 'refresh-command-sent'});
});
util.refreshPorts()
res.send({ result: 'refresh-command-sent' })
})

server.post('/sendmidi', function (req, res) {
let midiObj = req.body;
let midiObj = req.body

util.sendMIDI(midiObj, function(result) {
let commandname = midiObj.midicommand + '-sent-successfully'; //this is just a hack for older versions
res.send({result: commandname});
});
});
util.sendMIDI(midiObj, function (result) {
let commandname = midiObj.midicommand + '-sent-successfully' //this is just a hack for older versions
res.send({ result: commandname })
})
})

server.get('/sendmidi', function (req,res) {
let midiObj = req.query;
server.get('/sendmidi', function (req, res) {
let midiObj = req.query

util.sendMIDI(midiObj, function(result) {
let commandname = midiObj.midicommand + '-sent-successfully'; //this is just a hack for older versions
res.send({result: commandname});
});
});
util.sendMIDI(midiObj, function (result) {
let commandname = midiObj.midicommand + '-sent-successfully' //this is just a hack for older versions
res.send({ result: commandname })
})
})

server.get('/', function (req, res) {
res.redirect('/index.html');
});
res.redirect('/index.html')
})

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('midi_outputs', function() {
socket.emit('midi_outputs', util.getMIDIOutputs());
});
socket.on('midi_outputs', function () {
socket.emit('midi_outputs', util.getMIDIOutputs())
})

socket.on('refresh', function() {
util.refreshPorts();
});
socket.on('refresh', function () {
util.refreshPorts()
})

socket.on('sendmidi', function(midiObj) {
socket.on('sendmidi', function (midiObj) {
if (midiObj) {
util.sendMIDI(midiObj, function(result) {
socket.emit('result', result);
});
util.sendMIDI(midiObj, function (result) {
socket.emit('result', result)
})
}
});
})

socket.on('getMidiInputs', function() {
socket.emit('midi_inputs', util.getMIDIInputs());
});
socket.on('getMidiInputs', function () {
socket.emit('midi_inputs', util.getMIDIInputs())
})

socket.on('getTriggers', function() {
socket.emit('triggers', util.getTriggers());
});
socket.on('getTriggers', function () {
socket.emit('triggers', util.getTriggers())
})

socket.on('getTriggers_download', function() {
socket.emit('triggers_download', util.getTriggers());
});
socket.on('getTriggers_download', function () {
socket.emit('triggers_download', util.getTriggers())
})

socket.on('trigger_add', function(triggerObj) {
socket.on('trigger_add', function (triggerObj) {
if (triggerObj) {
util.addTrigger(triggerObj);
util.addTrigger(triggerObj)
}
});
})

socket.on('trigger_update', function(triggerObj) {
socket.on('trigger_update', function (triggerObj) {
if (triggerObj) {
util.updateTrigger(triggerObj);
util.updateTrigger(triggerObj)
}
});
})

socket.on('trigger_delete', function(triggerObj) {
socket.on('trigger_delete', function (triggerObj) {
if (triggerObj) {
util.deleteTrigger(triggerObj);
util.deleteTrigger(triggerObj)
}
});
});
})
})

try {
httpServer.listen(port);
console.log('REST/Socket.io API server started on: ' + port);
}
catch(error) {
httpServer.listen(port)
console.log('REST/Socket.io API server started on: ' + port)
} catch (error) {
if (error.toString().indexOf('EADDRINUSE') > -1) {
notifications.showNotification({
title: 'Error',
body: 'Unable to start server. is midi-relay already running?',
showNotification: true
});
showNotification: true,
})
}
}
util.startUp();

util.startUp()
}

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

static sendMIDIBack(midiObj) {
io.sockets.emit('midi_back', midiObj);
io.sockets.emit('midi_back', midiObj)
}
}

module.exports = API;
module.exports = API
Loading

0 comments on commit e7d22be

Please sign in to comment.