Hi! I’m working on realizing caldav support with meteor (especially from nextcloud).
I have tried a lot of packages, however the best results so far i get with:
- https://github.com/lambdabaa/dav/ (for dav)
- https://github.com/jens-maus/node-ical (for ical parsing)
Therefore i created a related method:
export const getCalendars = new ValidatedMethod({
name: 'caldav.getcalendars',
validate: new SimpleSchema({
name: { type: String },
}).validator(),
run(values: any) {
if (Meteor.isServer) {
console.log("getcalendars server");
var xhr = new dav.transport.Basic(
new dav.Credentials({
username: 'demo',
password: 'mtiof-ghds-d6PNj-CELed-C3wB4'
})
);
dav.createAccount({ server: 'https://192.168.112.12/remote.php/dav/', xhr: xhr })
.then(function (account) {
// account instanceof dav.Account
account.calendars.forEach(function (calendar) {
console.log('Found calendar named ' + calendar.displayName);
// console.log(calendar.data)
// const data = ical.parseICS(calendar.data);
// console.log(data);
});
let calendar = account.calendars[0];
const result: any = [];
dav.syncCalendar(calendar, { syncMethod: 'basic', xhr: xhr }).then((resolve) => {
// console.log(resolve);
resolve.objects.forEach(element => {
const directEvents = ical.sync.parseICS(element.calendarData);
// console.log("Ids",Object.keys(directEvents));
for (const event of Object.values(directEvents)) {
console.log("event", event.summary, moment(new Date(event.start)).format("DD.MM.YYYY HH:mm"));
result.push(event);
}
});
return result;
});
});
}
}
});
The call looks like this:
getCalendars.call({name:"Test"},(err,res) => {
if (err) {
console.log("Error",err);
} else {
console.log("res",res);
}
})
The reason why I put the method in “Meteor.isSever” is, that the client is not able to process it, with error
…has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
With this construct, i can call the method. However, as the dav.syncCalendar works asyc, i immediately get the result “undefined” from the getCalendars method. The server console output shows the related events after some time. But I cannot bring them into the client. Any recommendations?