node-fauxmo
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "node-fauxmo", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Make fake WeMo devices. Another Node.JS port of fauxmo, borrowing heavily from fauxmojs", | ||
@@ -35,3 +35,6 @@ "main": "src/index.js", | ||
}, | ||
"homepage": "https://github.com/lspiehler/node-fauxmo#readme" | ||
"homepage": "https://github.com/lspiehler/node-fauxmo#readme", | ||
"dependencies": { | ||
"ip": "^1.1.5" | ||
} | ||
} |
@@ -26,3 +26,2 @@ # node-fauxmo | ||
{ | ||
ipAddress: '192.168.1.198', | ||
devices: [{ | ||
@@ -29,0 +28,0 @@ name: 'Fake Device 1', |
@@ -5,2 +5,5 @@ 'use strict'; | ||
const serial = require('./deviceSerial'); | ||
const util = require('util'); | ||
var ip = require('ip'); | ||
const os = require('os'); | ||
@@ -11,3 +14,3 @@ let udpServer; | ||
let response = function() { | ||
let response = function(ip) { | ||
let deviceresp = []; | ||
@@ -21,3 +24,3 @@ let responses = []; | ||
'EXT:', | ||
'LOCATION: http://' + ipaddress + ':' + devices[i].port + '/setup.xml', | ||
'LOCATION: http://' + ip + ':' + devices[i].port + '/setup.xml', | ||
'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01', | ||
@@ -54,5 +57,18 @@ '01-NLS: ' + serial(devices[i]) + '', | ||
let findAddress = function(network) { | ||
let interfaces = os.networkInterfaces().Ethernet; | ||
for(let i = 0; i <= interfaces.length - 1; i++) { | ||
if(ip.cidr(interfaces[i].cidr)==network) { | ||
return interfaces[i].address; | ||
} | ||
} | ||
} | ||
module.exports.startSSDPServer = function(fauxMo) { | ||
devices = fauxMo.devices; | ||
ipaddress = fauxMo.ipAddress; | ||
if(fauxMo.hasOwnProperty('ipAddress')) { | ||
ipaddress = fauxMo.ipAddress; | ||
} else { | ||
ipaddress = '0.0.0.0'; | ||
} | ||
//console.log('here'); | ||
@@ -68,6 +84,13 @@ udpServer = dgram.createSocket({type: 'udp4'}); | ||
//debug(`<< server got: ${msg} from ${rinfo.address}:${rinfo.port}`); | ||
//console.log('Search request from ' + rinfo); | ||
//console.log('Search request from ' + util.inspect(rinfo)); | ||
//console.log(ip.cidr(rinfo.address + '/24')); | ||
let search = parseHeaders(msg); | ||
if(search) { | ||
let resp = response(); | ||
let srcip; | ||
if(ipaddress == '0.0.0.0') { | ||
srcip = findAddress(ip.cidr(rinfo.address + '/24')); | ||
} else { | ||
srcip = ipaddress; | ||
} | ||
let resp = response(srcip); | ||
for(let i = 0; i <= resp.length - 1; i++) { | ||
@@ -88,3 +111,3 @@ //console.log(resp[i].toString()); | ||
udpServer.setMulticastTTL(128); | ||
udpServer.addMembership('239.255.255.250', fauxMo.ipAddress); | ||
udpServer.addMembership('239.255.255.250', ipaddress); | ||
} catch (err) { | ||
@@ -98,3 +121,3 @@ //debug('udp server error: %s', err.message); | ||
udpServer.bind(1900, function() { | ||
udpServer.setMulticastInterface(fauxMo.ipAddress); | ||
udpServer.setMulticastInterface(ipaddress); | ||
}); | ||
@@ -101,0 +124,0 @@ } catch (err) { |
@@ -59,8 +59,6 @@ 'use strict'; | ||
} else if(action=="SetBinaryState") { | ||
//console.log('Current state is ' + getState(i)); | ||
if(state==0) { | ||
setState(i, 1); | ||
} else { | ||
setState(i, 0); | ||
} | ||
//console.log('Current state is ' + body); | ||
let searchstr = body.indexOf('</BinaryState>'); | ||
let statereq = body.substring(searchstr - 1, searchstr); | ||
setState(i, parseInt(statereq)); | ||
xmlresponse = `<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> | ||
@@ -67,0 +65,0 @@ <s:Body> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12043
1
8
266
60