summaryrefslogtreecommitdiffstats
path: root/server/lib/wolhelper.js
blob: 97c0958f048e63f823bf908a6b79056fcb2cfe44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const wol = require('node-wol')

function wakeUp (clients) {
  let i = 0
  const loop = () => {
    setTimeout(() => {
      let client = clients[i]
      if (client.mac !== null && client.ip !== null) {
        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)
  }
  if (clients.length !== 0) loop()
}

module.exports = { wakeUp }