Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/Advertiser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var mdns = require('mdns');
const bonjour = require('bonjour')();
const os = require('os');

module.exports = {
Advertiser: Advertiser
Expand Down Expand Up @@ -39,12 +40,26 @@ Advertiser.prototype.startAdvertising = function(port) {
"sf": this.accessoryInfo.paired() ? "0" : "1" // "sf == 1" means "discoverable by HomeKit iOS clients"
};

/**
* The host name of the component is probably better to be
* the username of the hosted accessory + '.local'.
* By default 'bonjour' doesnt add '.local' at the end of the os.hostname
* this causes to return 'raspberrypi' on raspberry pi / raspbian
* then when the phone queryies for A/AAAA record it is being queried
* on normal dns, not on mdns. By Adding the username of the accessory
* probably the problem will also fix a possible problem
* of having multiple pi's on same network
*/
var host = this.accessoryInfo.username.replace(/\:/ig, "_") + '.local';

// create/recreate our advertisement
this._advertisement = mdns.createAdvertisement(mdns.tcp('hap'), port, {
this._advertisement = bonjour.publish({
name: this.accessoryInfo.displayName,
txtRecord: txtRecord
type:'hap',
port: port,
txt:txtRecord,
host: host
});
this._advertisement.start();
}

Advertiser.prototype.isAdvertising = function() {
Expand All @@ -65,13 +80,14 @@ Advertiser.prototype.updateAdvertisement = function() {
"sf": this.accessoryInfo.paired() ? "0" : "1" // "sf == 1" means "discoverable by HomeKit iOS clients"
};

this._advertisement.updateTXTRecord(txtRecord);
this._advertisement.updateTxt(txtRecord);
}
}

Advertiser.prototype.stopAdvertising = function() {
if (this._advertisement) {
this._advertisement.stop();
this._advertisement.destroy();
this._advertisement = null;
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"node": ">=4.3.2"
},
"dependencies": {
"bonjour": "git+https://github.com/sokarovski/bonjour.git#refactoring_and_update_txt_support",
"buffer-shims": "^1.0.0",
"curve25519-n2": "^1.1.2",
"debug": "^2.2.0",
"decimal.js": "^7.2.3",
"ed25519": "^0.0.4",
"fast-srp-hap": "^1.0.1",
"ip": "^1.1.3",
"mdns": "^2.3.3",
"node-persist": "^0.0.11",
"decimal.js": "^7.2.3"
"node-persist": "^0.0.11"
},
"devDependencies": {
"simple-plist": "0.0.4"
Expand Down