Read the statement by Michael Teeuw here.
MMM-MyCalendar stopped working on MagicMirror 2.25
-
Hello, everyone,
I’ve encountered an issue with my MagicMirror setup and need help resolving it. I hope someone here can provide me with some advice or solutions.
Problem Description:
I’ve updated my MagicMirror software to version 2.25.0, and after the update, I’m receiving the following error when I attempt to start MagicMirror:
magic@magic:~/MagicMirror $ npm start > magicmirror@2.25.0 start > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js [26.10.2023 22:33.08.627] [LOG] Starting MagicMirror: v2.25.0 [26.10.2023 22:33.08.632] [LOG] Loading config ... [26.10.2023 22:33.08.635] [DEBUG] config template file not exists, no envsubst [26.10.2023 22:33.08.639] [LOG] Loading module helpers ... [26.10.2023 22:33.08.641] [LOG] No helper found for module: alert. [26.10.2023 22:33.08.665] [LOG] Initializing new module helper ... [26.10.2023 22:33.08.665] [LOG] Module helper loaded: updatenotification [26.10.2023 22:33.08.666] [LOG] No helper found for module: clock. [26.10.2023 22:33.08.832] [LOG] Initializing new module helper ... [26.10.2023 22:33.08.833] [LOG] Module helper loaded: calendar [26.10.2023 22:33.08.850] [ERROR] (node:4586) UnhandledPromiseRejectionWarning: Error: Cannot find module 'fetch' Require stack: - /home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js - /home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js - /home/magic/MagicMirror/js/app.js - /home/magic/MagicMirror/js/electron.js - /home/magic/MagicMirror/node_modules/electron/dist/resources/default_app.asar/main.js - at node:internal/modules/cjs/loader:1084:15 at Function.<anonymous> (node:electron/js2c/browser_init:2:117576) at Module._resolveFilename (/home/magic/MagicMirror/node_modules/module-alias/index.js:49:29) at node:internal/modules/cjs/loader:929:27 at Function._load (node:electron/js2c/asar_bundle:2:13327) at Module.require (node:internal/modules/cjs/loader:1150:19) at require (node:internal/modules/cjs/helpers:110:18) at Object.<anonymous> (/home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js:11:15) at Module._compile (node:internal/modules/cjs/loader:1271:14) at Object..js (node:internal/modules/cjs/loader:1326:10) at Module.load (node:internal/modules/cjs/loader:1126:32) at node:internal/modules/cjs/loader:967:12 at Function._load (node:electron/js2c/asar_bundle:2:13327) at Module.require (node:internal/modules/cjs/loader:1150:19) at require (node:internal/modules/cjs/helpers:110:18) at Object.<anonymous> (/home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js:16:25) (Use `electron --trace-warnings ...` to show where the warning was created) [26.10.2023 22:33.08.851] [ERROR] (node:4586) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) [4624:1026/223309.952248:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.954689:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.956392:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.957469:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.958667:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.960686:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.963488:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.969142:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.970385:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.971544:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.973025:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.974008:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.975862:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [4624:1026/223309.977751:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2)
It appears that the error is related to the MMM-MyCalendar module
Can anyone guide me on how to fix the error and get my MagicMirror working correctly again?
-
@sdetweil
It works nowFor others it doesn’t work too then I copy this code into calendarutils.js
cd ~/MagicMirror/modules/MMM-MyCalendar
/* MagicMirror² * Node Helper: Calendar - CalendarFetcher * * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ const CalendarUtils = require("./calendarutils"); const Log = require("logger"); const NodeHelper = require("node_helper"); const ical = require("node-ical"); /*const fetch = require("fetch");*/ /*const digest = require("digest-fetch");*/ const https = require("https"); /** * * @param {string} url The url of the calendar to fetch * @param {number} reloadInterval Time in ms the calendar is fetched again * @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown. * @param {number} maximumEntries The maximum number of events fetched. * @param {number} maximumNumberOfDays The maximum number of days an event should be in the future. * @param {object} auth The object containing options for authentication against the calendar. * @param {boolean} includePastEvents If true events from the past maximumNumberOfDays will be fetched too * @param {boolean} selfSignedCert If true, the server certificate is not verified against the list of supplied CAs. * @class */ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents, selfSignedCert) { let reloadTimer = null; let events = []; let fetchFailedCallback = function () {}; let eventsReceivedCallback = function () {}; /** * Initiates calendar fetch. */ const fetchCalendar = () => { clearTimeout(reloadTimer); reloadTimer = null; const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]); /* let fetcher = null;*/ let httpsAgent = null; let headers = { "User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version }; if (selfSignedCert) { httpsAgent = new https.Agent({ rejectUnauthorized: false }); } if (auth) { if (auth.method === "bearer") { headers.Authorization = "Bearer " + auth.pass; /* } else if (auth.method === "digest") { fetcher = new digest(auth.user, auth.pass).fetch(url, { headers: headers, agent: httpsAgent });*/ } else { headers.Authorization = "Basic " + Buffer.from(auth.user + ":" + auth.pass).toString("base64"); } } /* if (fetcher === null) { fetcher = fetch(url, { headers: headers, agent: httpsAgent }); }*/ fetch(url, { headers: headers, agent: httpsAgent }) .then(NodeHelper.checkFetchStatus) .then((response) => response.text()) .then((responseData) => { let data = []; try { data = ical.parseICS(responseData); Log.debug("parsed data=" + JSON.stringify(data)); events = CalendarUtils.filterEvents(data, { excludedEvents, includePastEvents, maximumEntries, maximumNumberOfDays }); } catch (error) { fetchFailedCallback(this, error); scheduleTimer(); return; } this.broadcastEvents(); scheduleTimer(); }) .catch((error) => { fetchFailedCallback(this, error); scheduleTimer(); }); }; /** * Schedule the timer for the next update. */ const scheduleTimer = function () { clearTimeout(reloadTimer); reloadTimer = setTimeout(function () { fetchCalendar(); }, reloadInterval); }; /* public methods */ /** * Initiate fetchCalendar(); */ this.startFetch = function () { fetchCalendar(); }; /** * Broadcast the existing events. */ this.broadcastEvents = function () { Log.info("Calendar-Fetcher: Broadcasting " + events.length + " events."); eventsReceivedCallback(this); }; /** * Sets the on success callback * * @param {Function} callback The on success callback. */ this.onReceive = function (callback) { eventsReceivedCallback = callback; }; /** * Sets the on error callback * * @param {Function} callback The on error callback. */ this.onError = function (callback) { fetchFailedCallback = callback; }; /** * Returns the url of this fetcher. * * @returns {string} The url of this fetcher. */ this.url = function () { return url; }; /** * Returns current available events for this fetcher. * * @returns {object[]} The current available events for this fetcher. */ this.events = function () { return events; }; }; module.exports = CalendarFetcher;
-
@svoe88 for MyCalendar
always look to the module github first
see https://github.com/jclarke0000/MMM-MyCalendar/issues/40
config template file not exists, no envsubst
this is a new optional feature where you can have a file of properties
and apply them to the config.js, not having them hard coded -
“My mirror is up now, but the calendar is just stuck loading.”
magic@magic:~/MagicMirror $ npm start > magicmirror@2.25.0 start > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js [26.10.2023 23:03.29.952] [LOG] Starting MagicMirror: v2.25.0 [26.10.2023 23:03.29.957] [LOG] Loading config ... [26.10.2023 23:03.29.960] [DEBUG] config template file not exists, no envsubst [26.10.2023 23:03.29.965] [LOG] Loading module helpers ... [26.10.2023 23:03.29.967] [LOG] No helper found for module: alert. [26.10.2023 23:03.29.993] [LOG] Initializing new module helper ... [26.10.2023 23:03.29.993] [LOG] Module helper loaded: updatenotification [26.10.2023 23:03.29.994] [LOG] No helper found for module: clock. [26.10.2023 23:03.30.170] [LOG] Initializing new module helper ... [26.10.2023 23:03.30.171] [LOG] Module helper loaded: calendar [26.10.2023 23:03.30.184] [LOG] Initializing new module helper ... [26.10.2023 23:03.30.185] [LOG] Module helper loaded: MMM-MyCalendar [26.10.2023 23:03.30.185] [LOG] All module helpers loaded. [26.10.2023 23:03.30.197] [LOG] Starting server on port 8080 ... [26.10.2023 23:03.30.436] [LOG] Server started ... [26.10.2023 23:03.30.437] [LOG] Connecting socket for: updatenotification [26.10.2023 23:03.30.438] [LOG] Starting module helper: updatenotification [26.10.2023 23:03.30.439] [LOG] Connecting socket for: calendar [26.10.2023 23:03.30.439] [LOG] Starting node helper for: calendar [26.10.2023 23:03.30.440] [LOG] Connecting socket for: MMM-MyCalendar [26.10.2023 23:03.30.441] [LOG] Starting node helper for: MMM-MyCalendar [26.10.2023 23:03.30.441] [LOG] Sockets connected & modules started ... [26.10.2023 23:03.30.465] [LOG] Launching application. [8619:1026/230331.393892:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.394518:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.395120:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.395594:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396030:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396460:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396903:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.398914:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.399422:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.399961:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.401074:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.401555:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.402996:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.403694:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [26.10.2023 23:03.32.519] [LOG] Create new calendarfetcher for url: https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false - Interval: 3600000 [26.10.2023 23:03.32.622] [LOG] Create new calendarfetcher for url: https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false - Interval: 300000 [26.10.2023 23:03.32.623] [ERROR] Whoops! There was an uncaught exception... [26.10.2023 23:03.32.625] [ERROR] ReferenceError: fetcher is not defined at fetchCalendar (/home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js:62:3) at CalendarFetcher.startFetch (/home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js:107:3) at Class.createFetcher (/home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js:81:11) at Class.socketNotificationReceived (/home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js:29:9) at Socket.<anonymous> (/home/magic/MagicMirror/js/node_helper.js:104:11) at Socket.emit (node:events:513:28) at Socket.emitUntyped (/home/magic/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22) at /home/magic/MagicMirror/node_modules/socket.io/dist/socket.js:704:39 at process.processTicksAndRejections (node:internal/process/task_queues:77:11) [26.10.2023 23:03.32.625] [ERROR] MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection? [26.10.2023 23:03.32.626] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues [26.10.2023 23:03.32.627] [INFO] Checking git for module: MMM-MyCalendar [26.10.2023 23:03.32.654] [INFO] Checking git for module: MagicMirror [26.10.2023 23:03.32.919] [INFO] Calendar-Fetcher: Broadcasting 77 events from https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false. [8619:1026/230338.077679:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times! [8619:1026/230342.063208:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 2 times! [8619:1026/230344.071380:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 3 times!
{ module: "MMM-MyCalendar", position: "top_left", // This can be any of the regions. Best results in left or right regions. config: { colored: true, calendars: [ { url: ".........", color: "#ffb350" }, ], } },
But I’m still new to getting it all up and running
-
@sdetweil
My mirror is up now, but the calendar is just stuck loadingmagic@magic:~/MagicMirror $ npm start > magicmirror@2.25.0 start > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js [26.10.2023 23:03.29.952] [LOG] Starting MagicMirror: v2.25.0 [26.10.2023 23:03.29.957] [LOG] Loading config ... [26.10.2023 23:03.29.960] [DEBUG] config template file not exists, no envsubst [26.10.2023 23:03.29.965] [LOG] Loading module helpers ... [26.10.2023 23:03.29.967] [LOG] No helper found for module: alert. [26.10.2023 23:03.29.993] [LOG] Initializing new module helper ... [26.10.2023 23:03.29.993] [LOG] Module helper loaded: updatenotification [26.10.2023 23:03.29.994] [LOG] No helper found for module: clock. [26.10.2023 23:03.30.170] [LOG] Initializing new module helper ... [26.10.2023 23:03.30.171] [LOG] Module helper loaded: calendar [26.10.2023 23:03.30.184] [LOG] Initializing new module helper ... [26.10.2023 23:03.30.185] [LOG] Module helper loaded: MMM-MyCalendar [26.10.2023 23:03.30.185] [LOG] All module helpers loaded. [26.10.2023 23:03.30.197] [LOG] Starting server on port 8080 ... [26.10.2023 23:03.30.436] [LOG] Server started ... [26.10.2023 23:03.30.437] [LOG] Connecting socket for: updatenotification [26.10.2023 23:03.30.438] [LOG] Starting module helper: updatenotification [26.10.2023 23:03.30.439] [LOG] Connecting socket for: calendar [26.10.2023 23:03.30.439] [LOG] Starting node helper for: calendar [26.10.2023 23:03.30.440] [LOG] Connecting socket for: MMM-MyCalendar [26.10.2023 23:03.30.441] [LOG] Starting node helper for: MMM-MyCalendar [26.10.2023 23:03.30.441] [LOG] Sockets connected & modules started ... [26.10.2023 23:03.30.465] [LOG] Launching application. [8619:1026/230331.393892:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.394518:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.395120:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.395594:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396030:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396460:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.396903:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.398914:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.399422:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.399961:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.401074:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.401555:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.402996:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [8619:1026/230331.403694:ERROR:gbm_wrapper.cc(253)] Failed to export buffer to dma_buf: No such file or directory (2) [26.10.2023 23:03.32.519] [LOG] Create new calendarfetcher for url: https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false - Interval: 3600000 [26.10.2023 23:03.32.622] [LOG] Create new calendarfetcher for url: https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false - Interval: 300000 [26.10.2023 23:03.32.623] [ERROR] Whoops! There was an uncaught exception... [26.10.2023 23:03.32.625] [ERROR] ReferenceError: fetcher is not defined at fetchCalendar (/home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js:62:3) at CalendarFetcher.startFetch (/home/magic/MagicMirror/modules/MMM-MyCalendar/calendarfetcher.js:107:3) at Class.createFetcher (/home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js:81:11) at Class.socketNotificationReceived (/home/magic/MagicMirror/modules/MMM-MyCalendar/node_helper.js:29:9) at Socket.<anonymous> (/home/magic/MagicMirror/js/node_helper.js:104:11) at Socket.emit (node:events:513:28) at Socket.emitUntyped (/home/magic/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22) at /home/magic/MagicMirror/node_modules/socket.io/dist/socket.js:704:39 at process.processTicksAndRejections (node:internal/process/task_queues:77:11) [26.10.2023 23:03.32.625] [ERROR] MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection? [26.10.2023 23:03.32.626] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues [26.10.2023 23:03.32.627] [INFO] Checking git for module: MMM-MyCalendar [26.10.2023 23:03.32.654] [INFO] Checking git for module: MagicMirror [26.10.2023 23:03.32.919] [INFO] Calendar-Fetcher: Broadcasting 77 events from https://mitstudie.au.dk/calendar?icalkey=65872d73a3fdacbf72ef30a86e962830&lang=da&getLmsEvents=false. [8619:1026/230338.077679:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times! [8619:1026/230342.063208:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 2 times! [8619:1026/230344.071380:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 3 times!
But I’m still new to getting it all up and running
-
@svoe88 said in config template file not exists:
ReferenceError: fetcher is not defined
at fetchCalendar (/home/magic/MagicMirror/modules/MMM-MyCalendar/didn’t do the patch right
-
title of this thread has nothing to do with the problem
-
@karsten13 I fixed the title
-
@sdetweil
How do I get it done? -
@svoe88 you missed one of the changes in the workaround. the author needs to fix their module.
-
@sdetweil
It works nowFor others it doesn’t work too then I copy this code into calendarutils.js
cd ~/MagicMirror/modules/MMM-MyCalendar
/* MagicMirror² * Node Helper: Calendar - CalendarFetcher * * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ const CalendarUtils = require("./calendarutils"); const Log = require("logger"); const NodeHelper = require("node_helper"); const ical = require("node-ical"); /*const fetch = require("fetch");*/ /*const digest = require("digest-fetch");*/ const https = require("https"); /** * * @param {string} url The url of the calendar to fetch * @param {number} reloadInterval Time in ms the calendar is fetched again * @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown. * @param {number} maximumEntries The maximum number of events fetched. * @param {number} maximumNumberOfDays The maximum number of days an event should be in the future. * @param {object} auth The object containing options for authentication against the calendar. * @param {boolean} includePastEvents If true events from the past maximumNumberOfDays will be fetched too * @param {boolean} selfSignedCert If true, the server certificate is not verified against the list of supplied CAs. * @class */ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents, selfSignedCert) { let reloadTimer = null; let events = []; let fetchFailedCallback = function () {}; let eventsReceivedCallback = function () {}; /** * Initiates calendar fetch. */ const fetchCalendar = () => { clearTimeout(reloadTimer); reloadTimer = null; const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]); /* let fetcher = null;*/ let httpsAgent = null; let headers = { "User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version }; if (selfSignedCert) { httpsAgent = new https.Agent({ rejectUnauthorized: false }); } if (auth) { if (auth.method === "bearer") { headers.Authorization = "Bearer " + auth.pass; /* } else if (auth.method === "digest") { fetcher = new digest(auth.user, auth.pass).fetch(url, { headers: headers, agent: httpsAgent });*/ } else { headers.Authorization = "Basic " + Buffer.from(auth.user + ":" + auth.pass).toString("base64"); } } /* if (fetcher === null) { fetcher = fetch(url, { headers: headers, agent: httpsAgent }); }*/ fetch(url, { headers: headers, agent: httpsAgent }) .then(NodeHelper.checkFetchStatus) .then((response) => response.text()) .then((responseData) => { let data = []; try { data = ical.parseICS(responseData); Log.debug("parsed data=" + JSON.stringify(data)); events = CalendarUtils.filterEvents(data, { excludedEvents, includePastEvents, maximumEntries, maximumNumberOfDays }); } catch (error) { fetchFailedCallback(this, error); scheduleTimer(); return; } this.broadcastEvents(); scheduleTimer(); }) .catch((error) => { fetchFailedCallback(this, error); scheduleTimer(); }); }; /** * Schedule the timer for the next update. */ const scheduleTimer = function () { clearTimeout(reloadTimer); reloadTimer = setTimeout(function () { fetchCalendar(); }, reloadInterval); }; /* public methods */ /** * Initiate fetchCalendar(); */ this.startFetch = function () { fetchCalendar(); }; /** * Broadcast the existing events. */ this.broadcastEvents = function () { Log.info("Calendar-Fetcher: Broadcasting " + events.length + " events."); eventsReceivedCallback(this); }; /** * Sets the on success callback * * @param {Function} callback The on success callback. */ this.onReceive = function (callback) { eventsReceivedCallback = callback; }; /** * Sets the on error callback * * @param {Function} callback The on error callback. */ this.onError = function (callback) { fetchFailedCallback = callback; }; /** * Returns the url of this fetcher. * * @returns {string} The url of this fetcher. */ this.url = function () { return url; }; /** * Returns current available events for this fetcher. * * @returns {object[]} The current available events for this fetcher. */ this.events = function () { return events; }; }; module.exports = CalendarFetcher;