* Creates a fetcher for a new url if it doesn't exist yet. * Otherwise it reuses the existing one. * @param {string} url The url of the calendar * @param {number} fetchInterval How often does the calendar needs to be fetched in ms * @param {string[]} excludedEvents An array of words / phrase
(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert, identifier)
| 39 | * @param {string} identifier ID of the module |
| 40 | */ |
| 41 | createFetcher (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert, identifier) { |
| 42 | try { |
| 43 | new URL(url); |
| 44 | } catch (error) { |
| 45 | Log.error("Malformed calendar url: ", url, error); |
| 46 | this.sendSocketNotification("CALENDAR_ERROR", { error_type: "MODULE_ERROR_MALFORMED_URL" }); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | let fetcher; |
| 51 | let fetchIntervalCorrected; |
| 52 | if (typeof this.fetchers[identifier + url] === "undefined") { |
| 53 | if (fetchInterval < 60000) { |
| 54 | Log.warn(`fetchInterval for url ${url} must be >= 60000`); |
| 55 | fetchIntervalCorrected = 60000; |
| 56 | } |
| 57 | Log.log(`Create new calendarfetcher for url: ${url} - Interval: ${fetchIntervalCorrected || fetchInterval}`); |
| 58 | fetcher = new CalendarFetcher(url, fetchIntervalCorrected || fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert); |
| 59 | |
| 60 | fetcher.onReceive((fetcher) => { |
| 61 | this.broadcastEvents(fetcher, identifier); |
| 62 | }); |
| 63 | |
| 64 | fetcher.onError((fetcher, errorInfo) => { |
| 65 | Log.error("Calendar Error. Could not fetch calendar: ", fetcher.url, errorInfo.message || errorInfo); |
| 66 | this.sendSocketNotification("CALENDAR_ERROR", { |
| 67 | id: identifier, |
| 68 | error_type: errorInfo.translationKey |
| 69 | }); |
| 70 | }); |
| 71 | |
| 72 | this.fetchers[identifier + url] = fetcher; |
| 73 | fetcher.fetchCalendar(); |
| 74 | } else { |
| 75 | Log.log(`Use existing calendarfetcher for url: ${url}`); |
| 76 | fetcher = this.fetchers[identifier + url]; |
| 77 | // Check if calendar data is stale and needs refresh |
| 78 | if (fetcher.shouldRefetch()) { |
| 79 | Log.log(`Calendar data is stale, fetching fresh data for url: ${url}`); |
| 80 | fetcher.fetchCalendar(); |
| 81 | } else { |
| 82 | fetcher.broadcastEvents(); |
| 83 | } |
| 84 | } |
| 85 | }, |
| 86 | |
| 87 | /** |
| 88 | * |
nothing calls this directly
no test coverage detected