/* global __appdir */ var path = require('path') const log = require(path.join(__appdir, 'lib', 'log')) const wol = require('node-wol') function wakeUp (clients) { let i = 0 const loop = () => { setTimeout(() => { let client = clients[i] // Regex for mac address const regex = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/ if (client.mac !== null && client.ip !== null && regex.test(client.mac)) { 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) }) log({ category: 'WAKE_ON_LAN', description: 'Wake on Lan signal sent to client.', client, clientId: client.id }) } else { log({ category: 'ERROR_WAKE_ON_LAN', description: 'Client has an invalid ip or mac address.', client, clientId: client.id }) } i++ if (i < clients.length) loop() }, 10) } if (clients.length !== 0) loop() } module.exports = { wakeUp }