summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorUdo Walter2019-04-16 16:10:17 +0200
committerUdo Walter2019-04-16 16:10:17 +0200
commit8c7fc0cd3154b8e6b725db2eba9c37abb092c980 (patch)
treed413f6578deee98ec6388276bf4fb564d8030613 /server
parent[server] add 10ms delay between wol packets (diff)
downloadbas-8c7fc0cd3154b8e6b725db2eba9c37abb092c980.tar.gz
bas-8c7fc0cd3154b8e6b725db2eba9c37abb092c980.tar.xz
bas-8c7fc0cd3154b8e6b725db2eba9c37abb092c980.zip
[wol] move wol stuff to lib
Diffstat (limited to 'server')
-rw-r--r--server/api/wakerequests.js16
-rw-r--r--server/bin/scheduler.js17
-rw-r--r--server/lib/wolhelper.js17
3 files changed, 22 insertions, 28 deletions
diff --git a/server/api/wakerequests.js b/server/api/wakerequests.js
index f619bd9..9791d41 100644
--- a/server/api/wakerequests.js
+++ b/server/api/wakerequests.js
@@ -1,26 +1,14 @@
/* global __appdir */
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
-var wol = require('node-wol')
+const wolHelper = require(path.join(__appdir, 'lib', 'wolhelper'))
var express = require('express')
const { decorateApp } = require('@awaitjs/express')
var router = decorateApp(express.Router())
router.postAsync('', async (req, res) => {
const clients = await db.client.findAll({ where: { id: req.body.clients } })
-
- let i = 0
- const loop = () => {
- setTimeout(() => {
- let client = clients[i]
- console.log('Waking up: ' + client.name + ' (' + client.mac + ')')
- wol.wake(client.mac, { address: client.ip.slice(0, client.ip.lastIndexOf('.') + 1) + '255' }, err => { if (err) console.log(err) })
- i++
- if (i < clients.length) loop()
- }, 10)
- }
- loop()
-
+ wolHelper.wakeUp(clients)
res.status(200).end()
})
diff --git a/server/bin/scheduler.js b/server/bin/scheduler.js
index 26774d6..ddb96d8 100644
--- a/server/bin/scheduler.js
+++ b/server/bin/scheduler.js
@@ -3,7 +3,7 @@ const path = require('path')
global.__appdir = path.join(__dirname, '..')
const db = require(path.join(__appdir, 'lib', 'sequelize'))
const groupHelper = require(path.join(__appdir, 'lib', 'grouphelper'))
-const wol = require('node-wol')
+const wolHelper = require(path.join(__appdir, 'lib', 'wolhelper'))
const zmq = require('zeromq')
const socket = zmq.socket('pull')
socket.bindSync('ipc:///tmp/bas_zeromq_events')
@@ -72,18 +72,7 @@ async function wakeUpClients (id) {
}
var childs = await groupHelper.getAllChildren(groups, blacklistGroups, blacklistClients)
clients = clients.concat(childs.clients)
- console.log(clients.length)
- // 2. Wake all clients
- let i = 0
- const loop = () => {
- setTimeout(() => {
- let client = clients[i]
- console.log('Waking up: ' + client.name + ' (' + client.mac + ')')
- wol.wake(client.mac, { address: client.ip.slice(0, client.ip.lastIndexOf('.') + 1) + '255' }, err => { if (err) console.log(err) })
- i++
- if (i < clients.length) loop()
- }, 10)
- }
- loop()
+ // 2. Wake all clients
+ wolHelper.wakeUp(clients)
}
diff --git a/server/lib/wolhelper.js b/server/lib/wolhelper.js
new file mode 100644
index 0000000..fb5bd95
--- /dev/null
+++ b/server/lib/wolhelper.js
@@ -0,0 +1,17 @@
+const wol = require('node-wol')
+
+function wakeUp (clients) {
+ let i = 0
+ const loop = () => {
+ setTimeout(() => {
+ let client = clients[i]
+ console.log('Waking up: ' + client.name + ' (' + client.mac + ')')
+ wol.wake(client.mac, { address: client.ip.slice(0, client.ip.lastIndexOf('.') + 1) + '255' }, err => { if (err) console.log(err) })
+ i++
+ if (i < clients.length) loop()
+ }, 10)
+ }
+ loop()
+}
+
+module.exports = { wakeUp } \ No newline at end of file