diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index e1813737..66e423db 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -38,41 +38,48 @@ module.exports = NodeHelper.create({ * @param {string} identifier ID of the module */ createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert, identifier) { - var self = this; - if (!validUrl.isUri(url)) { - self.sendSocketNotification("INCORRECT_URL", { id: identifier, url: url }); + this.sendSocketNotification("INCORRECT_URL", { id: identifier, url: url }); return; } - var fetcher; - if (typeof self.fetchers[identifier + url] === "undefined") { + let fetcher; + if (typeof this.fetchers[identifier + url] === "undefined") { Log.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert); - fetcher.onReceive(function (fetcher) { - self.sendSocketNotification("CALENDAR_EVENTS", { - id: identifier, - url: fetcher.url(), - events: fetcher.events() - }); + fetcher.onReceive((fetcher) => { + this.broadcastEvents(fetcher, identifier); }); - fetcher.onError(function (fetcher, error) { + fetcher.onError((fetcher, error) => { Log.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); - self.sendSocketNotification("FETCH_ERROR", { + this.sendSocketNotification("FETCH_ERROR", { id: identifier, url: fetcher.url(), error: error }); }); - self.fetchers[identifier + url] = fetcher; + this.fetchers[identifier + url] = fetcher; } else { Log.log("Use existing calendar fetcher for url: " + url); - fetcher = self.fetchers[identifier + url]; + fetcher = this.fetchers[identifier + url]; + fetcher.setReloadInterval(fetchInterval); + fetcher.broadcastEvents(); } fetcher.startFetch(); + }, + + /** + * + */ + broadcastEvents: function (fetcher, identifier) { + this.sendSocketNotification("CALENDAR_EVENTS", { + id: identifier, + url: fetcher.url(), + events: fetcher.events() + }); } });