Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation: how to run #36

Closed
schaumannj opened this issue Oct 31, 2018 · 3 comments
Closed

documentation: how to run #36

schaumannj opened this issue Oct 31, 2018 · 3 comments

Comments

@schaumannj
Copy link

schaumannj commented Oct 31, 2018

Hi All,
do you have any documentation how to run or how to integrate with already existing node application?
I thought that I will run

# set up and build for production
make

# install dependencies
make dev-setup

# build for dev and watch changes
make watch-js

then open the web browser on localhost:3000 and will see some client but nothing happens.
Thank you for advice
Jan

@georgehrke
Copy link
Member

georgehrke commented Nov 1, 2018

do you have any documentation how to run or how to integrate with already existing node application?

As far as i can tell this library does not run on pure node.js. I tried to write our Tests in jest first, but I ended up using karma, because we require certain browser APIs like DomParser and XMLSerializer, latter one having no decent polyfill on NPM.

then open the web browser on localhost:3000 and will see some client but nothing happens.

It seems like you are looking for some GUI? This is simply a library to access Nextcloud's CalDAV/CardDAV server, used by the Contacts app (and future versions of the Calendar / Tasks app).

Please take note that this library is meant to communicate with Nextcloud's CalDAV/CardDAV server. While it's simply CalDAV/CardDAV and should in theory work with other servers, we didn't test this against any other server than Nextcloud and don't accept issues for other servers. Pull-requests that fix compatibility with other servers are certainly welcome though :)

Edit: To answer your main question about docs: You can run npm run build-doc to automatically generate documentation (as in API-reference) from source-code.

@schaumannj
Copy link
Author

Hi George,
thanks fr answer, to be honest I seeking some first step for communication with nextcloud calendar via CalDAV. Just read/write/update the events for particular user.
I will go through yours test cases if there some for work with calendar.
any hint are welcomed
Best regards
Jan

@georgehrke
Copy link
Member

Ah, in that case:

  1. First you need to create the DavClient object.
    If you are running as a nextcloud app, you gotta hand over the requestToken
function xhrProvider() {
	var headers = {
		'X-Requested-With': 'XMLHttpRequest',
		'requesttoken': OC.requestToken
	}
	var xhr = new XMLHttpRequest()
	var oldOpen = xhr.open

	// override open() method to add headers
	xhr.open = function() {
		var result = oldOpen.apply(this, arguments)
		for (let name in headers) {
			xhr.setRequestHeader(name, headers[name])
		}
		return result
	}
	OC.registerXHRForErrorProcessing(xhr)
	return xhr
}

new DavClient({
	rootUrl: OC.linkToRemote('dav')
}, xhrProvider)

If you don't run inside Nextcloud, you gotta do the authentication yourself.

  1. Start the client
await client.connect({enableCalDAV: true});
const calendars = await client.calendarHomes[0].findAllCalDAVCollections()
const events = await calendars[0].findAllVObjects()
console.log(events[0].data);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants