New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hap-node-client

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hap-node-client - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

README.md.orig.2019-03-10_155148

136

HAPNodeJSClient.js
"use strict";
var request = require('./lib/hapRequest.js');
var request = require('requestretry');
// var request = require('./lib/hapRequest.js');
var hapRequest = require('./lib/hapRequest.js');
var EventEmitter = require('events').EventEmitter;

@@ -16,23 +18,11 @@ var inherits = require('util').inherits;

/*
HAPaccessories
HAPcontrol
HAPstatus
External events
Ready - Emitted after every discovery cycle
hapEvent - Emitted when an HAP EVENT message is revieved
*/
/**
* HAPNodeJSClient - description
* HAPNodeJSClient - Client for Homebridge and HAP-NodeJS in insecure mode.
*
* Events
*
* @class
* @param {type} options description
* @return {type} description
* @example
*
*/

@@ -63,2 +53,16 @@

debug('Event', event);
/**
* HomeKit Accessory Characteristic event pass thru
*
* @event HAPNodeJSClient#hapEvent
* @Type {object}
* @property {string} host - IP Address of homebridge instance generating event
* @property {number} port - Port of homebridge instance generating event
* @property {number} aid - Accessory ID of accessory generating event
* @property {number} iid - Instance ID of accessory characteristic generating event
* @property {???} status - Updated characteristic value
* @example Sample Message
*
* { host: '192.168.1.4', port: 51826, aid: 16, iid: 11, status: false }
*/
this.emit('hapEvent', event);

@@ -116,3 +120,3 @@ this.emit(event.host + event.port + event.aid + event.iid, event);

/**
* HAPNodeJSClient.prototype.HAPaccessories - description
* HAPNodeJSClient.prototype.HAPaccessories - Returns an array of all homebridge instances, and the accessories for each.
*

@@ -132,9 +136,8 @@ * @param {type} callback description

/**
* HAPNodeJSClient.prototype.HAPcontrol - description
* HAPNodeJSClient.prototype.HAPcontrol - Send a characteristic PUT Message to a particular homebridge instance
*
* @param {type} ipAddress description
* @param {type} port description
* @param {type} body description
* @param {type} callback description
* @return {type} description
* @param {type} ipAddress IP Address of homebridge instance
* @param {type} port Port of homebridge instance
* @param {type} body An array of HomeKit characteristic updates, [{ \"aid\": 2, \"iid\": 9, \"value\": 0}]
* @param {type} callback Callback to execute upon completion of characteristic setting, function(err, response)
*/

@@ -186,11 +189,62 @@

/**
* HAPNodeJSClient.prototype.HAPresource - description
* HAPNodeJSClient.prototype.HAPevent - Send a characteristic PUT Message to a particular homebridge instance, this maintains a socket connection for use in returning Events
*
* @param {type} ipAddress description
* @param {type} port description
* @param {type} body description
* @param {type} callback description
* @return {type} description
* @param {type} ipAddress IP Address of homebridge instance
* @param {type} port Port of homebridge instance
* @param {type} body An array of HomeKit characteristic updates, [{ \"aid\": 2, \"iid\": 9, \"value\": 0}]
* @param {type} callback Callback to execute upon completion of characteristic setting, function(err, response)
*/
HAPNodeJSClient.prototype.HAPevent = function(ipAddress, port, body, callback) {
hapRequest({
eventBus: this._eventBus,
method: 'PUT',
url: 'http://' + ipAddress + ':' + port + '/characteristics',
timeout: 7000,
maxAttempts: 1, // (default) try 5 times
headers: {
"Content-Type": "Application/json",
"authorization": this.pin,
"connection": "keep-alive"
},
body: body
}, function(err, response) {
// Response s/b 200 OK
if (err) {
debug("Homebridge event reg failed %s:%s", ipAddress, port, body, err);
callback(err);
} else if (response.statusCode !== 207) {
if (response.statusCode === 401) {
debug("Homebridge auth failed, invalid PIN %s %s:%s", this.pin, ipAddress, port, body, err, response.body);
callback(new Error("Homebridge auth failed, invalid PIN " + this.pin));
} else {
debug("Homebridge event reg failed %s:%s Status: %s ", ipAddress, port, response.statusCode, body, err, response.body);
callback(new Error("Homebridge event reg failed"));
}
} else {
var rsp;
try {
rsp = response.body;
} catch (ex) {
debug("Homebridge Response Failed %s:%s", ipAddress, port, response.statusCode, response.statusMessage);
debug("Homebridge Response Failed %s:%s", ipAddress, port, response.body, ex);
callback(new Error(ex));
}
callback(null, rsp);
}
});
};
/**
* HAPNodeJSClient.prototype.HAPresource - Send a characteristic PUT Message to a particular homebridge instance using resource interface, ie camera
*
* @param {type} ipAddress IP Address of homebridge instance
* @param {type} port Port of homebridge instance
* @param {type} body An array of HomeKit characteristic updates, [{ \"aid\": 2, \"iid\": 9, \"value\": 0}]
* @param {type} callback Callback to execute upon completion of characteristic setting, function(err, response)
*/
HAPNodeJSClient.prototype.HAPresource = function(ipAddress, port, body, callback) {

@@ -239,9 +293,8 @@ request({

/**
* HAPNodeJSClient.prototype.HAPstatus - description
* HAPNodeJSClient.prototype.HAPstatus - Get current status for characteristics
*
* @param {type} ipAddress description
* @param {type} port description
* @param {type} ipAddress IP Address of homebridge instance
* @param {type} port Port of homebridge instance
* @param {type} body description
* @param {type} callback description
* @return {type} description
* @param {type} callback Callback to execute upon completion of characteristic getting, function(err, response)
*/

@@ -278,3 +331,3 @@

try {
rsp = response.body;
rsp = JSON.parse(response.body);
} catch (ex) {

@@ -286,2 +339,3 @@ debug("Homebridge Response Failed %s:%s", ipAddress, port, response.statusCode, response.statusMessage);

}
// debug("HAPStatus callback", rsp);
callback(null, rsp);

@@ -326,8 +380,8 @@ }

} else {
// debug("RESPONSE", response, body);
if (response.body && Object.keys(response.body.accessories).length > 0) {
var message = JSON.parse(response.body);
if (message && Object.keys(message.accessories).length > 0) {
callback(null, {
"ipAddress": ipAddress,
"instance": instance,
"accessories": response.body
"accessories": message
});

@@ -334,0 +388,0 @@ } else {

@@ -102,4 +102,5 @@ // Monkey patch before you require http for the first time.

var url = URL.parse(response.url);
if (response.body.characteristics) {
response.body.characteristics.forEach(function(key, element) {
var message = JSON.parse(response.body);
if (message.characteristics) {
message.characteristics.forEach(function(key, element) {
// debug("char", key, element);

@@ -116,5 +117,4 @@ var event = {

} else {
debug("Incomplete EVENT", url, response.body);
debug("Incomplete EVENT", url, message);
}
// request.eventBus.emit('hapEvent', res, response.body);
}

@@ -121,0 +121,0 @@ }

@@ -133,5 +133,5 @@ // Borrowed and heaviliy modifed from https://github.com/miguelmota/http-message-parser

if (result.headers['Content-Length']) {
result.body = JSON.parse(body);
result.body = body;
} else {
result.body = JSON.parse(body.split('\n')[1]);
result.body = body.split('\n')[1];
}

@@ -138,0 +138,0 @@ } catch (err) {

{
"name": "hap-node-client",
"version": "0.0.14",
"version": "0.0.15",
"description": "Client for Hap-NodeJS",

@@ -28,3 +28,4 @@ "main": "HAPNodeJSClient.js",

"buffer": "^4.9.1",
"better-queue": ">=3.8.10"
"better-queue": ">=3.8.10",
"requestretry": "^=1.13.0"
},

@@ -31,0 +32,0 @@ "repository": {

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