Skip to content

Commit

Permalink
Add ability to pass in mdns config.
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaosT committed Jun 25, 2018
1 parent 7e20ed3 commit 17f33b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Accessory.js
Expand Up @@ -585,7 +585,7 @@ Accessory.prototype.publish = function(info, allowInsecureRequest) {
}

// create our Advertiser which broadcasts our presence over mdns
this._advertiser = new Advertiser(this._accessoryInfo);
this._advertiser = new Advertiser(this._accessoryInfo, info.mdns);

// create our HAP server which handles all communication between iOS devices and us
this._server = new HAPServer(this._accessoryInfo, this.relayServer);
Expand Down
9 changes: 6 additions & 3 deletions lib/Advertiser.js
@@ -1,6 +1,6 @@
'use strict';

var bonjour = require('bonjour-hap')();
var bonjour = require('bonjour-hap');
var os = require('os');
var crypto = require('crypto');

Expand All @@ -18,8 +18,9 @@ module.exports = {
* mdns payload).
*/

function Advertiser(accessoryInfo) {
function Advertiser(accessoryInfo, mdnsConfig) {
this.accessoryInfo = accessoryInfo;
this._bonjourService = bonjour(mdnsConfig);
this._advertisement = null;

this._setupHash = this._computeSetupHash();
Expand Down Expand Up @@ -60,7 +61,7 @@ Advertiser.prototype.startAdvertising = function(port) {
+ crypto.createHash('sha512').update(this.accessoryInfo.username, 'utf8').digest('hex').slice(0, 4).toUpperCase();

// create/recreate our advertisement
this._advertisement = bonjour.publish({
this._advertisement = this._bonjourService.publish({
name: advertiseName,
type: "hap",
port: port,
Expand Down Expand Up @@ -98,6 +99,8 @@ Advertiser.prototype.stopAdvertising = function() {
this._advertisement.destroy();
this._advertisement = null;
}

this._bonjourService.destroy();
}

Advertiser.prototype._computeSetupHash = function() {
Expand Down

0 comments on commit 17f33b7

Please sign in to comment.