Try the fastest and simplest way to install ONLYOFFICE

Plugin works locally, not on production server

Integration questions/issues

Plugin works locally, not on production server

Postby robertotomas » Wed Oct 04, 2017 7:20 pm

I've written here for support in writing a plugin that allows rich user interface elements from outside the docEditor to inject text into a document in the browser.

Thanks in no small measure to Maxim, I have a local server running and today, I have a working prototype.

However, when I try to install the same plugin on our server, it does not show up. Can't figure out why.

My plugin's source is:
Code: Select all
(function (window, undefined) {
    window.Asc.plugin.init = function () {
      
      function script () {
         try {
             console.log(`adding Tag "${window.Asc.addTag}"`);
             var oTagDocument = Api.GetDocument();
             oTagDocument.CreateNewHistoryPoint();
             oParagraph = Api.CreateParagraph();
             oParagraph.AddText(window.Asc.addTag);
             oTagDocument.InsertContent([oParagraph]);            
         } catch (e) {
            console.error(e)
         }
      }
      
      const sScript = script.toString()
         .replace(/^\s*function\s+script\s*\(\)\s*\{\s+/m, '')
         .replace(/\s*\}\s*$/m,'')
      
      console.log(sScript)

        window.Asc.plugin.info.recalculate = true;
        this.executeCommand("close", sScript);      
    };

    window.Asc.plugin.button = function (id) {
    };
   
})(window, undefined);


For this to work, I have to be able to trigger changes to the iframe window. This is done with an event listener, added to web-apps/apps/documenteditor/main/app.js:
Code: Select all
        window.addEventListener("message", receiveMessage, {captive: true, passive: true})
        function receiveMessage (event) {
console.log(window.Asc, event)
                let o
                try {
                        o = JSON.parse(event.data)
                } catch (e) {
                        console.warn(e)
                        o = {}
                }
                o.raw = event.data

                if(o.type !== 'addTag')
                        return

                o.tag? window.Asc.addTag = o.tag: triggerAddTag()
        }

        function triggerAddTag () { // assumes only 1 plugin is installed
                $('.item-plugins').click()
        }


With that, the local docker-version of documentServer serves up a page that can receive postMessages that set the variable and add it to the document via triggering a button press on the plugin, like this via the console:

Code: Select all
document.querySelector('iframe').contentWindow.postMessage(JSON.stringify({type: 'addTag', tag: 'hi mom!'}), '*')
document.querySelector('iframe').contentWindow.postMessage(JSON.stringify({type: 'addTag'}), '*')


It works, just that easy.

We realize that we will have to publish the code changes snce we are changing app.js .. but we're just fine with that.

However, on the server, documentServer is not running via docker, it is a direct installation (with /var/www/onlyoffice being the install path).

Under /var/www/onlyoffice/documentserver there was no `sdkjs-plugins` directory for some reason, so I created it. I put my plugin and the pluginsbase file in there:
Code: Select all
ubuntu@wbf:~$ ls -la /var/www/onlyoffice/documentserver/sdkjs-plugins/
total 40
drwxr-xr-x 3 onlyoffice onlyoffice  4096 Oct  4 17:15 .
drwxr-xr-x 6 onlyoffice onlyoffice  4096 Sep  7 00:21 ..
drwxr-xr-x 2 onlyoffice onlyoffice  4096 Oct  4 17:07 addTag
-rw-r--r-- 1 onlyoffice onlyoffice 27532 Oct  4 17:07 pluginBase.js
ubuntu@wbf:~$ ls -la /var/www/onlyoffice/documentserver/sdkjs-plugins/addTag/
total 56
drwxr-xr-x 2 onlyoffice onlyoffice  4096 Oct  4 17:07 .
drwxr-xr-x 3 onlyoffice onlyoffice  4096 Oct  4 17:15 ..
-rw-r--r-- 1 onlyoffice onlyoffice   785 Oct  4 17:07 code.js
-rw-r--r-- 1 onlyoffice onlyoffice   714 Oct  4 17:07 config.json
-rw-r--r-- 1 onlyoffice onlyoffice  2754 Oct  4 17:07 icon@2x.png
-rw-r--r-- 1 onlyoffice onlyoffice  2754 Oct  4 17:07 icon.png
-rw-r--r-- 1 onlyoffice onlyoffice   246 Oct  4 17:07 index.html


I also put my modified app.js:
Code: Select all
ubuntu@wbf:~$ find /var/www/onlyoffice -name app.js -ls
//...
   872242   1436 -rw-r--r--   1 onlyoffice onlyoffice  1468815 Oct  4 17:09 /var/www/onlyoffice/documentserver/web-apps/apps/documenteditor/main/app.js
//...


And that is clearly working because I see the console.log messages. But the plugin never appears in the docEditor window.

So, looking at the configurations:
Code: Select all
ubuntu@wbf:~$ ls -la  /etc/onlyoffice/documentserver
total 36
drwxr-xr-x 3 root root 4096 Oct  4 17:22 .
drwxr-xr-x 3 root root 4096 Aug  7 13:19 ..
-rw-r--r-- 1 root root 4288 Aug 26 20:10 default.json
-rw-r--r-- 1 root root 1121 Aug  7 13:19 development-mac.json
-rw-r--r-- 1 root root 1143 Aug  7 13:19 development-windows.json
drwxr-xr-x 2 root root 4096 Aug  7 13:19 log4js
-rw-r--r-- 1 root root 1501 Aug  7 13:19 production-linux.json
-rw-r--r-- 1 root root 1167 Aug  7 13:19 production-windows.json


I'm told that production-linux.json is probably the right one. It says:
Code: Select all
  "services": {
    "CoAuthoring": {
      "server": {
        "sockjsUrl": "/web-apps/vendor/sockjs/sockjs.min.js",
        "static_content": {
          "/sdkjs": {
            "path": "/var/www/onlyoffice/documentserver/sdkjs",
            "options": {"maxAge": "7d"}
          },
          "/web-apps": {
            "path": "/var/www/onlyoffice/documentserver/web-apps",
            "options": {"maxAge": "7d"}
          },
          "/welcome": {
            "path": "/var/www/onlyoffice/documentserver/server/welcome",
            "options": {"maxAge": "7d"}
          },
          "/sdkjs-plugins": {


I am seeing a different story in default.json:
Code: Select all
        "services": {
                "CoAuthoring": {
                        "server": {
                                "port": 8000,
                                "workerpercpu": 1,
//...going on
                        },
                        "token": {
                                "enable": {
                                        "browser": false,
                                        "request": {
                                                "inbox": false,
                                                "outbox": false
                                        }
                                },
                                "inbox": {
                                        "header": "Authorization",
                                        "prefix": "Bearer "
                                },
                                "outbox": {
                                        "header": "Authorization",
//... encryption configuration removed for this post
                                },
                                "session": {
//...
                                }
                        },
                        "plugins": {
                                "uri": "/sdkjs-plugins"
                        }


Anyway, you can see that the only place 'plugins' appears in these two files is very different. That the plugins folder did not exist is another issue. Why would the install be this way? How do I fix it so I can see my plugin?
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Re: Plugin works locally, not on production server

Postby Maxim » Thu Oct 05, 2017 7:18 am

Hello robertotomas!
1.
a plugin that allows rich user interface elements from outside the docEditor to inject text into a document in the browser

We have such plugin, you can use it.
2. Your plugin code is correct.
3. You shouldn't change source code
Maxim
 
Posts: 1077
Joined: Tue Oct 11, 2016 2:34 pm

Re: Plugin works locally, not on production server

Postby robertotomas » Thu Oct 05, 2017 5:46 pm

@Maxim that's water under the bridge at this point.

The problem we are having appears to be that the server builds and returns a plugin.json that looks like this:

Code: Select all
{"url":"","pluginsData":["https, https://dev.ourapp.com, dev.ourapp.com/sdkjs-plugins/addTag/config.json"]}


(the domain name is modified here since it is a work dev server)

from which the request for config.json is built:

https://dev.ourapp.com/web-apps/apps/do ... onfig.json

which is not found.

This happens whether or not I specify plugins in the docEditor config on the webpage as http://dev.ourapp.com/sdkjs-plugins/addTag/config.json
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Re: Plugin works locally, not on production server

Postby Maxim » Fri Oct 06, 2017 10:09 am

Hello robertotomas!
There is one moment that is very strange
...there was no `sdkjs-plugins` directory for some reason, so I created it.

It should not be. There must be such folder. Specify how you installed Onlyoffce Document Server for Docker.
Try to reinstall Onlyoffice Document Server
Maxim
 
Posts: 1077
Joined: Tue Oct 11, 2016 2:34 pm

Re: Plugin works locally, not on production server

Postby robertotomas » Fri Oct 06, 2017 9:07 pm

we did the reinstall. And this time ti did show up. However, the plugins don't load. And once we got the plugins folder ot look right (with my plugin only in there), we are definitely back to where we were before.

It seems that the moment we call it through an https proxy (nginx) we get that strange plugins.json return:
Code: Select all
{"url":"","pluginsData":["https, https://dev.ourapp.com, dev.ourapp.com/sdkjs-plugins/addTag/config.json"]}

We've tried compiling, from ubuntu repository install, and docker.

Running it from the docker without https, I load my plugin without issue.
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Re: Plugin works locally, not on production server

Postby Maxim » Mon Oct 09, 2017 6:34 am

Hello robertotomas!
1. After reinstall did you find `sdkjs-plugins` directory?
2.
Running it from the docker without https, I load my plugin without issue.
Do you use self signed certs?
Maxim
 
Posts: 1077
Joined: Tue Oct 11, 2016 2:34 pm

Re: Plugin works locally, not on production server

Postby robertotomas » Mon Oct 09, 2017 5:08 pm

We do not use self signed certs. The client browsers do not complain.
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm


Return to API

Who is online

Users browsing this forum: No registered users and 1 guest