index.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. var diont = require('diont')();
  2. // ======
  3. // Listen for announcements and renouncements in services
  4. // ======
  5. diont.on("serviceAnnounced", function(serviceInfo) {
  6. // A service was announced
  7. // This function triggers for services not yet available in diont.getServiceInfos()
  8. // serviceInfo is an Object { isOurService : Boolean, service: Object }
  9. // service.name, service.host and service.port are always filled
  10. console.log("A new service was announced", serviceInfo.service);
  11. // List currently known services
  12. console.log("All known services", diont.getServiceInfos());
  13. });
  14. diont.on("serviceRenounced", function(serviceInfo) {
  15. console.log("A service was renounced", serviceInfo.service);
  16. console.log("All known services", diont.getServiceInfos());
  17. });
  18. // ======
  19. // Announce our own service
  20. // ======
  21. var service = {
  22. name: "TestServer 1",
  23. host: "127.0.0.1", // when omitted, defaults to the local IP
  24. port: "1231"
  25. // any additional information is allowed and will be propagated
  26. };
  27. diont.announceService(service);