Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_helper.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. const NodeHelper = require("node_helper");
  3. const HafasFetcher = require("./core/HafasFetcher");
  4. module.exports = NodeHelper.create({
  5. start: function () {
  6. this.departuresFetchers = [];
  7. },
  8. socketNotificationReceived: function(notification, payload) {
  9. switch (notification) {
  10. case "CREATE_FETCHER":
  11. this.createFetcher(payload);
  12. break;
  13. case "FETCH_DEPARTURES":
  14. this.fetchDepartures(payload);
  15. break;
  16. }
  17. },
  18. createFetcher: function (config) {
  19. let fetcher;
  20. if (typeof this.departuresFetchers[config.identifier] === "undefined") {
  21. fetcher = new HafasFetcher(config);
  22. this.departuresFetchers[config.identifier] = fetcher;
  23. console.log("Transportation fetcher for station with id '" + fetcher.getStationID() + "' created.");
  24. this.sendFetcherLoaded(fetcher);
  25. } else {
  26. fetcher = this.departuresFetchers[config.identifier];
  27. console.log("Using existing transportation fetcher for station id '" + fetcher.getStationID() + "'.");
  28. this.sendFetcherLoaded(fetcher);
  29. }
  30. },
  31. sendFetcherLoaded: function (fetcher) {
  32. this.sendSocketNotification("FETCHER_INITIALIZED", {
  33. identifier: fetcher.getIdentifier()
  34. });
  35. },
  36. fetchDepartures(identifier) {
  37. let fetcher = this.departuresFetchers[identifier];
  38. fetcher.fetchDepartures().then((fetchedDepartures) => {
  39. let payload = {
  40. identifier: fetcher.getIdentifier(),
  41. departures: fetchedDepartures
  42. };
  43. this.sendSocketNotification("DEPARTURES_FETCHED", payload);
  44. }).catch((error) => {
  45. let payload = {
  46. identifier: fetcher.getIdentifier(),
  47. error: error
  48. };
  49. this.sendSocketNotification("FETCH_ERROR", payload);
  50. });
  51. }
  52. });