Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hap-nodejs

Package Overview
Dependencies
Maintainers
1
Versions
550
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hap-nodejs - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

LICENSE

94

lib/Accessory.js

@@ -156,2 +156,12 @@ var debug = require('debug')('Accessory');

Accessory.prototype.updateReachability = function(reachable) {
if (!this.bridged)
throw new Error("Cannot update reachability on non-bridged accessory!");
this
.getService(Service.BridgingState)
.getCharacteristic(Characteristic.Reachable)
.setValue((reachable == true));
}
Accessory.prototype.addBridgedAccessory = function(accessory) {

@@ -168,2 +178,12 @@ if (accessory._isBridge)

if(accessory.getService(Service.BridgingState) == undefined) {
// Setup Bridging State Service
accessory.addService(Service.BridgingState);
}
accessory
.getService(Service.BridgingState)
.getCharacteristic(Characteristic.LinkAddress)
.setValue(accessory.UUID);
// listen for changes in ANY characteristics of ANY services on this Accessory

@@ -175,6 +195,75 @@ accessory.on('service-characteristic-change', function(change) {

accessory.bridged = true;
this.bridgedAccessories.push(accessory);
if(this._advertiser && this._advertiser.isAdvertising()) {
// get our accessory information in HAP format and determine if our configuration (that is, our
// Accessories/Services/Characteristics) has changed since the last time we were published. make
// sure to omit actual values since these are not part of the "configuration".
var config = this.toHAP({omitValues:true});
// now convert it into a hash code and check it against the last one we made, if we have one
var shasum = crypto.createHash('sha1');
shasum.update(JSON.stringify(config));
var configHash = shasum.digest('hex');
if (configHash !== this._accessoryInfo.configHash) {
// our configuration has changed! we'll need to bump our config version number
this._accessoryInfo.configVersion++;
this._accessoryInfo.configHash = configHash;
this._accessoryInfo.save();
}
// update our advertisement so HomeKit on iOS can pickup new accessory
this._advertiser.updateAdvertisement();
}
return accessory;
}
Accessory.prototype.removeBridgedAccessory = function(accessory) {
if (accessory._isBridge)
throw new Error("Cannot Bridge another Bridge!");
var foundMatchAccessory = false;
// check for UUID conflict
for (var index in this.bridgedAccessories) {
var existing = this.bridgedAccessories[index];
if (existing.UUID === accessory.UUID) {
foundMatchAccessory = true;
this.bridgedAccessories.splice(index, 1);
break;
}
}
if (!foundMatchAccessory)
throw new Error("Cannot find the bridged Accessory to remove.");
accessory.removeAllListeners();
if(this._advertiser && this._advertiser.isAdvertising()) {
// get our accessory information in HAP format and determine if our configuration (that is, our
// Accessories/Services/Characteristics) has changed since the last time we were published. make
// sure to omit actual values since these are not part of the "configuration".
var config = this.toHAP({omitValues:true});
// now convert it into a hash code and check it against the last one we made, if we have one
var shasum = crypto.createHash('sha1');
shasum.update(JSON.stringify(config));
var configHash = shasum.digest('hex');
if (configHash !== this._accessoryInfo.configHash) {
// our configuration has changed! we'll need to bump our config version number
this._accessoryInfo.configVersion++;
this._accessoryInfo.configHash = configHash;
this._accessoryInfo.save();
}
// update our advertisement so HomeKit on iOS can pickup new accessory
this._advertiser.updateAdvertisement();
}
}
Accessory.prototype.getCharacteristicByIID = function(iid) {

@@ -372,5 +461,4 @@ for (var index in this.services) {

// restart our advertisement so it can pick up on the paired status of AccessoryInfo
// (it will need to stop broadcasting as "discoverable" - see notes at top of Advertiser.js)
this._advertiser.startAdvertising();
// update our advertisement so it can pick up on the paired status of AccessoryInfo
this._advertiser.updateAdvertisement();

@@ -377,0 +465,0 @@ callback();

@@ -50,2 +50,24 @@ var mdns = require('mdns');

Advertiser.prototype.isAdvertising = function() {
return (this._advertisement != null);
}
Advertiser.prototype.updateAdvertisement = function() {
if (this._advertisement) {
var txtRecord = {
md: this.accessoryInfo.displayName,
pv: "1.0",
id: this.accessoryInfo.username,
"c#": this.accessoryInfo.configVersion + "", // "accessory conf" - represents the "configuration version" of an Accessory. Increasing this "version number" signals iOS devices to re-fetch /accessories data.
"s#": "1", // "accessory state"
"ff": "0",
"ci": this.accessoryInfo.category,
"sf": this.accessoryInfo.paired() ? "0" : "1" // "sf == 1" means "discoverable by HomeKit iOS clients"
};
this._advertisement.updateTXTRecord(txtRecord);
}
}
Advertiser.prototype.stopAdvertising = function() {

@@ -52,0 +74,0 @@ if (this._advertisement) {

2

lib/Characteristic.js

@@ -187,3 +187,3 @@ var inherits = require('util').inherits;

Characteristic.prototype.getDefaultValue = function() {
switch (this.format) {
switch (this.props.format) {
case Characteristic.Formats.BOOL: return false;

@@ -190,0 +190,0 @@ case Characteristic.Formats.STRING: return null;

@@ -246,2 +246,19 @@ // THIS FILE IS AUTO-GENERATED - DO NOT MODIFY

/**
* Characteristic "Category"
*/
Characteristic.Category = function() {
Characteristic.call(this, 'Category', '00000103-0000-1000-8000-0026BB765291');
this.setProps({
format: Characteristic.Formats.UINT16,
maxValue: 65535,
minValue: 1,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(Characteristic.Category, Characteristic);
/**
* Characteristic "Charging State"

@@ -558,2 +575,51 @@ */

/**
* Characteristic "Link Address"
*/
Characteristic.LinkAddress = function() {
Characteristic.call(this, 'Link Address', '00000102-0000-1000-8000-0026BB765291');
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(Characteristic.LinkAddress, Characteristic);
/**
* Characteristic "Link Quality"
*/
Characteristic.LinkQuality = function() {
Characteristic.call(this, 'Link Quality', '0000009C-0000-1000-8000-0026BB765291');
this.setProps({
format: Characteristic.Formats.UINT8,
maxValue: 3,
minValue: 1,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(Characteristic.LinkQuality, Characteristic);
/**
* Characteristic "Link Type"
*/
Characteristic.LinkType = function() {
Characteristic.call(this, 'Link Type', '00000104-0000-1000-8000-0026BB765291');
this.setProps({
format: Characteristic.Formats.UINT8,
maxValue: 255,
minValue: 1,
perms: [Characteristic.Perms.READ]
});
this.value = this.getDefaultValue();
};
inherits(Characteristic.LinkType, Characteristic);
/**
* Characteristic "Leak Detected"

@@ -882,3 +948,3 @@ */

});
this.value = this.getDefaultValue();
this.value = true;
};

@@ -1381,6 +1447,7 @@

// Required Characteristics
this.addCharacteristic(Characteristic.Category);
this.addCharacteristic(Characteristic.LinkAddress);
this.addCharacteristic(Characteristic.LinkQuality);
this.addCharacteristic(Characteristic.LinkType);
this.addCharacteristic(Characteristic.Reachable);
// Optional Characteristics
this.addOptionalCharacteristic(Characteristic.Name);
};

@@ -1387,0 +1454,0 @@

@@ -655,2 +655,9 @@ var debug = require('debug')('HAPServer');

var query = url.parse(request.url, parseQueryString).query; // { id: '1.9,2.14' }
if(query == undefined || query.id == undefined) {
response.writeHead(500);
response.end();
return;
}
var sets = query.id.split(','); // ["1.9","2.14"]

@@ -692,2 +699,9 @@ var data = []; // [{aid:1,iid:9},{aid:2,iid:14}]

else if (request.method == "PUT") {
// to be safe, prevent doing any change without a secure session
if(session.encryption == undefined) {
response.writeHead(403);
response.end();
return;
}

@@ -694,0 +708,0 @@ // requestData is a JSON payload like { characteristics: [ { aid: 1, iid: 8, value: true, ev: true } ] }

{
"name": "hap-nodejs",
"version": "0.0.7",
"version": "0.1.0",
"description": "HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.",

@@ -10,3 +10,3 @@ "main": "index.js",

"ed25519": "git://github.com/KhaosT/ed25519",
"mdns": "^2.2.4",
"mdns": "git://github.com/KhaosT/node_mdns",
"node-persist": "^0.0.6",

@@ -13,0 +13,0 @@ "srp": "git://github.com/KhaosT/node-srp"

@@ -23,3 +23,3 @@ HAP-NodeJS

```sh
node Code.js
node Core.js
```

@@ -56,2 +56,2 @@

If you are interested in HAP over BTLE, you might want to check [this](https://gist.github.com/KhaosT/6ff09ba71d306d4c1079).
If you are interested in HAP over BTLE, you might want to check [this](https://gist.github.com/KhaosT/6ff09ba71d306d4c1079).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc