Skip to content

Commit

Permalink
Clean up style; add bare .eslintrc.js with comma-style
Browse files Browse the repository at this point in the history
  • Loading branch information
dhleong committed Aug 18, 2017
1 parent ee5d5aa commit 6792c8e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
"rules": {
"comma-style": [ "error", "first" ]
}
};
2 changes: 1 addition & 1 deletion bin/wemore-toggle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var wemore = require('../')
, TIMEOUT = 1500; // impatience

var minLen = 2;
var exe = process.argv[0];
if (exe == 'node' || exe.endsWith('/node')) {
Expand Down
7 changes: 5 additions & 2 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ var util = require('util')
, parseXml = require('xml2js').parseString
, Q = require('q')

, COPY_FIELDS = ['friendlyName', 'modelName', 'modelNumber',
'modelURL', 'serialNumber', 'macAddress', 'firmwareVersion']
, COPY_FIELDS = [
'friendlyName'
, 'modelName', 'modelNumber', 'modelURL'
, 'serialNumber', 'macAddress', 'firmwareVersion'
]
// NB: binaryState IS returned, but seems to be 0 even if
// the thing is on :(

Expand Down
6 changes: 3 additions & 3 deletions lib/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ function Search(friendlyName, timeout) {
}

module.exports = {
Discovery: Discovery,
Search: Search
}
Discovery: Discovery
, Search: Search
};
82 changes: 43 additions & 39 deletions lib/emulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var util = require('util')
, BELKIN_BASICEVENT = "urn:Belkin:service:basicevent:1"
, SETUP_XMLNS = 'urn:Belkin:device-1-0'
, SETUP_TYPE = BELKIN_CONTROLLEE

// NB: xml2js.Builder has a bug where attrs aren't
// handled correctly, so we use its dependency directly
, XML = function(obj) {
Expand All @@ -31,34 +31,34 @@ var __getSSDPHeader = SsdpServer.prototype._getSSDPHeader;
SsdpServer.prototype._getSSDPHeader = function(method, headers, isResponse) {
var server = SERVER._nested.filter(function(nested) {
return nested._location == headers.LOCATION;
})
});

// not all requests will pass location; those that don't
// do not need our extra headers
var uuid = server.length ? server[0].__device.uuid : undefined;

return __getSSDPHeader.call(this,
return __getSSDPHeader.call(this,
method, _.extend(headers, {
OPT: '"http://schemas.upnp.org/upnp/1/0/"; ns=01'
, '01-NLS': uuid
, 'X-User-Agent': 'redsonic'
}), isResponse);
}
OPT: '"http://schemas.upnp.org/upnp/1/0/"; ns=01'
, '01-NLS': uuid
, 'X-User-Agent': 'redsonic'
}), isResponse);
};

SERVER._respondToSearch = function(serviceType, rinfo) {
SERVER._nested.forEach(function(nested) {
nested._respondToSearch(serviceType, rinfo);
});
}
};
SERVER.advertise = function(alive) {
SERVER._nested.forEach(function(nested) {
nested.advertise(alive);
});
}
};
SERVER.add = function(child) {
SERVER._nested.push(child);
}
};

/**
* All params except for friendlyName are optional
* @param friendlyName The human-readable name for
Expand Down Expand Up @@ -105,7 +105,7 @@ util.inherits(EmulatedDevice, events.EventEmitter);

EmulatedDevice.prototype.close = function() {
this.http.close();
}
};

EmulatedDevice.prototype._initSsdp = function() {
this.ssdp = new SsdpServer({
Expand All @@ -121,7 +121,7 @@ EmulatedDevice.prototype._initSsdp = function() {
SERVER.add(this.ssdp);
process.on('exit', this.close.bind(this));
this.emit('listening', this);
}
};

EmulatedDevice.prototype._onHttpRequest = function(req, res) {

Expand All @@ -141,7 +141,7 @@ EmulatedDevice.prototype._onHttpRequest = function(req, res) {
}

handler.call(this, req, res);
}
};

EmulatedDevice.prototype._endpoints = {
'/setup.xml': function(req, res) {
Expand Down Expand Up @@ -170,13 +170,15 @@ EmulatedDevice.prototype._endpoints = {
, UDN: this.serial // Echo uses this to identify
, UPC: 123456789
, serviceList: [
{service: {
serviceType: 'urn:Belkin:service:basicevent:1'
, serviceId: 'urn:Belkin:serviceId:basicevent1'
, controlURL: '/upnp/control/basicevent1'
, eventSubURL: '/upnp/event/basicevent1'
, SCPDURL: '/eventservice.xml'
}}
{
service: {
serviceType: 'urn:Belkin:service:basicevent:1'
, serviceId: 'urn:Belkin:serviceId:basicevent1'
, controlURL: '/upnp/control/basicevent1'
, eventSubURL: '/upnp/event/basicevent1'
, SCPDURL: '/eventservice.xml'
}
}
]
}
}
Expand All @@ -189,23 +191,27 @@ EmulatedDevice.prototype._endpoints = {
, '/eventservice.xml': function(req, res) {
res.writeHead(200);

var xml = XML({
scpd: {
var xml = XML({
scpd: {
'@xmlns': SETUP_XMLNS
, specVersion: {
major: 1
, minor: 0
},
actionList: [
{action: {
name: 'GetBinaryState'
}}
, {action: {
name: 'SetBinaryState'
}}
]
}
, actionList: [
{
action: {
name: 'GetBinaryState'
}
}
, {
action: {
name: 'SetBinaryState'
}
}
]
}
});
});

res.write(xml);
res.end();
Expand Down Expand Up @@ -265,7 +271,7 @@ EmulatedDevice.prototype._endpoints = {
res.writeHead(400);
res.end();
}
}
};

// this isn't terribly efficient, but these
// requests shouldn't be that large anyway
Expand All @@ -290,7 +296,7 @@ EmulatedDevice.prototype._endpoints = {
});
});
}
}
};

module.exports = function Emulate(opts) {
var device = new EmulatedDevice(opts);
Expand All @@ -308,6 +314,4 @@ module.exports = function Emulate(opts) {
device.on('listening', serverStarter);
}
return device;
}


};

0 comments on commit 6792c8e

Please sign in to comment.