forked from homebridge/HAP-NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvertiser.js
38 lines (35 loc) · 1013 Bytes
/
Advertiser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var mdns = require('mdns');
Advertiser.prototype = {
startAdvertising: function startAdvertising() {
if (!this._private.isAdvertising) {
this._private.ad.start();
this._private.isAdvertising = true;
}
},
}
function Advertiser(port, accessory_name, accessory_id, accessory_conf, accessory_state) {
if (!(this instanceof Advertiser)) {
return new Advertiser(port, accessory_name, accessory_id, accessory_conf, accessory_state);
}
this.targetPort = port;
this.acc_name = accessory_name;
this.acc_id = accessory_id;
this.acc_conf = accessory_conf;
this.acc_state = accessory_state;
this._private = {
isAdvertising: false
}
this._private.txt_record = {
md: this.acc_name,
pv: "1.0",
id: this.acc_id,
"c#": this.acc_conf,
"s#": this.acc_state,
sf: "1",
"ff": "0"
};
this._private.ad = mdns.createAdvertisement(mdns.tcp('hap'), this.targetPort, {name: this.acc_name, txtRecord: this._private.txt_record});
}
module.exports = {
Advertiser: Advertiser
};