Try the fastest and simplest way to install ONLYOFFICE

callbackURL integration confusion.

Integration questions/issues

callbackURL integration confusion.

Postby devgs » Mon Aug 22, 2016 7:57 am

I have read every page of the docs from top to bottom, some of them even a few times. Still I can't figure out why I am getting this error message:

"The file version has been changed. The page will be reloaded."

I am trying to integrate our document storage service. As a test case I have set up callbackURL endpoint to simply dump all input to log file and always respond with '{ "error" : 0 }'. The problem occurs after I edit the file, close page and wait for callbackURL to be called with "status":2. Then I open same page again and that error message is prompted. I suspect that I need to modify the
config
object somehow, after document was edited, to address the new version. But how to do that? Which property should be added to open the edited file without an error?

Here's my minimal test page:

Code: Select all
<html>
<div id="placeholder"></div>
<script type="text/javascript" src="http://example.com/web-apps/apps/api/documents/api.js"></script>

<script type="text/javascript">

new DocsAPI.DocEditor("placeholder", {
    "documentType": "text",
    "document": {
        "fileType": "docx",
        "key": "Khirz6zTPdfd79",
        "title": "Example Document Title.docx",
        "url": "http://example.com/demo.docx",
        "permissions": {
            "download": true,
            "edit": true,
            "print": true,
            "review": true,
        },
    },
    "editorConfig": {
        "callbackUrl": "http://example.com/only_office_callback",
      "mode": "edit",
      "user": {
            "firstname": "John",
            "id": "78e1e841",
            "lastname": "Smith",
        },
    },
});
</script>

</html>
devgs
 
Posts: 3
Joined: Fri Aug 19, 2016 11:09 am

Re: callbackURL integration confusion.

Postby Eugenie » Tue Aug 23, 2016 12:37 pm

Please note that every time the document is edited and saved, the key must be generated anew.
http://api.onlyoffice.com/editors/config/document#key
Eugenie
 
Posts: 134
Joined: Mon Aug 25, 2014 10:11 am

Re: callbackURL integration confusion.

Postby devgs » Tue Aug 23, 2016 2:55 pm

So, correct me if I'm wrong here. After each save, every new instance of Only Office application should be initialised with different key.

What about a scenario, wen client_1 edits the file, 10 seconds later callbackURL is invoked to save changes (as documented here http://api.onlyoffice.com/editors/callback), and then client_2 wants to join co-editing. What key should be specified, The old one or the new one? I suppose it's not the new one, since client 1 knows nothing about the new key but it still has a capabilities to continue editing the file. It is not in the design of callbackURL to report back new key value.

Probably key is updated after the last collaborator disconnects from co-editing? It's not clear from the documentation.

Also in this model there seems to be a window for a race condition. Right after the config object was initialised with key, but prior to initialisation of Only Office application, that document could be saved by someone else and that key becomes outdated. How can we prevent this condition?
devgs
 
Posts: 3
Joined: Fri Aug 19, 2016 11:09 am

Re: callbackURL integration confusion.

Postby Eugenie » Mon Aug 29, 2016 3:37 pm

Actually the document is saved after it is closed by all users. You need to change the key after you recieve the event that the document is saved.
Eugenie
 
Posts: 134
Joined: Mon Aug 25, 2014 10:11 am

Re: callbackURL integration confusion.

Postby devgs » Tue Aug 30, 2016 10:10 am

Oh, I see, thank you! Somehow I misinterpreted the wording and thought it is auto-saved every 10 seconds.

But what about described race condition? How can it be avoided? It is very likely that some user can retrieve key from server at there same moment when callback is being executed with status 2(3), effectively making that key outdated.
devgs
 
Posts: 3
Joined: Fri Aug 19, 2016 11:09 am

Re: callbackURL integration confusion.

Postby Eugenie » Tue Sep 06, 2016 9:06 am

Hello,

The server gives an old key while callback saves the changes. After the changes are saved the message "The file version has been changed. The page will be reloaded." will appear in Editors.
After the page is re-loaded the server gives you a new key. The page re-fresh solved the issue.
Eugenie
 
Posts: 134
Joined: Mon Aug 25, 2014 10:11 am


Return to API

Who is online

Users browsing this forum: No registered users and 1 guest