|
@@ -0,0 +1,25 @@
|
|
1
|
+var diont = require('diont')({
|
|
2
|
+ broadcast: true
|
|
3
|
+});
|
|
4
|
+
|
|
5
|
+// ======
|
|
6
|
+// Listen for announcements and renouncements in services
|
|
7
|
+// ======
|
|
8
|
+diont.on("serviceAnnounced", function(serviceInfo) {
|
|
9
|
+ // A service was announced
|
|
10
|
+ // This function triggers for services not yet available in diont.getServiceInfos()
|
|
11
|
+ // serviceInfo is an Object { isOurService : Boolean, service: Object }
|
|
12
|
+ // service.name, service.host and service.port are always filled
|
|
13
|
+ console.log("A new service was announced", serviceInfo.service);
|
|
14
|
+ // List currently known services
|
|
15
|
+ console.log("All known services", diont.getServiceInfos());
|
|
16
|
+});
|
|
17
|
+
|
|
18
|
+diont.on("serviceRenounced", function(serviceInfo) {
|
|
19
|
+ // A service available in diont.getServiceInfos() was renounced
|
|
20
|
+ // serviceInfo is an Object { isOurService : Boolean, service: Object }
|
|
21
|
+ // service.name, service.host and service.port are always filled
|
|
22
|
+ console.log("A service was renounced", serviceInfo.service);
|
|
23
|
+ // List currently known services
|
|
24
|
+ console.log("All known services", diont.getServiceInfos());
|
|
25
|
+});
|