There’s a part of the collaboration guide that doesn’t look quitre right to me.
The code example is given here:
Client Setup for Collaborating with PDF.js Express | Documentation
annotManager.on('annotationChanged', (annotations, type, { imported }) => {
if (imported) {
return;
}
annotations.forEach(annotation => {
annotManager.exportAnnotCommand().then(xfdf =>{
if (type === 'add') {
let parentAuthorId = null;
if (annotation.InReplyTo) {
parentAuthorId = annotManager.getAnnotationById(annotation.InReplyTo).authorId || 'default';
}
...
The code above listens for the annotationChanged event and receives a list of changed annotations. It iterates through them and calls exportAnnotCommand() on each one. I thought that exportAnnotCommand() just returns a command for all changes since the last time it was called. The annotations returned are not directly related to the annotation in the current iteration.
Also, the annotationChangedEvent seems to group changes by change ‘type’ (add, modify, delete). Whereas exportAnnotCommand could in theory produce a mixed bag of changes in the xfdf command.
In fact, it looks like the exportAnnotCommand() is not synchronised with the annotationChanged event. It’s difficult to reproduce, but I think I’ve seen the annotationChanged event fire before exportAnnotCommand is able to return any changes. I.e I’ve called exportAnnotCommand in the event handler and it doesn’t return any changes in the xfdf command, but a subsequent call does. I’ve noticed it in the logs, but haven’t been able to reproduce it, so I caould be mistaken about this.