Skip to content

Commit a852da3

Browse files
committed
1.2.0
1 parent a3dd1ef commit a852da3

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

lib/lib.discoverHostDevice.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ module.exports = class DiscoverHostDevice extends BaseManager
1313
super();
1414
this.bonjourClient = null
1515
this.bonjourBrowser = null
16-
this.ssdpClient = null;
16+
this.ssdpClient = null
17+
this.deviceFoundSign = false
18+
this.deviceLostSign = false
1719
}
1820

1921

2022
init()
2123
{
2224
var self = this
2325

24-
self.stopDiscover()
25-
//self.tinkerhubMDSNBrowser = null
26-
//self.tinkerhubMDSNBrowser = new TinkerhubMDSN.browser({type: '', protocol: 'udp'})
27-
//this.ssdpClient = new SsdpClient({customLogger : this.logUPNP(this), explicitSocketBind : true});
28-
//this.ssdpClient = new SsdpClient({explicitSocketBind : true})
29-
26+
self.stopDiscover()
3027
self.createBonjourClient()
31-
//self.createSSDPClient();
28+
self.createSSDPClient();
3229

3330
}
3431

@@ -54,14 +51,14 @@ module.exports = class DiscoverHostDevice extends BaseManager
5451
this.bonjourBrowser.on("up", function (_service) {
5552
if(_service.fqdn.startsWith("RaumfeldControl"))
5653
{
57-
self.deviceFound(_service.referer.address, _service.fqdn, _service)
54+
self.deviceFound(_service.referer.address, _service.fqdn, _service, "BONJOUR")
5855
}
5956
})
6057

6158
this.bonjourBrowser.on("down", function (_service) {
6259
if(_service.fqdn.startsWith("RaumfeldControl"))
6360
{
64-
self.deviceLost(_service.referer.address, _service.fqdn, _service)
61+
self.deviceLost(_service.referer.address, _service.fqdn, _service, "BONJOUR")
6562
}
6663
})
6764
}
@@ -76,34 +73,44 @@ module.exports = class DiscoverHostDevice extends BaseManager
7673
this.ssdpClient = new SsdpClient({explicitSocketBind : true})
7774

7875
this.ssdpClient.on('response', function (_headers, _statusCode, _rinfo) {
79-
self.deviceFound(_headers.LOCATION, "", _headers)
76+
self.deviceFound(_headers.LOCATION, "", _headers, "SSDP")
8077
});
8178

8279
this.ssdpClient.on('advertise-alive', function (_headers) {
83-
self.deviceFound(_headers.LOCATION, "", _headers)
80+
self.deviceFound(_headers.LOCATION, "", _headers, "SSDP")
8481
});
8582

8683
this.ssdpClient.on('advertise-bye', function (_headers) {
87-
self.deviceLost(_headers.LOCATION, "", _headers)
84+
self.deviceLost(_headers.LOCATION, "", _headers, "SSDP")
8885
});
8986

9087
self.ssdpClient.search('urn:schemas-raumfeld-com:device:ConfigDevice:1');
9188
}
9289

9390

94-
deviceFound(_address, _name, _service)
91+
deviceFound(_address, _name, _service, _type)
9592
{
96-
this.emit("deviceFound", { "address" : _address, "name" : _name, origService: _service })
93+
if(!this.deviceFoundSign)
94+
{
95+
this.deviceFoundSign = true
96+
this.emit("deviceFound", { "address" : _address, "name" : _name, "type" : _type, origService: _service })
97+
}
9798
}
9899

99100
deviceLost(_service)
100101
{
101-
this.emit("deviceLost", { "address" : _address, "name" : _name, origService: _service })
102+
if(!this.devicLostSign)
103+
{
104+
this.deviceLostSign = true
105+
this.emit("deviceLost", { "address" : _address, "name" : _name, "type" : _type, origService: _service })
106+
}
102107
}
103108

104109

105110
startDiscover()
106-
{
111+
{
112+
// start discovering with both types of discover (bonjour and ssdp)
113+
// the one who will find the device firts is the winner
107114
if(this.bonjourBrowser)
108115
this.bonjourBrowser.start()
109116
if(this.ssdpClient)
@@ -122,10 +129,15 @@ module.exports = class DiscoverHostDevice extends BaseManager
122129

123130
updateDiscover()
124131
{
132+
// clear found devices list for the update to catch again
133+
this.deviceFoundSign = false
134+
this.deviceLostSign = false
135+
136+
// recreate bonjour and ssdp client to be sure it works well
125137
this.createBonjourBrowser()
126138
this.bonjourBrowser.start()
127-
//this.createSSDPClient()
128-
//this.ssdpClient.start()
139+
this.createSSDPClient()
140+
this.ssdpClient.start()
129141
}
130142

131143
}

lib/lib.manager.deviceManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ module.exports = class DeviceManager extends ManagerBase
9090
self.discoverHostDevice.parmLogger(self.parmLogger())
9191
self.discoverHostDevice.init()
9292
self.discoverHostDevice.on("deviceFound", function (_deviceData) {
93-
self.logVerbose("Found Service on: " + _deviceData.address)
93+
self.logVerbose("Found Host-Service on: " + _deviceData.address + " via " + _deviceData.type)
9494
self.systemHostDeviceFound(_deviceData.address)
9595
});
9696
self.discoverHostDevice.on("deviceLost", function (_deviceData) {
97-
self.logVerbose("Removed Service on: " +_deviceData.address)
97+
self.logVerbose("Removed Host-Service on: " +_deviceData.address + " via " + _deviceData.type)
9898
self.systemHostDeviceLost(_deviceData.address)
9999
});
100100
self.discoverHostDevice.startDiscover();

0 commit comments

Comments
 (0)