Skip to content

Commit

Permalink
Merge pull request #2036 from DarthBrento/develop
Browse files Browse the repository at this point in the history
Fix #1109 - multiple calendar instances with different config
  • Loading branch information
MichMich authored Jun 2, 2020
2 parents aac6757 + 4d21f8d commit 3b32605
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _This release is scheduled to be released on 2020-07-01._

- The broken modules due to Socket.io change from last release [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
- Add backward compatibility for old module code in socketclient.js [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
- Support multiple instances of calendar module with different config [#1109](https://github.com/MichMich/MagicMirror/issues/1109)
- Fix the use of "maxNumberOfDays" in the module "weatherforecast" [#2018](https://github.com/MichMich/MagicMirror/issues/2018)

## [2.11.0] - 2020-04-01
Expand Down
5 changes: 5 additions & 0 deletions modules/default/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ Module.register("calendar", {

// Override socket notification handler.
socketNotificationReceived: function (notification, payload) {
if (this.identifier !== payload.id) {
return;
}

if (notification === "CALENDAR_EVENTS") {
if (this.hasCalendarURL(payload.url)) {
this.calendarData[payload.url] = payload.events;
Expand Down Expand Up @@ -541,6 +545,7 @@ Module.register("calendar", {
*/
addCalendar: function (url, auth, calendarConfig) {
this.sendSocketNotification("ADD_CALENDAR", {
id: this.identifier,
url: url,
excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents,
maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries,
Expand Down
14 changes: 8 additions & 6 deletions modules/default/calendar/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
if (notification === "ADD_CALENDAR") {
//console.log('ADD_CALENDAR: ');
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents);
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id);
}
},

Expand All @@ -35,16 +35,16 @@ module.exports = NodeHelper.create({
* attribute reloadInterval number - Reload interval in milliseconds.
*/

createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents) {
createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) {
var self = this;

if (!validUrl.isUri(url)) {
self.sendSocketNotification("INCORRECT_URL", { url: url });
self.sendSocketNotification("INCORRECT_URL", { id: identifier, url: url });
return;
}

var fetcher;
if (typeof self.fetchers[url] === "undefined") {
if (typeof self.fetchers[identifier + url] === "undefined") {
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);

Expand All @@ -53,6 +53,7 @@ module.exports = NodeHelper.create({
//console.log(fetcher.events());

self.sendSocketNotification("CALENDAR_EVENTS", {
id: identifier,
url: fetcher.url(),
events: fetcher.events()
});
Expand All @@ -61,15 +62,16 @@ module.exports = NodeHelper.create({
fetcher.onError(function (fetcher, error) {
console.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error);
self.sendSocketNotification("FETCH_ERROR", {
id: identifier,
url: fetcher.url(),
error: error
});
});

self.fetchers[url] = fetcher;
self.fetchers[identifier + url] = fetcher;
} else {
//console.log('Use existing news fetcher for url: ' + url);
fetcher = self.fetchers[url];
fetcher = self.fetchers[identifier + url];
fetcher.broadcastEvents();
}

Expand Down

0 comments on commit 3b32605

Please sign in to comment.